Skip to content

Instantly share code, notes, and snippets.

@nathansmith
Last active August 9, 2020 10:51
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nathansmith/76f1d39f91ffe1d3fc01d5950731b15d to your computer and use it in GitHub Desktop.
Save nathansmith/76f1d39f91ffe1d3fc01d5950731b15d to your computer and use it in GitHub Desktop.
Script to move NPM files from "dist" to package root
const { existsSync } = require('fs');
const { execSync } = require('child_process');
// ================
// Check existence.
// ================
const distFolderExists = existsSync('dist');
const srcFolderExists = existsSync('src');
// =============
// CLI commands.
// =============
const commandCopy = 'mv ./dist/* ./';
const commandDelete = 'rm -rf ./dist';
/*
=====
NOTE:
=====
We only want to do cleanup if we are in the
"distribution" mode. Ignore if "source" mode.
*/
const doCleanup = distFolderExists && !srcFolderExists;
// Cleanup necessary?
if (doCleanup) {
execSync(commandCopy);
execSync(commandDelete);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment