@factorialco/gat 0.0.20 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/cli.js +21 -4
  2. package/package.json +2 -2
package/dist/cli.js CHANGED
@@ -9,20 +9,22 @@ const path_1 = __importDefault(require("path"));
9
9
  const child_process_1 = require("child_process");
10
10
  const commander_1 = require("commander");
11
11
  const util_1 = require("util");
12
+ const debounce_1 = __importDefault(require("lodash/debounce"));
12
13
  const execPromise = (0, util_1.promisify)(child_process_1.exec);
13
14
  const writeFilePromise = (0, util_1.promisify)(fs_1.default.writeFile);
15
+ const folder = path_1.default.join(process.cwd(), ".github", "templates");
14
16
  const parseFile = async (templateFile) => {
17
+ // NOTE: can we improve this using ts-node or typescript programatically?
15
18
  const { stdout } = await execPromise(`npx ts-node ${templateFile}`);
16
19
  await writeFilePromise(path_1.default.join(process.cwd(), ".github", "workflows", templateFile.split("/").at(-1).replace(".ts", ".yml")), stdout);
17
20
  };
18
21
  const cli = new commander_1.Command();
19
- cli.version("0.0.1").description("TODO");
22
+ cli.version("1.0.0").description("Write your GitHub Actions workflows using TypeScript");
20
23
  cli
21
24
  .command("build")
22
- .description("TODO")
23
- .argument("[file]", "TODO")
25
+ .description("Transpile all Gat templates into GitHub Actions workflows.")
26
+ .argument("[file]", "(Optional) A Gat template file")
24
27
  .action(async (file) => {
25
- const folder = path_1.default.join(process.cwd(), ".github", "templates");
26
28
  if (!fs_1.default.existsSync(path_1.default.join(folder, "..", "workflows"))) {
27
29
  fs_1.default.mkdirSync(path_1.default.join(folder, "..", "workflows"));
28
30
  }
@@ -38,4 +40,19 @@ cli
38
40
  }
39
41
  process.exit(0);
40
42
  });
43
+ cli
44
+ .command("watch")
45
+ .description("Watch file changes in your Gat templates folder and transpile them automatically.")
46
+ .action(async () => {
47
+ const parseWatchedFile = (0, debounce_1.default)(async (fileName) => {
48
+ const start = process.hrtime.bigint();
49
+ process.stdout.write(`😸 Detected change on file ${fileName}. Transpiling... `);
50
+ await parseFile(path_1.default.join(folder, fileName.toString()));
51
+ console.log(`Done in ${((Number(process.hrtime.bigint() - start)) / 1000000).toFixed(2)}ms`);
52
+ }, 1000);
53
+ console.log(`😼 Watching file changes on ${folder}...`);
54
+ fs_1.default.watch(folder).on("change", (_eventName, fileName) => {
55
+ parseWatchedFile(fileName);
56
+ });
57
+ });
41
58
  cli.parse(process.argv);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@factorialco/gat",
3
- "version": "0.0.20",
4
- "description": "TODO",
3
+ "version": "1.0.0",
4
+ "description": "Write your GitHub Actions workflows using TypeScript",
5
5
  "bin": {
6
6
  "gat": "dist/cli.js"
7
7
  },