@o3co/create-auth-policy-verifier 0.3.1

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/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 1o1 Co. Ltd.
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.ja.md ADDED
@@ -0,0 +1,94 @@
1
+ # @o3co/create-auth-policy-verifier
2
+
3
+ auth.policy-verifier 用の CLI スキャフォルダーです。組み込みテンプレートから新しいスタンドアロンサーバープロジェクトを生成します。
4
+
5
+ ## 使い方
6
+
7
+ ```sh
8
+ npx @o3co/create-auth-policy-verifier <project-name> [--dir <dir-name>]
9
+ ```
10
+
11
+ `<project-name>` はスコープ付き npm 名 (`@scope/pkg`) とスコープなしの名前 (`pkg`) のどちらでも指定できます。
12
+
13
+ スコープなしの例:
14
+
15
+ ```sh
16
+ npx @o3co/create-auth-policy-verifier my-verifier
17
+ cd my-verifier
18
+ npm install
19
+ npm run debug
20
+ ```
21
+
22
+ スコープ付きの例(ディレクトリ名はパッケージ部分がデフォルト):
23
+
24
+ ```sh
25
+ npx @o3co/create-auth-policy-verifier @my-org/auth.policy-verifier
26
+ cd auth.policy-verifier
27
+ npm install
28
+ npm run debug
29
+ ```
30
+
31
+ `--dir` でディレクトリ名を明示指定:
32
+
33
+ ```sh
34
+ npx @o3co/create-auth-policy-verifier @my-org/auth.policy-verifier --dir verifier
35
+ cd verifier
36
+ ```
37
+
38
+ ## 処理内容
39
+
40
+ 1. `<project-name>` を検証する(バリデーションルール参照)。
41
+ 2. 生成先ディレクトリ名を決定する: `--dir <value>` が指定されていればその値、そうでなければスコープ付き名のパッケージ部分、最終的には入力値そのもの。
42
+ 3. 生成先ディレクトリがすでに存在する場合はエラーを出力して終了する。
43
+ 4. `templates/standalone/` を生成先ディレクトリにコピーする(`node_modules/` と `dist/` は除外)。
44
+ 5. `package.json` を書き換える: `name` を `<project-name>` をそのまま設定し(スコープを保持)、`private` を削除し、`workspace:*` のバージョン参照を `templates/versions.json` の公開 semver バージョンに置き換える。
45
+ 6. 次のステップの手順を表示する。
46
+
47
+ ## バリデーションルール
48
+
49
+ `<project-name>` は以下のいずれかに一致する必要があります:
50
+
51
+ - スコープなし: `^[a-z0-9][a-z0-9-._~]*$`
52
+ - スコープ付き: `^@[a-z0-9][a-z0-9-._~]*/[a-z0-9][a-z0-9-._~]*$`
53
+
54
+ いずれも空文字・`.`・`..` は不可、最大 214 文字。
55
+
56
+ `--dir <value>` はスコープなしのパターンと同じ制約です。
57
+
58
+ ## 既知の制約
59
+
60
+ 内包されているテンプレートの `README.md` / `README.ja.md` の見出しは `@o3co/auth-policy-verifier-standalone` のままです。スコープ付きでプロジェクトを生成した場合、この見出しは生成された `package.json` の `name` と一致しません。必要に応じて手動で修正してください。
61
+
62
+ ## 生成される構造
63
+
64
+ ```
65
+ <project-name>/
66
+ ├── config/
67
+ │ └── application.conf # HOCON 設定ファイル(環境変数で上書き可)
68
+ ├── src/
69
+ │ └── main.mts # コンポジションルート — 設定を読み込みサーバーを起動する
70
+ ├── Dockerfile
71
+ ├── Makefile
72
+ ├── docker-compose.yml
73
+ ├── docker-compose.test.yml
74
+ ├── package.json
75
+ └── tsconfig.json
76
+ ```
77
+
78
+ ## プログラム API
79
+
80
+ スキャフォルダーは内部実装をエクスポートしており、プログラムから利用できます。
81
+
82
+ ```ts
83
+ import { scaffold, main } from "@o3co/create-auth-policy-verifier";
84
+ ```
85
+
86
+ | エクスポート | シグネチャ | 説明 |
87
+ |---|---|---|
88
+ | `scaffold` | `(targetDir: string, projectName: string): void` | テンプレートをコピーして `package.json` を書き換える |
89
+ | `main` | `(): void` | CLI エントリポイント — `process.argv` を解析して `scaffold` を呼び出す |
90
+
91
+ ## 関連
92
+
93
+ - [`@o3co/auth-policy-verifier-standalone`](../templates/standalone) — このツールが生成するテンプレート
94
+ - [`@o3co/auth.policy-verifier.server`](../packages/server) — 生成されたプロジェクトが使用する Express アプリファクトリ
package/README.md ADDED
@@ -0,0 +1,94 @@
1
+ # @o3co/create-auth-policy-verifier
2
+
3
+ CLI scaffolder for auth.policy-verifier. Generates a new standalone server project from the built-in template.
4
+
5
+ ## Usage
6
+
7
+ ```sh
8
+ npx @o3co/create-auth-policy-verifier <project-name> [--dir <dir-name>]
9
+ ```
10
+
11
+ `<project-name>` may be either a scoped npm name (`@scope/pkg`) or an unscoped name (`pkg`).
12
+
13
+ Unscoped example:
14
+
15
+ ```sh
16
+ npx @o3co/create-auth-policy-verifier my-verifier
17
+ cd my-verifier
18
+ npm install
19
+ npm run debug
20
+ ```
21
+
22
+ Scoped example (directory defaults to the package portion):
23
+
24
+ ```sh
25
+ npx @o3co/create-auth-policy-verifier @my-org/auth.policy-verifier
26
+ cd auth.policy-verifier
27
+ npm install
28
+ npm run debug
29
+ ```
30
+
31
+ Override the directory name with `--dir`:
32
+
33
+ ```sh
34
+ npx @o3co/create-auth-policy-verifier @my-org/auth.policy-verifier --dir verifier
35
+ cd verifier
36
+ ```
37
+
38
+ ## What It Does
39
+
40
+ 1. Validates `<project-name>` (see Validation Rules).
41
+ 2. Derives the target directory name: `--dir <value>` if given, else the unscoped part of a scoped name, else the name itself.
42
+ 3. Aborts with an error if the target directory already exists.
43
+ 4. Copies `templates/standalone/` to the target directory, excluding `node_modules/` and `dist/`.
44
+ 5. Rewrites `package.json`: sets `name` to `<project-name>` verbatim (scope-preserving), removes `private`, and replaces `workspace:*` dependency versions with published semver versions from `templates/versions.json`.
45
+ 6. Prints next-step instructions.
46
+
47
+ ## Validation Rules
48
+
49
+ `<project-name>` must match one of:
50
+
51
+ - Unscoped: `^[a-z0-9][a-z0-9-._~]*$`
52
+ - Scoped: `^@[a-z0-9][a-z0-9-._~]*/[a-z0-9][a-z0-9-._~]*$`
53
+
54
+ Both forms must be non-empty, not `.` or `..`, and ≤ 214 characters.
55
+
56
+ `--dir <value>` must match the unscoped pattern above (same constraints).
57
+
58
+ ## Known Limitations
59
+
60
+ The bundled template's `README.md` / `README.ja.md` still carry the upstream title `@o3co/auth-policy-verifier-standalone`. When generating a scoped project, that title will not match your `package.json` name; edit it manually if it matters for your use case.
61
+
62
+ ## Generated Structure
63
+
64
+ ```
65
+ <project-name>/
66
+ ├── config/
67
+ │ └── application.conf # HOCON config (env var overrides)
68
+ ├── src/
69
+ │ └── main.mts # Composition root — loads config and starts server
70
+ ├── Dockerfile
71
+ ├── Makefile
72
+ ├── docker-compose.yml
73
+ ├── docker-compose.test.yml
74
+ ├── package.json
75
+ └── tsconfig.json
76
+ ```
77
+
78
+ ## Programmatic API
79
+
80
+ The scaffolder also exports its internals for programmatic use:
81
+
82
+ ```ts
83
+ import { scaffold, main } from "@o3co/create-auth-policy-verifier";
84
+ ```
85
+
86
+ | Export | Signature | Description |
87
+ |---|---|---|
88
+ | `scaffold` | `(targetDir: string, projectName: string): void` | Copies the template and rewrites `package.json` |
89
+ | `main` | `(): void` | CLI entry point — parses `process.argv` and calls `scaffold` |
90
+
91
+ ## See Also
92
+
93
+ - [`@o3co/auth-policy-verifier-standalone`](../templates/standalone) — the template that this tool generates
94
+ - [`@o3co/auth.policy-verifier.server`](../packages/server) — Express app factory used by the generated project
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.test.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.test.d.mts","sourceRoot":"","sources":["../../src/__tests__/index.test.mts"],"names":[],"mappings":""}
@@ -0,0 +1,213 @@
1
+ // SPDX-FileCopyrightText: 2026 1o1 Co. Ltd.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync } from "node:fs";
4
+ import { tmpdir } from "node:os";
5
+ import { join } from "node:path";
6
+ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
7
+ import { isValidDirName, isValidProjectName, main, scaffold } from "../index.mjs";
8
+ describe("scaffold", () => {
9
+ let tempDir;
10
+ beforeEach(() => {
11
+ tempDir = mkdtempSync(join(tmpdir(), "create-policy-verifier-test-"));
12
+ });
13
+ afterEach(() => {
14
+ rmSync(tempDir, { recursive: true, force: true });
15
+ });
16
+ it("copies template files to target directory", () => {
17
+ const targetDir = join(tempDir, "verifier");
18
+ scaffold(targetDir, "verifier");
19
+ expect(existsSync(join(targetDir, "package.json"))).toBe(true);
20
+ expect(existsSync(join(targetDir, "tsconfig.json"))).toBe(true);
21
+ expect(existsSync(join(targetDir, "src", "main.mts"))).toBe(true);
22
+ expect(existsSync(join(targetDir, "config", "application.conf"))).toBe(true);
23
+ });
24
+ it("rewrites package.json name to project name", () => {
25
+ const targetDir = join(tempDir, "verifier");
26
+ scaffold(targetDir, "verifier");
27
+ const pkg = JSON.parse(readFileSync(join(targetDir, "package.json"), "utf-8"));
28
+ expect(pkg.name).toBe("verifier");
29
+ });
30
+ it("replaces all workspace:* dependencies with caret versions", () => {
31
+ const targetDir = join(tempDir, "verifier");
32
+ scaffold(targetDir, "verifier");
33
+ const pkg = JSON.parse(readFileSync(join(targetDir, "package.json"), "utf-8"));
34
+ for (const section of ["dependencies", "devDependencies", "peerDependencies"]) {
35
+ const deps = pkg[section];
36
+ if (!deps)
37
+ continue;
38
+ for (const [name, version] of Object.entries(deps)) {
39
+ expect(version, `${section}.${name} should not be workspace:*`).not.toBe("workspace:*");
40
+ }
41
+ }
42
+ });
43
+ it("removes private field from package.json", () => {
44
+ const targetDir = join(tempDir, "verifier");
45
+ scaffold(targetDir, "verifier");
46
+ const pkg = JSON.parse(readFileSync(join(targetDir, "package.json"), "utf-8"));
47
+ expect(pkg.private).toBeUndefined();
48
+ });
49
+ it("writes scoped project name verbatim into package.json", () => {
50
+ const targetDir = join(tempDir, "auth.policy-verifier");
51
+ scaffold(targetDir, "@piratis-blossoms/auth.policy-verifier");
52
+ const pkg = JSON.parse(readFileSync(join(targetDir, "package.json"), "utf-8"));
53
+ expect(pkg.name).toBe("@piratis-blossoms/auth.policy-verifier");
54
+ });
55
+ });
56
+ describe("isValidProjectName", () => {
57
+ it.each([
58
+ ["my-verifier"],
59
+ ["auth.policy-verifier"],
60
+ ["a"],
61
+ ["foo_bar~baz.1"],
62
+ ["@piratis-blossoms/auth.policy-verifier"],
63
+ ["@foo-bar/baz_qux~1"],
64
+ ])("accepts %s", (name) => {
65
+ expect(isValidProjectName(name)).toBe(true);
66
+ });
67
+ it.each([
68
+ [""],
69
+ ["."],
70
+ [".."],
71
+ ["UPPER"],
72
+ ["with space"],
73
+ ["with/slash"],
74
+ ["with\\back"],
75
+ ["@"],
76
+ ["@/"],
77
+ ["@scope"],
78
+ ["@/pkg"],
79
+ ["@scope/"],
80
+ ["@scope//pkg"],
81
+ ["@SCOPE/pkg"],
82
+ ["a".repeat(215)],
83
+ ])("rejects %s", (name) => {
84
+ expect(isValidProjectName(name)).toBe(false);
85
+ });
86
+ });
87
+ describe("isValidDirName", () => {
88
+ it.each([
89
+ ["my-verifier"],
90
+ ["auth.policy-verifier"],
91
+ ["a"],
92
+ ["foo_bar~baz.1"],
93
+ ])("accepts %s", (name) => {
94
+ expect(isValidDirName(name)).toBe(true);
95
+ });
96
+ it.each([
97
+ [""],
98
+ ["."],
99
+ [".."],
100
+ ["@scope/pkg"],
101
+ ["with/slash"],
102
+ ["with\\back"],
103
+ ["@piratis-blossoms"],
104
+ ["UPPER"],
105
+ ["a".repeat(215)],
106
+ ])("rejects %s", (name) => {
107
+ expect(isValidDirName(name)).toBe(false);
108
+ });
109
+ });
110
+ describe("main (argv parsing and directory derivation)", () => {
111
+ let cwdBackup;
112
+ let workdir;
113
+ let argvBackup;
114
+ beforeEach(() => {
115
+ cwdBackup = process.cwd();
116
+ workdir = mkdtempSync(join(tmpdir(), "create-policy-verifier-main-"));
117
+ process.chdir(workdir);
118
+ argvBackup = process.argv;
119
+ });
120
+ afterEach(() => {
121
+ process.chdir(cwdBackup);
122
+ process.argv = argvBackup;
123
+ rmSync(workdir, { recursive: true, force: true });
124
+ });
125
+ const runMain = (args) => {
126
+ process.argv = ["node", "cli", ...args];
127
+ const exitSpy = vi.spyOn(process, "exit").mockImplementation(((code) => {
128
+ throw new Error(`__exit__:${code ?? 0}`);
129
+ }));
130
+ const errSpy = vi.spyOn(console, "error").mockImplementation(() => { });
131
+ const logSpy = vi.spyOn(console, "log").mockImplementation(() => { });
132
+ let exitCode = 0;
133
+ try {
134
+ main();
135
+ }
136
+ catch (e) {
137
+ const m = /__exit__:(\d+)/.exec(e.message);
138
+ exitCode = m ? Number(m[1]) : null;
139
+ }
140
+ const stderr = errSpy.mock.calls.map((c) => c.join(" ")).join("\n");
141
+ exitSpy.mockRestore();
142
+ errSpy.mockRestore();
143
+ logSpy.mockRestore();
144
+ return { exitCode, stderr };
145
+ };
146
+ it("unscoped name: dir = name, pkg.name = name", () => {
147
+ const r = runMain(["my-verifier"]);
148
+ expect(r.exitCode).toBe(0);
149
+ const pkg = JSON.parse(readFileSync(join(workdir, "my-verifier", "package.json"), "utf-8"));
150
+ expect(pkg.name).toBe("my-verifier");
151
+ });
152
+ it("scoped name: dir = pkg part, pkg.name = full scoped", () => {
153
+ const r = runMain(["@piratis-blossoms/auth.policy-verifier"]);
154
+ expect(r.exitCode).toBe(0);
155
+ const pkg = JSON.parse(readFileSync(join(workdir, "auth.policy-verifier", "package.json"), "utf-8"));
156
+ expect(pkg.name).toBe("@piratis-blossoms/auth.policy-verifier");
157
+ });
158
+ it("scoped name with --dir <val>: dir = val, pkg.name = full scoped", () => {
159
+ const r = runMain(["@piratis-blossoms/auth.policy-verifier", "--dir", "verifier"]);
160
+ expect(r.exitCode).toBe(0);
161
+ const pkg = JSON.parse(readFileSync(join(workdir, "verifier", "package.json"), "utf-8"));
162
+ expect(pkg.name).toBe("@piratis-blossoms/auth.policy-verifier");
163
+ });
164
+ it("scoped name with --dir=<val>: dir = val, pkg.name = full scoped", () => {
165
+ const r = runMain(["@piratis-blossoms/auth.policy-verifier", "--dir=verifier2"]);
166
+ expect(r.exitCode).toBe(0);
167
+ const pkg = JSON.parse(readFileSync(join(workdir, "verifier2", "package.json"), "utf-8"));
168
+ expect(pkg.name).toBe("@piratis-blossoms/auth.policy-verifier");
169
+ });
170
+ it("unscoped name with --dir <val>: dir = val, pkg.name = unscoped", () => {
171
+ const r = runMain(["my-verifier", "--dir", "custom"]);
172
+ expect(r.exitCode).toBe(0);
173
+ const pkg = JSON.parse(readFileSync(join(workdir, "custom", "package.json"), "utf-8"));
174
+ expect(pkg.name).toBe("my-verifier");
175
+ });
176
+ it("flags before positional: --dir custom my-verifier", () => {
177
+ const r = runMain(["--dir", "custom", "my-verifier"]);
178
+ expect(r.exitCode).toBe(0);
179
+ const pkg = JSON.parse(readFileSync(join(workdir, "custom", "package.json"), "utf-8"));
180
+ expect(pkg.name).toBe("my-verifier");
181
+ });
182
+ it.each([
183
+ { case: "no args", args: [] },
184
+ { case: "two positionals", args: ["foo", "bar"] },
185
+ { case: "dot", args: ["."] },
186
+ { case: "dotdot", args: [".."] },
187
+ { case: "backslash in name", args: ["back\\slash"] },
188
+ { case: "empty scope", args: ["@/pkg"] },
189
+ { case: "empty pkg", args: ["@scope/"] },
190
+ { case: "double slash", args: ["@scope//pkg"] },
191
+ { case: "name too long", args: ["a".repeat(215)] },
192
+ { case: "--dir invalid (dot)", args: ["foo", "--dir", "."] },
193
+ { case: "--dir invalid (slash)", args: ["foo", "--dir", "a/b"] },
194
+ { case: "--dir invalid (at)", args: ["foo", "--dir", "@foo"] },
195
+ { case: "--dir invalid (back)", args: ["foo", "--dir", "a\\b"] },
196
+ { case: "--dir empty space form", args: ["foo", "--dir", ""] },
197
+ { case: "--dir empty equals form", args: ["foo", "--dir="] },
198
+ { case: "--dir missing value", args: ["foo", "--dir"] },
199
+ { case: "--dir duplicated", args: ["foo", "--dir", "a", "--dir", "b"] },
200
+ { case: "unknown flag", args: ["foo", "--unknown"] },
201
+ { case: "literal double-dash", args: ["foo", "--"] },
202
+ ])("rejects: $case", ({ args }) => {
203
+ const r = runMain(args);
204
+ expect(r.exitCode).toBe(1);
205
+ expect(r.stderr.length).toBeGreaterThan(0);
206
+ });
207
+ it("target directory already exists", () => {
208
+ mkdirSync(join(workdir, "foo"));
209
+ const r = runMain(["foo"]);
210
+ expect(r.exitCode).toBe(1);
211
+ expect(r.stderr.length).toBeGreaterThan(0);
212
+ });
213
+ });
package/dist/cli.d.mts ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=cli.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.mts","sourceRoot":"","sources":["../src/cli.mts"],"names":[],"mappings":""}
package/dist/cli.mjs ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env node
2
+ // SPDX-FileCopyrightText: 2026 1o1 Co. Ltd.
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ import { main } from "./index.mjs";
5
+ main();
@@ -0,0 +1,18 @@
1
+ export declare const isValidProjectName: (name: string) => boolean;
2
+ export declare const isValidDirName: (name: string) => boolean;
3
+ /**
4
+ * Copies the bundled standalone template into `targetDir`, rewrites
5
+ * `package.json` with the new `projectName`, and replaces every `workspace:*`
6
+ * dependency with the concrete published version from `versions.json`.
7
+ *
8
+ * Throws if the template directory is missing (unprebuilt) or if any
9
+ * workspace dependency is not pinned in `versions.json`.
10
+ */
11
+ export declare const scaffold: (targetDir: string, projectName: string) => void;
12
+ /**
13
+ * CLI entry point: parses argv, validates project name and optional --dir flag,
14
+ * ensures the target directory does not exist, and scaffolds the template.
15
+ * Exits with non-zero on any validation failure.
16
+ */
17
+ export declare const main: () => void;
18
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.mts"],"names":[],"mappings":"AA2BA,eAAO,MAAM,kBAAkB,GAAI,MAAM,MAAM,KAAG,OAIjD,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,MAAM,MAAM,KAAG,OAI7C,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,QAAQ,GAAI,WAAW,MAAM,EAAE,aAAa,MAAM,KAAG,IA0CjE,CAAC;AAqDF;;;;GAIG;AACH,eAAO,MAAM,IAAI,QAAO,IA4CvB,CAAC"}