@factorialco/gat 1.5.0 → 2.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.
package/dist/cli.js CHANGED
@@ -9,52 +9,20 @@ 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"));
13
12
  const execPromise = (0, util_1.promisify)(child_process_1.exec);
14
- const writeFilePromise = (0, util_1.promisify)(fs_1.default.writeFile);
15
13
  const folder = path_1.default.join(process.cwd(), ".github", "templates");
16
- const parseFile = async (templateFile) => {
17
- // NOTE: can we improve this using ts-node or typescript programatically?
18
- const { stdout } = await execPromise(`npx ts-node ${process.env["GAT_BUILD_FLAGS"] ?? "--swc -T"} ${templateFile}`);
19
- await writeFilePromise(path_1.default.join(process.cwd(), ".github", "workflows", templateFile.split("/").at(-1).replace(".ts", ".yml")), stdout);
20
- };
21
14
  const cli = new commander_1.Command();
22
15
  cli
23
- .version("1.0.0")
16
+ .version("2.0.0")
24
17
  .description("Write your GitHub Actions workflows using TypeScript");
25
18
  cli
26
19
  .command("build")
27
20
  .description("Transpile all Gat templates into GitHub Actions workflows.")
28
- .argument("[file]", "(Optional) A Gat template file")
29
- .action(async (file) => {
21
+ .action(async () => {
30
22
  if (!fs_1.default.existsSync(path_1.default.join(folder, "..", "workflows"))) {
31
23
  fs_1.default.mkdirSync(path_1.default.join(folder, "..", "workflows"));
32
24
  }
33
- if (file !== undefined) {
34
- await parseFile(file);
35
- }
36
- else {
37
- await Promise.all(fs_1.default.readdirSync(folder).map(async (templateFile) => {
38
- if (!templateFile.match(/^shared$/)) {
39
- await parseFile(`${path_1.default.join(folder, templateFile)}`);
40
- }
41
- }));
42
- }
25
+ await execPromise(`npx ts-node ${process.env["GAT_BUILD_FLAGS"] ?? "--swc -T"} ${path_1.default.join(folder, "index.ts")}`);
43
26
  process.exit(0);
44
27
  });
45
- cli
46
- .command("watch")
47
- .description("Watch file changes in your Gat templates folder and transpile them automatically.")
48
- .action(async () => {
49
- const parseWatchedFile = (0, debounce_1.default)(async (fileName) => {
50
- const start = process.hrtime.bigint();
51
- process.stdout.write(`😸 Detected change on file ${fileName}. Transpiling... `);
52
- await parseFile(path_1.default.join(folder, fileName.toString()));
53
- console.log(`Done in ${(Number(process.hrtime.bigint() - start) / 1000000).toFixed(2)}ms`);
54
- }, 1000);
55
- console.log(`😼 Watching file changes on ${folder}...`);
56
- fs_1.default.watch(folder).on("change", (_eventName, fileName) => {
57
- parseWatchedFile(fileName);
58
- });
59
- });
60
28
  cli.parse(process.argv);
@@ -24,6 +24,6 @@ export declare class Workflow<JobStep extends BaseStep = Step, Runner = typeof D
24
24
  setConcurrencyGroup(concurrencyGroup: ConcurrencyGroup): this;
25
25
  defaultRunner(): string;
26
26
  private assignRunner;
27
- compile(): string;
27
+ compile(filepath?: string): string | Promise<void>;
28
28
  }
29
29
  export {};
package/dist/workflow.js CHANGED
@@ -6,6 +6,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Workflow = void 0;
7
7
  const js_yaml_1 = require("js-yaml");
8
8
  const kebabCase_1 = __importDefault(require("lodash/kebabCase"));
9
+ const fs_1 = __importDefault(require("fs"));
10
+ const path_1 = __importDefault(require("path"));
11
+ const util_1 = require("util");
12
+ const writeFilePromise = (0, util_1.promisify)(fs_1.default.writeFile);
9
13
  const DEFAULT_RUNNERS = ["ubuntu-22.04"];
10
14
  class Workflow {
11
15
  constructor(name) {
@@ -43,7 +47,7 @@ class Workflow {
43
47
  const isSelfHosted = !DEFAULT_RUNNERS.includes(runnerName);
44
48
  return isSelfHosted ? ["self-hosted", runnerName] : runnerName;
45
49
  }
46
- compile() {
50
+ compile(filepath) {
47
51
  const result = {
48
52
  name: this.name,
49
53
  on: Object.fromEntries(this.events.map(({ name, options }) => [name, options ? options : null])),
@@ -82,10 +86,15 @@ class Workflow {
82
86
  strategy: matrix
83
87
  ? {
84
88
  "fail-fast": false,
85
- matrix: typeof matrix === 'string' ? matrix : {
86
- ...Object.fromEntries(matrix.elements.map(({ id, options }) => [id, options])),
87
- include: matrix.extra,
88
- },
89
+ matrix: typeof matrix === "string"
90
+ ? matrix
91
+ : {
92
+ ...Object.fromEntries(matrix.elements.map(({ id, options }) => [
93
+ id,
94
+ options,
95
+ ])),
96
+ include: matrix.extra,
97
+ },
89
98
  }
90
99
  : undefined,
91
100
  env,
@@ -114,8 +123,9 @@ class Workflow {
114
123
  lineWidth: 200,
115
124
  noCompatMode: true,
116
125
  })}`;
117
- console.log(compiled);
118
- return compiled;
126
+ if (!filepath)
127
+ return compiled;
128
+ return writeFilePromise(path_1.default.join(process.cwd(), ".github", "workflows", filepath), compiled);
119
129
  }
120
130
  }
121
131
  exports.Workflow = Workflow;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@factorialco/gat",
3
- "version": "1.5.0",
3
+ "version": "2.0.0",
4
4
  "description": "Write your GitHub Actions workflows using TypeScript",
5
5
  "bin": {
6
6
  "gat": "dist/cli.js"