From 83312d68d7106ab6ef5afc1622152aa5dbe2efee Mon Sep 17 00:00:00 2001 From: Jonathan Greenemeier Date: Thu, 16 Sep 2021 21:08:36 -0600 Subject: [PATCH] fix: add additional targets to postpackage rewrite script --- scripts/postpackage.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/scripts/postpackage.js b/scripts/postpackage.js index 30cfc6a..7f10c48 100644 --- a/scripts/postpackage.js +++ b/scripts/postpackage.js @@ -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 }); @@ -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'`); @@ -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());