@open-nodo/cli 0.6.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/LICENSE +202 -0
- package/README.md +19 -0
- package/bin/nodo.js +35 -0
- package/package.json +35 -0
- package/src/add.js +91 -0
- package/src/console.js +67 -0
- package/src/deploy.js +28 -0
- package/src/init.js +150 -0
- package/src/module-registry.js +45 -0
- package/src/project-files.js +87 -0
- package/src/versions.generated.json +28 -0
- package/template/.env.example +15 -0
- package/template/README.md +35 -0
- package/template/app/api/health/route.ts +7 -0
- package/template/app/globals.css +107 -0
- package/template/app/layout.tsx +16 -0
- package/template/app/page.tsx +87 -0
- package/template/gitignore +12 -0
- package/template/instrumentation.ts +10 -0
- package/template/next-env.d.ts +6 -0
- package/template/next.config.ts +12 -0
- package/template/package.json +29 -0
- package/template/src/lib/keystore.ts +71 -0
- package/template/src/lib/nodo.ts +94 -0
- package/template/tsconfig.json +41 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# @open-nodo/cli
|
|
2
|
+
|
|
3
|
+
Scaffolds a self-hosted Open Nodo instance and installs supported public
|
|
4
|
+
modules.
|
|
5
|
+
|
|
6
|
+
```sh
|
|
7
|
+
export NODE_AUTH_TOKEN=$(gh auth token) # GitHub Packages: read:packages
|
|
8
|
+
npx @open-nodo/cli init <selection-token> [directory]
|
|
9
|
+
npx @open-nodo/cli add accounting
|
|
10
|
+
npx @open-nodo/cli add patrimony
|
|
11
|
+
npx @open-nodo/cli add donors
|
|
12
|
+
npx @open-nodo/cli add beneficiaries
|
|
13
|
+
npx @open-nodo/cli add members
|
|
14
|
+
npx @open-nodo/cli add codec-onlus
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Use `--public-npm` only after the packages have been released on npmjs. The
|
|
18
|
+
scaffold writes the one-shot selection token to an ignored `.env`; its first Git
|
|
19
|
+
commit never contains that credential.
|
package/bin/nodo.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Nodo self-host CLI — argument parsing and dispatch only. Each command lives in src/.
|
|
4
|
+
*
|
|
5
|
+
* npx @open-nodo/cli init <selection-token> [dir] [--public-npm]
|
|
6
|
+
* npx @open-nodo/cli add <module>[@version]
|
|
7
|
+
* npx @open-nodo/cli deploy [--target vercel]
|
|
8
|
+
*
|
|
9
|
+
* Registry (dual-mode until the public npm cutover):
|
|
10
|
+
* Default: write scaffold .npmrc → GitHub Packages (NODE_AUTH_TOKEN required).
|
|
11
|
+
* --public-npm / OPENNODO_PUBLIC_NPM=1: no .npmrc (after packages land on npmjs).
|
|
12
|
+
* Dependency lines are always @open-nodo/* either way.
|
|
13
|
+
*/
|
|
14
|
+
import { usage } from "../src/console.js";
|
|
15
|
+
import { cmdInit } from "../src/init.js";
|
|
16
|
+
import { cmdAdd } from "../src/add.js";
|
|
17
|
+
import { cmdDeploy } from "../src/deploy.js";
|
|
18
|
+
|
|
19
|
+
const [cmd, ...rest] = process.argv.slice(2).filter((a) => a !== "--public-npm");
|
|
20
|
+
|
|
21
|
+
if (!cmd || cmd === "-h" || cmd === "--help") usage(0);
|
|
22
|
+
|
|
23
|
+
if (cmd === "init") {
|
|
24
|
+
const [token, dirArg] = rest;
|
|
25
|
+
if (!token) usage(1);
|
|
26
|
+
cmdInit(token, dirArg);
|
|
27
|
+
} else if (cmd === "add") {
|
|
28
|
+
cmdAdd(rest[0]);
|
|
29
|
+
} else if (cmd === "deploy") {
|
|
30
|
+
const target = rest[0] === "--target" ? rest[1] : rest[0];
|
|
31
|
+
cmdDeploy(target || "vercel");
|
|
32
|
+
} else {
|
|
33
|
+
console.error(` Unknown command: ${cmd}`);
|
|
34
|
+
usage(1);
|
|
35
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@open-nodo/cli",
|
|
3
|
+
"version": "0.6.0",
|
|
4
|
+
"description": "Self-host scaffolder and installer for supported Open Nodo modules.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"bin": {
|
|
8
|
+
"nodo": "bin/nodo.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"bin",
|
|
12
|
+
"src",
|
|
13
|
+
"template"
|
|
14
|
+
],
|
|
15
|
+
"engines": {
|
|
16
|
+
"node": ">=20.11"
|
|
17
|
+
},
|
|
18
|
+
"publishConfig": {
|
|
19
|
+
"access": "public"
|
|
20
|
+
},
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/Eddy1919/open-nodo.git",
|
|
24
|
+
"directory": "packages/cli"
|
|
25
|
+
},
|
|
26
|
+
"homepage": "https://github.com/Eddy1919/open-nodo#readme",
|
|
27
|
+
"bugs": {
|
|
28
|
+
"url": "https://github.com/Eddy1919/open-nodo/issues"
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"bundle-template": "node scripts/bundle-template.mjs",
|
|
32
|
+
"sync-registry": "node scripts/sync-registry.mjs",
|
|
33
|
+
"test": "vitest run"
|
|
34
|
+
}
|
|
35
|
+
}
|
package/src/add.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/** `nodo add <module>[@version]` — install a supported module into an existing app. */
|
|
2
|
+
import { copyFileSync, existsSync, mkdirSync, readdirSync } from "node:fs";
|
|
3
|
+
import { spawnSync } from "node:child_process";
|
|
4
|
+
import { basename, join } from "node:path";
|
|
5
|
+
import { checkRegistryAuth, die, usage } from "./console.js";
|
|
6
|
+
import { MODULE_PACKAGES } from "./module-registry.js";
|
|
7
|
+
import { parseModuleSpec, readModulesJson, writeModulesJson, writeProjectNpmrc } from "./project-files.js";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Copy any Prisma schema fragments the package ships into the app's prisma/ directory.
|
|
11
|
+
* An existing file is never overwritten — the copy lands as `.new` for the operator to merge,
|
|
12
|
+
* because the app's fragment may carry local edits.
|
|
13
|
+
*/
|
|
14
|
+
function copyPrismaFragments(cwd, pkgName) {
|
|
15
|
+
try {
|
|
16
|
+
const pkgRoot = join(cwd, "node_modules", ...pkgName.split("/"));
|
|
17
|
+
const prismaDir = join(pkgRoot, "prisma");
|
|
18
|
+
const fragments = existsSync(prismaDir)
|
|
19
|
+
? readdirSync(prismaDir).filter((f) => f.endsWith(".prisma"))
|
|
20
|
+
: [];
|
|
21
|
+
if (fragments.length === 0) {
|
|
22
|
+
console.log(" · No Prisma fragment in package — skip schema copy.");
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const destDir = join(cwd, "prisma");
|
|
26
|
+
mkdirSync(destDir, { recursive: true });
|
|
27
|
+
for (const f of fragments) {
|
|
28
|
+
const dest = join(destDir, f);
|
|
29
|
+
if (existsSync(dest)) {
|
|
30
|
+
copyFileSync(join(prismaDir, f), `${dest}.new`);
|
|
31
|
+
console.log(` ⚠ ${dest} exists — package copy → ${basename(dest)}.new`);
|
|
32
|
+
} else {
|
|
33
|
+
copyFileSync(join(prismaDir, f), dest);
|
|
34
|
+
console.log(` ✓ Prisma fragment → ${dest}`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
console.log(" Ensure prisma multi-file schema points at prisma/ then: npx prisma generate");
|
|
38
|
+
} catch (e) {
|
|
39
|
+
die(`Could not copy Prisma fragment: ${e instanceof Error ? e.message : e}`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function cmdAdd(spec) {
|
|
44
|
+
if (!spec) usage(1);
|
|
45
|
+
const usePublicNpm = checkRegistryAuth();
|
|
46
|
+
|
|
47
|
+
const { key, version } = parseModuleSpec(spec);
|
|
48
|
+
const pkgName = MODULE_PACKAGES[key] ?? null;
|
|
49
|
+
if (!pkgName) {
|
|
50
|
+
die(`Unknown or STAGED module "${key}". Installable: ${Object.keys(MODULE_PACKAGES).join(", ")}.`);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const cwd = process.cwd();
|
|
54
|
+
if (!existsSync(join(cwd, "package.json"))) die("No package.json in cwd — run this inside your Nodo app.");
|
|
55
|
+
|
|
56
|
+
if (!usePublicNpm && !existsSync(join(cwd, ".npmrc"))) {
|
|
57
|
+
writeProjectNpmrc(cwd);
|
|
58
|
+
console.log(" ✓ wrote .npmrc for GitHub Packages");
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const depSpec = version ? `${pkgName}@${version}` : pkgName;
|
|
62
|
+
console.log(`\n Nodo — add module ${key}`);
|
|
63
|
+
console.log(` Package: ${depSpec}\n`);
|
|
64
|
+
|
|
65
|
+
const install = spawnSync("npm", ["install", depSpec, "--save"], {
|
|
66
|
+
cwd,
|
|
67
|
+
stdio: "inherit",
|
|
68
|
+
shell: process.platform === "win32",
|
|
69
|
+
env: process.env,
|
|
70
|
+
});
|
|
71
|
+
if (install.status !== 0) {
|
|
72
|
+
die(
|
|
73
|
+
`npm install ${depSpec} failed (exit ${install.status}).\n` +
|
|
74
|
+
` export NODE_AUTH_TOKEN=$(gh auth token) # read:packages\n` +
|
|
75
|
+
` ensure .npmrc has: @open-nodo:registry=https://npm.pkg.github.com`,
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const { modules } = readModulesJson(cwd);
|
|
80
|
+
if (!modules.includes(key)) {
|
|
81
|
+
modules.push(key);
|
|
82
|
+
writeModulesJson(cwd, modules);
|
|
83
|
+
console.log(` ✓ nodo.modules.json → ${modules.join(", ")}`);
|
|
84
|
+
} else {
|
|
85
|
+
console.log(` · ${key} already listed in nodo.modules.json`);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
copyPrismaFragments(cwd, pkgName);
|
|
89
|
+
|
|
90
|
+
console.log(`\n ✓ Module ${key} added. Restart the app and confirm entitlements on next check-in.\n`);
|
|
91
|
+
}
|
package/src/console.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/** Process exit, usage text, and registry-auth guidance — everything that only talks to the user. */
|
|
2
|
+
import { MODULE_PACKAGES } from "./module-registry.js";
|
|
3
|
+
|
|
4
|
+
const GH_PACKAGES = "https://npm.pkg.github.com";
|
|
5
|
+
|
|
6
|
+
export function die(msg) {
|
|
7
|
+
console.error(`\n ✗ ${msg}\n`);
|
|
8
|
+
process.exit(1);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function authToken() {
|
|
12
|
+
return (process.env["NODE_AUTH_TOKEN"] || process.env["GITHUB_TOKEN"] || "").trim();
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function publicNpmMode(argv = process.argv) {
|
|
16
|
+
return (
|
|
17
|
+
process.env["OPENNODO_PUBLIC_NPM"] === "1" ||
|
|
18
|
+
process.env["OPENNODO_PUBLIC_NPM"] === "true" ||
|
|
19
|
+
argv.includes("--public-npm")
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function printAuthHelp() {
|
|
24
|
+
console.error(`
|
|
25
|
+
@open-nodo/* is on GitHub Packages (auth required even to download the CLI).
|
|
26
|
+
|
|
27
|
+
One-shot (recommended):
|
|
28
|
+
export NODE_AUTH_TOKEN=$(gh auth token) # needs read:packages (or write:packages)
|
|
29
|
+
npx @open-nodo/cli init <selection-token> [dir]
|
|
30
|
+
|
|
31
|
+
Permanent (~/.npmrc — never commit):
|
|
32
|
+
@open-nodo:registry=${GH_PACKAGES}
|
|
33
|
+
//npm.pkg.github.com/:_authToken=<your-github-token>
|
|
34
|
+
`);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Warn once when the registry needs a token we do not have. Returns public-npm mode. */
|
|
38
|
+
export function checkRegistryAuth() {
|
|
39
|
+
const usePublicNpm = publicNpmMode();
|
|
40
|
+
if (!usePublicNpm && !authToken()) {
|
|
41
|
+
console.warn(" ⚠ NODE_AUTH_TOKEN / GITHUB_TOKEN unset — npm install will 401 on @open-nodo/*.");
|
|
42
|
+
printAuthHelp();
|
|
43
|
+
}
|
|
44
|
+
return usePublicNpm;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function usage(exit = 0) {
|
|
48
|
+
console.log(`
|
|
49
|
+
Nodo CLI — self-host scaffolder and module installer
|
|
50
|
+
|
|
51
|
+
Usage:
|
|
52
|
+
npx @open-nodo/cli init <selection-token> [directory] [--public-npm]
|
|
53
|
+
npx @open-nodo/cli add <module>[@version]
|
|
54
|
+
npx @open-nodo/cli deploy [--target vercel]
|
|
55
|
+
|
|
56
|
+
Installable modules (add / init auto-deps):
|
|
57
|
+
${Object.keys(MODULE_PACKAGES).join(", ")}
|
|
58
|
+
|
|
59
|
+
Registry:
|
|
60
|
+
default GitHub Packages (.npmrc + NODE_AUTH_TOKEN)
|
|
61
|
+
--public-npm public npmjs (no GitHub token; after packages publish)
|
|
62
|
+
|
|
63
|
+
Auth (GitHub Packages):
|
|
64
|
+
export NODE_AUTH_TOKEN=$(gh auth token)
|
|
65
|
+
`);
|
|
66
|
+
process.exit(exit);
|
|
67
|
+
}
|
package/src/deploy.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/** `nodo deploy [--target vercel]` — thin convenience wrapper over the host's own CLI. */
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
3
|
+
import { spawnSync } from "node:child_process";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { die } from "./console.js";
|
|
6
|
+
|
|
7
|
+
export function cmdDeploy(target) {
|
|
8
|
+
const t = (target || "vercel").replace(/^--target=?/, "") || "vercel";
|
|
9
|
+
if (t !== "vercel") die(`Unknown deploy target "${t}". Supported: vercel`);
|
|
10
|
+
|
|
11
|
+
const cwd = process.cwd();
|
|
12
|
+
if (!existsSync(join(cwd, "package.json"))) die("No package.json — run from the app directory.");
|
|
13
|
+
console.log("\n Nodo — deploy helper (Vercel)\n");
|
|
14
|
+
|
|
15
|
+
if (spawnSync("vercel", ["--version"], { encoding: "utf8" }).status !== 0) {
|
|
16
|
+
console.log(" Vercel CLI not found. Install and deploy:");
|
|
17
|
+
console.log(" npm i -g vercel");
|
|
18
|
+
console.log(" vercel link");
|
|
19
|
+
console.log(" vercel env add NODE_AUTH_TOKEN");
|
|
20
|
+
console.log(" vercel --prod\n");
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
console.log(" Running: vercel --prod\n");
|
|
25
|
+
const r = spawnSync("vercel", ["--prod"], { cwd, stdio: "inherit", shell: process.platform === "win32" });
|
|
26
|
+
if (r.status !== 0) die(`vercel exited ${r.status}`);
|
|
27
|
+
console.log("\n ✓ Deploy requested.\n");
|
|
28
|
+
}
|
package/src/init.js
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/** `nodo init <selection-token> [dir]` — scaffold a self-hosted app from the bundled template. */
|
|
2
|
+
import { cpSync, existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { spawnSync } from "node:child_process";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { basename, join, resolve } from "node:path";
|
|
6
|
+
import { checkRegistryAuth, die } from "./console.js";
|
|
7
|
+
import { MODULE_PACKAGES, SDK_PACKAGE, installableKeys, rangeFor, stagedKeys } from "./module-registry.js";
|
|
8
|
+
import {
|
|
9
|
+
decodeToken,
|
|
10
|
+
ensureGitignoreHidesEnv,
|
|
11
|
+
setEnvLine,
|
|
12
|
+
writeModulesJson,
|
|
13
|
+
writeProjectNpmrc,
|
|
14
|
+
} from "./project-files.js";
|
|
15
|
+
|
|
16
|
+
const RAIL_DEFAULT = "https://nodo-rail.vercel.app/v1";
|
|
17
|
+
|
|
18
|
+
function gitInitFirstCommit(dir) {
|
|
19
|
+
const init = spawnSync("git", ["init"], { cwd: dir, encoding: "utf8" });
|
|
20
|
+
if (init.status !== 0) {
|
|
21
|
+
console.warn(" ⚠ git init failed — skip first commit");
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
spawnSync("git", ["add", "-A"], { cwd: dir });
|
|
25
|
+
const commit = spawnSync(
|
|
26
|
+
"git",
|
|
27
|
+
["commit", "-m", "chore: initial Nodo self-host scaffold (npx @open-nodo/cli init)"],
|
|
28
|
+
{
|
|
29
|
+
cwd: dir,
|
|
30
|
+
encoding: "utf8",
|
|
31
|
+
env: {
|
|
32
|
+
...process.env,
|
|
33
|
+
GIT_AUTHOR_NAME: "nodo-cli",
|
|
34
|
+
GIT_AUTHOR_EMAIL: "nodo@localhost",
|
|
35
|
+
GIT_COMMITTER_NAME: "nodo-cli",
|
|
36
|
+
GIT_COMMITTER_EMAIL: "nodo@localhost",
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
);
|
|
40
|
+
if (commit.status === 0) console.log(" ✓ git init + first commit");
|
|
41
|
+
else console.warn(" ⚠ git commit skipped (configure user.name/email or empty tree)");
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Point the scaffold's package.json at published ranges for the chosen modules. */
|
|
45
|
+
function writeScaffoldManifest(targetDir, installable) {
|
|
46
|
+
const pkgPath = join(targetDir, "package.json");
|
|
47
|
+
try {
|
|
48
|
+
const pkg = JSON.parse(readFileSync(pkgPath, "utf8"));
|
|
49
|
+
pkg.name = basename(targetDir).replace(/[^a-z0-9-]/gi, "-").toLowerCase() || "nodo-app";
|
|
50
|
+
pkg.version = "0.1.0";
|
|
51
|
+
pkg.private = true;
|
|
52
|
+
delete pkg.publishConfig;
|
|
53
|
+
pkg.dependencies = pkg.dependencies || {};
|
|
54
|
+
// The bundled template carries workspace: specifiers, which mean nothing outside this repo.
|
|
55
|
+
if (pkg.dependencies[SDK_PACKAGE]?.startsWith?.("workspace:")) {
|
|
56
|
+
pkg.dependencies[SDK_PACKAGE] = rangeFor(SDK_PACKAGE);
|
|
57
|
+
}
|
|
58
|
+
for (const key of installable) {
|
|
59
|
+
const name = MODULE_PACKAGES[key];
|
|
60
|
+
pkg.dependencies[name] = rangeFor(name);
|
|
61
|
+
}
|
|
62
|
+
writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + "\n");
|
|
63
|
+
} catch {
|
|
64
|
+
/* leave package.json as-is if it can't be parsed */
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function printNextSteps(dirName, usePublicNpm, installable) {
|
|
69
|
+
console.log(` ✓ Wrote .env (NODO_SELECTION_TOKEN + NODO_RAIL_URL)`);
|
|
70
|
+
if (usePublicNpm) {
|
|
71
|
+
console.log(` ✓ Public npm mode — no .npmrc (packages resolve from registry.npmjs.org)`);
|
|
72
|
+
} else {
|
|
73
|
+
console.log(` ✓ Wrote .npmrc (@open-nodo → GitHub Packages)`);
|
|
74
|
+
}
|
|
75
|
+
if (installable.length) {
|
|
76
|
+
console.log(` ✓ package.json deps for: ${installable.map((k) => MODULE_PACKAGES[k]).join(", ")}`);
|
|
77
|
+
}
|
|
78
|
+
console.log("");
|
|
79
|
+
console.log(" Next steps (self-host E2E):");
|
|
80
|
+
if (!usePublicNpm) {
|
|
81
|
+
console.log(` export NODE_AUTH_TOKEN=$(gh auth token) # if not already set`);
|
|
82
|
+
}
|
|
83
|
+
console.log(` cd ${dirName}`);
|
|
84
|
+
console.log(" npm install");
|
|
85
|
+
console.log(" npm run dev");
|
|
86
|
+
console.log("");
|
|
87
|
+
console.log(" On first boot the app will:");
|
|
88
|
+
console.log(" 1. register with the rail using the selection token (one-shot)");
|
|
89
|
+
console.log(" 2. check in and cache entitlements for the modules you picked");
|
|
90
|
+
console.log(" 3. appear in the operator fleet console\n");
|
|
91
|
+
console.log(" Add modules later: npx @open-nodo/cli add accounting\n");
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function cmdInit(token, dirArg) {
|
|
95
|
+
const usePublicNpm = checkRegistryAuth();
|
|
96
|
+
|
|
97
|
+
const claims = decodeToken(token);
|
|
98
|
+
const modules = Array.isArray(claims.modules)
|
|
99
|
+
? claims.modules.map((m) => m.key).filter(Boolean)
|
|
100
|
+
: [];
|
|
101
|
+
if (claims.exp && claims.exp * 1000 < Date.now()) {
|
|
102
|
+
console.warn(
|
|
103
|
+
" ⚠ This selection token has expired — mint a fresh one from /join before first boot register.",
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const targetDir = resolve(process.cwd(), dirArg || "nodo-app");
|
|
108
|
+
if (existsSync(targetDir)) die(`Directory already exists: ${targetDir}`);
|
|
109
|
+
|
|
110
|
+
const templateDir = fileURLToPath(new URL("../template", import.meta.url));
|
|
111
|
+
if (!existsSync(templateDir)) die("Bundled template is missing (packaging error). Please report this.");
|
|
112
|
+
|
|
113
|
+
console.log("\n Nodo — scaffolding a self-hosted app");
|
|
114
|
+
console.log(` Modules: ${modules.join(", ") || "(none selected)"}`);
|
|
115
|
+
|
|
116
|
+
const installable = installableKeys(modules);
|
|
117
|
+
const staged = stagedKeys(modules);
|
|
118
|
+
if (staged.length) {
|
|
119
|
+
console.log(
|
|
120
|
+
` ⚠ No published package yet (STAGED): ${staged.join(", ")} — recorded in nodo.modules.json only.`,
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
mkdirSync(targetDir, { recursive: true });
|
|
125
|
+
cpSync(templateDir, targetDir, {
|
|
126
|
+
recursive: true,
|
|
127
|
+
filter: (s) => basename(s) !== ".nodo",
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
// npm strips a file literally named .gitignore from tarballs, so the template ships it
|
|
131
|
+
// as `gitignore` and we restore the name here.
|
|
132
|
+
const giSafe = join(targetDir, "gitignore");
|
|
133
|
+
if (existsSync(giSafe)) renameSync(giSafe, join(targetDir, ".gitignore"));
|
|
134
|
+
ensureGitignoreHidesEnv(targetDir);
|
|
135
|
+
|
|
136
|
+
const examplePath = join(targetDir, ".env.example");
|
|
137
|
+
let env = existsSync(examplePath) ? readFileSync(examplePath, "utf8") : "";
|
|
138
|
+
env = setEnvLine(env, "NODO_RAIL_URL", RAIL_DEFAULT);
|
|
139
|
+
env = setEnvLine(env, "NODO_SELECTION_TOKEN", token);
|
|
140
|
+
writeFileSync(join(targetDir, ".env"), env);
|
|
141
|
+
|
|
142
|
+
if (!usePublicNpm) writeProjectNpmrc(targetDir);
|
|
143
|
+
writeModulesJson(targetDir, modules);
|
|
144
|
+
writeScaffoldManifest(targetDir, installable);
|
|
145
|
+
|
|
146
|
+
gitInitFirstCommit(targetDir);
|
|
147
|
+
|
|
148
|
+
console.log(` ✓ Created ${targetDir}`);
|
|
149
|
+
printNextSteps(basename(targetDir), usePublicNpm, installable);
|
|
150
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which catalog module maps to which npm package, and at what range.
|
|
3
|
+
*
|
|
4
|
+
* The MAPPING is a product decision and is written by hand below. The RANGES are a fact
|
|
5
|
+
* about what this monorepo publishes, and were previously a second hand-maintained copy of
|
|
6
|
+
* the workspace versions — kept honest only by a test that ran after the fact. They are now
|
|
7
|
+
* generated into `versions.generated.json` by `scripts/sync-registry.mjs`, which runs on
|
|
8
|
+
* prepack, so a published CLI cannot scaffold against a stale range.
|
|
9
|
+
*
|
|
10
|
+
* Keys match the rail catalog module keys carried in a selection token.
|
|
11
|
+
*/
|
|
12
|
+
import { createRequire } from "node:module";
|
|
13
|
+
|
|
14
|
+
const require = createRequire(import.meta.url);
|
|
15
|
+
/** @type {Record<string, string>} package name → version published from this monorepo */
|
|
16
|
+
const VERSIONS = require("./versions.generated.json");
|
|
17
|
+
|
|
18
|
+
/** Catalog key → npm package. A key absent here is STAGED: recorded, not installed. */
|
|
19
|
+
export const MODULE_PACKAGES = Object.freeze({
|
|
20
|
+
accounting: "@open-nodo/module-accounting",
|
|
21
|
+
patrimony: "@open-nodo/module-patrimony",
|
|
22
|
+
donors: "@open-nodo/module-donors",
|
|
23
|
+
beneficiaries: "@open-nodo/module-beneficiaries",
|
|
24
|
+
members: "@open-nodo/module-members",
|
|
25
|
+
"codec-onlus": "@open-nodo/codec-onlus",
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
/** The SDK every scaffold depends on, independent of the modules chosen. */
|
|
29
|
+
export const SDK_PACKAGE = "@open-nodo/sdk";
|
|
30
|
+
|
|
31
|
+
/** Caret range for a package this monorepo publishes; "latest" if it is not one of ours. */
|
|
32
|
+
export function rangeFor(packageName) {
|
|
33
|
+
const version = VERSIONS[packageName];
|
|
34
|
+
return version ? `^${version}` : "latest";
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Catalog keys that resolve to a published package, in the order given. */
|
|
38
|
+
export function installableKeys(keys) {
|
|
39
|
+
return keys.filter((key) => key in MODULE_PACKAGES);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Catalog keys with no package yet — recorded in nodo.modules.json only. */
|
|
43
|
+
export function stagedKeys(keys) {
|
|
44
|
+
return keys.filter((key) => !(key in MODULE_PACKAGES));
|
|
45
|
+
}
|