Skip to content

Commit

Permalink
fix: add additional targets to postpackage rewrite script
Browse files Browse the repository at this point in the history
  • Loading branch information
6eDesign committed Sep 17, 2021
1 parent e19de04 commit 83312d6
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions scripts/postpackage.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ import { promises as fs } from 'fs';
import path from 'path';

const PACKAGE_FOLDER = process.env.PACKAGE_FOLDER || 'package';
const TARGETS = ['components', 'config', 'src', 'stores'];
const BASE_DIR = path.join(process.cwd(), PACKAGE_FOLDER);
const CWD = process.cwd();

const getFolder = async (folder, depth = 0) => {
const contents = await fs.readdir(path.join(process.cwd(), PACKAGE_FOLDER, folder), {
const contents = await fs.readdir(path.join(CWD, folder), {
withFileTypes: true
});

Expand All @@ -24,7 +23,7 @@ const getFolder = async (folder, depth = 0) => {
const transformFolder = async ({ folders, files, depth }) => {
await Promise.all(
files.map(async (f) => {
const filepath = path.join(BASE_DIR, f);
const filepath = path.join(CWD, f);
const contents = await fs.readFile(filepath, 'utf-8');
const base = depth ? [...Array(depth + 1).fill('..')].join('/') : './';
const updated = contents.replace(/from '\$lib(.*)'/g, `from '${base}$1'`);
Expand All @@ -38,4 +37,7 @@ const transformFolder = async ({ folders, files, depth }) => {
);
};

Promise.all(TARGETS.map((t) => getFolder(t).then(transformFolder)));
getFolder(PACKAGE_FOLDER)
.then(transformFolder)
.catch(console.error)
.finally(() => process.exit());

0 comments on commit 83312d6

Please sign in to comment.