@factorialco/gat
Advanced tools
Comparing version 1.5.0 to 2.0.0
@@ -12,14 +12,7 @@ #!/usr/bin/env node | ||
const util_1 = require("util"); | ||
const debounce_1 = __importDefault(require("lodash/debounce")); | ||
const execPromise = (0, util_1.promisify)(child_process_1.exec); | ||
const writeFilePromise = (0, util_1.promisify)(fs_1.default.writeFile); | ||
const folder = path_1.default.join(process.cwd(), ".github", "templates"); | ||
const parseFile = async (templateFile) => { | ||
// NOTE: can we improve this using ts-node or typescript programatically? | ||
const { stdout } = await execPromise(`npx ts-node ${process.env["GAT_BUILD_FLAGS"] ?? "--swc -T"} ${templateFile}`); | ||
await writeFilePromise(path_1.default.join(process.cwd(), ".github", "workflows", templateFile.split("/").at(-1).replace(".ts", ".yml")), stdout); | ||
}; | ||
const cli = new commander_1.Command(); | ||
cli | ||
.version("1.0.0") | ||
.version("2.0.0") | ||
.description("Write your GitHub Actions workflows using TypeScript"); | ||
@@ -29,34 +22,9 @@ cli | ||
.description("Transpile all Gat templates into GitHub Actions workflows.") | ||
.argument("[file]", "(Optional) A Gat template file") | ||
.action(async (file) => { | ||
.action(async () => { | ||
if (!fs_1.default.existsSync(path_1.default.join(folder, "..", "workflows"))) { | ||
fs_1.default.mkdirSync(path_1.default.join(folder, "..", "workflows")); | ||
} | ||
if (file !== undefined) { | ||
await parseFile(file); | ||
} | ||
else { | ||
await Promise.all(fs_1.default.readdirSync(folder).map(async (templateFile) => { | ||
if (!templateFile.match(/^shared$/)) { | ||
await parseFile(`${path_1.default.join(folder, templateFile)}`); | ||
} | ||
})); | ||
} | ||
await execPromise(`npx ts-node ${process.env["GAT_BUILD_FLAGS"] ?? "--swc -T"} ${path_1.default.join(folder, "index.ts")}`); | ||
process.exit(0); | ||
}); | ||
cli | ||
.command("watch") | ||
.description("Watch file changes in your Gat templates folder and transpile them automatically.") | ||
.action(async () => { | ||
const parseWatchedFile = (0, debounce_1.default)(async (fileName) => { | ||
const start = process.hrtime.bigint(); | ||
process.stdout.write(`😸 Detected change on file ${fileName}. Transpiling... `); | ||
await parseFile(path_1.default.join(folder, fileName.toString())); | ||
console.log(`Done in ${(Number(process.hrtime.bigint() - start) / 1000000).toFixed(2)}ms`); | ||
}, 1000); | ||
console.log(`😼 Watching file changes on ${folder}...`); | ||
fs_1.default.watch(folder).on("change", (_eventName, fileName) => { | ||
parseWatchedFile(fileName); | ||
}); | ||
}); | ||
cli.parse(process.argv); |
@@ -27,4 +27,4 @@ import { ConcurrencyGroup, Job, JobOptions, StringWithNoSpaces } from "./job"; | ||
private assignRunner; | ||
compile(): string; | ||
compile(filepath?: string): string | Promise<void>; | ||
} | ||
export {}; |
@@ -9,2 +9,6 @@ "use strict"; | ||
const kebabCase_1 = __importDefault(require("lodash/kebabCase")); | ||
const fs_1 = __importDefault(require("fs")); | ||
const path_1 = __importDefault(require("path")); | ||
const util_1 = require("util"); | ||
const writeFilePromise = (0, util_1.promisify)(fs_1.default.writeFile); | ||
const DEFAULT_RUNNERS = ["ubuntu-22.04"]; | ||
@@ -47,3 +51,3 @@ class Workflow { | ||
} | ||
compile() { | ||
compile(filepath) { | ||
const result = { | ||
@@ -87,6 +91,11 @@ name: this.name, | ||
"fail-fast": false, | ||
matrix: typeof matrix === 'string' ? matrix : { | ||
...Object.fromEntries(matrix.elements.map(({ id, options }) => [id, options])), | ||
include: matrix.extra, | ||
}, | ||
matrix: typeof matrix === "string" | ||
? matrix | ||
: { | ||
...Object.fromEntries(matrix.elements.map(({ id, options }) => [ | ||
id, | ||
options, | ||
])), | ||
include: matrix.extra, | ||
}, | ||
} | ||
@@ -120,6 +129,7 @@ : undefined, | ||
})}`; | ||
console.log(compiled); | ||
return compiled; | ||
if (!filepath) | ||
return compiled; | ||
return writeFilePromise(path_1.default.join(process.cwd(), ".github", "workflows", filepath), compiled); | ||
} | ||
} | ||
exports.Workflow = Workflow; |
{ | ||
"name": "@factorialco/gat", | ||
"version": "1.5.0", | ||
"version": "2.0.0", | ||
"description": "Write your GitHub Actions workflows using TypeScript", | ||
@@ -5,0 +5,0 @@ "bin": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
23989
552
3
2