Skip to content

Commit

Permalink
#248 add bin scripts to npm.scripts.
Browse files Browse the repository at this point in the history
Make sure all print help with no arguments.


Former-commit-id: 571af24
  • Loading branch information
pmeijer committed Mar 20, 2015
1 parent 4f12b33 commit c4ed52f
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 83 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ Naba Bana <[email protected]>
Kevin Smyth <[email protected]>
Hakan Tunc <[email protected]>
Peter Volgyesi <[email protected]>
Patrik Meijer <[email protected]>
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@
"test_cover": "node ./node_modules/istanbul/lib/cli.js --hook-run-in-context cover node_modules/mocha/bin/_mocha -- -R spec --recursive test",
"test_browser": "node ./node_modules/karma/bin/karma start karma.conf.js --browsers Firefox --single-run",
"prepublish": "gulp compile-all",
"postinstall": "node ./node_modules/requirejs/bin/r.js -o ./utils/build/webgme.classes/cbuild.js"
"postinstall": "node ./node_modules/requirejs/bin/r.js -o ./utils/build/webgme.classes/cbuild.js",
"apply": "node ./src/bin/apply.js",
"diff": "node ./src/bin/diff.js",
"export": "node ./src/bin/export.js",
"import": "node ./src/bin/import.js",
"merge": "node ./src/bin/merge.js",
"plugin": "node ./src/bin/run_plugin.js",
"users": "node ./src/bin/usermanager.js"
}
}
13 changes: 3 additions & 10 deletions src/bin/apply.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,29 +105,22 @@ if (require.main === module) {
.option('-n, --no-update', 'show if we should not update the branch')
.parse(process.argv);
//check necessary arguments
if (program.args.length !== 1) {
console.warn('wrong parameters');
}

if (!program.mongoDatabaseUri) {
console.warn('mongoDB URL is a mandatory parameter!');
process.exit(0);
}
if (!program.projectIdentifier) {
console.warn('project identifier is a mandatory parameter!');
process.exit(0);
program.help();
}
if (!program.target) {
console.warn('target is a mandatory parameter!');
process.exit(0);
program.help();
}

//load path file
try {
patchJson = JSON.parse(FS.readFileSync(program.args[0], 'utf-8'));
} catch (err) {
console.warn('unable to load patch file: ', err);
process.exit(0);
process.exit(1);
}

applyPatch(program.mongoDatabaseUri, program.projectIdentifier, program.target, patchJson, program.noUpdate,
Expand Down
47 changes: 25 additions & 22 deletions src/bin/diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,38 +113,41 @@ if (require.main === module) {
.parse(process.argv);

//check necessary arguments
if (!program.mongoDatabaseUri) {
console.warn('mongoDB URL is a mandatory parameter!');
process.exit(0);
}
// if (!program.mongoDatabaseUri) {
// console.warn('mongoDB URL is a mandatory parameter!');
// process.exit(0);
// }
if (!program.projectIdentifier) {
console.warn('project identifier is a mandatory parameter!');
process.exit(0);
program.help();
}
if (!program.source) {
console.warn('source is a mandatory parameter!');
process.exit(0);
program.help();
}
if (!program.target) {
console.warn('target is a mandatory parameter!');
process.exit(0);
program.help();
}

generateDiff(program.mongoDatabaseUri, program.projectIdentifier, program.source, program.target, function (err, diff) {
if (err) {
console.warn('diff generation finished with error: ', err);
process.exit(0);
}
if (program.out) {
try {
FS.writeFileSync(program.out, JSON.stringify(diff, null, 2));
} catch (err) {
console.warn('unable to create output file:', err);
generateDiff(program.mongoDatabaseUri, program.projectIdentifier, program.source, program.target,
function (err, diff) {
'use strict';
if (err) {
console.warn('diff generation finished with error: ', err);
process.exit(0);
}
if (program.out) {
try {
FS.writeFileSync(program.out, JSON.stringify(diff, null, 2));
} catch (err) {
console.warn('unable to create output file:', err);
}
} else {
console.log('generated diff:');
console.log(JSON.stringify(diff, null, 2));
}
} else {
console.log('generated diff:');
console.log(JSON.stringify(diff, null, 2));
process.exit(0);
}
process.exit(0);
});
);
}
48 changes: 26 additions & 22 deletions src/bin/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,41 +76,45 @@ if (require.main === module) {
.parse(process.argv);
//check necessary arguments

if (!program.mongoDatabaseUri) {
console.warn('mongoDB URL is a mandatory parameter!');
process.exit(0);
}
if (!program.projectIdentifier) {
console.warn('project identifier is a mandatory parameter!');
process.exit(0);
program.help();
}

if (!program.source) {
console.warn('source is a mandatory parameter!');
process.exit(0);
program.help();
}
if (!BRANCH_REGEXP.test(program.source) && !HASH_REGEXP.test(program.source)) {
console.warn('source format is invalid!');
process.exit(0);
program.help();
}

//calling the export function
exportProject(program.mongoDatabaseUri, program.projectIdentifier, program.source, function (err, jsonProject) {
if (err) {
console.warn('error during project export: ', err);
} else {
if (program.out) {
try {
FS.writeFileSync(program.out, JSON.stringify(jsonProject, null, 2));
console.warn('project \'' + program.projectIdentifier + '\' hase been successfully written to \'' + program.out + '\'');
} catch (err) {
console.warn('failed to create output file: ' + err);
}
exportProject(program.mongoDatabaseUri, program.projectIdentifier, program.source,
function (err, jsonProject) {
'use strict';
if (err) {
console.error('error during project export: ', err);
process.exit(1);
} else {
console.warn('project \'' + program.projectIdentifier + '\':');
console.warn(JSON.stringify(jsonProject, null, 2));
if (program.out) {
try {
FS.writeFileSync(program.out, JSON.stringify(jsonProject, null, 2));
console.log('project \'' + program.projectIdentifier +
'\' hase been successfully written to \'' + program.out + '\'');
process.exit(0);
} catch (err) {
console.error('failed to create output file: ' + err);
process.exit(1);
}
} else {
console.log('project \'' + program.projectIdentifier + '\':');
console.log(JSON.stringify(jsonProject, null, 2));
process.exit(0);
}
}

}
process.exit(0);
});
);
}
27 changes: 10 additions & 17 deletions src/bin/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,46 +107,39 @@ if (require.main === module) {
.option('-o --overwrite [boolean]', 'if a project exist it will be deleted and created again')
.parse(process.argv);
//check necessary arguments
if (program.args.length !== 1) {
console.warn('wrong parameters');
program.help();
}

//if (!program.mongoDatabaseUri) {
// console.warn('mongoDB URL is a mandatory parameter!');
// process.exit(1);
//}
if (!program.projectIdentifier) {
console.warn('project identifier is a mandatory parameter!');
process.exit(1);
console.error('project identifier is a mandatory parameter!');
program.help();
}
if (program.branch && !BRANCH_REGEXP.test(program.branch)) {
console.warn(program.branch + ' is not a valid branch name!');
process.exit(1);
console.error(program.branch + ' is not a valid branch name!');
program.help();
}

if (!program.branch) {
console.log('branch is not given, master will be used');
console.warn('branch is not given, master will be used');
}

//loading the project file and seeing if it is a valid JSON object
try {
jsonProject = JSON.parse(FS.readFileSync(program.args[0], 'utf-8'));
} catch (err) {
console.warn('unable to load project file: ', err);
process.exit(0);
console.error('unable to load project file: ', err);
process.exit(1);
}
//calling the import function
importProject(program.mongoDatabaseUri, program.projectIdentifier, jsonProject, program.branch, program.overwrite,
function (err, commitHash) {
'use strict';
if (err) {
console.warn('error during project import: ', err);
console.error('error during project import: ', err);
process.exit(0);
} else {
console.warn('branch "' + program.branch + '" of project "' + program.projectIdentifier +
'" have been successfully imported at commitHash: ' + commitHash + '.');
process.exit(0);
}
process.exit(0);
}
);
}
23 changes: 12 additions & 11 deletions src/bin/run_plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ main = function (argv, callback) {

webGme.addToRequireJsPaths(gmeConfig);

program.option('-p, --project <name>', 'Name of the project.', 'projectName');
program.option('-p, --project <name><mandatory>', 'Name of the project.');
program.option('-b, --branch <name>', 'Name of the branch.', 'master');
program.option('-j, --pluginConfigPath <name>',
'Path to json file with plugin options that should be overwritten.',
Expand All @@ -36,19 +36,20 @@ main = function (argv, callback) {
program.option('-s, --selectedObjID <webGMEID>', 'ID to selected component.', '');
program.parse(argv);

if (program.pluginName === undefined) {
if (!(program.pluginName && program.project)) {
program.help();
} else {
//getting program options
projectName = program.project;
branch = program.branch;
pluginName = program.pluginName;
activeNode = program.selectedObjID;
configFilename = program.config;
pluginConfigFilename = program.pluginConfigPath;
console.log('A project and pluginName must be specified.');
}

console.log('executing ' + pluginName + ' plugin');
//getting program options
projectName = program.project;
branch = program.branch;
pluginName = program.pluginName;
activeNode = program.selectedObjID;
configFilename = program.config;
pluginConfigFilename = program.pluginConfigPath;

console.log('Executing ' + pluginName + ' plugin');

if (pluginConfigFilename) {
resolvedPluginConfigFilename = path.resolve(pluginConfigFilename);
Expand Down

0 comments on commit c4ed52f

Please sign in to comment.