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 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,10 @@
1
+ import { defineRoutePolicy } from "@demiurgejs/core";
2
+
3
+ export const policy = defineRoutePolicy({
4
+ security: {
5
+ request: {
6
+ allowedMethods: ["GET"],
7
+ maxBodySize: "32kb",
8
+ },
9
+ },
10
+ });
@@ -0,0 +1,3 @@
1
+ import { json } from "@demiurgejs/core";
2
+
3
+ export const GET = json({ ok: true });
@@ -0,0 +1 @@
1
+ /// <reference types="vite/client" />
@@ -0,0 +1,6 @@
1
+ import { defineConfig } from "vite";
2
+ import { demiurge } from "@demiurgejs/core/vite";
3
+
4
+ export default defineConfig({
5
+ plugins: [demiurge({ styles: false, typedRoutes: true })],
6
+ });
@@ -0,0 +1,5 @@
1
+ import type { RouteErrorProps } from "@demiurgejs/core";
2
+
3
+ export default function ErrorPage({ pathname, status }: RouteErrorProps) {
4
+ return <main>Error {status} while loading {pathname}.</main>;
5
+ }
@@ -0,0 +1,6 @@
1
+ import "../styles.css";
2
+ import type { LayoutProps } from "@demiurgejs/core";
3
+
4
+ export default function RootLayout({ children }: LayoutProps) {
5
+ return children;
6
+ }
@@ -0,0 +1,5 @@
1
+ import type { NotFoundProps } from "@demiurgejs/core";
2
+
3
+ export default function NotFound({ pathname }: NotFoundProps) {
4
+ return <main>Nothing was found at {pathname}.</main>;
5
+ }
@@ -0,0 +1,10 @@
1
+ import { defineRoutePolicy } from "@demiurgejs/core";
2
+
3
+ export const policy = defineRoutePolicy({
4
+ security: {
5
+ request: {
6
+ allowedMethods: ["GET"],
7
+ maxBodySize: "32kb",
8
+ },
9
+ },
10
+ });
@@ -0,0 +1,10 @@
1
+ import { page } from "@demiurgejs/core";
2
+
3
+ export const GET = page({
4
+ view: () => (
5
+ <main className="home">
6
+ <h1>Demiurge</h1>
7
+ <p>Edit src/routes/index.tsx to start your application.</p>
8
+ </main>
9
+ ),
10
+ });
@@ -0,0 +1,5 @@
1
+ .home {
2
+ margin: 4rem auto;
3
+ max-width: 42rem;
4
+ padding: 0 1rem;
5
+ }
@@ -0,0 +1 @@
1
+ /// <reference types="vite/client" />
@@ -0,0 +1,7 @@
1
+ import react from "@vitejs/plugin-react";
2
+ import { defineConfig } from "vite";
3
+ import { demiurge } from "@demiurgejs/core/vite";
4
+
5
+ export default defineConfig({
6
+ plugins: [demiurge({ typedRoutes: true }), react()],
7
+ });
@@ -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
+ }