@notation/factory-cli 0.1.2 → 0.1.5

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/commands/infra.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { existsSync } from "node:fs";
2
2
  import { join } from "node:path";
3
- import { loadConfig, shell } from "./shell.ts";
3
+ import { type HubConfig, loadConfig, shell } from "./shell.ts";
4
4
 
5
5
  const hubDir = () => {
6
6
  const dir = process.cwd();
@@ -14,7 +14,7 @@ const hubDir = () => {
14
14
  // node_modules, so Notation runs on bun.
15
15
  const notation = async (args: string) => {
16
16
  const dir = hubDir();
17
- const { loadEnv } = await loadConfig(dir);
17
+ const { loadEnv } = await loadConfig<HubConfig>(join(dir, "factory.config.ts"));
18
18
  await shell(`${loadEnv ? `${loadEnv} ` : ""}bun x --bun notation ${args} --pretty`, dir);
19
19
  };
20
20
 
package/commands/repo.ts CHANGED
@@ -4,7 +4,7 @@ import { createInterface } from "node:readline/promises";
4
4
  import { pathToFileURL } from "node:url";
5
5
  import { appName } from "@notation/factory-github/app-name";
6
6
  import { collectResourceGraph } from "@notation/resource";
7
- import { loadConfig, openBrowser, output } from "./shell.ts";
7
+ import { loadConfig, openBrowser, type OutpostCliConfig, output } from "./shell.ts";
8
8
 
9
9
  /** The repo's `owner/name`, from its `origin` remote on GitHub. */
10
10
  const githubRepo = async (dir: string) => {
@@ -14,10 +14,10 @@ const githubRepo = async (dir: string) => {
14
14
  return `${match[1]}/${match[2]}`;
15
15
  };
16
16
 
17
- /** The names of the GitHub connections that `.factory/config.ts` uses. */
18
- const githubConnections = async (config: string) => {
17
+ /** The names of the GitHub connections that `.factory/infra.ts` uses. */
18
+ const githubConnections = async (infra: string) => {
19
19
  const graph = await collectResourceGraph(async () => {
20
- await import(pathToFileURL(config).href);
20
+ await import(pathToFileURL(infra).href);
21
21
  });
22
22
  return graph.resourceGroups
23
23
  .filter((group) => group.type === "github/ConnectionRef")
@@ -34,30 +34,33 @@ const appSlug = (name: string) =>
34
34
  const gh = async <T>(path: string) =>
35
35
  JSON.parse(await output("gh", ["api", path])) as T;
36
36
 
37
- /** The outpost's directory: this one if it has `.factory/config.ts`, otherwise the root of its git repo. */
37
+ /** The outpost's directory: this one if it has `.factory/infra.ts`, otherwise the root of its git repo. */
38
38
  const outpostDir = async () => {
39
- if (existsSync(join(process.cwd(), ".factory", "config.ts"))) {
39
+ if (existsSync(join(process.cwd(), ".factory", "infra.ts"))) {
40
40
  return process.cwd();
41
41
  }
42
42
  const root = await output("git", ["rev-parse", "--show-toplevel"]);
43
- if (!existsSync(join(root, ".factory", "config.ts"))) {
44
- throw new Error(`There's no .factory/config.ts here or in ${root}.`);
43
+ if (!existsSync(join(root, ".factory", "infra.ts"))) {
44
+ throw new Error(`There's no .factory/infra.ts here or in ${root}.`);
45
45
  }
46
46
  return root;
47
47
  };
48
48
 
49
+ /** The outpost's `.factory/config.ts`. */
50
+ const outpostConfig = (dir: string) => loadConfig<OutpostCliConfig>(join(dir, ".factory", "config.ts"));
51
+
49
52
  /**
50
- * The outpost's repo: `given`, then `repo` in `factory.config.ts`, then the
53
+ * The outpost's repo: `given`, then `repo` in `.factory/config.ts`, then the
51
54
  * `origin` remote. The remote only names the outpost's repo when the outpost
52
55
  * is at the root of the git repo.
53
56
  */
54
57
  const outpostRepo = async (dir: string, given?: string) => {
55
- const repo = given ?? (await loadConfig(dir)).repo;
58
+ const repo = given ?? (await outpostConfig(dir)).repo;
56
59
  if (repo) return repo;
57
60
  const root = await output("git", ["rev-parse", "--show-toplevel"], dir);
58
61
  if (realpathSync(root) !== realpathSync(dir)) {
59
62
  throw new Error(
60
- `${dir} isn't the root of its git repo, so its origin remote may be another repo's. Pass --repo <owner/name>, or set repo in factory.config.ts.`,
63
+ `${dir} isn't the root of its git repo, so its origin remote may be another repo's. Pass --repo <owner/name>, or set repo in .factory/config.ts.`,
61
64
  );
62
65
  }
63
66
  return githubRepo(dir);
@@ -124,18 +127,17 @@ export const repoStatus = async ({ repo: given }: { repo?: string }) => {
124
127
  */
125
128
  export const repoInstall = async ({ repo: given }: { repo?: string }) => {
126
129
  const dir = await outpostDir();
127
- const config = join(dir, ".factory", "config.ts");
128
130
  const repo = await outpostRepo(dir, given);
129
131
  const since = new Date();
130
- const names = await githubConnections(config);
132
+ const names = await githubConnections(join(dir, ".factory", "infra.ts"));
131
133
  if (names.length === 0) {
132
- console.log(".factory/config.ts uses no GitHub connection, so there's nothing to install.");
134
+ console.log(".factory/infra.ts uses no GitHub connection, so there's nothing to install.");
133
135
  return;
134
136
  }
135
- const { hub } = await loadConfig(dir);
137
+ const { hub } = await outpostConfig(dir);
136
138
  if (!hub) {
137
139
  throw new Error(
138
- `Set hub in factory.config.ts to the hub's Notation app and stage, such as hub: { app: "factory", stage: "prod" }, which name its GitHub Apps.`,
140
+ `Set hub in .factory/config.ts to the hub's Notation app and stage, such as hub: { app: "factory", stage: "prod" }, which name its GitHub Apps.`,
139
141
  );
140
142
  }
141
143
  const { id: repoId, owner } = await gh<{ id: number; owner: { id: number } }>(`repos/${repo}`);
package/commands/shell.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import { execFile, spawn } from "node:child_process";
2
2
  import { existsSync } from "node:fs";
3
- import { join } from "node:path";
4
3
  import { pathToFileURL } from "node:url";
5
4
 
6
5
  /** Runs `command` in a shell, with the terminal's input and output. */
@@ -35,18 +34,22 @@ export const openBrowser = (url: string) => {
35
34
  execFile(cmd, [url], () => {});
36
35
  };
37
36
 
38
- export type FactoryConfig = {
37
+ /** A hub's `factory.config.ts`. */
38
+ export type HubConfig = {
39
39
  /** A command prefix that sets credentials in the environment, such as `op run --env-file .env --`. */
40
40
  loadEnv?: string;
41
- /** An outpost's repo, as `owner/name`, when its git remote doesn't name it. */
41
+ };
42
+
43
+ /** An outpost's `.factory/config.ts`. */
44
+ export type OutpostCliConfig = {
45
+ /** The outpost's repo, as `owner/name`, when its git remote doesn't name it. */
42
46
  repo?: string;
43
- /** The hub an outpost subscribes to: its Notation app and stage, which name the hub's GitHub Apps. */
47
+ /** The hub the outpost subscribes to: its Notation app and stage, which name the hub's GitHub Apps. */
44
48
  hub?: { app: string; stage: string };
45
49
  };
46
50
 
47
- /** Reads `factory.config.ts` in `dir`, if there is one. */
48
- export const loadConfig = async (dir: string): Promise<FactoryConfig> => {
49
- const file = join(dir, "factory.config.ts");
50
- if (!existsSync(file)) return {};
51
- return ((await import(pathToFileURL(file).href)).default ?? {}) as FactoryConfig;
51
+ /** Reads the default export of the config file at `file`, if there is one. */
52
+ export const loadConfig = async <T>(file: string): Promise<T> => {
53
+ if (!existsSync(file)) return {} as T;
54
+ return ((await import(pathToFileURL(file).href)).default ?? {}) as T;
52
55
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@notation/factory-cli",
3
- "version": "0.1.2",
3
+ "version": "0.1.5",
4
4
  "author": "Daniel Grant",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -20,7 +20,7 @@
20
20
  "access": "public"
21
21
  },
22
22
  "dependencies": {
23
- "@notation/resource": "0.28.0",
24
- "@notation/factory-github": "0.1.2"
23
+ "@notation/resource": "0.28.1",
24
+ "@notation/factory-github": "0.1.5"
25
25
  }
26
26
  }