github-action-yaml 0.0.2 → 0.0.4

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.
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
 
3
3
  // src/bin/action-yaml.ts
4
+ var import_node_fs = require("fs");
4
5
  var import_promises2 = require("fs/promises");
5
6
  var import_node_path = require("path");
6
7
  var import_commander = require("commander");
@@ -50,7 +51,7 @@ ${Object.keys(actionInputs ?? {}).map(
50
51
  }
51
52
  }`;
52
53
  return `// @ts-ignore
53
- import * as core from "@github/core";
54
+ import * as core from "@actions/core";
54
55
  import { Prettify, InputOptions, InputsValues } from "github-action-yaml"
55
56
 
56
57
  export const raw = ${JSON.stringify(action, null, 2)} as const;
@@ -86,17 +87,16 @@ var universalReadFile = async (path) => {
86
87
 
87
88
  // src/bin/action-yaml.ts
88
89
  var program = new import_commander.Command();
89
- program.name("generate").description("generate typescript code from action.yaml file").argument("<file>", "output typescript file").option("-i, --input <file>", "input action.yaml file", "action.yml").option("--watch", "watch mode", false).action(async (file, options) => {
90
- const yaml = (0, import_yaml.parse)(await universalReadFile(options.input));
90
+ program.name("generate").description("generate typescript code from action.yaml file").argument("<file>", "output typescript file").option("-i, --input <file>", "input action.yaml file", "action.yaml").option("--watch", "watch mode", false).action(async (file, options) => {
91
+ const inputFile = (0, import_node_fs.existsSync)(options.input) ? options.input : (0, import_node_fs.existsSync)("action.yaml") ? "action.yaml" : "action.yml";
92
+ const yaml = (0, import_yaml.parse)(await universalReadFile(inputFile));
91
93
  await (0, import_promises2.mkdir)((0, import_node_path.dirname)(file), { recursive: true });
92
94
  await (0, import_promises2.writeFile)(file, actionToType(yaml));
93
95
  if (!options.watch) {
94
96
  return;
95
97
  }
96
- for await (const _ of (0, import_promises2.watch)(options.input)) {
97
- const yaml2 = (0, import_yaml.parse)(
98
- await universalReadFile(options.input)
99
- );
98
+ for await (const _ of (0, import_promises2.watch)(inputFile)) {
99
+ const yaml2 = (0, import_yaml.parse)(await universalReadFile(inputFile));
100
100
  await (0, import_promises2.mkdir)((0, import_node_path.dirname)(file), { recursive: true });
101
101
  await (0, import_promises2.writeFile)(file, actionToType(yaml2));
102
102
  console.log("Updated", file);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/bin/action-yaml.ts","../../src/action-to-type.ts","../../src/utils.ts"],"sourcesContent":["import { mkdir, watch, writeFile } from \"node:fs/promises\";\nimport { dirname } from \"node:path\";\nimport type { GithubAction } from \"@schemastore/github-action\";\nimport { Command } from \"commander\";\nimport { parse } from \"yaml\";\nimport { actionToType } from \"../action-to-type\";\nimport { universalReadFile } from \"../utils\";\n\nconst program = new Command();\n\nprogram\n .name(\"generate\")\n .description(\"generate typescript code from action.yaml file\")\n .argument(\"<file>\", \"output typescript file\")\n .option(\"-i, --input <file>\", \"input action.yaml file\", \"action.yml\")\n .option(\"--watch\", \"watch mode\", false)\n .action(async (file: string, options: { input: string; watch: boolean }) => {\n const yaml = parse(await universalReadFile(options.input)) as GithubAction;\n\n await mkdir(dirname(file), { recursive: true });\n await writeFile(file, actionToType(yaml));\n\n if (!options.watch) {\n return;\n }\n\n for await (const _ of watch(options.input)) {\n const yaml = parse(\n await universalReadFile(options.input),\n ) as GithubAction;\n\n await mkdir(dirname(file), { recursive: true });\n await writeFile(file, actionToType(yaml));\n console.log(\"Updated\", file);\n }\n });\n\nprogram.parse();\n","import type { GithubAction } from \"@schemastore/github-action\";\n\nexport const actionToType = (action: GithubAction) => {\n const actionInputs = action.inputs ?? {};\n\n const inputsType = `\\\nexport type Inputs<T extends InputOptions<typeof raw> = InputOptions<typeof raw>, V extends InputsValues<typeof raw, T> = InputsValues<typeof raw,T>> = {\n${Object.entries(actionInputs ?? {})\n .map(\n ([key, value]) => `\\\n /**\n * ${value.description}\n * \n${value.default ? ` * @default ${value.default}\\n` : \"\"}\\\n${value.deprecationMessage ? ` * @deprecated ${value.deprecationMessage}\\n` : \"\"}\\\n */\n '${key}'${value.required || typeof value.default !== \"undefined\" ? \"\" : \"?\"}: V[\"${key}\"];\\\n`,\n )\n .join(\"\\n\")}\n}`;\n\n const outputsType = `\\\nexport type Outputs = {\n${Object.entries(\n (action.outputs as Record<string, { description?: string }>) ?? {},\n)\n .map(\n ([key, value]) => `\\\n /**\n * ${value.description}\n * \n */\n '${key}'?: string;\\\n`,\n )\n .join(\"\\n\")}\n}`;\n\n const parseInputs = `\\\nconst getInput = {\n string: core.getInput,\n boolean: core.getBooleanInput,\n multiline: core.getMultilineInput,\n};\n\nexport const parseInputs = <T extends InputOptions<typeof raw>>(options?: T): Prettify<Inputs<T>> => {\n return {\n${Object.keys(actionInputs ?? {})\n .map(\n (key) =>\n ` \"${key}\": getInput[options?.[\"${key}\"]?.type ?? \"string\"](\"${key}\", {trimWhitespace: options?.cwd?.trimWhitespace}),`,\n )\n .join(\"\\n\")}\n } as Inputs<T>;\n}`;\n\n const dumpOutputs = `\\\nexport const dumpOutputs = (outputs: Partial<Outputs>) => {\n for (const [name, value] of Object.entries(outputs)) {\n core.setOutput(name, value)\n }\n}`;\n\n return `\\\n// @ts-ignore\nimport * as core from \"@github/core\";\nimport { Prettify, InputOptions, InputsValues } from \"github-action-yaml\"\n\nexport const raw = ${JSON.stringify(action, null, 2)} as const;\n\n${inputsType}\n\n${outputsType}\n\n${parseInputs}\n\n${dumpOutputs}\n`;\n};\n","import { readFile } from \"node:fs/promises\";\n\nfunction isUrl(input: string): boolean {\n try {\n const url = new URL(input);\n return url.protocol === \"http:\" || url.protocol === \"https:\";\n } catch {\n return false;\n }\n}\n\nexport const universalReadFile = async (path: string) => {\n if (isUrl(path)) {\n const response = await fetch(path);\n return response.text();\n }\n const file = await readFile(path, \"utf-8\");\n return file;\n};\n"],"mappings":";;;AAAA,IAAAA,mBAAwC;AACxC,uBAAwB;AAExB,uBAAwB;AACxB,kBAAsB;;;ACFf,IAAM,eAAe,CAAC,WAAyB;AACpD,QAAM,eAAe,OAAO,UAAU,CAAC;AAEvC,QAAM,aAAa;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;AAEO,IAAM,oBAAoB,OAAO,SAAiB;AACvD,MAAI,MAAM,IAAI,GAAG;AACf,UAAM,WAAW,MAAM,MAAM,IAAI;AACjC,WAAO,SAAS,KAAK;AAAA,EACvB;AACA,QAAM,OAAO,UAAM,0BAAS,MAAM,OAAO;AACzC,SAAO;AACT;;;AFVA,IAAM,UAAU,IAAI,yBAAQ;AAE5B,QACG,KAAK,UAAU,EACf,YAAY,gDAAgD,EAC5D,SAAS,UAAU,wBAAwB,EAC3C,OAAO,sBAAsB,0BAA0B,YAAY,EACnE,OAAO,WAAW,cAAc,KAAK,EACrC,OAAO,OAAO,MAAc,YAA+C;AAC1E,QAAM,WAAO,mBAAM,MAAM,kBAAkB,QAAQ,KAAK,CAAC;AAEzD,YAAM,4BAAM,0BAAQ,IAAI,GAAG,EAAE,WAAW,KAAK,CAAC;AAC9C,YAAM,4BAAU,MAAM,aAAa,IAAI,CAAC;AAExC,MAAI,CAAC,QAAQ,OAAO;AAClB;AAAA,EACF;AAEA,mBAAiB,SAAK,wBAAM,QAAQ,KAAK,GAAG;AAC1C,UAAMC,YAAO;AAAA,MACX,MAAM,kBAAkB,QAAQ,KAAK;AAAA,IACvC;AAEA,cAAM,4BAAM,0BAAQ,IAAI,GAAG,EAAE,WAAW,KAAK,CAAC;AAC9C,cAAM,4BAAU,MAAM,aAAaA,KAAI,CAAC;AACxC,YAAQ,IAAI,WAAW,IAAI;AAAA,EAC7B;AACF,CAAC;AAEH,QAAQ,MAAM;","names":["import_promises","yaml"]}
1
+ {"version":3,"sources":["../../src/bin/action-yaml.ts","../../src/action-to-type.ts","../../src/utils.ts"],"sourcesContent":["import { existsSync } from \"node:fs\";\nimport { mkdir, watch, writeFile } from \"node:fs/promises\";\nimport { dirname } from \"node:path\";\nimport type { GithubAction } from \"@schemastore/github-action\";\nimport { Command } from \"commander\";\nimport { parse } from \"yaml\";\nimport { actionToType } from \"../action-to-type\";\nimport { universalReadFile } from \"../utils\";\n\nconst program = new Command();\n\nprogram\n .name(\"generate\")\n .description(\"generate typescript code from action.yaml file\")\n .argument(\"<file>\", \"output typescript file\")\n .option(\"-i, --input <file>\", \"input action.yaml file\", \"action.yaml\")\n .option(\"--watch\", \"watch mode\", false)\n .action(async (file: string, options: { input: string; watch: boolean }) => {\n const inputFile = existsSync(options.input)\n ? options.input\n : existsSync(\"action.yaml\")\n ? \"action.yaml\"\n : \"action.yml\";\n const yaml = parse(await universalReadFile(inputFile)) as GithubAction;\n\n await mkdir(dirname(file), { recursive: true });\n await writeFile(file, actionToType(yaml));\n\n if (!options.watch) {\n return;\n }\n\n for await (const _ of watch(inputFile)) {\n const yaml = parse(await universalReadFile(inputFile)) as GithubAction;\n\n await mkdir(dirname(file), { recursive: true });\n await writeFile(file, actionToType(yaml));\n console.log(\"Updated\", file);\n }\n });\n\nprogram.parse();\n","import type { GithubAction } from \"@schemastore/github-action\";\n\nexport const actionToType = (action: GithubAction) => {\n const actionInputs = action.inputs ?? {};\n\n const inputsType = `\\\nexport type Inputs<T extends InputOptions<typeof raw> = InputOptions<typeof raw>, V extends InputsValues<typeof raw, T> = InputsValues<typeof raw,T>> = {\n${Object.entries(actionInputs ?? {})\n .map(\n ([key, value]) => `\\\n /**\n * ${value.description}\n * \n${value.default ? ` * @default ${value.default}\\n` : \"\"}\\\n${value.deprecationMessage ? ` * @deprecated ${value.deprecationMessage}\\n` : \"\"}\\\n */\n '${key}'${value.required || typeof value.default !== \"undefined\" ? \"\" : \"?\"}: V[\"${key}\"];\\\n`,\n )\n .join(\"\\n\")}\n}`;\n\n const outputsType = `\\\nexport type Outputs = {\n${Object.entries(\n (action.outputs as Record<string, { description?: string }>) ?? {},\n)\n .map(\n ([key, value]) => `\\\n /**\n * ${value.description}\n * \n */\n '${key}'?: string;\\\n`,\n )\n .join(\"\\n\")}\n}`;\n\n const parseInputs = `\\\nconst getInput = {\n string: core.getInput,\n boolean: core.getBooleanInput,\n multiline: core.getMultilineInput,\n};\n\nexport const parseInputs = <T extends InputOptions<typeof raw>>(options?: T): Prettify<Inputs<T>> => {\n return {\n${Object.keys(actionInputs ?? {})\n .map(\n (key) =>\n ` \"${key}\": getInput[options?.[\"${key}\"]?.type ?? \"string\"](\"${key}\", {trimWhitespace: options?.cwd?.trimWhitespace}),`,\n )\n .join(\"\\n\")}\n } as Inputs<T>;\n}`;\n\n const dumpOutputs = `\\\nexport const dumpOutputs = (outputs: Partial<Outputs>) => {\n for (const [name, value] of Object.entries(outputs)) {\n core.setOutput(name, value)\n }\n}`;\n\n return `\\\n// @ts-ignore\nimport * as core from \"@actions/core\";\nimport { Prettify, InputOptions, InputsValues } from \"github-action-yaml\"\n\nexport const raw = ${JSON.stringify(action, null, 2)} as const;\n\n${inputsType}\n\n${outputsType}\n\n${parseInputs}\n\n${dumpOutputs}\n`;\n};\n","import { readFile } from \"node:fs/promises\";\n\nfunction isUrl(input: string): boolean {\n try {\n const url = new URL(input);\n return url.protocol === \"http:\" || url.protocol === \"https:\";\n } catch {\n return false;\n }\n}\n\nexport const universalReadFile = async (path: string) => {\n if (isUrl(path)) {\n const response = await fetch(path);\n return response.text();\n }\n const file = await readFile(path, \"utf-8\");\n return file;\n};\n"],"mappings":";;;AAAA,qBAA2B;AAC3B,IAAAA,mBAAwC;AACxC,uBAAwB;AAExB,uBAAwB;AACxB,kBAAsB;;;ACHf,IAAM,eAAe,CAAC,WAAyB;AACpD,QAAM,eAAe,OAAO,UAAU,CAAC;AAEvC,QAAM,aAAa;AAAA,EAEnB,OAAO,QAAQ,gBAAgB,CAAC,CAAC,EAChC;AAAA,IACC,CAAC,CAAC,KAAK,KAAK,MAAM;AAAA,OAEf,MAAM,WAAW;AAAA;AAAA,EAEtB,MAAM,UAAU,iBAAiB,MAAM,OAAO;AAAA,IAAO,EAAE,GACvD,MAAM,qBAAqB,oBAAoB,MAAM,kBAAkB;AAAA,IAAO,EAAE;AAAA,KAE7E,GAAG,IAAI,MAAM,YAAY,OAAO,MAAM,YAAY,cAAc,KAAK,GAAG,QAAQ,GAAG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a,EACpE,OAAO,WAAW,cAAc,KAAK,EACrC,OAAO,OAAO,MAAc,YAA+C;AAC1E,QAAM,gBAAY,2BAAW,QAAQ,KAAK,IACtC,QAAQ,YACR,2BAAW,aAAa,IACtB,gBACA;AACN,QAAM,WAAO,mBAAM,MAAM,kBAAkB,SAAS,CAAC;AAErD,YAAM,4BAAM,0BAAQ,IAAI,GAAG,EAAE,WAAW,KAAK,CAAC;AAC9C,YAAM,4BAAU,MAAM,aAAa,IAAI,CAAC;AAExC,MAAI,CAAC,QAAQ,OAAO;AAClB;AAAA,EACF;AAEA,mBAAiB,SAAK,wBAAM,SAAS,GAAG;AACtC,UAAMC,YAAO,mBAAM,MAAM,kBAAkB,SAAS,CAAC;AAErD,cAAM,4BAAM,0BAAQ,IAAI,GAAG,EAAE,WAAW,KAAK,CAAC;AAC9C,cAAM,4BAAU,MAAM,aAAaA,KAAI,CAAC;AACxC,YAAQ,IAAI,WAAW,IAAI;AAAA,EAC7B;AACF,CAAC;AAEH,QAAQ,MAAM;","names":["import_promises","yaml"]}
@@ -1,4 +1,5 @@
1
1
  // src/bin/action-yaml.ts
2
+ import { existsSync } from "node:fs";
2
3
  import { mkdir, watch, writeFile } from "node:fs/promises";
3
4
  import { dirname } from "node:path";
4
5
  import { Command } from "commander";
@@ -48,7 +49,7 @@ ${Object.keys(actionInputs ?? {}).map(
48
49
  }
49
50
  }`;
50
51
  return `// @ts-ignore
51
- import * as core from "@github/core";
52
+ import * as core from "@actions/core";
52
53
  import { Prettify, InputOptions, InputsValues } from "github-action-yaml"
53
54
 
54
55
  export const raw = ${JSON.stringify(action, null, 2)} as const;
@@ -84,17 +85,16 @@ var universalReadFile = async (path) => {
84
85
 
85
86
  // src/bin/action-yaml.ts
86
87
  var program = new Command();
87
- program.name("generate").description("generate typescript code from action.yaml file").argument("<file>", "output typescript file").option("-i, --input <file>", "input action.yaml file", "action.yml").option("--watch", "watch mode", false).action(async (file, options) => {
88
- const yaml = parse(await universalReadFile(options.input));
88
+ program.name("generate").description("generate typescript code from action.yaml file").argument("<file>", "output typescript file").option("-i, --input <file>", "input action.yaml file", "action.yaml").option("--watch", "watch mode", false).action(async (file, options) => {
89
+ const inputFile = existsSync(options.input) ? options.input : existsSync("action.yaml") ? "action.yaml" : "action.yml";
90
+ const yaml = parse(await universalReadFile(inputFile));
89
91
  await mkdir(dirname(file), { recursive: true });
90
92
  await writeFile(file, actionToType(yaml));
91
93
  if (!options.watch) {
92
94
  return;
93
95
  }
94
- for await (const _ of watch(options.input)) {
95
- const yaml2 = parse(
96
- await universalReadFile(options.input)
97
- );
96
+ for await (const _ of watch(inputFile)) {
97
+ const yaml2 = parse(await universalReadFile(inputFile));
98
98
  await mkdir(dirname(file), { recursive: true });
99
99
  await writeFile(file, actionToType(yaml2));
100
100
  console.log("Updated", file);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/bin/action-yaml.ts","../../src/action-to-type.ts","../../src/utils.ts"],"sourcesContent":["import { mkdir, watch, writeFile } from \"node:fs/promises\";\nimport { dirname } from \"node:path\";\nimport type { GithubAction } from \"@schemastore/github-action\";\nimport { Command } from \"commander\";\nimport { parse } from \"yaml\";\nimport { actionToType } from \"../action-to-type\";\nimport { universalReadFile } from \"../utils\";\n\nconst program = new Command();\n\nprogram\n .name(\"generate\")\n .description(\"generate typescript code from action.yaml file\")\n .argument(\"<file>\", \"output typescript file\")\n .option(\"-i, --input <file>\", \"input action.yaml file\", \"action.yml\")\n .option(\"--watch\", \"watch mode\", false)\n .action(async (file: string, options: { input: string; watch: boolean }) => {\n const yaml = parse(await universalReadFile(options.input)) as GithubAction;\n\n await mkdir(dirname(file), { recursive: true });\n await writeFile(file, actionToType(yaml));\n\n if (!options.watch) {\n return;\n }\n\n for await (const _ of watch(options.input)) {\n const yaml = parse(\n await universalReadFile(options.input),\n ) as GithubAction;\n\n await mkdir(dirname(file), { recursive: true });\n await writeFile(file, actionToType(yaml));\n console.log(\"Updated\", file);\n }\n });\n\nprogram.parse();\n","import type { GithubAction } from \"@schemastore/github-action\";\n\nexport const actionToType = (action: GithubAction) => {\n const actionInputs = action.inputs ?? {};\n\n const inputsType = `\\\nexport type Inputs<T extends InputOptions<typeof raw> = InputOptions<typeof raw>, V extends InputsValues<typeof raw, T> = InputsValues<typeof raw,T>> = {\n${Object.entries(actionInputs ?? {})\n .map(\n ([key, value]) => `\\\n /**\n * ${value.description}\n * \n${value.default ? ` * @default ${value.default}\\n` : \"\"}\\\n${value.deprecationMessage ? ` * @deprecated ${value.deprecationMessage}\\n` : \"\"}\\\n */\n '${key}'${value.required || typeof value.default !== \"undefined\" ? \"\" : \"?\"}: V[\"${key}\"];\\\n`,\n )\n .join(\"\\n\")}\n}`;\n\n const outputsType = `\\\nexport type Outputs = {\n${Object.entries(\n (action.outputs as Record<string, { description?: string }>) ?? {},\n)\n .map(\n ([key, value]) => `\\\n /**\n * ${value.description}\n * \n */\n '${key}'?: string;\\\n`,\n )\n .join(\"\\n\")}\n}`;\n\n const parseInputs = `\\\nconst getInput = {\n string: core.getInput,\n boolean: core.getBooleanInput,\n multiline: core.getMultilineInput,\n};\n\nexport const parseInputs = <T extends InputOptions<typeof raw>>(options?: T): Prettify<Inputs<T>> => {\n return {\n${Object.keys(actionInputs ?? {})\n .map(\n (key) =>\n ` \"${key}\": getInput[options?.[\"${key}\"]?.type ?? \"string\"](\"${key}\", {trimWhitespace: options?.cwd?.trimWhitespace}),`,\n )\n .join(\"\\n\")}\n } as Inputs<T>;\n}`;\n\n const dumpOutputs = `\\\nexport const dumpOutputs = (outputs: Partial<Outputs>) => {\n for (const [name, value] of Object.entries(outputs)) {\n core.setOutput(name, value)\n }\n}`;\n\n return `\\\n// @ts-ignore\nimport * as core from \"@github/core\";\nimport { Prettify, InputOptions, InputsValues } from \"github-action-yaml\"\n\nexport const raw = ${JSON.stringify(action, null, 2)} as const;\n\n${inputsType}\n\n${outputsType}\n\n${parseInputs}\n\n${dumpOutputs}\n`;\n};\n","import { readFile } from \"node:fs/promises\";\n\nfunction isUrl(input: string): boolean {\n try {\n const url = new URL(input);\n return url.protocol === \"http:\" || url.protocol === \"https:\";\n } catch {\n return false;\n }\n}\n\nexport const universalReadFile = async (path: string) => {\n if (isUrl(path)) {\n const response = await fetch(path);\n return response.text();\n }\n const file = await readFile(path, \"utf-8\");\n return file;\n};\n"],"mappings":";AAAA,SAAS,OAAO,OAAO,iBAAiB;AACxC,SAAS,eAAe;AAExB,SAAS,eAAe;AACxB,SAAS,aAAa;;;ACFf,IAAM,eAAe,CAAC,WAAyB;AACpD,QAAM,eAAe,OAAO,UAAU,CAAC;AAEvC,QAAM,aAAa;AAAA,EAEnB,OAAO,QAAQ,gBAAgB,CAAC,CAAC,EAChC;AAAA,IACC,CAAC,CAAC,KAAK,KAAK,MAAM;AAAA,OAEf,MAAM,WAAW;AAAA;AAAA,EAEtB,MAAM,UAAU,iBAAiB,MAAM,OAAO;AAAA,IAAO,EAAE,GACvD,MAAM,qBAAqB,oBAAoB,MAAM,kBAAkB;AAAA,IAAO,EAAE;AAAA,KAE7E,GAAG,IAAI,MAAM,YAAY,OAAO,MAAM,YAAY,cAAc,KAAK,GAAG,QAAQ,GAAG;AAAA,EAEtF,EACC,KAAK,IAAI,CAAC;AAAA;AAGX,QAAM,cAAc;AAAA,EAEpB,OAAO;AAAA,IACN,OAAO,WAAwD,CAAC;AAAA,EACnE,EACG;AAAA,IACC,CAAC,CAAC,KAAK,KAAK,MAAM;AAAA,OAEf,MAAM,WAAW;AAAA;AAAA;AAAA,KAGnB,GAAG;AAAA,EAEN,EACC,KAAK,IAAI,CAAC;AAAA;AAGX,QAAM,cAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASpB,OAAO,KAAK,gBAAgB,CAAC,CAAC,EAC7B;AAAA,IACC,CAAC,QACC,QAAQ,GAAG,0BAA0B,GAAG,0BAA0B,GAAG;AAAA,EACzE,EACC,KAAK,IAAI,CAAC;AAAA;AAAA;AAIX,QAAM,cAAc;AAAA;AAAA;AA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I,WAAW,IAAI;AAAA,EAC7B;AACF,CAAC;AAEH,QAAQ,MAAM;","names":["yaml"]}
1
+ {"version":3,"sources":["../../src/bin/action-yaml.ts","../../src/action-to-type.ts","../../src/utils.ts"],"sourcesContent":["import { existsSync } from \"node:fs\";\nimport { mkdir, watch, writeFile } from \"node:fs/promises\";\nimport { dirname } from \"node:path\";\nimport type { GithubAction } from \"@schemastore/github-action\";\nimport { Command } from \"commander\";\nimport { parse } from \"yaml\";\nimport { actionToType } from \"../action-to-type\";\nimport { universalReadFile } from \"../utils\";\n\nconst program = new Command();\n\nprogram\n .name(\"generate\")\n .description(\"generate typescript code from action.yaml file\")\n .argument(\"<file>\", \"output typescript file\")\n .option(\"-i, --input <file>\", \"input action.yaml file\", \"action.yaml\")\n .option(\"--watch\", \"watch mode\", false)\n .action(async (file: string, options: { input: string; watch: boolean }) => {\n const inputFile = existsSync(options.input)\n ? options.input\n : existsSync(\"action.yaml\")\n ? \"action.yaml\"\n : \"action.yml\";\n const yaml = parse(await universalReadFile(inputFile)) as GithubAction;\n\n await mkdir(dirname(file), { recursive: true });\n await writeFile(file, actionToType(yaml));\n\n if (!options.watch) {\n return;\n }\n\n for await (const _ of watch(inputFile)) {\n const yaml = parse(await universalReadFile(inputFile)) as GithubAction;\n\n await mkdir(dirname(file), { recursive: true });\n await writeFile(file, actionToType(yaml));\n console.log(\"Updated\", file);\n }\n });\n\nprogram.parse();\n","import type { GithubAction } from \"@schemastore/github-action\";\n\nexport const actionToType = (action: GithubAction) => {\n const actionInputs = action.inputs ?? {};\n\n const inputsType = `\\\nexport type Inputs<T extends InputOptions<typeof raw> = InputOptions<typeof raw>, V extends InputsValues<typeof raw, T> = InputsValues<typeof raw,T>> = {\n${Object.entries(actionInputs ?? {})\n .map(\n ([key, value]) => `\\\n /**\n * ${value.description}\n * \n${value.default ? ` * @default ${value.default}\\n` : \"\"}\\\n${value.deprecationMessage ? ` * @deprecated ${value.deprecationMessage}\\n` : \"\"}\\\n */\n '${key}'${value.required || typeof value.default !== \"undefined\" ? \"\" : \"?\"}: V[\"${key}\"];\\\n`,\n )\n .join(\"\\n\")}\n}`;\n\n const outputsType = `\\\nexport type Outputs = {\n${Object.entries(\n (action.outputs as Record<string, { description?: string }>) ?? {},\n)\n .map(\n ([key, value]) => `\\\n /**\n * ${value.description}\n * \n */\n '${key}'?: string;\\\n`,\n )\n .join(\"\\n\")}\n}`;\n\n const parseInputs = `\\\nconst getInput = {\n string: core.getInput,\n boolean: core.getBooleanInput,\n multiline: core.getMultilineInput,\n};\n\nexport const parseInputs = <T extends InputOptions<typeof raw>>(options?: T): Prettify<Inputs<T>> => {\n return {\n${Object.keys(actionInputs ?? {})\n .map(\n (key) =>\n ` \"${key}\": getInput[options?.[\"${key}\"]?.type ?? \"string\"](\"${key}\", {trimWhitespace: options?.cwd?.trimWhitespace}),`,\n )\n .join(\"\\n\")}\n } as Inputs<T>;\n}`;\n\n const dumpOutputs = `\\\nexport const dumpOutputs = (outputs: Partial<Outputs>) => {\n for (const [name, value] of Object.entries(outputs)) {\n core.setOutput(name, value)\n }\n}`;\n\n return `\\\n// @ts-ignore\nimport * as core from \"@actions/core\";\nimport { Prettify, InputOptions, InputsValues } from \"github-action-yaml\"\n\nexport const raw = ${JSON.stringify(action, null, 2)} as const;\n\n${inputsType}\n\n${outputsType}\n\n${parseInputs}\n\n${dumpOutputs}\n`;\n};\n","import { readFile } from \"node:fs/promises\";\n\nfunction isUrl(input: string): boolean {\n try {\n const url = new URL(input);\n return url.protocol === \"http:\" || url.protocol === \"https:\";\n } catch {\n return false;\n }\n}\n\nexport const universalReadFile = async (path: string) => {\n if (isUrl(path)) {\n const response = await fetch(path);\n return response.text();\n }\n const file = await readFile(path, \"utf-8\");\n return file;\n};\n"],"mappings":";AAAA,SAAS,kBAAkB;AAC3B,SAAS,OAAO,OAAO,iBAAiB;AACxC,SAAS,eAAe;AAExB,SAAS,eAAe;AACxB,SAAS,aAAa;;;ACHf,IAAM,eAAe,CAAC,WAAyB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WAAW,IAAI,aAAa;AAAA,EACtD,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEO,IAAM,oBAAoB,OAAO,SAAiB;AACvD,MAAI,MAAM,IAAI,GAAG;AACf,UAAM,WAAW,MAAM,MAAM,IAAI;AACjC,WAAO,SAAS,KAAK;AAAA,EACvB;AACA,QAAM,OAAO,MAAM,SAAS,MAAM,OAAO;AACzC,SAAO;AACT;;;AFTA,IAAM,UAAU,IAAI,QAAQ;AAE5B,QACG,KAAK,UAAU,EACf,YAAY,gDAAgD,EAC5D,SAAS,UAAU,wBAAwB,EAC3C,OAAO,sBAAsB,0BAA0B,aAAa,EACpE,OAAO,WAAW,cAAc,KAAK,EACrC,OAAO,OAAO,MAAc,YAA+C;AAC1E,QAAM,YAAY,WAAW,QAAQ,KAAK,IACtC,QAAQ,QACR,WAAW,aAAa,IACtB,gBACA;AACN,QAAM,OAAO,MAAM,MAAM,kBAAkB,SAAS,CAAC;AAErD,QAAM,MAAM,QAAQ,IAAI,GAAG,EAAE,WAAW,KAAK,CAAC;AAC9C,QAAM,UAAU,MAAM,aAAa,IAAI,CAAC;AAExC,MAAI,CAAC,QAAQ,OAAO;AAClB;AAAA,EACF;AAEA,mBAAiB,KAAK,MAAM,SAAS,GAAG;AACtC,UAAMA,QAAO,MAAM,MAAM,kBAAkB,SAAS,CAAC;AAErD,UAAM,MAAM,QAAQ,IAAI,GAAG,EAAE,WAAW,KAAK,CAAC;AAC9C,UAAM,UAAU,MAAM,aAAaA,KAAI,CAAC;AACxC,YAAQ,IAAI,WAAW,IAAI;AAAA,EAC7B;AACF,CAAC;AAEH,QAAQ,MAAM;","names":["yaml"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "github-action-yaml",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "github-action-yaml": "./dist/bin/action-yaml.js"
@@ -64,7 +64,7 @@ export const dumpOutputs = (outputs: Partial<Outputs>) => {
64
64
 
65
65
  return `\
66
66
  // @ts-ignore
67
- import * as core from "@github/core";
67
+ import * as core from "@actions/core";
68
68
  import { Prettify, InputOptions, InputsValues } from "github-action-yaml"
69
69
 
70
70
  export const raw = ${JSON.stringify(action, null, 2)} as const;
@@ -1,3 +1,4 @@
1
+ import { existsSync } from "node:fs";
1
2
  import { mkdir, watch, writeFile } from "node:fs/promises";
2
3
  import { dirname } from "node:path";
3
4
  import type { GithubAction } from "@schemastore/github-action";
@@ -12,10 +13,15 @@ program
12
13
  .name("generate")
13
14
  .description("generate typescript code from action.yaml file")
14
15
  .argument("<file>", "output typescript file")
15
- .option("-i, --input <file>", "input action.yaml file", "action.yml")
16
+ .option("-i, --input <file>", "input action.yaml file", "action.yaml")
16
17
  .option("--watch", "watch mode", false)
17
18
  .action(async (file: string, options: { input: string; watch: boolean }) => {
18
- const yaml = parse(await universalReadFile(options.input)) as GithubAction;
19
+ const inputFile = existsSync(options.input)
20
+ ? options.input
21
+ : existsSync("action.yaml")
22
+ ? "action.yaml"
23
+ : "action.yml";
24
+ const yaml = parse(await universalReadFile(inputFile)) as GithubAction;
19
25
 
20
26
  await mkdir(dirname(file), { recursive: true });
21
27
  await writeFile(file, actionToType(yaml));
@@ -24,10 +30,8 @@ program
24
30
  return;
25
31
  }
26
32
 
27
- for await (const _ of watch(options.input)) {
28
- const yaml = parse(
29
- await universalReadFile(options.input),
30
- ) as GithubAction;
33
+ for await (const _ of watch(inputFile)) {
34
+ const yaml = parse(await universalReadFile(inputFile)) as GithubAction;
31
35
 
32
36
  await mkdir(dirname(file), { recursive: true });
33
37
  await writeFile(file, actionToType(yaml));