create-demiurge 0.2.0-beta.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 +21 -0
- package/README.md +24 -0
- package/bin/create-demiurge.mjs +163 -0
- package/package.json +36 -0
- package/templates/api/src/routes/@policy.ts +10 -0
- package/templates/api/src/routes/api/health.ts +3 -0
- package/templates/api/src/vite-env.d.ts +1 -0
- package/templates/api/vite.config.ts +6 -0
- package/templates/page/src/routes/@error.tsx +5 -0
- package/templates/page/src/routes/@layout.tsx +6 -0
- package/templates/page/src/routes/@not-found.tsx +5 -0
- package/templates/page/src/routes/@policy.ts +10 -0
- package/templates/page/src/routes/index.tsx +10 -0
- package/templates/page/src/styles.css +5 -0
- package/templates/page/src/vite-env.d.ts +1 -0
- package/templates/page/vite.config.ts +7 -0
- package/templates/shared/package.json +24 -0
- package/templates/shared/tsconfig.json +15 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 North Shore Software Labs
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# create-demiurge
|
|
2
|
+
|
|
3
|
+
Create a Demiurge application with an editable starting point.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
Run the interactive command:
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm create demiurge
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Pass a directory and template for non-interactive use:
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
npm create demiurge my-app -- --template page
|
|
17
|
+
npm create demiurge my-api -- --template api
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
The page template includes a layout, fallback documents, a policy, styles, and
|
|
21
|
+
a page route. The fallback documents use plain markup without fallback styles.
|
|
22
|
+
|
|
23
|
+
The API template includes a policy and a health route. It does not include page
|
|
24
|
+
routes, layouts, fallback documents, or styles.
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/* global console, process */
|
|
4
|
+
|
|
5
|
+
import { createInterface } from "node:readline/promises";
|
|
6
|
+
import { stdin, stdout } from "node:process";
|
|
7
|
+
import { cp, mkdir, readFile, readdir, writeFile } from "node:fs/promises";
|
|
8
|
+
import { basename, dirname, join, resolve } from "node:path";
|
|
9
|
+
import { fileURLToPath } from "node:url";
|
|
10
|
+
|
|
11
|
+
const packageRoot = resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
|
12
|
+
|
|
13
|
+
async function main() {
|
|
14
|
+
const options = parseArguments(process.argv.slice(2));
|
|
15
|
+
|
|
16
|
+
if (options.help) {
|
|
17
|
+
printHelp();
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (options.version) {
|
|
22
|
+
const metadata = JSON.parse(
|
|
23
|
+
await readFile(join(packageRoot, "package.json"), "utf8"),
|
|
24
|
+
);
|
|
25
|
+
console.log(metadata.version);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const answers = await getAnswers(options);
|
|
30
|
+
const target = resolve(process.cwd(), answers.directory);
|
|
31
|
+
await assertEmptyTarget(target);
|
|
32
|
+
await mkdir(target, { recursive: true });
|
|
33
|
+
await cp(join(packageRoot, "templates", "shared"), target, { recursive: true });
|
|
34
|
+
await cp(join(packageRoot, "templates", answers.template), target, {
|
|
35
|
+
recursive: true,
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const packageFile = join(target, "package.json");
|
|
39
|
+
const packageSource = await readFile(packageFile, "utf8");
|
|
40
|
+
await writeFile(
|
|
41
|
+
packageFile,
|
|
42
|
+
packageSource.replace("__PACKAGE_NAME__", packageName(target)),
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
console.log(`\nCreated ${answers.template} application in ${target}.`);
|
|
46
|
+
console.log("\nRun these commands:");
|
|
47
|
+
if (target !== process.cwd()) {
|
|
48
|
+
console.log(` cd ${JSON.stringify(answers.directory)}`);
|
|
49
|
+
}
|
|
50
|
+
console.log(" npm install");
|
|
51
|
+
console.log(" npm run dev");
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function parseArguments(arguments_) {
|
|
55
|
+
const options = { directory: undefined, help: false, template: undefined, version: false, yes: false };
|
|
56
|
+
|
|
57
|
+
for (let index = 0; index < arguments_.length; index += 1) {
|
|
58
|
+
const argument = arguments_[index];
|
|
59
|
+
|
|
60
|
+
if (argument === "--help" || argument === "-h") {
|
|
61
|
+
options.help = true;
|
|
62
|
+
} else if (argument === "--version" || argument === "-v") {
|
|
63
|
+
options.version = true;
|
|
64
|
+
} else if (argument === "--yes" || argument === "-y") {
|
|
65
|
+
options.yes = true;
|
|
66
|
+
} else if (argument === "--template" || argument === "-t") {
|
|
67
|
+
options.template = arguments_[index + 1];
|
|
68
|
+
index += 1;
|
|
69
|
+
} else if (argument.startsWith("--template=")) {
|
|
70
|
+
options.template = argument.slice("--template=".length);
|
|
71
|
+
} else if (argument.startsWith("-")) {
|
|
72
|
+
throw new Error(`Unknown option: ${argument}`);
|
|
73
|
+
} else if (options.directory) {
|
|
74
|
+
throw new Error("Specify only one application directory.");
|
|
75
|
+
} else {
|
|
76
|
+
options.directory = argument;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (options.template && !["api", "page"].includes(options.template)) {
|
|
81
|
+
throw new Error('Template must be "page" or "api".');
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return options;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
async function getAnswers(options) {
|
|
88
|
+
if (options.yes) {
|
|
89
|
+
return {
|
|
90
|
+
directory: options.directory ?? "demiurge-app",
|
|
91
|
+
template: options.template ?? "page",
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (!stdin.isTTY || !stdout.isTTY) {
|
|
96
|
+
if (!options.directory || !options.template) {
|
|
97
|
+
throw new Error(
|
|
98
|
+
"Non-interactive use requires a directory and --template page|api, or --yes.",
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
return options;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const prompt = createInterface({ input: stdin, output: stdout });
|
|
105
|
+
try {
|
|
106
|
+
const directory = options.directory ?? (
|
|
107
|
+
(await prompt.question("Application directory (demiurge-app): ")) ||
|
|
108
|
+
"demiurge-app"
|
|
109
|
+
);
|
|
110
|
+
let template = options.template;
|
|
111
|
+
|
|
112
|
+
while (!template) {
|
|
113
|
+
const answer = (await prompt.question("Template, page or api (page): "))
|
|
114
|
+
.trim()
|
|
115
|
+
.toLowerCase() || "page";
|
|
116
|
+
if (["api", "page"].includes(answer)) {
|
|
117
|
+
template = answer;
|
|
118
|
+
} else {
|
|
119
|
+
console.error('Enter "page" or "api".');
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return { directory, template };
|
|
124
|
+
} finally {
|
|
125
|
+
prompt.close();
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
async function assertEmptyTarget(target) {
|
|
130
|
+
try {
|
|
131
|
+
const entries = await readdir(target);
|
|
132
|
+
if (entries.length > 0) {
|
|
133
|
+
throw new Error(`Target directory is not empty: ${target}`);
|
|
134
|
+
}
|
|
135
|
+
} catch (error) {
|
|
136
|
+
if (error?.code !== "ENOENT") {
|
|
137
|
+
throw error;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function packageName(target) {
|
|
143
|
+
const normalized = basename(target)
|
|
144
|
+
.toLowerCase()
|
|
145
|
+
.replace(/[^a-z0-9._-]+/g, "-")
|
|
146
|
+
.replace(/^[._-]+|[._-]+$/g, "");
|
|
147
|
+
return normalized || "demiurge-app";
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function printHelp() {
|
|
151
|
+
console.log(`Usage: npm create demiurge [directory] [options]
|
|
152
|
+
|
|
153
|
+
Options:
|
|
154
|
+
-t, --template <page|api> Select the application template
|
|
155
|
+
-y, --yes Use the page template and default directory
|
|
156
|
+
-h, --help Show this help
|
|
157
|
+
-v, --version Show the package version`);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
main().catch((error) => {
|
|
161
|
+
console.error(`create-demiurge: ${error.message}`);
|
|
162
|
+
process.exitCode = 1;
|
|
163
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "create-demiurge",
|
|
3
|
+
"version": "0.2.0-beta.1",
|
|
4
|
+
"description": "Create a Demiurge application.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "North Shore Software Labs",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/NorthShoreSoftwareLabs/demiurge.git",
|
|
10
|
+
"directory": "packages/create-demiurge"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://github.com/NorthShoreSoftwareLabs/demiurge#readme",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/NorthShoreSoftwareLabs/demiurge/issues"
|
|
15
|
+
},
|
|
16
|
+
"type": "module",
|
|
17
|
+
"bin": {
|
|
18
|
+
"create-demiurge": "./bin/create-demiurge.mjs"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"bin",
|
|
22
|
+
"templates",
|
|
23
|
+
"LICENSE",
|
|
24
|
+
"README.md"
|
|
25
|
+
],
|
|
26
|
+
"scripts": {
|
|
27
|
+
"test": "node --test"
|
|
28
|
+
},
|
|
29
|
+
"engines": {
|
|
30
|
+
"node": ">=22.13.0"
|
|
31
|
+
},
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public",
|
|
34
|
+
"provenance": true
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/// <reference types="vite/client" />
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/// <reference types="vite/client" />
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "__PACKAGE_NAME__",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "vite",
|
|
8
|
+
"build": "vite build",
|
|
9
|
+
"typecheck": "tsc --noEmit"
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"@demiurgejs/core": "^0.2.0-beta.1",
|
|
13
|
+
"react": "^19.0.0",
|
|
14
|
+
"react-dom": "^19.0.0"
|
|
15
|
+
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"@types/node": "^22.13.0",
|
|
18
|
+
"@types/react": "^19.0.2",
|
|
19
|
+
"@types/react-dom": "^19.0.2",
|
|
20
|
+
"@vitejs/plugin-react": "^4.3.4",
|
|
21
|
+
"typescript": "^5.7.2",
|
|
22
|
+
"vite": "^6.0.7"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"lib": ["DOM", "DOM.Iterable", "ES2022"],
|
|
5
|
+
"strict": true,
|
|
6
|
+
"module": "ESNext",
|
|
7
|
+
"moduleResolution": "Bundler",
|
|
8
|
+
"resolveJsonModule": true,
|
|
9
|
+
"isolatedModules": true,
|
|
10
|
+
"noEmit": true,
|
|
11
|
+
"jsx": "react-jsx",
|
|
12
|
+
"types": ["node", "vite/client"]
|
|
13
|
+
},
|
|
14
|
+
"include": ["src", "vite.config.ts"]
|
|
15
|
+
}
|