forked from spotify/reactochart
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update npm scripts to build into root folder
- Loading branch information
Dan Delany
committed
Dec 19, 2017
1 parent
a43007a
commit 0e36abf
Showing
2 changed files
with
31 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`); | ||
} | ||
}); |