Skip to content
This repository has been archived by the owner on Oct 17, 2019. It is now read-only.

Commit

Permalink
Merge pull request #224 from standardhealth/remove-out-before-build
Browse files Browse the repository at this point in the history
Added archive flag to save old builds
  • Loading branch information
Dylan Mahalingam authored Aug 7, 2019
2 parents 88a21a9 + acfcb45 commit c539aa7
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
/yarn-error.log
/node_modules
/out*
/archive*
/.settings
/CommentReintegration
txCache
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ $ node . --help
-d, --duplicate show duplicate error messages (default: false)
-j, --export-es6 export ES6 JavaScript classes (experimental, default: false)
-i, --import-cimcore import CIMCORE files instead of CIMPL (default: false)
-n, --clean Save archive of old output directory and perform clean build (default: false)
-h, --help output usage information
```

Expand Down
26 changes: 26 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ program
.option('-d, --duplicate', 'show duplicate error messages (default: false)')
.option('-j, --export-es6', 'export ES6 JavaScript classes (experimental, default: false)')
.option('-i, --import-cimcore', 'import CIMCORE files instead of CIMPL (default: false)')
.option('-n, --clean', 'Save archive of old output directory and perform clean build (default: false)')
.arguments('<path-to-shr-defs>')
.action(function (pathToShrDefs) {
input = pathToShrDefs;
Expand All @@ -61,6 +62,31 @@ const doDD = program.skip.every(a => a.toLowerCase() != 'data-dict' && a.toLower
const showDuplicateErrors = program.duplicate;
const importCimcore = program.importCimcore;
const doES6 = program.exportEs6;
const clean = program.clean;

// Archive old output directory if it exists
if (clean && fs.existsSync(program.out)) {
let archiveDir;
let targetDir;
let slashIndex = program.out.lastIndexOf('/') > 0 ?
program.out.lastIndexOf('/') : program.out.lastIndexOf('\\');
// Figure out path to move directory into archive
if (slashIndex > 0) {
archiveDir = path.join(program.out.substring(0, slashIndex), 'archive');
targetDir = path.join(archiveDir, program.out.substr(slashIndex));
} else {
archiveDir = 'archive';
targetDir = path.join(archiveDir, program.out);
}
// If archive does not exist, create it
if (!fs.existsSync(archiveDir)) {
mkdirp.sync(archiveDir);
}
// Ensure no naming conflicts with previous archives
let counter = 1;
while(fs.existsSync(targetDir + '-' + counter)) { counter += 1; }
fs.renameSync(program.out, targetDir + '-' + counter);
}

// Create the output folder if necessary
mkdirp.sync(program.out);
Expand Down

0 comments on commit c539aa7

Please sign in to comment.