create-dreamer-app 0.0.0-stage → 1.0.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/index.js +94 -0
- package/package.json +12 -4
- package/template/package.json +27 -0
- package/template/src/components/GameScreen/index.tsx +10 -0
- package/template/src/components/Message/index.tsx +6 -0
- package/template/src/index.html +13 -0
- package/template/src/index.tsx +8 -0
- package/template/src/main.css +17 -0
- package/template/src/main.ts +6 -0
- package/template/tsconfig.json +44 -0
- package/template/vite.config.js +21 -0
- package/README.md +0 -3
package/index.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require("node:fs/promises");
|
|
4
|
+
const path = require("node:path");
|
|
5
|
+
const readline = require("node:readline/promises");
|
|
6
|
+
const { spawnSync } = require("node:child_process");
|
|
7
|
+
|
|
8
|
+
const usage = `Usage: create-dreamer-app [directory] [--skip-install]
|
|
9
|
+
|
|
10
|
+
Create a Disco Dreamer app and install its dependencies.
|
|
11
|
+
If no directory is supplied, you will be prompted for one.
|
|
12
|
+
|
|
13
|
+
Options:
|
|
14
|
+
--skip-install Create the project without running npm install
|
|
15
|
+
-h, --help Show this help message
|
|
16
|
+
|
|
17
|
+
Example:
|
|
18
|
+
npx create-dreamer-app my-dreamer-app`;
|
|
19
|
+
|
|
20
|
+
async function main() {
|
|
21
|
+
const args = process.argv.slice(2);
|
|
22
|
+
if (args.includes("--help") || args.includes("-h")) {
|
|
23
|
+
console.log(usage);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const unknownOption = args.find((arg) => arg.startsWith("-") && arg !== "--skip-install");
|
|
28
|
+
if (unknownOption) throw new Error(`Unknown option: ${unknownOption}\n\n${usage}`);
|
|
29
|
+
const directories = args.filter((arg) => arg !== "--skip-install");
|
|
30
|
+
if (directories.length > 1) throw new Error(`Supply only one project directory.\n\n${usage}`);
|
|
31
|
+
|
|
32
|
+
let directory = directories[0];
|
|
33
|
+
if (directory === undefined) {
|
|
34
|
+
if (!process.stdin.isTTY) throw new Error(`Supply a project directory.\n\n${usage}`);
|
|
35
|
+
const prompt = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
36
|
+
try {
|
|
37
|
+
directory = (await prompt.question("Project directory (my-dreamer-app): ")).trim() || "my-dreamer-app";
|
|
38
|
+
} finally {
|
|
39
|
+
prompt.close();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (!directory.trim()) throw new Error("The project directory cannot be empty.");
|
|
43
|
+
|
|
44
|
+
const destination = path.resolve(directory);
|
|
45
|
+
const name = path.basename(destination).toLowerCase().replace(/[^a-z0-9._-]+/g, "-");
|
|
46
|
+
if (!/^[a-z0-9][a-z0-9._-]*$/.test(name) || name.length > 214 || ["node_modules", "favicon.ico"].includes(name)) {
|
|
47
|
+
throw new Error("Choose a directory whose name starts with a letter or number and can be used as an npm package name.");
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Refuse symlinks and nonempty directories before copying any files.
|
|
51
|
+
try {
|
|
52
|
+
const stat = await fs.lstat(destination);
|
|
53
|
+
if (!stat.isDirectory() || (await fs.readdir(destination)).length > 0) {
|
|
54
|
+
throw new Error(`Destination already exists and is not an empty directory: ${destination}`);
|
|
55
|
+
}
|
|
56
|
+
} catch (error) {
|
|
57
|
+
if (error.code !== "ENOENT") throw error;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
console.log(`Creating ${name} in ${destination}...`);
|
|
61
|
+
await fs.cp(path.join(__dirname, "template"), destination, {
|
|
62
|
+
recursive: true,
|
|
63
|
+
force: false,
|
|
64
|
+
errorOnExist: true,
|
|
65
|
+
filter: (source) => ![".DS_Store", "node_modules", "dist"].includes(path.basename(source)),
|
|
66
|
+
});
|
|
67
|
+
const packagePath = path.join(destination, "package.json");
|
|
68
|
+
const manifest = JSON.parse(await fs.readFile(packagePath, "utf8"));
|
|
69
|
+
manifest.name = name;
|
|
70
|
+
await fs.writeFile(packagePath, `${JSON.stringify(manifest, null, 2)}\n`);
|
|
71
|
+
|
|
72
|
+
const skipInstall = args.includes("--skip-install");
|
|
73
|
+
if (!skipInstall) {
|
|
74
|
+
console.log("Installing dependencies...");
|
|
75
|
+
const result = spawnSync(process.platform === "win32" ? "npm.cmd" : "npm", ["install"], {
|
|
76
|
+
cwd: destination,
|
|
77
|
+
stdio: "inherit",
|
|
78
|
+
shell: process.platform === "win32",
|
|
79
|
+
});
|
|
80
|
+
if (result.error || result.status !== 0) {
|
|
81
|
+
throw new Error(`Dependency installation failed${result.error ? `: ${result.error.message}` : ""}. Your project files are saved in ${destination}. Run npm install there to retry.`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
console.log(`\nCreated ${name}!\n\nNext steps:`);
|
|
86
|
+
if (destination !== process.cwd()) console.log(` cd ${JSON.stringify(path.relative(process.cwd(), destination))}`);
|
|
87
|
+
if (skipInstall) console.log(" npm install");
|
|
88
|
+
console.log(" npm run dev");
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
main().catch((error) => {
|
|
92
|
+
console.error(`\nError: ${error.message}`);
|
|
93
|
+
process.exitCode = 1;
|
|
94
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-dreamer-app",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "The scaffolding application for using Disco Dreamer.",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"create-dreamer-app": "./index.js"
|
|
8
|
+
},
|
|
9
|
+
"engines": {
|
|
10
|
+
"node": "^20.19.0 || >=22.12.0"
|
|
11
|
+
},
|
|
12
|
+
"author": "",
|
|
13
|
+
"license": "ISC"
|
|
14
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "mydreamerapp",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "vite",
|
|
8
|
+
"typecheck": "tsc --noEmit",
|
|
9
|
+
"build": "npm run typecheck && vite build",
|
|
10
|
+
"preview": "vite preview"
|
|
11
|
+
},
|
|
12
|
+
"type": "module",
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": "^20.19.0 || >=22.12.0"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [],
|
|
17
|
+
"author": "",
|
|
18
|
+
"license": "ISC",
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@types/node": "^26.6.4",
|
|
21
|
+
"typescript": "^7.0.2",
|
|
22
|
+
"vite": "^8.3.2"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"discodreamer": "^1.0.0"
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
+
<title>My Dreamer App!</title>
|
|
7
|
+
<link rel="stylesheet" href="./main.css">
|
|
8
|
+
<script type="module" src="./main.ts"></script>
|
|
9
|
+
</head>
|
|
10
|
+
<body>
|
|
11
|
+
<canvas id="c"></canvas>
|
|
12
|
+
</body>
|
|
13
|
+
</html>
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
// Visit https://aka.ms/tsconfig to read more about this file
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
// File Layout
|
|
5
|
+
"rootDir": "./src",
|
|
6
|
+
"outDir": "./dist",
|
|
7
|
+
|
|
8
|
+
// Environment Settings
|
|
9
|
+
// See also https://aka.ms/tsconfig/module
|
|
10
|
+
"module": "esnext",
|
|
11
|
+
"moduleResolution": "bundler",
|
|
12
|
+
"noEmit": true,
|
|
13
|
+
"target": "esnext",
|
|
14
|
+
|
|
15
|
+
// Browser environment and Vite asset imports:
|
|
16
|
+
"lib": ["esnext", "DOM"],
|
|
17
|
+
"types": ["vite/client"],
|
|
18
|
+
|
|
19
|
+
// Other Outputs
|
|
20
|
+
"sourceMap": true,
|
|
21
|
+
|
|
22
|
+
// Stricter Typechecking Options
|
|
23
|
+
"noUncheckedIndexedAccess": true,
|
|
24
|
+
"exactOptionalPropertyTypes": false,
|
|
25
|
+
|
|
26
|
+
// Style Options
|
|
27
|
+
// "noImplicitReturns": true,
|
|
28
|
+
// "noImplicitOverride": true,
|
|
29
|
+
// "noUnusedLocals": true,
|
|
30
|
+
// "noUnusedParameters": true,
|
|
31
|
+
// "noFallthroughCasesInSwitch": true,
|
|
32
|
+
// "noPropertyAccessFromIndexSignature": true,
|
|
33
|
+
|
|
34
|
+
// Recommended Options
|
|
35
|
+
"strict": true,
|
|
36
|
+
"jsx": "preserve",
|
|
37
|
+
"verbatimModuleSyntax": true,
|
|
38
|
+
"isolatedModules": true,
|
|
39
|
+
"noUncheckedSideEffectImports": true,
|
|
40
|
+
"moduleDetection": "force",
|
|
41
|
+
"skipLibCheck": true,
|
|
42
|
+
},
|
|
43
|
+
"include": ["src"]
|
|
44
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { defineConfig } from "vite";
|
|
2
|
+
|
|
3
|
+
export default defineConfig({
|
|
4
|
+
root: "src",
|
|
5
|
+
base: "./",
|
|
6
|
+
oxc: {
|
|
7
|
+
jsxInject: 'import { DreamFactory as __DreamFactory } from "discodreamer"',
|
|
8
|
+
jsx: {
|
|
9
|
+
runtime: "classic",
|
|
10
|
+
pragma: "__DreamFactory",
|
|
11
|
+
pure: false,
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
server: {
|
|
15
|
+
port: 3000,
|
|
16
|
+
},
|
|
17
|
+
build: {
|
|
18
|
+
outDir: "../dist",
|
|
19
|
+
emptyOutDir: true,
|
|
20
|
+
},
|
|
21
|
+
});
|
package/README.md
DELETED