@canonical/summon 0.29.0 → 0.30.0
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/dist/generators/example/hello/index.js +104 -0
- package/dist/generators/example/hello/index.js.map +1 -0
- package/dist/generators/example/webapp/index.js +374 -0
- package/dist/generators/example/webapp/index.js.map +1 -0
- package/dist/generators/init/index.js +98 -0
- package/dist/generators/init/index.js.map +1 -0
- package/dist/src/bin.js +153 -0
- package/dist/src/bin.js.map +1 -0
- package/dist/src/completion.js +375 -0
- package/dist/src/completion.js.map +1 -0
- package/dist/src/components/App.js +621 -0
- package/dist/src/components/App.js.map +1 -0
- package/dist/src/components/ExecutionProgress.js +132 -0
- package/dist/src/components/ExecutionProgress.js.map +1 -0
- package/dist/src/components/FileTreePreview.js +55 -0
- package/dist/src/components/FileTreePreview.js.map +1 -0
- package/dist/src/components/PromptSequence.js +215 -0
- package/dist/src/components/PromptSequence.js.map +1 -0
- package/dist/src/components/Spinner.js +20 -0
- package/dist/src/components/Spinner.js.map +1 -0
- package/{src/components/index.ts → dist/src/components/index.js} +1 -6
- package/dist/src/components/index.js.map +1 -0
- package/{src/discovery/index.ts → dist/src/discovery/index.js} +1 -0
- package/dist/src/discovery/index.js.map +1 -0
- package/dist/src/discovery/loadGenerator.js +29 -0
- package/dist/src/discovery/loadGenerator.js.map +1 -0
- package/{src/display/index.ts → dist/src/display/index.js} +1 -0
- package/dist/src/display/index.js.map +1 -0
- package/dist/src/display/printGeneratorHelp.js +99 -0
- package/dist/src/display/printGeneratorHelp.js.map +1 -0
- package/dist/src/display/printNode.js +64 -0
- package/dist/src/display/printNode.js.map +1 -0
- package/dist/src/registration/buildCommandBarrel.js +45 -0
- package/dist/src/registration/buildCommandBarrel.js.map +1 -0
- package/{src/registration/index.ts → dist/src/registration/index.js} +1 -1
- package/dist/src/registration/index.js.map +1 -0
- package/dist/src/registration/registerFromBarrel.js +408 -0
- package/dist/src/registration/registerFromBarrel.js.map +1 -0
- package/dist/src/registration/types.js +2 -0
- package/dist/src/registration/types.js.map +1 -0
- package/package.json +13 -15
- package/generators/application/react/index.ts +0 -4
- package/generators/domain/index.ts +0 -4
- package/generators/example/hello/index.ts +0 -126
- package/generators/example/webapp/index.ts +0 -511
- package/generators/init/index.ts +0 -119
- package/generators/route/index.ts +0 -4
- package/generators/wrapper/index.ts +0 -4
- package/src/bin.tsx +0 -199
- package/src/completion.test.ts +0 -202
- package/src/completion.ts +0 -492
- package/src/components/App.tsx +0 -1053
- package/src/components/ExecutionProgress.tsx +0 -209
- package/src/components/FileTreePreview.tsx +0 -97
- package/src/components/PromptSequence.tsx +0 -483
- package/src/components/Spinner.tsx +0 -36
- package/src/discovery/loadGenerator.ts +0 -37
- package/src/display/printGeneratorHelp.ts +0 -128
- package/src/display/printNode.ts +0 -76
- package/src/registration/buildCommandBarrel.ts +0 -57
- package/src/registration/registerFromBarrel.tsx +0 -548
- package/src/registration/types.ts +0 -28
- /package/{generators → dist/generators}/example/hello/templates/README.md.ejs +0 -0
- /package/{generators → dist/generators}/example/hello/templates/index.ts.ejs +0 -0
- /package/{generators → dist/generators}/example/webapp/templates/ARCHITECTURE.md.ejs +0 -0
- /package/{generators → dist/generators}/example/webapp/templates/App.tsx.ejs +0 -0
- /package/{generators → dist/generators}/example/webapp/templates/README.md.ejs +0 -0
- /package/{generators → dist/generators}/example/webapp/templates/app.test.ts.ejs +0 -0
- /package/{generators → dist/generators}/example/webapp/templates/app.ts.ejs +0 -0
- /package/{generators → dist/generators}/example/webapp/templates/feature.ts.ejs +0 -0
- /package/{generators → dist/generators}/example/webapp/templates/index.html.ejs +0 -0
- /package/{generators → dist/generators}/example/webapp/templates/main.tsx.ejs +0 -0
- /package/{generators → dist/generators}/example/webapp/templates/styles.css.ejs +0 -0
- /package/{generators → dist/generators}/init/templates/generator.ts.ejs +0 -0
- /package/{generators → dist/generators}/init/templates/template-index.ts.ejs +0 -0
- /package/{generators → dist/generators}/init/templates/template-test.ts.ejs +0 -0
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Hello World Generator (Demo)
|
|
3
|
-
*
|
|
4
|
-
* A simple example generator that demonstrates the core features of Summon,
|
|
5
|
-
* including EJS templates and the withHelpers utility.
|
|
6
|
-
*
|
|
7
|
-
* Use this as a reference when building your own generators.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import * as path from "node:path";
|
|
11
|
-
import type { GeneratorDefinition } from "@canonical/summon-core";
|
|
12
|
-
import { template, withHelpers } from "@canonical/summon-core";
|
|
13
|
-
import { info, mkdir, sequence_, when } from "@canonical/task";
|
|
14
|
-
|
|
15
|
-
// =============================================================================
|
|
16
|
-
// Types
|
|
17
|
-
// =============================================================================
|
|
18
|
-
|
|
19
|
-
interface HelloAnswers {
|
|
20
|
-
name: string;
|
|
21
|
-
description: string;
|
|
22
|
-
greeting: string;
|
|
23
|
-
withReadme: boolean;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// =============================================================================
|
|
27
|
-
// Generator Definition
|
|
28
|
-
// =============================================================================
|
|
29
|
-
|
|
30
|
-
export const generator: GeneratorDefinition<HelloAnswers> = {
|
|
31
|
-
meta: {
|
|
32
|
-
name: "hello",
|
|
33
|
-
description: "A demo generator that creates a simple hello world project",
|
|
34
|
-
version: "0.1.0",
|
|
35
|
-
help: `This generator demonstrates the core features of Summon:
|
|
36
|
-
|
|
37
|
-
- EJS templates for dynamic file generation
|
|
38
|
-
- The withHelpers utility for case transformations (camelCase, pascalCase, etc.)
|
|
39
|
-
- Conditional file generation with the 'when' combinator
|
|
40
|
-
- Sequential task composition with 'sequence_' or fluent '.then()' chains
|
|
41
|
-
|
|
42
|
-
Use this generator as a reference when building your own generators.`,
|
|
43
|
-
examples: [
|
|
44
|
-
// Zero-config: interactive prompts with defaults
|
|
45
|
-
"summon hello",
|
|
46
|
-
// Minimal: just the name
|
|
47
|
-
"summon hello --name=my-app",
|
|
48
|
-
// Partial: customize greeting
|
|
49
|
-
"summon hello --name=my-app --greeting=Hey",
|
|
50
|
-
// Skip optional file
|
|
51
|
-
"summon hello --name=my-app --no-withReadme",
|
|
52
|
-
// Preview without writing
|
|
53
|
-
"summon hello --dry-run",
|
|
54
|
-
// Full non-interactive
|
|
55
|
-
"summon hello --name=demo --greeting=Hello --description='A demo' --yes",
|
|
56
|
-
],
|
|
57
|
-
},
|
|
58
|
-
|
|
59
|
-
prompts: [
|
|
60
|
-
{
|
|
61
|
-
name: "name",
|
|
62
|
-
type: "text",
|
|
63
|
-
message: "Project name:",
|
|
64
|
-
default: "my-project",
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
name: "description",
|
|
68
|
-
type: "text",
|
|
69
|
-
message: "Description (optional):",
|
|
70
|
-
default: "",
|
|
71
|
-
},
|
|
72
|
-
{
|
|
73
|
-
name: "greeting",
|
|
74
|
-
type: "select",
|
|
75
|
-
message: "Choose a greeting:",
|
|
76
|
-
choices: [
|
|
77
|
-
{ label: "Hello", value: "Hello" },
|
|
78
|
-
{ label: "Hi", value: "Hi" },
|
|
79
|
-
{ label: "Hey", value: "Hey" },
|
|
80
|
-
{ label: "Greetings", value: "Greetings" },
|
|
81
|
-
],
|
|
82
|
-
default: "Hello",
|
|
83
|
-
},
|
|
84
|
-
{
|
|
85
|
-
name: "withReadme",
|
|
86
|
-
type: "confirm",
|
|
87
|
-
message: "Include README.md?",
|
|
88
|
-
default: true,
|
|
89
|
-
},
|
|
90
|
-
],
|
|
91
|
-
|
|
92
|
-
generate: (answers) => {
|
|
93
|
-
const { name, withReadme } = answers;
|
|
94
|
-
|
|
95
|
-
// withHelpers adds camelCase, kebabCase, pascalCase, etc. to the template vars
|
|
96
|
-
const vars = withHelpers(answers);
|
|
97
|
-
|
|
98
|
-
return sequence_([
|
|
99
|
-
info(`Creating ${name}...`),
|
|
100
|
-
|
|
101
|
-
// Create project directory
|
|
102
|
-
mkdir(name),
|
|
103
|
-
|
|
104
|
-
// Create main file using EJS template
|
|
105
|
-
template({
|
|
106
|
-
source: path.join(__dirname, "templates", "index.ts.ejs"),
|
|
107
|
-
dest: path.join(name, "index.ts"),
|
|
108
|
-
vars,
|
|
109
|
-
}),
|
|
110
|
-
|
|
111
|
-
// Conditionally create README using EJS template
|
|
112
|
-
when(
|
|
113
|
-
withReadme,
|
|
114
|
-
template({
|
|
115
|
-
source: path.join(__dirname, "templates", "README.md.ejs"),
|
|
116
|
-
dest: path.join(name, "README.md"),
|
|
117
|
-
vars,
|
|
118
|
-
}),
|
|
119
|
-
),
|
|
120
|
-
|
|
121
|
-
info(`Done! Run: cd ${name} && bun run index.ts`),
|
|
122
|
-
]);
|
|
123
|
-
},
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
export default generator;
|
|
@@ -1,511 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Web App Generator (Advanced Demo)
|
|
3
|
-
*
|
|
4
|
-
* A comprehensive example generator that demonstrates the full power of Summon,
|
|
5
|
-
* including parallel operations, file I/O, conditionals, error handling,
|
|
6
|
-
* context management, and template rendering.
|
|
7
|
-
*
|
|
8
|
-
* Use this as a reference for building complex generators.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import * as path from "node:path";
|
|
12
|
-
import type { GeneratorDefinition } from "@canonical/summon-core";
|
|
13
|
-
import { template, withHelpers } from "@canonical/summon-core";
|
|
14
|
-
import type { Task } from "@canonical/task";
|
|
15
|
-
import {
|
|
16
|
-
appendFile,
|
|
17
|
-
debug,
|
|
18
|
-
exec,
|
|
19
|
-
exists,
|
|
20
|
-
flatMap,
|
|
21
|
-
getContext,
|
|
22
|
-
ifElse,
|
|
23
|
-
info,
|
|
24
|
-
map,
|
|
25
|
-
mkdir,
|
|
26
|
-
orElse,
|
|
27
|
-
parallel,
|
|
28
|
-
pure,
|
|
29
|
-
readFile,
|
|
30
|
-
sequence_,
|
|
31
|
-
setContext,
|
|
32
|
-
traverse_,
|
|
33
|
-
warn,
|
|
34
|
-
when,
|
|
35
|
-
writeFile,
|
|
36
|
-
} from "@canonical/task";
|
|
37
|
-
|
|
38
|
-
// =============================================================================
|
|
39
|
-
// Types
|
|
40
|
-
// =============================================================================
|
|
41
|
-
|
|
42
|
-
interface WebAppAnswers {
|
|
43
|
-
name: string;
|
|
44
|
-
description: string;
|
|
45
|
-
framework: "react" | "vanilla";
|
|
46
|
-
styling: "css" | "tailwind" | "none";
|
|
47
|
-
features: string[];
|
|
48
|
-
withTests: boolean;
|
|
49
|
-
withDocs: boolean;
|
|
50
|
-
installDeps: boolean;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// =============================================================================
|
|
54
|
-
// Helper Tasks
|
|
55
|
-
// =============================================================================
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Check if a directory exists, creating it if not.
|
|
59
|
-
* Demonstrates: exists + ifElse + info logging
|
|
60
|
-
*/
|
|
61
|
-
const ensureDir = (dirPath: string): Task<void> =>
|
|
62
|
-
flatMap(exists(dirPath), (doesExist) =>
|
|
63
|
-
ifElse(
|
|
64
|
-
doesExist,
|
|
65
|
-
debug(`Directory ${dirPath} already exists`),
|
|
66
|
-
mkdir(dirPath),
|
|
67
|
-
),
|
|
68
|
-
);
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Write a JSON file with pretty formatting.
|
|
72
|
-
* Demonstrates: writeFile with transformation
|
|
73
|
-
*/
|
|
74
|
-
const writeJson = (filePath: string, data: object): Task<void> =>
|
|
75
|
-
writeFile(filePath, `${JSON.stringify(data, null, 2)}\n`);
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Try to read an existing config, falling back to default.
|
|
79
|
-
* Demonstrates: orElse for error recovery
|
|
80
|
-
*/
|
|
81
|
-
const _readConfigOrDefault = <T>(
|
|
82
|
-
configPath: string,
|
|
83
|
-
defaultValue: T,
|
|
84
|
-
): Task<T> =>
|
|
85
|
-
orElse(
|
|
86
|
-
map(readFile(configPath), (content) => JSON.parse(content) as T),
|
|
87
|
-
pure(defaultValue),
|
|
88
|
-
);
|
|
89
|
-
|
|
90
|
-
// =============================================================================
|
|
91
|
-
// Generator Definition
|
|
92
|
-
// =============================================================================
|
|
93
|
-
|
|
94
|
-
export const generator: GeneratorDefinition<WebAppAnswers> = {
|
|
95
|
-
meta: {
|
|
96
|
-
name: "webapp",
|
|
97
|
-
description:
|
|
98
|
-
"Create a web application with configurable framework, styling, and features",
|
|
99
|
-
version: "0.1.0",
|
|
100
|
-
help: `This advanced generator demonstrates the full capabilities of Summon:
|
|
101
|
-
|
|
102
|
-
EFFECTS DEMONSTRATED:
|
|
103
|
-
- File Operations: readFile, writeFile, copyFile, mkdir, exists
|
|
104
|
-
- Process Execution: exec (npm/bun commands)
|
|
105
|
-
- Logging: info, warn, debug
|
|
106
|
-
- Context: getContext, setContext (for passing data between tasks)
|
|
107
|
-
|
|
108
|
-
COMBINATORS DEMONSTRATED:
|
|
109
|
-
- sequence_: Sequential task composition
|
|
110
|
-
- parallel: Concurrent task execution
|
|
111
|
-
- traverse_: Mapping over arrays with tasks
|
|
112
|
-
- when/ifElse: Conditional task execution
|
|
113
|
-
- orElse: Error recovery with fallbacks
|
|
114
|
-
- flatMap/map: Monadic composition
|
|
115
|
-
|
|
116
|
-
TEMPLATES:
|
|
117
|
-
- EJS templates with withHelpers (camelCase, pascalCase, etc.)
|
|
118
|
-
- Conditional template sections
|
|
119
|
-
- Dynamic content based on answers`,
|
|
120
|
-
examples: [
|
|
121
|
-
// Zero-config: uses all defaults, interactive prompts
|
|
122
|
-
"summon webapp",
|
|
123
|
-
// Minimal: just override the name, rest uses defaults
|
|
124
|
-
"summon webapp --name=my-app",
|
|
125
|
-
// Partial: specify stack choices, defaults for the rest
|
|
126
|
-
"summon webapp --name=my-app --framework=react --styling=tailwind",
|
|
127
|
-
// Features: add specific modules
|
|
128
|
-
"summon webapp --name=my-app --features=router,state,api",
|
|
129
|
-
// Full non-interactive: all options specified, skip prompts
|
|
130
|
-
"summon webapp --name=my-app --framework=react --styling=tailwind --features=router,state --no-withDocs --yes",
|
|
131
|
-
// Preview mode: see what would be generated without writing
|
|
132
|
-
"summon webapp --dry-run",
|
|
133
|
-
],
|
|
134
|
-
},
|
|
135
|
-
|
|
136
|
-
prompts: [
|
|
137
|
-
{
|
|
138
|
-
name: "name",
|
|
139
|
-
type: "text",
|
|
140
|
-
message: "Project name:",
|
|
141
|
-
default: "my-webapp",
|
|
142
|
-
group: "Project",
|
|
143
|
-
},
|
|
144
|
-
{
|
|
145
|
-
name: "description",
|
|
146
|
-
type: "text",
|
|
147
|
-
message: "Description:",
|
|
148
|
-
default: "A web application",
|
|
149
|
-
group: "Project",
|
|
150
|
-
},
|
|
151
|
-
{
|
|
152
|
-
name: "framework",
|
|
153
|
-
type: "select",
|
|
154
|
-
message: "Framework:",
|
|
155
|
-
choices: [
|
|
156
|
-
{ label: "React", value: "react" },
|
|
157
|
-
{ label: "Vanilla JS", value: "vanilla" },
|
|
158
|
-
],
|
|
159
|
-
default: "react",
|
|
160
|
-
group: "Stack",
|
|
161
|
-
},
|
|
162
|
-
{
|
|
163
|
-
name: "styling",
|
|
164
|
-
type: "select",
|
|
165
|
-
message: "Styling solution:",
|
|
166
|
-
choices: [
|
|
167
|
-
{ label: "Plain CSS", value: "css" },
|
|
168
|
-
{ label: "Tailwind CSS", value: "tailwind" },
|
|
169
|
-
{ label: "None", value: "none" },
|
|
170
|
-
],
|
|
171
|
-
default: "css",
|
|
172
|
-
group: "Stack",
|
|
173
|
-
},
|
|
174
|
-
{
|
|
175
|
-
name: "features",
|
|
176
|
-
type: "multiselect",
|
|
177
|
-
message: "Additional features:",
|
|
178
|
-
choices: [
|
|
179
|
-
{ label: "Router", value: "router" },
|
|
180
|
-
{ label: "State Management", value: "state" },
|
|
181
|
-
{ label: "API Client", value: "api" },
|
|
182
|
-
{ label: "Logging", value: "logging" },
|
|
183
|
-
],
|
|
184
|
-
default: [],
|
|
185
|
-
group: "Stack",
|
|
186
|
-
},
|
|
187
|
-
{
|
|
188
|
-
name: "withTests",
|
|
189
|
-
type: "confirm",
|
|
190
|
-
message: "Include test setup?",
|
|
191
|
-
default: true,
|
|
192
|
-
group: "Extras",
|
|
193
|
-
},
|
|
194
|
-
{
|
|
195
|
-
name: "withDocs",
|
|
196
|
-
type: "confirm",
|
|
197
|
-
message: "Include documentation?",
|
|
198
|
-
default: true,
|
|
199
|
-
group: "Extras",
|
|
200
|
-
},
|
|
201
|
-
{
|
|
202
|
-
name: "installDeps",
|
|
203
|
-
type: "confirm",
|
|
204
|
-
message: "Install dependencies after generation?",
|
|
205
|
-
default: false,
|
|
206
|
-
group: "Extras",
|
|
207
|
-
},
|
|
208
|
-
],
|
|
209
|
-
|
|
210
|
-
generate: (answers) => {
|
|
211
|
-
const { name, framework, styling, withTests, withDocs, installDeps } =
|
|
212
|
-
answers;
|
|
213
|
-
|
|
214
|
-
// Filter out empty strings from features (handles --features= edge case)
|
|
215
|
-
const features = (answers.features ?? []).filter((f) => f.length > 0);
|
|
216
|
-
|
|
217
|
-
// Enhance answers with case transformation helpers
|
|
218
|
-
const vars = withHelpers({
|
|
219
|
-
...answers,
|
|
220
|
-
features, // Use cleaned features
|
|
221
|
-
hasRouter: features.includes("router"),
|
|
222
|
-
hasState: features.includes("state"),
|
|
223
|
-
hasApi: features.includes("api"),
|
|
224
|
-
hasLogging: features.includes("logging"),
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
const projectDir = name;
|
|
228
|
-
|
|
229
|
-
// =========================================================================
|
|
230
|
-
// Task 1: Setup directory structure (parallel)
|
|
231
|
-
// Demonstrates: parallel + ensureDir helper
|
|
232
|
-
// =========================================================================
|
|
233
|
-
const createDirectories = sequence_([
|
|
234
|
-
info("Setting up directory structure..."),
|
|
235
|
-
// Store project path in context for later tasks
|
|
236
|
-
setContext("projectDir", projectDir),
|
|
237
|
-
// Create directories in parallel for efficiency
|
|
238
|
-
parallel([
|
|
239
|
-
ensureDir(projectDir),
|
|
240
|
-
ensureDir(path.join(projectDir, "src")),
|
|
241
|
-
ensureDir(path.join(projectDir, "src", "components")),
|
|
242
|
-
ensureDir(path.join(projectDir, "public")),
|
|
243
|
-
when(withTests, ensureDir(path.join(projectDir, "tests"))),
|
|
244
|
-
when(withDocs, ensureDir(path.join(projectDir, "docs"))),
|
|
245
|
-
]),
|
|
246
|
-
]);
|
|
247
|
-
|
|
248
|
-
// =========================================================================
|
|
249
|
-
// Task 2: Generate configuration files
|
|
250
|
-
// Demonstrates: writeJson, readConfigOrDefault, parallel
|
|
251
|
-
// =========================================================================
|
|
252
|
-
const generateConfigs = sequence_([
|
|
253
|
-
info("Generating configuration files..."),
|
|
254
|
-
parallel([
|
|
255
|
-
// Package.json with dependencies based on choices
|
|
256
|
-
writeJson(path.join(projectDir, "package.json"), {
|
|
257
|
-
name,
|
|
258
|
-
version: "0.1.0",
|
|
259
|
-
description: answers.description,
|
|
260
|
-
type: "module",
|
|
261
|
-
scripts: {
|
|
262
|
-
dev: framework === "react" ? "vite" : "live-server public",
|
|
263
|
-
build:
|
|
264
|
-
framework === "react" ? "vite build" : "echo 'No build step'",
|
|
265
|
-
...(withTests ? { test: "vitest" } : {}),
|
|
266
|
-
},
|
|
267
|
-
dependencies: {
|
|
268
|
-
...(framework === "react"
|
|
269
|
-
? { react: "^18.2.0", "react-dom": "^18.2.0" }
|
|
270
|
-
: {}),
|
|
271
|
-
...(styling === "tailwind" ? { tailwindcss: "^3.4.0" } : {}),
|
|
272
|
-
...(features.includes("router") && framework === "react"
|
|
273
|
-
? { "react-router-dom": "^6.20.0" }
|
|
274
|
-
: {}),
|
|
275
|
-
...(features.includes("state") && framework === "react"
|
|
276
|
-
? { zustand: "^4.4.0" }
|
|
277
|
-
: {}),
|
|
278
|
-
...(features.includes("api") ? { ky: "^1.1.0" } : {}),
|
|
279
|
-
},
|
|
280
|
-
devDependencies: {
|
|
281
|
-
...(framework === "react"
|
|
282
|
-
? { vite: "^5.0.0", "@vitejs/plugin-react": "^4.2.0" }
|
|
283
|
-
: {}),
|
|
284
|
-
...(withTests ? { vitest: "^1.0.0" } : {}),
|
|
285
|
-
typescript: "^5.3.0",
|
|
286
|
-
...(styling === "tailwind"
|
|
287
|
-
? { autoprefixer: "^10.4.0", postcss: "^8.4.0" }
|
|
288
|
-
: {}),
|
|
289
|
-
},
|
|
290
|
-
}),
|
|
291
|
-
|
|
292
|
-
// TypeScript config
|
|
293
|
-
writeJson(path.join(projectDir, "tsconfig.json"), {
|
|
294
|
-
compilerOptions: {
|
|
295
|
-
target: "ES2022",
|
|
296
|
-
module: "ESNext",
|
|
297
|
-
moduleResolution: "bundler",
|
|
298
|
-
strict: true,
|
|
299
|
-
jsx: framework === "react" ? "react-jsx" : undefined,
|
|
300
|
-
esModuleInterop: true,
|
|
301
|
-
skipLibCheck: true,
|
|
302
|
-
outDir: "dist",
|
|
303
|
-
},
|
|
304
|
-
include: ["src/**/*"],
|
|
305
|
-
exclude: ["node_modules"],
|
|
306
|
-
}),
|
|
307
|
-
|
|
308
|
-
// Tailwind config (conditional)
|
|
309
|
-
when(
|
|
310
|
-
styling === "tailwind",
|
|
311
|
-
writeFile(
|
|
312
|
-
path.join(projectDir, "tailwind.config.js"),
|
|
313
|
-
`/** @type {import('tailwindcss').Config} */
|
|
314
|
-
export default {
|
|
315
|
-
content: ["./index.html", "./src/**/*.{js,ts,jsx,tsx}"],
|
|
316
|
-
theme: {
|
|
317
|
-
extend: {},
|
|
318
|
-
},
|
|
319
|
-
plugins: [],
|
|
320
|
-
};
|
|
321
|
-
`,
|
|
322
|
-
),
|
|
323
|
-
),
|
|
324
|
-
]),
|
|
325
|
-
]);
|
|
326
|
-
|
|
327
|
-
// =========================================================================
|
|
328
|
-
// Task 3: Generate source files using templates
|
|
329
|
-
// Demonstrates: template, traverse_, when
|
|
330
|
-
// =========================================================================
|
|
331
|
-
const generateSourceFiles = sequence_([
|
|
332
|
-
info("Generating source files..."),
|
|
333
|
-
|
|
334
|
-
// Main entry point
|
|
335
|
-
template({
|
|
336
|
-
source: path.join(__dirname, "templates", "main.tsx.ejs"),
|
|
337
|
-
dest: path.join(
|
|
338
|
-
projectDir,
|
|
339
|
-
"src",
|
|
340
|
-
`main.${framework === "react" ? "tsx" : "ts"}`,
|
|
341
|
-
),
|
|
342
|
-
vars,
|
|
343
|
-
}),
|
|
344
|
-
|
|
345
|
-
// App component (React) or main module (Vanilla)
|
|
346
|
-
template({
|
|
347
|
-
source: path.join(
|
|
348
|
-
__dirname,
|
|
349
|
-
"templates",
|
|
350
|
-
framework === "react" ? "App.tsx.ejs" : "app.ts.ejs",
|
|
351
|
-
),
|
|
352
|
-
dest: path.join(
|
|
353
|
-
projectDir,
|
|
354
|
-
"src",
|
|
355
|
-
framework === "react" ? "App.tsx" : "app.ts",
|
|
356
|
-
),
|
|
357
|
-
vars,
|
|
358
|
-
}),
|
|
359
|
-
|
|
360
|
-
// Index HTML
|
|
361
|
-
template({
|
|
362
|
-
source: path.join(__dirname, "templates", "index.html.ejs"),
|
|
363
|
-
dest: path.join(projectDir, "index.html"),
|
|
364
|
-
vars,
|
|
365
|
-
}),
|
|
366
|
-
|
|
367
|
-
// Optional: Generate feature modules
|
|
368
|
-
when(
|
|
369
|
-
features.length > 0,
|
|
370
|
-
sequence_([
|
|
371
|
-
info(`Adding ${features.length} feature module(s)...`),
|
|
372
|
-
traverse_(features, (feature) =>
|
|
373
|
-
template({
|
|
374
|
-
source: path.join(__dirname, "templates", "feature.ts.ejs"),
|
|
375
|
-
dest: path.join(projectDir, "src", `${feature}.ts`),
|
|
376
|
-
vars: { ...vars, featureName: feature },
|
|
377
|
-
}),
|
|
378
|
-
),
|
|
379
|
-
// Create barrel file (index.ts) with exports for each feature
|
|
380
|
-
// Demonstrates: appendFile for creating/updating barrel files
|
|
381
|
-
info("Creating barrel file (src/index.ts)..."),
|
|
382
|
-
writeFile(
|
|
383
|
-
path.join(projectDir, "src", "index.ts"),
|
|
384
|
-
`// Barrel file - auto-generated by summon webapp\n// Re-exports all modules for easy importing\n\n`,
|
|
385
|
-
),
|
|
386
|
-
traverse_(features, (feature) =>
|
|
387
|
-
appendFile(
|
|
388
|
-
path.join(projectDir, "src", "index.ts"),
|
|
389
|
-
`export * from "./${feature}.js";\n`,
|
|
390
|
-
),
|
|
391
|
-
),
|
|
392
|
-
]),
|
|
393
|
-
),
|
|
394
|
-
|
|
395
|
-
// Optional: Styles
|
|
396
|
-
when(
|
|
397
|
-
styling !== "none",
|
|
398
|
-
template({
|
|
399
|
-
source: path.join(__dirname, "templates", "styles.css.ejs"),
|
|
400
|
-
dest: path.join(projectDir, "src", "styles.css"),
|
|
401
|
-
vars,
|
|
402
|
-
}),
|
|
403
|
-
),
|
|
404
|
-
]);
|
|
405
|
-
|
|
406
|
-
// =========================================================================
|
|
407
|
-
// Task 4: Generate tests (conditional)
|
|
408
|
-
// Demonstrates: when + parallel for optional features
|
|
409
|
-
// =========================================================================
|
|
410
|
-
const generateTests = when(
|
|
411
|
-
withTests,
|
|
412
|
-
sequence_([
|
|
413
|
-
info("Setting up tests..."),
|
|
414
|
-
parallel([
|
|
415
|
-
template({
|
|
416
|
-
source: path.join(__dirname, "templates", "app.test.ts.ejs"),
|
|
417
|
-
dest: path.join(projectDir, "tests", "app.test.ts"),
|
|
418
|
-
vars,
|
|
419
|
-
}),
|
|
420
|
-
writeFile(
|
|
421
|
-
path.join(projectDir, "vitest.config.ts"),
|
|
422
|
-
`import { defineConfig } from 'vitest/config';
|
|
423
|
-
|
|
424
|
-
export default defineConfig({
|
|
425
|
-
test: {
|
|
426
|
-
environment: '${framework === "react" ? "jsdom" : "node"}',
|
|
427
|
-
include: ['tests/**/*.test.ts'],
|
|
428
|
-
},
|
|
429
|
-
});
|
|
430
|
-
`,
|
|
431
|
-
),
|
|
432
|
-
]),
|
|
433
|
-
]),
|
|
434
|
-
);
|
|
435
|
-
|
|
436
|
-
// =========================================================================
|
|
437
|
-
// Task 5: Generate documentation (conditional)
|
|
438
|
-
// Demonstrates: when + traverse_ for multiple docs
|
|
439
|
-
// =========================================================================
|
|
440
|
-
const generateDocs = when(
|
|
441
|
-
withDocs,
|
|
442
|
-
sequence_([
|
|
443
|
-
info("Generating documentation..."),
|
|
444
|
-
traverse_(
|
|
445
|
-
[
|
|
446
|
-
{ name: "README.md", template: "README.md.ejs", dest: "" },
|
|
447
|
-
{
|
|
448
|
-
name: "ARCHITECTURE.md",
|
|
449
|
-
template: "ARCHITECTURE.md.ejs",
|
|
450
|
-
dest: "docs",
|
|
451
|
-
},
|
|
452
|
-
],
|
|
453
|
-
(doc) =>
|
|
454
|
-
template({
|
|
455
|
-
source: path.join(__dirname, "templates", doc.template),
|
|
456
|
-
dest: path.join(projectDir, doc.dest, doc.name),
|
|
457
|
-
vars,
|
|
458
|
-
}),
|
|
459
|
-
),
|
|
460
|
-
]),
|
|
461
|
-
);
|
|
462
|
-
|
|
463
|
-
// =========================================================================
|
|
464
|
-
// Task 6: Install dependencies (conditional)
|
|
465
|
-
// Demonstrates: exec + context reading + warn
|
|
466
|
-
// =========================================================================
|
|
467
|
-
const installDependencies = when(
|
|
468
|
-
installDeps,
|
|
469
|
-
sequence_([
|
|
470
|
-
info("Installing dependencies..."),
|
|
471
|
-
warn("This may take a moment..."),
|
|
472
|
-
flatMap(getContext<string>("projectDir"), (dir) =>
|
|
473
|
-
flatMap(exec("bun", ["install"], dir ?? projectDir), (result) =>
|
|
474
|
-
ifElse(
|
|
475
|
-
result.exitCode === 0,
|
|
476
|
-
info("Dependencies installed successfully!"),
|
|
477
|
-
warn(
|
|
478
|
-
`Installation completed with warnings (exit code: ${result.exitCode})`,
|
|
479
|
-
),
|
|
480
|
-
),
|
|
481
|
-
),
|
|
482
|
-
),
|
|
483
|
-
]),
|
|
484
|
-
);
|
|
485
|
-
|
|
486
|
-
// =========================================================================
|
|
487
|
-
// Final: Compose all tasks sequentially
|
|
488
|
-
// =========================================================================
|
|
489
|
-
return sequence_([
|
|
490
|
-
info(`Creating ${name} with ${framework} + ${styling}...`),
|
|
491
|
-
debug(`Features: ${features.join(", ") || "none"}`),
|
|
492
|
-
|
|
493
|
-
createDirectories,
|
|
494
|
-
generateConfigs,
|
|
495
|
-
generateSourceFiles,
|
|
496
|
-
generateTests,
|
|
497
|
-
generateDocs,
|
|
498
|
-
installDependencies,
|
|
499
|
-
|
|
500
|
-
info(`
|
|
501
|
-
Done! Your web app is ready.
|
|
502
|
-
|
|
503
|
-
Next steps:
|
|
504
|
-
cd ${name}
|
|
505
|
-
${installDeps ? "" : "bun install\n "}bun run dev
|
|
506
|
-
`),
|
|
507
|
-
]);
|
|
508
|
-
},
|
|
509
|
-
};
|
|
510
|
-
|
|
511
|
-
export default generator;
|