@orthograph/preset 0.0.0-stage → 0.1.0-next.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 +202 -0
- package/README.md +2 -2
- package/dist/index.d.ts +5 -0
- package/dist/index.js +4 -0
- package/dist/main.d.ts +3 -0
- package/dist/main.js +4 -0
- package/dist/modules/app/internal/folder.d.ts +2 -0
- package/dist/modules/app/internal/folder.js +9 -0
- package/dist/modules/app/internal/names.d.ts +6 -0
- package/dist/modules/app/internal/names.js +10 -0
- package/dist/modules/app/service.d.ts +2 -0
- package/dist/modules/app/service.js +38 -0
- package/dist/modules/app/types.d.ts +26 -0
- package/dist/modules/app/types.js +5 -0
- package/dist/modules/starter/internal/project.d.ts +57 -0
- package/dist/modules/starter/internal/project.js +96 -0
- package/dist/modules/starter/service.d.ts +2 -0
- package/dist/modules/starter/service.js +38 -0
- package/dist/modules/starter/types.d.ts +25 -0
- package/dist/modules/starter/types.js +1 -0
- package/files/blueprint/environments/local.ts +8 -0
- package/files/blueprint/environments/production.ts +10 -0
- package/files/blueprint/environments/staging.ts +9 -0
- package/files/blueprint/environments/test.ts +8 -0
- package/files/blueprint/refusals.lock +85 -0
- package/files/blueprint/starting-worlds/founded.ts +11 -0
- package/files/blueprint/starting-worlds/invited.ts +12 -0
- package/files/blueprint/things/api-key/thing.ts +8 -0
- package/files/blueprint/things/api-key/verbs/create.ts +15 -0
- package/files/blueprint/things/invitation/events.ts +7 -0
- package/files/blueprint/things/invitation/machine.ts +13 -0
- package/files/blueprint/things/invitation/roles.ts +5 -0
- package/files/blueprint/things/invitation/thing.ts +8 -0
- package/files/blueprint/things/invitation/verbs/accept.ts +16 -0
- package/files/blueprint/things/invitation/verbs/revoke.ts +14 -0
- package/files/blueprint/things/invitation/verbs/send.ts +14 -0
- package/files/blueprint/things/membership/roles.ts +5 -0
- package/files/blueprint/things/membership/thing.ts +9 -0
- package/files/blueprint/things/membership/verbs/get.ts +11 -0
- package/files/blueprint/things/organization/events.ts +4 -0
- package/files/blueprint/things/organization/machine.ts +9 -0
- package/files/blueprint/things/organization/roles.ts +5 -0
- package/files/blueprint/things/organization/thing.ts +7 -0
- package/files/blueprint/things/organization/verbs/create.ts +14 -0
- package/files/blueprint/things/organization/verbs/get.ts +10 -0
- package/files/blueprint/things/person/errors.ts +3 -0
- package/files/blueprint/things/person/thing.ts +6 -0
- package/files/blueprint/things/person/verbs/sign-up.ts +14 -0
- package/files/blueprint/things/session/errors.ts +3 -0
- package/files/blueprint/things/session/thing.ts +7 -0
- package/files/blueprint/things/session/verbs/show.ts +13 -0
- package/files/blueprint/things/session/verbs/sign-in.ts +15 -0
- package/files/blueprint/things/system/thing.ts +6 -0
- package/files/blueprint/things/system/verbs/health.ts +11 -0
- package/files/blueprint/values/identity.ts +15 -0
- package/files/generated/model/model.json +3658 -0
- package/files/journeys/README.md +112 -0
- package/files/journeys/an-invitation-is-used-once.ts +38 -0
- package/files/journeys/an-owner-makes-an-api-key.ts +50 -0
- package/files/journeys/health-is-up.ts +17 -0
- package/files/journeys/invite-and-accept.ts +103 -0
- package/files/journeys/sign-up-and-sign-in.ts +48 -0
- package/files/src/api-key/create.ts +20 -0
- package/files/src/invitation/accept.ts +24 -0
- package/files/src/invitation/revoke.ts +8 -0
- package/files/src/invitation/send.ts +21 -0
- package/files/src/organization/create.ts +25 -0
- package/files/src/person/sign-up.ts +22 -0
- package/files/src/session/show.ts +14 -0
- package/files/src/session/sign-in.ts +22 -0
- package/files/src/system/health.ts +8 -0
- package/generators.json +9 -0
- package/package.json +34 -3
- package/schema.json +8 -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
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @orthograph/preset
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The create-nx-workspace preset: the starter project. Built; what each part does and how far it goes is in the package map in `docs/canon/status.md`.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { Starter } from "#modules/starter/service.js";
|
|
2
|
+
export type { PresetOptions, StarterApi, StarterSource } from "#modules/starter/types.js";
|
|
3
|
+
export { App } from "#modules/app/service.js";
|
|
4
|
+
export { AppRefused } from "#modules/app/types.js";
|
|
5
|
+
export type { AppApi } from "#modules/app/types.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
// @orthograph/preset: the create-nx-workspace preset, which writes the starter project, and the same project made as a folder.
|
|
2
|
+
export { Starter } from "#modules/starter/service.js";
|
|
3
|
+
export { App } from "#modules/app/service.js";
|
|
4
|
+
export { AppRefused } from "#modules/app/types.js";
|
package/dist/main.d.ts
ADDED
package/dist/main.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { existsSync, readdirSync, statSync } from "node:fs";
|
|
2
|
+
/** Why `dir` can't be filled, or nothing when it isn't there or is an empty folder. A link is judged by what it points to. */
|
|
3
|
+
export const occupied = (dir, name) => {
|
|
4
|
+
if (!existsSync(dir))
|
|
5
|
+
return undefined;
|
|
6
|
+
if (!statSync(dir).isDirectory())
|
|
7
|
+
return `${name} already exists and is not a folder: choose another name, or move it`;
|
|
8
|
+
return readdirSync(dir).length > 0 ? `${name}/ is not empty: choose another name, or empty it` : undefined;
|
|
9
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Names a package of the app's own name would clash with: it depends on both. */
|
|
2
|
+
export declare const RESERVED: ReadonlyArray<string>;
|
|
3
|
+
/** Lower case words joined by dashes: `bakery`, `pastry-shop`. */
|
|
4
|
+
export declare const isName: (name: string) => boolean;
|
|
5
|
+
/** What is wrong with `name`, or nothing. */
|
|
6
|
+
export declare const problem: (name: string) => string | undefined;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Names a package of the app's own name would clash with: it depends on both. */
|
|
2
|
+
export const RESERVED = ["orthograph", "effect"];
|
|
3
|
+
/** Lower case words joined by dashes: `bakery`, `pastry-shop`. */
|
|
4
|
+
export const isName = (name) => /^[a-z][a-z0-9]*(-[a-z0-9]+)*$/.test(name);
|
|
5
|
+
/** What is wrong with `name`, or nothing. */
|
|
6
|
+
export const problem = (name) => !isName(name)
|
|
7
|
+
? `${JSON.stringify(name)} isn't a name for an app: use lower case words joined by dashes, like bakery or pastry-shop`
|
|
8
|
+
: RESERVED.includes(name)
|
|
9
|
+
? `${JSON.stringify(name)} is a reserved name (an app of that name would be a package that depends on itself): choose another`
|
|
10
|
+
: undefined;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { mkdirSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { Effect } from "effect";
|
|
4
|
+
// Nx has no public export of FsTree or flushChanges; this deep import is why nx is a run-time dependency of the preset, and so of every app's cli.
|
|
5
|
+
import { FsTree, flushChanges } from "nx/src/generators/tree";
|
|
6
|
+
import { Starter } from "#modules/starter/service.js";
|
|
7
|
+
import { AppRefused } from "./types.js";
|
|
8
|
+
import { isName, problem } from "./internal/names.js";
|
|
9
|
+
import { occupied } from "./internal/folder.js";
|
|
10
|
+
const create = ({ parent, name }) => Effect.gen(function* () {
|
|
11
|
+
const wrong = problem(name);
|
|
12
|
+
if (wrong !== undefined)
|
|
13
|
+
return yield* new AppRefused({ message: wrong });
|
|
14
|
+
const dir = join(parent, name);
|
|
15
|
+
const taken = yield* Effect.try({
|
|
16
|
+
try: () => occupied(dir, name),
|
|
17
|
+
catch: (e) => new AppRefused({ message: `could not read ${name}/: ${String(e)}` }),
|
|
18
|
+
});
|
|
19
|
+
if (taken !== undefined)
|
|
20
|
+
return yield* new AppRefused({ message: taken });
|
|
21
|
+
yield* Effect.try({
|
|
22
|
+
try: () => {
|
|
23
|
+
mkdirSync(dir, { recursive: true });
|
|
24
|
+
// The starter writes into a tree; the tree is put on disk as a whole. The install task it returns is never run.
|
|
25
|
+
const tree = new FsTree(dir, false);
|
|
26
|
+
Starter.write(tree, { name }, Starter.bundled());
|
|
27
|
+
flushChanges(dir, tree.listChanges());
|
|
28
|
+
},
|
|
29
|
+
catch: (e) => new AppRefused({ message: `could not write ${name}/: ${String(e)}` }),
|
|
30
|
+
});
|
|
31
|
+
return [`made ${name}/`, "", "next:", ` cd ${name}`, " pnpm install", " pnpm ortho check", " pnpm ortho prove"];
|
|
32
|
+
});
|
|
33
|
+
const nameIn = (args) => args.length === 0
|
|
34
|
+
? Effect.fail(new AppRefused({ message: "an app needs a name: use lower case words joined by dashes, like bakery or pastry-shop" }))
|
|
35
|
+
: args.length > 1
|
|
36
|
+
? Effect.fail(new AppRefused({ message: `one name only, and ${JSON.stringify(args[1])} is another: an app takes just its name` }))
|
|
37
|
+
: Effect.succeed(args[0]);
|
|
38
|
+
export const App = { create, nameIn, isName };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type Effect } from "effect";
|
|
2
|
+
declare const AppRefused_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
|
|
3
|
+
readonly _tag: "AppRefused";
|
|
4
|
+
} & Readonly<A>;
|
|
5
|
+
/** Nothing was written: the message says what is wrong with the name or the folder, and names it. */
|
|
6
|
+
export declare class AppRefused extends AppRefused_base<{
|
|
7
|
+
readonly message: string;
|
|
8
|
+
}> {
|
|
9
|
+
}
|
|
10
|
+
export interface AppApi {
|
|
11
|
+
/**
|
|
12
|
+
* Makes `<parent>/<name>/` the way `create-nx-workspace <name> --preset=@orthograph/preset` would, without installing
|
|
13
|
+
* anything and without touching anything outside that folder. An existing empty folder is filled; a folder with anything
|
|
14
|
+
* in it (a hidden file too), or a file in its place, is refused untouched, and so is a name that is not lower case words
|
|
15
|
+
* joined by dashes, or is one a package of that name would clash with. The lines say what was made and what to do next.
|
|
16
|
+
*/
|
|
17
|
+
readonly create: (input: {
|
|
18
|
+
readonly parent: string;
|
|
19
|
+
readonly name: string;
|
|
20
|
+
}) => Effect.Effect<ReadonlyArray<string>, AppRefused>;
|
|
21
|
+
/** The one name in `args` (the words after the command), or why there isn't one: none, or an extra word, named. */
|
|
22
|
+
readonly nameIn: (args: ReadonlyArray<string>) => Effect.Effect<string, AppRefused>;
|
|
23
|
+
/** Whether `name` is one an app can have. */
|
|
24
|
+
readonly isName: (name: string) => boolean;
|
|
25
|
+
}
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// `ortho new app <name>` and `npm create orthograph <name>`: the starter project, made as a folder of its own.
|
|
2
|
+
import { Data } from "effect";
|
|
3
|
+
/** Nothing was written: the message says what is wrong with the name or the folder, and names it. */
|
|
4
|
+
export class AppRefused extends Data.TaggedError("AppRefused") {
|
|
5
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
export declare const packageJson: (existing: Record<string, unknown>, name: string, version: string) => {
|
|
2
|
+
type: string;
|
|
3
|
+
packageManager: string;
|
|
4
|
+
scripts: {
|
|
5
|
+
ortho: "ortho";
|
|
6
|
+
};
|
|
7
|
+
bin: {
|
|
8
|
+
[x: string]: string;
|
|
9
|
+
};
|
|
10
|
+
dependencies: {
|
|
11
|
+
effect: string;
|
|
12
|
+
"@effect/platform-node": string;
|
|
13
|
+
"@effect/sql-d1": string;
|
|
14
|
+
};
|
|
15
|
+
devDependencies: {
|
|
16
|
+
"@cloudflare/workers-types": string;
|
|
17
|
+
"@types/node": string;
|
|
18
|
+
"@typescript/native": string;
|
|
19
|
+
oxlint: string;
|
|
20
|
+
wrangler: string;
|
|
21
|
+
"@orthograph/cli": string;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
export declare const TSCONFIG: {
|
|
25
|
+
compilerOptions: {
|
|
26
|
+
target: string;
|
|
27
|
+
module: string;
|
|
28
|
+
moduleResolution: string;
|
|
29
|
+
lib: string[];
|
|
30
|
+
types: string[];
|
|
31
|
+
strict: boolean;
|
|
32
|
+
exactOptionalPropertyTypes: boolean;
|
|
33
|
+
noUncheckedIndexedAccess: boolean;
|
|
34
|
+
noImplicitOverride: boolean;
|
|
35
|
+
verbatimModuleSyntax: boolean;
|
|
36
|
+
erasableSyntaxOnly: boolean;
|
|
37
|
+
allowImportingTsExtensions: boolean;
|
|
38
|
+
noEmit: boolean;
|
|
39
|
+
skipLibCheck: boolean;
|
|
40
|
+
resolveJsonModule: boolean;
|
|
41
|
+
isolatedModules: boolean;
|
|
42
|
+
};
|
|
43
|
+
include: string[];
|
|
44
|
+
};
|
|
45
|
+
export declare const IGNORES: string[];
|
|
46
|
+
/** pnpm settings the project needs: workerd and esbuild build for the local world; kysely held as in Orthograph (D2 #68). */
|
|
47
|
+
export declare const WORKSPACE: Readonly<Record<string, Readonly<Record<string, string>>>>;
|
|
48
|
+
/** Merge flat two-level maps into a pnpm-workspace.yaml: each entry is set under its key, which is added if missing. */
|
|
49
|
+
export declare const mergeWorkspace: (yaml: string, settings: typeof WORKSPACE) => string;
|
|
50
|
+
/** What pnpm's minimum release age must not hold back: the framework's own packages, which are published as often as it is built (K28). */
|
|
51
|
+
export declare const AGE_EXEMPT: string[];
|
|
52
|
+
/**
|
|
53
|
+
* Add entries to a top-level list of a pnpm-workspace.yaml (created if missing), each once, keeping every entry already there.
|
|
54
|
+
* The file is parsed, so a block list, an inline list (`key: ['nx']`) and a key with a trailing comment all take the entries
|
|
55
|
+
* under the one key; the file's other keys and comments are kept as the parser keeps them.
|
|
56
|
+
*/
|
|
57
|
+
export declare const addToList: (text: string, key: string, entries: ReadonlyArray<string>) => string;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
// The files around the blueprint that make the workspace a project: its package.json, tsconfig and ignores.
|
|
2
|
+
import { Names } from "orthograph/server";
|
|
3
|
+
import { YAMLSeq, isScalar, isSeq, parseDocument } from "yaml";
|
|
4
|
+
const EXACT = {
|
|
5
|
+
effect: "4.1.4",
|
|
6
|
+
"@effect/platform-node": "4.1.4",
|
|
7
|
+
"@effect/sql-d1": "4.1.4",
|
|
8
|
+
};
|
|
9
|
+
const DEV = {
|
|
10
|
+
"@cloudflare/workers-types": "5.20261101.1",
|
|
11
|
+
"@types/node": "24.19.2",
|
|
12
|
+
"@typescript/native": "npm:typescript@7.0.2",
|
|
13
|
+
oxlint: "1.90.0",
|
|
14
|
+
wrangler: "4.156.1",
|
|
15
|
+
};
|
|
16
|
+
export const packageJson = (existing, name, version) => {
|
|
17
|
+
const framework = Object.fromEntries([Names.frontDoor, ...["host-cloudflare", "portal", "language-effect"].map(Names.pkg)].map((p) => [p, version]));
|
|
18
|
+
return {
|
|
19
|
+
...existing,
|
|
20
|
+
type: "module",
|
|
21
|
+
packageManager: "pnpm@11.20.0",
|
|
22
|
+
scripts: { ...existing["scripts"], [Names.short]: Names.short },
|
|
23
|
+
bin: { [name]: "./generated/cli/src/main.ts" },
|
|
24
|
+
dependencies: { ...existing["dependencies"], ...framework, ...EXACT },
|
|
25
|
+
devDependencies: { ...existing["devDependencies"], [Names.pkg("cli")]: version, ...DEV },
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
export const TSCONFIG = {
|
|
29
|
+
compilerOptions: {
|
|
30
|
+
target: "es2024", module: "nodenext", moduleResolution: "nodenext", lib: ["es2024"],
|
|
31
|
+
types: ["node", "@cloudflare/workers-types"],
|
|
32
|
+
strict: true, exactOptionalPropertyTypes: true, noUncheckedIndexedAccess: true, noImplicitOverride: true,
|
|
33
|
+
verbatimModuleSyntax: true, erasableSyntaxOnly: true, allowImportingTsExtensions: true, noEmit: true,
|
|
34
|
+
skipLibCheck: true, resolveJsonModule: true, isolatedModules: true,
|
|
35
|
+
},
|
|
36
|
+
include: ["blueprint/**/*.ts", "generated/**/*.ts", "src/**/*.ts", "journeys/**/*.ts"],
|
|
37
|
+
};
|
|
38
|
+
export const IGNORES = [`${Names.folder}/`, ".wrangler/", "node_modules/"];
|
|
39
|
+
/** pnpm settings the project needs: workerd and esbuild build for the local world; kysely held as in Orthograph (D2 #68). */
|
|
40
|
+
export const WORKSPACE = {
|
|
41
|
+
allowBuilds: { esbuild: "true", nx: "true", workerd: "true" },
|
|
42
|
+
overrides: { kysely: "0.29.7" },
|
|
43
|
+
};
|
|
44
|
+
/** Merge flat two-level maps into a pnpm-workspace.yaml: each entry is set under its key, which is added if missing. */
|
|
45
|
+
export const mergeWorkspace = (yaml, settings) => {
|
|
46
|
+
const lines = yaml.trimEnd() === "" ? [] : yaml.trimEnd().split("\n");
|
|
47
|
+
for (const [key, entries] of Object.entries(settings)) {
|
|
48
|
+
let at = lines.findIndex((l) => l === `${key}:`);
|
|
49
|
+
if (at === -1) {
|
|
50
|
+
lines.push(`${key}:`);
|
|
51
|
+
at = lines.length - 1;
|
|
52
|
+
}
|
|
53
|
+
let end = at + 1;
|
|
54
|
+
while (end < lines.length && lines[end].startsWith(" "))
|
|
55
|
+
end++;
|
|
56
|
+
for (const [name, value] of Object.entries(entries)) {
|
|
57
|
+
const line = ` ${name}: ${value}`;
|
|
58
|
+
const found = lines.slice(at + 1, end).findIndex((l) => l.trimStart().replace(/^'|'(?=:)/g, "").startsWith(`${name}:`));
|
|
59
|
+
if (found === -1) {
|
|
60
|
+
lines.splice(end, 0, line);
|
|
61
|
+
end++;
|
|
62
|
+
}
|
|
63
|
+
else
|
|
64
|
+
lines[at + 1 + found] = line;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return lines.join("\n") + "\n";
|
|
68
|
+
};
|
|
69
|
+
/** What pnpm's minimum release age must not hold back: the framework's own packages, which are published as often as it is built (K28). */
|
|
70
|
+
export const AGE_EXEMPT = ["orthograph", "@orthograph/*"];
|
|
71
|
+
/**
|
|
72
|
+
* Add entries to a top-level list of a pnpm-workspace.yaml (created if missing), each once, keeping every entry already there.
|
|
73
|
+
* The file is parsed, so a block list, an inline list (`key: ['nx']`) and a key with a trailing comment all take the entries
|
|
74
|
+
* under the one key; the file's other keys and comments are kept as the parser keeps them.
|
|
75
|
+
*/
|
|
76
|
+
export const addToList = (text, key, entries) => {
|
|
77
|
+
const doc = parseDocument(text);
|
|
78
|
+
const found = doc.get(key, true);
|
|
79
|
+
const list = isSeq(found) ? found : new YAMLSeq();
|
|
80
|
+
if (!isSeq(found)) {
|
|
81
|
+
if (isScalar(found)) {
|
|
82
|
+
list.commentBefore = found.commentBefore ?? null;
|
|
83
|
+
list.comment = found.comment ?? null;
|
|
84
|
+
}
|
|
85
|
+
doc.set(key, list);
|
|
86
|
+
}
|
|
87
|
+
if (list.items.length === 0)
|
|
88
|
+
list.flow = false;
|
|
89
|
+
const present = new Set(list.items.map((i) => String(isScalar(i) ? i.value : i)));
|
|
90
|
+
for (const e of entries)
|
|
91
|
+
if (!present.has(e)) {
|
|
92
|
+
list.add(doc.createNode(e));
|
|
93
|
+
present.add(e);
|
|
94
|
+
}
|
|
95
|
+
return doc.toString({ singleQuote: true });
|
|
96
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { existsSync, readFileSync, readdirSync } from "node:fs";
|
|
2
|
+
import { join, relative, resolve } from "node:path";
|
|
3
|
+
import { installPackagesTask } from "@nx/devkit";
|
|
4
|
+
import { Effect } from "effect";
|
|
5
|
+
import { Render } from "@orthograph/generators/render";
|
|
6
|
+
import { AGE_EXEMPT, IGNORES, TSCONFIG, WORKSPACE, addToList, mergeWorkspace, packageJson } from "./internal/project.js";
|
|
7
|
+
const PARTS = ["blueprint", "src", "journeys"];
|
|
8
|
+
const walk = (dir) => existsSync(dir) ? readdirSync(dir, { withFileTypes: true }).flatMap((d) => (d.isDirectory() ? walk(join(dir, d.name)) : [join(dir, d.name)])) : [];
|
|
9
|
+
const read = (root, version) => ({
|
|
10
|
+
files: PARTS.flatMap((p) => walk(join(root, p))).map((f) => ({ path: relative(root, f), content: readFileSync(f, "utf8") })),
|
|
11
|
+
model: readFileSync(join(root, "generated/model/model.json"), "utf8"),
|
|
12
|
+
version,
|
|
13
|
+
});
|
|
14
|
+
const write = (tree, { name }, source) => {
|
|
15
|
+
for (const f of source.files)
|
|
16
|
+
tree.write(f.path, f.content);
|
|
17
|
+
// generated/ is rendered for this project's name; the handlers are the starter's own, so no scaffold is written.
|
|
18
|
+
// The starter mounts no projection, so the model, the api and the server are rendered as they always were.
|
|
19
|
+
for (const f of Effect.runSync(Render.files({ name, model: JSON.parse(source.model) })))
|
|
20
|
+
if (!f.scaffold)
|
|
21
|
+
tree.write(f.path, f.content);
|
|
22
|
+
const existing = tree.exists("package.json") ? JSON.parse(tree.read("package.json", "utf8")) : {};
|
|
23
|
+
tree.write("package.json", JSON.stringify(packageJson(existing, name, source.version), null, 2) + "\n");
|
|
24
|
+
tree.write("tsconfig.json", JSON.stringify(TSCONFIG, null, 2) + "\n");
|
|
25
|
+
const ignore = tree.exists(".gitignore") ? tree.read(".gitignore", "utf8") : "";
|
|
26
|
+
tree.write(".gitignore", [ignore.trimEnd(), ...IGNORES.filter((i) => !ignore.includes(i))].filter(Boolean).join("\n") + "\n");
|
|
27
|
+
const workspace = tree.exists("pnpm-workspace.yaml") ? tree.read("pnpm-workspace.yaml", "utf8") : "";
|
|
28
|
+
tree.write("pnpm-workspace.yaml", addToList(mergeWorkspace(workspace, WORKSPACE), "minimumReleaseAgeExclude", AGE_EXEMPT));
|
|
29
|
+
return () => installPackagesTask(tree);
|
|
30
|
+
};
|
|
31
|
+
// This file sits three folders below the package root (src/ or dist/, modules/, starter/), which holds package.json.
|
|
32
|
+
const packageRoot = resolve(import.meta.dirname, "../../..");
|
|
33
|
+
const bundled = () => {
|
|
34
|
+
const root = [join(packageRoot, "files"), join(packageRoot, "../../examples/starter")].find((d) => existsSync(join(d, "blueprint")));
|
|
35
|
+
const { version } = JSON.parse(readFileSync(join(packageRoot, "package.json"), "utf8"));
|
|
36
|
+
return read(root, version);
|
|
37
|
+
};
|
|
38
|
+
export const Starter = { read, write, bundled };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Tree } from "@nx/devkit";
|
|
2
|
+
export interface PresetOptions {
|
|
3
|
+
/** The workspace's name, which names the project, its CLI and its SDK client. */
|
|
4
|
+
readonly name: string;
|
|
5
|
+
}
|
|
6
|
+
/** Where the starter's own files are read from: the published package's `files/`, or the repository's example. */
|
|
7
|
+
export interface StarterSource {
|
|
8
|
+
/** Each file under blueprint/, src/ and journeys/, by its path from the project root. */
|
|
9
|
+
readonly files: ReadonlyArray<{
|
|
10
|
+
readonly path: string;
|
|
11
|
+
readonly content: string;
|
|
12
|
+
}>;
|
|
13
|
+
/** The starter's compiled model, `generated/model/model.json`. */
|
|
14
|
+
readonly model: string;
|
|
15
|
+
/** The version every `@orthograph/*` package is installed at: the preset's own. */
|
|
16
|
+
readonly version: string;
|
|
17
|
+
}
|
|
18
|
+
export interface StarterApi {
|
|
19
|
+
/** Lay the starter into `tree` at its root, as project `name`. Returns the task that installs its packages. */
|
|
20
|
+
readonly write: (tree: Tree, options: PresetOptions, source: StarterSource) => () => void;
|
|
21
|
+
/** Read the starter from a folder holding `blueprint/`, `src/`, `journeys/` and `generated/model/`. */
|
|
22
|
+
readonly read: (root: string, version: string) => StarterSource;
|
|
23
|
+
/** The starter this package carries: `files/` beside the published package, or `examples/starter` in the repository. */
|
|
24
|
+
readonly bundled: () => StarterSource;
|
|
25
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Blueprint, Cloud, Identity, Telemetry } from "orthograph";
|
|
2
|
+
|
|
3
|
+
export default Blueprint.environment({
|
|
4
|
+
runs: "on this machine",
|
|
5
|
+
identity: Identity.testPrincipals, // fixed test people, no sign-in
|
|
6
|
+
database: Cloud.d1.local(), // the local runtime emulates D1: no database process
|
|
7
|
+
telemetry: [Telemetry.sink.local()], // prove's Collector, a process of its own
|
|
8
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Blueprint, Cloud, Deploy, Identity } from "orthograph";
|
|
2
|
+
|
|
3
|
+
export default Blueprint.environment({
|
|
4
|
+
runs: "always on",
|
|
5
|
+
identity: Identity.betterAuth,
|
|
6
|
+
cloud: Cloud.cloudflare({ database: Cloud.d1() }),
|
|
7
|
+
promotesFrom: "staging", // only a revision with a green verdict there
|
|
8
|
+
deploy: { server: Deploy.worker() }, // add a domain: Deploy.worker({ domain: "api.example.com" })
|
|
9
|
+
publish: { sdk: Deploy.npm(), cli: Deploy.npm() },
|
|
10
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Blueprint, Cloud, Deploy, Identity } from "orthograph";
|
|
2
|
+
|
|
3
|
+
export default Blueprint.environment({
|
|
4
|
+
runs: "always on",
|
|
5
|
+
identity: Identity.betterAuth,
|
|
6
|
+
cloud: Cloud.cloudflare({ database: Cloud.d1() }),
|
|
7
|
+
deploy: { server: Deploy.worker() }, // add a domain: Deploy.worker({ domain: "api.staging.example.com" })
|
|
8
|
+
publish: { sdk: Deploy.npm({ tag: "next" }), cli: Deploy.npm({ tag: "next" }) },
|
|
9
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Blueprint, Cloud, Identity } from "orthograph";
|
|
2
|
+
|
|
3
|
+
export default Blueprint.environment({
|
|
4
|
+
runs: "a fresh world for each pull request",
|
|
5
|
+
lifetime: "2 hours", // created and destroyed as one unit, with an owner and an expiry
|
|
6
|
+
identity: Identity.testPrincipals,
|
|
7
|
+
cloud: Cloud.cloudflare({ database: Cloud.d1() }),
|
|
8
|
+
});
|