Skip to content

Commit

Permalink
update npm scripts to build into root folder
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Delany committed Dec 19, 2017
1 parent a43007a commit 0e36abf
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
},
"scripts": {
"dev": "webpack-dev-server --config webpack.config.base.js",
"build-lib": "rm -rf lib/ && babel src --out-dir lib --source-maps",
"clean": "node scripts/clean.js",
"build-lib": "npm run clean && babel src --out-dir ./ --source-maps",
"build-docs": "BABEL_ENV=production webpack --config webpack.config.build.js",
"build": "npm run build-lib && npm run make-docs && npm run build-docs",
"make-docs": "node scripts/makeDocs.js",
Expand Down
29 changes: 29 additions & 0 deletions scripts/clean.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const fs = require("fs");
const sh = require("shelljs");

const {fileExists, dirExists} = require("./utils");

const srcContents = sh.ls("src");

// We don't want to commit built files, so it is useful to have a `clean` script which deletes them if they exist.
// However, Reactochart is built in the root directory
// (so that modules may be required with eg. `require('reactochart/LineChart')`).
// This makes cleanup harder than simply deleting a `build` directory.
// Instead this looks for any files in the root directory which match the name of a file in the `src` directory,
// and deletes them if they exist.
// Sounds dangerous, but any files in root which share a name with src would have been overwritten by the build anyway.

srcContents.forEach(fileOrDir => {
if (fileExists(`src/${fileOrDir}`) && fileExists(`./${fileOrDir}`)) {
console.log(`deleting file ./${fileOrDir}`);
sh.rm(`./${fileOrDir}`);
} else if (dirExists(`src/${fileOrDir}`) && dirExists(fileOrDir)) {
console.log(`deleting directory ./${fileOrDir}`);
sh.rm("-rf", `./${fileOrDir}`);
}
// check for source maps too
if(fileExists(`./${fileOrDir}.map`)) {
console.log(`deleting file ./${fileOrDir}.map`);
sh.rm(`./${fileOrDir}.map`);
}
});

0 comments on commit 0e36abf

Please sign in to comment.