Files
docx-js/demo/index.ts

38 lines
984 B
TypeScript
Raw Normal View History

// tslint:disable:no-console
2021-09-30 14:52:50 +01:00
import fs from "fs";
import prompt from "prompt";
import shelljs from "shelljs";
console.log("What demo do you wish to run? (Enter a number)");
const schema = {
properties: {
number: {
pattern: /^[0-9]+$/,
message: "Please enter a number.",
required: true,
},
},
};
prompt.start();
2021-09-30 14:52:50 +01:00
prompt.get(schema as any, (_, result) => {
const demoNumber = result.number as string;
2019-08-06 23:08:21 +01:00
const files = fs.readdirSync("./demo").filter((fn) => fn.startsWith(demoNumber));
2019-08-06 23:08:21 +01:00
if (files.length === 0) {
console.error(`demo number ${demoNumber} does not exist`);
return;
}
2019-08-06 23:08:21 +01:00
const filePath = `./demo/${files[0]}`;
console.log(`Running demo ${demoNumber}: ${files[0]}`);
if (shelljs.exec(`npm run ts-node -- ${filePath}`).code === 0) {
console.log("Document created successfully");
} else {
console.error("Something went wrong with the demo");
}
});