made a mini app which you can select the demo you want from a list with an interactive prompt.

This commit is contained in:
Dolan
2017-04-14 15:48:12 +01:00
parent a706455a7c
commit 30f826fd3d
3 changed files with 32 additions and 2 deletions

29
demo/index.js Normal file
View File

@ -0,0 +1,29 @@
var prompt = require('prompt');
var shelljs = require('shelljs');
var fs = require('fs');
console.log('What demo do you wish to run? (Enter a number)');
var schema = {
properties: {
number: {
pattern: /^[0-9]+$/,
message: 'Please enter a number.',
required: true
}
}
};
prompt.start();
prompt.get(schema, function (err, result) {
var demoNumber = result.number;
var filePath = `./demo/demo${demoNumber}.js`;
if (!fs.existsSync(filePath)) {
console.error(`demo${demoNumber} does not exist: ${filePath}`);
return;
}
console.log(`Running demo ${demoNumber}`);
shelljs.exec(`node ${filePath}`);
});

View File

@ -9,8 +9,7 @@
"prepublishOnly": "npm run build",
"lint": "tslint --project ./ts",
"build": "rimraf ./build && tsc -p ts",
"demo": "npm run build && node ./demo/demo.js",
"demo2": "npm run build && node ./demo/demo2.js"
"demo": "npm run build && node ./demo"
},
"files": [
"ts",
@ -49,7 +48,9 @@
"@types/mocha": "^2.2.39",
"chai": "^3.5.0",
"mocha": "^3.2.0",
"prompt": "^1.0.0",
"rimraf": "^2.5.2",
"shelljs": "^0.7.7",
"tslint": "^4.5.1",
"typescript": "^2.2.1"
}