@sprig-and-prose/create-scene-tutorial 0.1.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/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # @sprig-and-prose/create-scene-tutorial
2
+
3
+ ## 0.1.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 9557987: Add dataset expectations, sprig-edge initial commit, and scene tutorial scaffolder
package/dist/index.js ADDED
@@ -0,0 +1,176 @@
1
+ #!/usr/bin/env node
2
+ import { mkdir, writeFile } from "node:fs/promises";
3
+ import { join } from "node:path";
4
+ const UNIVERSE_PROSE = `universe DemoUniverse {
5
+ note {
6
+ Tutorial for sprig scene attestations.
7
+
8
+ This universe demonstrates how to use sprig-edge
9
+ to validate data files against scene expectations.
10
+ }
11
+ }
12
+ `;
13
+ const DEMO_SCENE_PROSE = `scene DemoScene {
14
+ locations {
15
+ GameDataFiles {
16
+ kind { 'files' }
17
+ }
18
+ }
19
+
20
+ actors {
21
+ Item {
22
+ kind {
23
+ id { integer }
24
+ name { string }
25
+ }
26
+
27
+ identity { id }
28
+
29
+ expects {
30
+ project {
31
+ to { GameDataFiles }
32
+ as { dataset { Items } }
33
+ }
34
+ }
35
+ }
36
+ }
37
+
38
+ portals {
39
+ Items {
40
+ kind { [ Item ] }
41
+ }
42
+ }
43
+ }
44
+ `;
45
+ const EQUIPMENT_YAML = `- id: 1
46
+ name: "Iron Sword"
47
+ - id: 2
48
+ name: "Wooden Shield"
49
+ `;
50
+ const RESOURCES_YAML = `- id: 10
51
+ name: "Gold Coin"
52
+ - id: 11
53
+ name: "Health Potion"
54
+ `;
55
+ const EDGE_CONFIG = {
56
+ version: 1,
57
+ defaults: {
58
+ attestationsDir: "artifacts",
59
+ appDir: "app",
60
+ },
61
+ scenes: [
62
+ {
63
+ scene: "DemoScene",
64
+ manifestPath: "artifacts/DemoScene.scene.json",
65
+ attestationsPath: "artifacts/DemoScene.attestations.json",
66
+ locations: {
67
+ GameDataFiles: { baseDir: "app/data" },
68
+ },
69
+ datasets: {
70
+ Items: {
71
+ files: ["items/equipment.yaml", "items/resources.yaml"],
72
+ format: "yaml",
73
+ mode: "array",
74
+ },
75
+ },
76
+ },
77
+ ],
78
+ };
79
+ const PACKAGE_JSON = {
80
+ name: "sprig-scene-tutorial",
81
+ version: "1.0.0",
82
+ type: "module",
83
+ scripts: {
84
+ compile: "sprig compile sprig --out artifacts",
85
+ attest: "sprig-edge attest",
86
+ check: "sprig-edge check",
87
+ },
88
+ devDependencies: {
89
+ "@sprig-and-prose/sprig": "*",
90
+ "@sprig-and-prose/sprig-edge": "*",
91
+ },
92
+ };
93
+ const GITIGNORE = `node_modules/
94
+ dist/
95
+ .DS_Store
96
+ `;
97
+ const README = `# Sprig Scene Tutorial
98
+
99
+ This tutorial demonstrates how to use sprig-edge to validate data files against scene expectations.
100
+
101
+ ## Quick Start
102
+
103
+ \`\`\`bash
104
+ npm install
105
+ npm run compile
106
+ npm run attest
107
+ npm run check
108
+ \`\`\`
109
+
110
+ ## What's Included
111
+
112
+ - **sprig/**: Truth definitions (universe and scene prose files)
113
+ - **app/**: Edge application data files
114
+ - **artifacts/**: Compiled manifests and attestations
115
+
116
+ ## Commands
117
+
118
+ - \`npm run compile\`: Compile prose files to JSON manifests
119
+ - \`npm run attest\`: Generate attestations from data files
120
+ - \`npm run check\`: Check expectations against attestations
121
+
122
+ ## Learn More
123
+
124
+ - [Sprig Documentation](https://sprig-and-prose.io)
125
+ - [Scene Engine Guide](https://sprig-and-prose.io/scenes)
126
+ `;
127
+ async function createTutorial(targetDir) {
128
+ try {
129
+ // Create directory structure
130
+ await mkdir(join(targetDir, "sprig"), { recursive: true });
131
+ await mkdir(join(targetDir, "app", "data", "items"), { recursive: true });
132
+ await mkdir(join(targetDir, "artifacts"), { recursive: true });
133
+ // Write prose files
134
+ await writeFile(join(targetDir, "sprig", "universe.prose"), UNIVERSE_PROSE, "utf-8");
135
+ await writeFile(join(targetDir, "sprig", "DemoScene.scene.prose"), DEMO_SCENE_PROSE, "utf-8");
136
+ // Write data files
137
+ await writeFile(join(targetDir, "app", "data", "items", "equipment.yaml"), EQUIPMENT_YAML, "utf-8");
138
+ await writeFile(join(targetDir, "app", "data", "items", "resources.yaml"), RESOURCES_YAML, "utf-8");
139
+ // Write config files
140
+ await writeFile(join(targetDir, "sprig.edge.json"), JSON.stringify(EDGE_CONFIG, null, 2), "utf-8");
141
+ await writeFile(join(targetDir, "package.json"), JSON.stringify(PACKAGE_JSON, null, 2), "utf-8");
142
+ await writeFile(join(targetDir, ".gitignore"), GITIGNORE, "utf-8");
143
+ await writeFile(join(targetDir, "README.md"), README, "utf-8");
144
+ // Print success message
145
+ console.log(`✓ Tutorial created in ${targetDir}/`);
146
+ console.log("");
147
+ console.log("Next steps:");
148
+ console.log(` cd ${targetDir}`);
149
+ console.log(" npm install");
150
+ console.log(" npm run compile");
151
+ console.log(" npm run attest");
152
+ console.log(" npm run check");
153
+ console.log("");
154
+ console.log("Learn more: https://sprig-and-prose.io/scenes");
155
+ }
156
+ catch (error) {
157
+ const message = error instanceof Error ? error.message : String(error);
158
+ console.error(`Error creating tutorial: ${message}`);
159
+ process.exit(1);
160
+ }
161
+ }
162
+ async function main() {
163
+ const args = process.argv.slice(2);
164
+ // Default directory name
165
+ let targetDir = "sprig-scene-tutorial";
166
+ // Check for custom directory name
167
+ for (let i = 0; i < args.length; i++) {
168
+ const arg = args[i];
169
+ if (!arg.startsWith("-")) {
170
+ targetDir = arg;
171
+ break;
172
+ }
173
+ }
174
+ await createTutorial(targetDir);
175
+ }
176
+ main();
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "@sprig-and-prose/create-scene-tutorial",
3
+ "version": "0.1.1",
4
+ "type": "module",
5
+ "description": "Scaffolder for Sprig scene tutorial projects",
6
+ "main": "dist/index.js",
7
+ "bin": {
8
+ "create-scene-tutorial": "./dist/index.js"
9
+ },
10
+ "scripts": {
11
+ "build": "tsc",
12
+ "prepare": "npm run build"
13
+ },
14
+ "keywords": [
15
+ "sprig",
16
+ "tutorial",
17
+ "scaffolder",
18
+ "create"
19
+ ],
20
+ "author": "",
21
+ "license": "ISC",
22
+ "devDependencies": {
23
+ "@types/node": "^22.0.0",
24
+ "typescript": "^5.7.2"
25
+ }
26
+ }
package/src/index.ts ADDED
@@ -0,0 +1,210 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { mkdir, writeFile } from "node:fs/promises";
4
+ import { join } from "node:path";
5
+
6
+ const UNIVERSE_PROSE = `universe DemoUniverse {
7
+ note {
8
+ Tutorial for sprig scene attestations.
9
+
10
+ This universe demonstrates how to use sprig-edge
11
+ to validate data files against scene expectations.
12
+ }
13
+ }
14
+ `;
15
+
16
+ const DEMO_SCENE_PROSE = `scene DemoScene {
17
+ locations {
18
+ GameDataFiles {
19
+ kind { 'files' }
20
+ }
21
+ }
22
+
23
+ actors {
24
+ Item {
25
+ kind {
26
+ id { integer }
27
+ name { string }
28
+ }
29
+
30
+ identity { id }
31
+
32
+ expects {
33
+ project {
34
+ to { GameDataFiles }
35
+ as { dataset { Items } }
36
+ }
37
+ }
38
+ }
39
+ }
40
+
41
+ portals {
42
+ Items {
43
+ kind { [ Item ] }
44
+ }
45
+ }
46
+ }
47
+ `;
48
+
49
+ const EQUIPMENT_YAML = `- id: 1
50
+ name: "Iron Sword"
51
+ - id: 2
52
+ name: "Wooden Shield"
53
+ `;
54
+
55
+ const RESOURCES_YAML = `- id: 10
56
+ name: "Gold Coin"
57
+ - id: 11
58
+ name: "Health Potion"
59
+ `;
60
+
61
+ const EDGE_CONFIG = {
62
+ version: 1,
63
+ defaults: {
64
+ attestationsDir: "artifacts",
65
+ appDir: "app",
66
+ },
67
+ scenes: [
68
+ {
69
+ scene: "DemoScene",
70
+ manifestPath: "artifacts/DemoScene.scene.json",
71
+ attestationsPath: "artifacts/DemoScene.attestations.json",
72
+ locations: {
73
+ GameDataFiles: { baseDir: "app/data" },
74
+ },
75
+ datasets: {
76
+ Items: {
77
+ files: ["items/equipment.yaml", "items/resources.yaml"],
78
+ format: "yaml",
79
+ mode: "array",
80
+ },
81
+ },
82
+ },
83
+ ],
84
+ };
85
+
86
+ const PACKAGE_JSON = {
87
+ name: "sprig-scene-tutorial",
88
+ version: "1.0.0",
89
+ type: "module",
90
+ scripts: {
91
+ compile: "sprig compile sprig --out artifacts",
92
+ attest: "sprig-edge attest",
93
+ check: "sprig-edge check",
94
+ },
95
+ devDependencies: {
96
+ "@sprig-and-prose/sprig": "*",
97
+ "@sprig-and-prose/sprig-edge": "*",
98
+ },
99
+ };
100
+
101
+ const GITIGNORE = `node_modules/
102
+ dist/
103
+ .DS_Store
104
+ `;
105
+
106
+ const README = `# Sprig Scene Tutorial
107
+
108
+ This tutorial demonstrates how to use sprig-edge to validate data files against scene expectations.
109
+
110
+ ## Quick Start
111
+
112
+ \`\`\`bash
113
+ npm install
114
+ npm run compile
115
+ npm run attest
116
+ npm run check
117
+ \`\`\`
118
+
119
+ ## What's Included
120
+
121
+ - **sprig/**: Truth definitions (universe and scene prose files)
122
+ - **app/**: Edge application data files
123
+ - **artifacts/**: Compiled manifests and attestations
124
+
125
+ ## Commands
126
+
127
+ - \`npm run compile\`: Compile prose files to JSON manifests
128
+ - \`npm run attest\`: Generate attestations from data files
129
+ - \`npm run check\`: Check expectations against attestations
130
+
131
+ ## Learn More
132
+
133
+ - [Sprig Documentation](https://sprig-and-prose.io)
134
+ - [Scene Engine Guide](https://sprig-and-prose.io/scenes)
135
+ `;
136
+
137
+ async function createTutorial(targetDir: string): Promise<void> {
138
+ try {
139
+ // Create directory structure
140
+ await mkdir(join(targetDir, "sprig"), { recursive: true });
141
+ await mkdir(join(targetDir, "app", "data", "items"), { recursive: true });
142
+ await mkdir(join(targetDir, "artifacts"), { recursive: true });
143
+
144
+ // Write prose files
145
+ await writeFile(join(targetDir, "sprig", "universe.prose"), UNIVERSE_PROSE, "utf-8");
146
+ await writeFile(join(targetDir, "sprig", "DemoScene.scene.prose"), DEMO_SCENE_PROSE, "utf-8");
147
+
148
+ // Write data files
149
+ await writeFile(
150
+ join(targetDir, "app", "data", "items", "equipment.yaml"),
151
+ EQUIPMENT_YAML,
152
+ "utf-8",
153
+ );
154
+ await writeFile(
155
+ join(targetDir, "app", "data", "items", "resources.yaml"),
156
+ RESOURCES_YAML,
157
+ "utf-8",
158
+ );
159
+
160
+ // Write config files
161
+ await writeFile(
162
+ join(targetDir, "sprig.edge.json"),
163
+ JSON.stringify(EDGE_CONFIG, null, 2),
164
+ "utf-8",
165
+ );
166
+ await writeFile(
167
+ join(targetDir, "package.json"),
168
+ JSON.stringify(PACKAGE_JSON, null, 2),
169
+ "utf-8",
170
+ );
171
+ await writeFile(join(targetDir, ".gitignore"), GITIGNORE, "utf-8");
172
+ await writeFile(join(targetDir, "README.md"), README, "utf-8");
173
+
174
+ // Print success message
175
+ console.log(`✓ Tutorial created in ${targetDir}/`);
176
+ console.log("");
177
+ console.log("Next steps:");
178
+ console.log(` cd ${targetDir}`);
179
+ console.log(" npm install");
180
+ console.log(" npm run compile");
181
+ console.log(" npm run attest");
182
+ console.log(" npm run check");
183
+ console.log("");
184
+ console.log("Learn more: https://sprig-and-prose.io/scenes");
185
+ } catch (error) {
186
+ const message = error instanceof Error ? error.message : String(error);
187
+ console.error(`Error creating tutorial: ${message}`);
188
+ process.exit(1);
189
+ }
190
+ }
191
+
192
+ async function main() {
193
+ const args = process.argv.slice(2);
194
+
195
+ // Default directory name
196
+ let targetDir = "sprig-scene-tutorial";
197
+
198
+ // Check for custom directory name
199
+ for (let i = 0; i < args.length; i++) {
200
+ const arg = args[i];
201
+ if (!arg.startsWith("-")) {
202
+ targetDir = arg;
203
+ break;
204
+ }
205
+ }
206
+
207
+ await createTutorial(targetDir);
208
+ }
209
+
210
+ main();
package/tsconfig.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "ES2022",
5
+ "lib": ["ES2022"],
6
+ "moduleResolution": "bundler",
7
+ "outDir": "./dist",
8
+ "rootDir": "./src",
9
+ "strict": true,
10
+ "esModuleInterop": true,
11
+ "skipLibCheck": true,
12
+ "forceConsistentCasingInFileNames": true,
13
+ "resolveJsonModule": true
14
+ },
15
+ "include": ["src/**/*"],
16
+ "exclude": ["node_modules", "dist"]
17
+ }