Files
docx-js/demo/index.ts

42 lines
1.1 KiB
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";
2023-03-30 20:13:35 +01:00
// import shelljs from "shelljs";
import { $ } from "execa";
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();
2023-03-30 20:13:35 +01:00
prompt.get(schema as any, async (_, result) => {
2021-09-30 14:52:50 +01:00
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]}`);
2023-03-30 20:13:35 +01:00
const { stdout } = await $`npm run ts-node -- ${filePath}`;
console.log(stdout);
// if (shelljs.exec(`npm run ts-node -- ${filePath}`).code === 0) {
// console.log("Document created successfully");
// } else {
// console.error("Something went wrong with the demo");
// }
});