Skip to content

Commit

Permalink
fix: remove broken tasks
Browse files Browse the repository at this point in the history
Signed-off-by: Mike Murray <[email protected]>
  • Loading branch information
mikemurray committed Feb 26, 2020
1 parent 64cab61 commit 69fe363
Showing 1 changed file with 0 additions and 40 deletions.
40 changes: 0 additions & 40 deletions package/scripts/postbuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@

const path = require("path");
const fse = require("fs-extra");
const replaceInFiles = require("replace-in-files");

const DIST_FOLDER = path.join(process.cwd(), "dist");
const DIST_MODULES_FOLDER = path.join(process.cwd(), "dist-modules-temp");
const COMPONENTS_FOLDER = path.join(DIST_FOLDER, "components");

/**
* @summary Recursively changes all files with one extension to another
Expand Down Expand Up @@ -64,26 +62,6 @@ async function createPackageFile() {
return newPackageData;
}

/**
* @summary After a component has been moved to `dist` and flattened,
* change all "../../../utils" to "../../utils"
* @param {String} componentFolderPath The full path to the components folder
* @returns {Promise<undefined>} Nothing
*/
async function replaceUtilsPathForComponent(componentFolderPath) {
await replaceInFiles({
files: `${componentFolderPath}/**/*.js`,
from: /\.\.\/\.\.\/utils/g,
to: "../utils"
});

await replaceInFiles({
files: `${componentFolderPath}/**/*.mjs`,
from: /\.\.\/\.\.\/utils/g,
to: "../utils"
});
}

/**
* @summary The main post-build script.
* 1. Rename all `.js` files in `dist-modules-temp` to `.mjs` extension
Expand All @@ -105,24 +83,6 @@ async function run() {
// Delete `dist-modules-temp`
await fse.remove(DIST_MODULES_FOLDER);

// We now have a `dist` folder but we want to remove the extra `components`
// folder inside it in order to have flatter import paths. We"ll traverse the `dist/components/*`
// folders here and move them up a level.
const directoryContents = await fse.readdir(COMPONENTS_FOLDER);
const promises = directoryContents.map(async (componentName) => {
if (componentName.indexOf(".") !== -1) return Promise.resolve();
const componentFolder = path.join(COMPONENTS_FOLDER, componentName);
const distComponentFolder = path.join(DIST_FOLDER, componentName);
await fse.copy(componentFolder, distComponentFolder);

// The relative path to global `utils` folder has changed, so do a multi-file search/replace
return replaceUtilsPathForComponent(distComponentFolder);
});
await Promise.all(promises);

// Then delete `dist/components`
await fse.remove(COMPONENTS_FOLDER);

// Then copy the package.json file into the `dist` folder so that we can do `npm publish dist`
// and thereby remove the `dist` from the import paths, flattening them more.
await createPackageFile();
Expand Down

0 comments on commit 69fe363

Please sign in to comment.