@sweetener/cli 0.1.0-alpha.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/LICENSE +21 -0
- package/README.md +16 -0
- package/bin/sweetener.mjs +29 -0
- package/dist/src/bin.d.ts +3 -0
- package/dist/src/bin.d.ts.map +1 -0
- package/dist/src/bin.js +45 -0
- package/dist/src/bin.js.map +1 -0
- package/dist/src/command-line.d.ts +48 -0
- package/dist/src/command-line.d.ts.map +1 -0
- package/dist/src/command-line.js +449 -0
- package/dist/src/command-line.js.map +1 -0
- package/dist/src/configuration.d.ts +2 -0
- package/dist/src/configuration.d.ts.map +1 -0
- package/dist/src/configuration.js +2 -0
- package/dist/src/configuration.js.map +1 -0
- package/dist/src/default-expansion-provider.d.ts +2 -0
- package/dist/src/default-expansion-provider.d.ts.map +1 -0
- package/dist/src/default-expansion-provider.js +2 -0
- package/dist/src/default-expansion-provider.js.map +1 -0
- package/dist/src/expansion-tools.d.ts +2 -0
- package/dist/src/expansion-tools.d.ts.map +1 -0
- package/dist/src/expansion-tools.js +2 -0
- package/dist/src/expansion-tools.js.map +1 -0
- package/dist/src/incremental-equivalence.d.ts +26 -0
- package/dist/src/incremental-equivalence.d.ts.map +1 -0
- package/dist/src/incremental-equivalence.js +115 -0
- package/dist/src/incremental-equivalence.js.map +1 -0
- package/dist/src/index.d.ts +12 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +12 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/project-command.d.ts +2 -0
- package/dist/src/project-command.d.ts.map +1 -0
- package/dist/src/project-command.js +2 -0
- package/dist/src/project-command.js.map +1 -0
- package/dist/src/project-runner.d.ts +39 -0
- package/dist/src/project-runner.d.ts.map +1 -0
- package/dist/src/project-runner.js +150 -0
- package/dist/src/project-runner.js.map +1 -0
- package/dist/src/scaffold.d.ts +56 -0
- package/dist/src/scaffold.d.ts.map +1 -0
- package/dist/src/scaffold.js +410 -0
- package/dist/src/scaffold.js.map +1 -0
- package/dist/src/source-kind.d.ts +2 -0
- package/dist/src/source-kind.d.ts.map +1 -0
- package/dist/src/source-kind.js +2 -0
- package/dist/src/source-kind.js.map +1 -0
- package/dist/src/standalone-emit.d.ts +26 -0
- package/dist/src/standalone-emit.d.ts.map +1 -0
- package/dist/src/standalone-emit.js +56 -0
- package/dist/src/standalone-emit.js.map +1 -0
- package/package.json +50 -0
|
@@ -0,0 +1,410 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { dirname, join, resolve } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
const macros = `// A macro is declared with \`syntax\`, and exported like anything else.
|
|
5
|
+
// \`:expr\` is where it may be written: in expression position.
|
|
6
|
+
export syntax twice:expr {
|
|
7
|
+
// A rule is a pattern and the syntax it expands to. \`$value:expr\` captures
|
|
8
|
+
// one expression under the name \`value\`.
|
|
9
|
+
rule { twice($value:expr) } => { [$value, $value] }
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// Macros can introduce bindings without capturing the ones around them.
|
|
13
|
+
// \`total\` here cannot collide with a \`total\` at the call site.
|
|
14
|
+
export syntax sum:expr {
|
|
15
|
+
rule { sum($values:expr) } => {
|
|
16
|
+
(($values).reduce((total: number, next: number) => total + next, 0))
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
`;
|
|
20
|
+
const main = `// Macros are imported \`for syntax\`, which says they run at compile time.
|
|
21
|
+
// The import itself does not survive into the emitted TypeScript.
|
|
22
|
+
import { sum, twice } from "./macros.sts" for syntax;
|
|
23
|
+
|
|
24
|
+
export const pair: readonly number[] = twice(21);
|
|
25
|
+
export const total: number = sum([1, 2, 3]);
|
|
26
|
+
|
|
27
|
+
// A binding of the same name as one a macro introduces is left alone.
|
|
28
|
+
const values = [total];
|
|
29
|
+
export const doubled: readonly (readonly number[])[] = values.map((value) =>
|
|
30
|
+
twice(value),
|
|
31
|
+
);
|
|
32
|
+
`;
|
|
33
|
+
function packageManifest(name, cliSpecifier) {
|
|
34
|
+
return `${JSON.stringify({
|
|
35
|
+
name,
|
|
36
|
+
private: true,
|
|
37
|
+
type: "module",
|
|
38
|
+
scripts: {
|
|
39
|
+
build: "sweetener build -p tsconfig.json",
|
|
40
|
+
check: "sweetener check -p tsconfig.json",
|
|
41
|
+
watch: "sweetener watch -p tsconfig.json",
|
|
42
|
+
},
|
|
43
|
+
dependencies: {
|
|
44
|
+
"@sweetener/cli": cliSpecifier,
|
|
45
|
+
typescript: "npm:@typescript/typescript6@6.0.2",
|
|
46
|
+
},
|
|
47
|
+
}, null, 2)}\n`;
|
|
48
|
+
}
|
|
49
|
+
const tsconfig = `${JSON.stringify({
|
|
50
|
+
compilerOptions: {
|
|
51
|
+
strict: true,
|
|
52
|
+
declaration: true,
|
|
53
|
+
outDir: "dist",
|
|
54
|
+
rootDir: "src",
|
|
55
|
+
target: "ES2022",
|
|
56
|
+
module: "ESNext",
|
|
57
|
+
moduleResolution: "Bundler",
|
|
58
|
+
},
|
|
59
|
+
sweet: {
|
|
60
|
+
languageVersion: "1",
|
|
61
|
+
macroExtensions: [".sts"],
|
|
62
|
+
},
|
|
63
|
+
files: ["src/macros.sts", "src/main.sts"],
|
|
64
|
+
}, null, 2)}\n`;
|
|
65
|
+
/**
|
|
66
|
+
* Where to point a new project's dependency on the command line.
|
|
67
|
+
*
|
|
68
|
+
* Run from a checkout, a scaffolded project has to reach the packages through
|
|
69
|
+
* that checkout: the version on the registry is a different build from the one
|
|
70
|
+
* being worked on, and pointing at it would scaffold a project that does not
|
|
71
|
+
* exercise the change under way. Anywhere else the version is the right answer
|
|
72
|
+
* and the path is not.
|
|
73
|
+
*/
|
|
74
|
+
function cliSpecifier() {
|
|
75
|
+
// Walked up to the package rather than counted, because this file sits at a
|
|
76
|
+
// different depth built than it does in source, and counting gets one of
|
|
77
|
+
// them wrong.
|
|
78
|
+
let packaged = dirname(fileURLToPath(import.meta.url));
|
|
79
|
+
while (!existsSync(join(packaged, "package.json"))) {
|
|
80
|
+
const parent = dirname(packaged);
|
|
81
|
+
if (parent === packaged)
|
|
82
|
+
return { specifier: "^0.1.0-alpha.0", note: undefined };
|
|
83
|
+
packaged = parent;
|
|
84
|
+
}
|
|
85
|
+
// A checkout, rather than an install from a registry, is the only place a
|
|
86
|
+
// link can point at.
|
|
87
|
+
if (!existsSync(resolve(packaged, "..", "..", "pnpm-workspace.yaml")))
|
|
88
|
+
return { specifier: "^0.1.0-alpha.0", note: undefined };
|
|
89
|
+
// Absolute, because a relative one is read from wherever the project ends up
|
|
90
|
+
// and quietly resolves somewhere else — a scaffold under a symlinked
|
|
91
|
+
// directory links to nothing at all.
|
|
92
|
+
return {
|
|
93
|
+
specifier: `link:${packaged}`,
|
|
94
|
+
note: `Scaffolded from a checkout, so this project links to it at ${packaged} rather than to the published version. Build that checkout once (pnpm build) before installing here, and expect the link to break if it moves.`,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
export function scaffoldProject(options) {
|
|
98
|
+
const directory = resolve(options.directory);
|
|
99
|
+
const name = options.name ?? (directory.split(/[/\\]/u).at(-1) || "sweet-app");
|
|
100
|
+
const cli = cliSpecifier();
|
|
101
|
+
const files = [
|
|
102
|
+
{ path: "package.json", text: packageManifest(name, cli.specifier) },
|
|
103
|
+
{ path: "tsconfig.json", text: tsconfig },
|
|
104
|
+
{ path: join("src", "macros.sts"), text: macros },
|
|
105
|
+
{ path: join("src", "main.sts"), text: main },
|
|
106
|
+
];
|
|
107
|
+
return Object.freeze({
|
|
108
|
+
files: Object.freeze(files),
|
|
109
|
+
notes: Object.freeze([
|
|
110
|
+
...(cli.note === undefined ? [] : [cli.note]),
|
|
111
|
+
"Install dependencies, then `npm run check` to type-check and `npm run build` to emit into dist/.",
|
|
112
|
+
"Macros live in .sts files and are imported `for syntax`. Editing src/macros.sts changes the language src/main.sts is written in.",
|
|
113
|
+
]),
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
/** Writes a scaffold, refusing to overwrite anything already there. */
|
|
117
|
+
export function writeScaffold(project, directory) {
|
|
118
|
+
const root = resolve(directory);
|
|
119
|
+
const existing = project.files
|
|
120
|
+
.map(({ path }) => path)
|
|
121
|
+
.filter((path) => existsSync(join(root, path)));
|
|
122
|
+
if (existing.length > 0)
|
|
123
|
+
throw new Error(`Refusing to overwrite ${existing.join(", ")} in ${root}. Move or delete them, or scaffold into a different directory.`);
|
|
124
|
+
for (const { path, text } of project.files) {
|
|
125
|
+
const target = join(root, path);
|
|
126
|
+
mkdirSync(dirname(target), { recursive: true });
|
|
127
|
+
writeFileSync(target, text, "utf8");
|
|
128
|
+
}
|
|
129
|
+
return Object.freeze(project.files.map(({ path }) => path));
|
|
130
|
+
}
|
|
131
|
+
const viteWiring = (importPath, plugins) => [
|
|
132
|
+
`Add the plugin to your config:`,
|
|
133
|
+
``,
|
|
134
|
+
` import sweetener from "${importPath}";`,
|
|
135
|
+
` import { resolve } from "node:path";`,
|
|
136
|
+
``,
|
|
137
|
+
` ${plugins}`,
|
|
138
|
+
` ...sweetener({`,
|
|
139
|
+
` configFile: resolve(import.meta.dirname, "sweetener.json"),`,
|
|
140
|
+
` }),`,
|
|
141
|
+
` ]`,
|
|
142
|
+
];
|
|
143
|
+
/**
|
|
144
|
+
* Which integration a project needs, read from what it already depends on.
|
|
145
|
+
*
|
|
146
|
+
* Every one of these is how one of the projects under `examples/` is wired, or
|
|
147
|
+
* — for Rsbuild and Farm, which have an entry point but no example — how
|
|
148
|
+
* `docs/integrations.md` says to wire it. Working it out otherwise means
|
|
149
|
+
* finding the example that matches your host and reading its config, which is
|
|
150
|
+
* only discoverable if you know to look.
|
|
151
|
+
*/
|
|
152
|
+
export function detectHost(options) {
|
|
153
|
+
const dependencies = {
|
|
154
|
+
...options.manifest?.dependencies,
|
|
155
|
+
...options.manifest?.devDependencies,
|
|
156
|
+
};
|
|
157
|
+
const has = (name) => Object.hasOwn(dependencies, name);
|
|
158
|
+
// A runtime is recognised by its own config, because a project built for one
|
|
159
|
+
// may carry no package.json to declare anything in.
|
|
160
|
+
const hasFile = (...names) => names.some((name) => existsSync(join(options.directory, name)));
|
|
161
|
+
if (hasFile("deno.json", "deno.jsonc"))
|
|
162
|
+
return {
|
|
163
|
+
name: "Deno",
|
|
164
|
+
integration: "@sweetener/deno",
|
|
165
|
+
wiring: [
|
|
166
|
+
`Preload the loader hook, which expands sources as they are imported:`,
|
|
167
|
+
``,
|
|
168
|
+
` deno run --import @sweetener/deno/register app.ts`,
|
|
169
|
+
``,
|
|
170
|
+
`Then import a .sts file directly; there is no build step. Point`,
|
|
171
|
+
`SWEETENER_CONFIG at this project's sweetener.json if it is not beside`,
|
|
172
|
+
`the sources.`,
|
|
173
|
+
``,
|
|
174
|
+
`Deno builds the module graph for \`deno test\` and \`deno check\` before`,
|
|
175
|
+
`loader hooks apply, so those two reject a .sts import. For them,`,
|
|
176
|
+
`expand ahead of time with emitStandalone from @sweetener/cli and`,
|
|
177
|
+
`point them at the output.`,
|
|
178
|
+
],
|
|
179
|
+
};
|
|
180
|
+
if (has("bun") || hasFile("bunfig.toml"))
|
|
181
|
+
return {
|
|
182
|
+
name: "Bun",
|
|
183
|
+
integration: "@sweetener/unplugin",
|
|
184
|
+
wiring: [
|
|
185
|
+
`Add the plugin to your Bun build:`,
|
|
186
|
+
``,
|
|
187
|
+
` import sweetener from "@sweetener/unplugin/bun";`,
|
|
188
|
+
` import { resolve } from "node:path";`,
|
|
189
|
+
``,
|
|
190
|
+
` await Bun.build({`,
|
|
191
|
+
` entrypoints: ["src/index.ts"],`,
|
|
192
|
+
` plugins: [`,
|
|
193
|
+
` sweetener({`,
|
|
194
|
+
` configFile: resolve(import.meta.dir, "sweetener.json"),`,
|
|
195
|
+
` }),`,
|
|
196
|
+
` ],`,
|
|
197
|
+
` });`,
|
|
198
|
+
``,
|
|
199
|
+
`To import .sts directly under \`bun run\`, register the same plugin from`,
|
|
200
|
+
`a preload named in bunfig.toml:`,
|
|
201
|
+
``,
|
|
202
|
+
` preload = ["./sweetener.preload.ts"]`,
|
|
203
|
+
``,
|
|
204
|
+
` // sweetener.preload.ts`,
|
|
205
|
+
` Bun.plugin(sweetener({ configFile: resolve(import.meta.dir, "sweetener.json") }));`,
|
|
206
|
+
],
|
|
207
|
+
};
|
|
208
|
+
if (has("next"))
|
|
209
|
+
return {
|
|
210
|
+
name: "Next.js",
|
|
211
|
+
integration: "@sweetener/webpack-loader",
|
|
212
|
+
wiring: [
|
|
213
|
+
`Add a rule for .sts files in next.config, loading them as TypeScript:`,
|
|
214
|
+
``,
|
|
215
|
+
` turbopack: {`,
|
|
216
|
+
` rules: {`,
|
|
217
|
+
` "*.sts": {`,
|
|
218
|
+
` loaders: [`,
|
|
219
|
+
` {`,
|
|
220
|
+
` loader: require.resolve("@sweetener/webpack-loader"),`,
|
|
221
|
+
` options: { configFile: resolve(here, "sweetener.json") },`,
|
|
222
|
+
` },`,
|
|
223
|
+
` ],`,
|
|
224
|
+
` as: "*.ts",`,
|
|
225
|
+
` },`,
|
|
226
|
+
` },`,
|
|
227
|
+
` }`,
|
|
228
|
+
],
|
|
229
|
+
};
|
|
230
|
+
if (has("@sveltejs/kit"))
|
|
231
|
+
return {
|
|
232
|
+
name: "SvelteKit",
|
|
233
|
+
integration: "@sweetener/unplugin",
|
|
234
|
+
wiring: viteWiring("@sweetener/unplugin/vite", "plugins: ["),
|
|
235
|
+
};
|
|
236
|
+
if (has("nuxt"))
|
|
237
|
+
return {
|
|
238
|
+
name: "Nuxt",
|
|
239
|
+
integration: "@sweetener/unplugin",
|
|
240
|
+
wiring: viteWiring("@sweetener/unplugin/vite", "vite: { plugins: ["),
|
|
241
|
+
};
|
|
242
|
+
if (has("astro"))
|
|
243
|
+
return {
|
|
244
|
+
name: "Astro",
|
|
245
|
+
integration: "@sweetener/unplugin",
|
|
246
|
+
wiring: viteWiring("@sweetener/unplugin/vite", "vite: { plugins: ["),
|
|
247
|
+
};
|
|
248
|
+
// Before Rspack and webpack: an Rsbuild project depends on Rsbuild, and the
|
|
249
|
+
// entry point that knows how to register with it is the one it wants.
|
|
250
|
+
if (has("@rsbuild/core"))
|
|
251
|
+
return {
|
|
252
|
+
name: "Rsbuild",
|
|
253
|
+
integration: "@sweetener/unplugin",
|
|
254
|
+
wiring: [
|
|
255
|
+
`Add the plugin to rsbuild.config.ts:`,
|
|
256
|
+
``,
|
|
257
|
+
` import sweetener from "@sweetener/unplugin/rsbuild";`,
|
|
258
|
+
` import { resolve } from "node:path";`,
|
|
259
|
+
``,
|
|
260
|
+
` plugins: [`,
|
|
261
|
+
` sweetener({`,
|
|
262
|
+
` configFile: resolve(import.meta.dirname, "sweetener.json"),`,
|
|
263
|
+
` }),`,
|
|
264
|
+
` ]`,
|
|
265
|
+
],
|
|
266
|
+
};
|
|
267
|
+
if (has("@farmfe/core"))
|
|
268
|
+
return {
|
|
269
|
+
name: "Farm",
|
|
270
|
+
integration: "@sweetener/unplugin",
|
|
271
|
+
wiring: [
|
|
272
|
+
`Add the plugin to farm.config.ts:`,
|
|
273
|
+
``,
|
|
274
|
+
` import sweetener from "@sweetener/unplugin/farm";`,
|
|
275
|
+
` import { resolve } from "node:path";`,
|
|
276
|
+
``,
|
|
277
|
+
` plugins: [`,
|
|
278
|
+
` sweetener({ configFile: resolve(process.cwd(), "sweetener.json") }),`,
|
|
279
|
+
` ]`,
|
|
280
|
+
``,
|
|
281
|
+
`Farm bundles farm.config.ts into node_modules/.farm before running it,`,
|
|
282
|
+
`so import.meta.dirname there is that directory, not this one.`,
|
|
283
|
+
],
|
|
284
|
+
};
|
|
285
|
+
if (has("vite"))
|
|
286
|
+
return {
|
|
287
|
+
name: "Vite",
|
|
288
|
+
integration: "@sweetener/unplugin",
|
|
289
|
+
wiring: viteWiring("@sweetener/unplugin/vite", "plugins: ["),
|
|
290
|
+
};
|
|
291
|
+
if (has("parcel") || has("@parcel/core"))
|
|
292
|
+
return {
|
|
293
|
+
name: "Parcel",
|
|
294
|
+
integration: "@sweetener/parcel-transformer",
|
|
295
|
+
wiring: [
|
|
296
|
+
`Add the transformer to .parcelrc:`,
|
|
297
|
+
``,
|
|
298
|
+
` { "transformers": { "*.sts": ["@sweetener/parcel-transformer"] } }`,
|
|
299
|
+
],
|
|
300
|
+
};
|
|
301
|
+
if (has("webpack"))
|
|
302
|
+
return {
|
|
303
|
+
name: "webpack",
|
|
304
|
+
integration: "@sweetener/webpack-loader",
|
|
305
|
+
wiring: [
|
|
306
|
+
`Add a rule to your webpack config:`,
|
|
307
|
+
``,
|
|
308
|
+
` {`,
|
|
309
|
+
` test: /\\.sts$/,`,
|
|
310
|
+
` use: {`,
|
|
311
|
+
` loader: "@sweetener/webpack-loader",`,
|
|
312
|
+
` options: { configFile: resolve("sweetener.json") },`,
|
|
313
|
+
` },`,
|
|
314
|
+
` }`,
|
|
315
|
+
],
|
|
316
|
+
};
|
|
317
|
+
if (has("jest"))
|
|
318
|
+
return {
|
|
319
|
+
name: "Jest",
|
|
320
|
+
integration: "@sweetener/jest",
|
|
321
|
+
wiring: [
|
|
322
|
+
`Add the transform to your Jest config:`,
|
|
323
|
+
``,
|
|
324
|
+
` transform: {`,
|
|
325
|
+
` "^.+\\.sts$": ["@sweetener/jest", { configFile: "sweetener.json" }],`,
|
|
326
|
+
` }`,
|
|
327
|
+
``,
|
|
328
|
+
`The configFile is what tells it which macros this project has, and`,
|
|
329
|
+
`what to re-expand when one of them changes.`,
|
|
330
|
+
],
|
|
331
|
+
};
|
|
332
|
+
return undefined;
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* The config beside a project that already builds itself.
|
|
336
|
+
*
|
|
337
|
+
* A bundler emits the result itself and only wants the expansion, so nothing
|
|
338
|
+
* should be written to disk. Where no bundler was recognised the advice is to
|
|
339
|
+
* run `sweetener build`, and a config that cannot emit would have reported
|
|
340
|
+
* success while producing no files.
|
|
341
|
+
*/
|
|
342
|
+
const consumerConfig = (files, emit) => `${JSON.stringify({
|
|
343
|
+
compilerOptions: {
|
|
344
|
+
target: "ES2022",
|
|
345
|
+
module: "ESNext",
|
|
346
|
+
moduleResolution: "Bundler",
|
|
347
|
+
strict: true,
|
|
348
|
+
skipLibCheck: true,
|
|
349
|
+
// What lets an ordinary `.ts` file import a `.sts` one: with this on,
|
|
350
|
+
// `sourceDeclarations` writes a `main.d.sts.ts` that TypeScript
|
|
351
|
+
// resolves `./main.sts` through.
|
|
352
|
+
allowArbitraryExtensions: true,
|
|
353
|
+
...(emit
|
|
354
|
+
? { declaration: true, outDir: "dist", rootDir: "src" }
|
|
355
|
+
: { noEmit: true }),
|
|
356
|
+
},
|
|
357
|
+
// Under a bundler the rest of the app is TypeScript that imports these,
|
|
358
|
+
// and without declarations beside them `tsc` cannot resolve the import
|
|
359
|
+
// — which breaks the build script the project already had.
|
|
360
|
+
sweet: { sourceDeclarations: true },
|
|
361
|
+
files,
|
|
362
|
+
}, null, 2)}\n`;
|
|
363
|
+
/**
|
|
364
|
+
* What to add to a project that already builds itself somehow.
|
|
365
|
+
*
|
|
366
|
+
* Nothing it already has is touched. The parts that belong in a file someone
|
|
367
|
+
* else wrote — a bundler config — are printed rather than edited in.
|
|
368
|
+
*/
|
|
369
|
+
export function scaffoldIntoProject(options) {
|
|
370
|
+
const host = detectHost({
|
|
371
|
+
manifest: options.manifest,
|
|
372
|
+
directory: options.directory,
|
|
373
|
+
});
|
|
374
|
+
const cli = cliSpecifier();
|
|
375
|
+
const integration = host?.integration ?? "@sweetener/cli";
|
|
376
|
+
// Telling someone to install what they have just run reads as though the
|
|
377
|
+
// scaffolder did not look. The manifest says whether it is already there.
|
|
378
|
+
const dependencies = {
|
|
379
|
+
...(options.manifest?.dependencies ?? {}),
|
|
380
|
+
...(options.manifest?.devDependencies ?? {}),
|
|
381
|
+
};
|
|
382
|
+
const install = cli.specifier.startsWith("link:") && host !== undefined
|
|
383
|
+
? `Add ${integration} as a link: dependency pointing into this checkout, the way ${cliSpecifier().specifier} does, so it matches the command line this was scaffolded with.`
|
|
384
|
+
: integration in dependencies
|
|
385
|
+
? `${integration} is already a dependency here.`
|
|
386
|
+
: `Install ${integration}.`;
|
|
387
|
+
return Object.freeze({
|
|
388
|
+
files: Object.freeze([
|
|
389
|
+
{
|
|
390
|
+
path: "sweetener.json",
|
|
391
|
+
text: consumerConfig(["src/macros.sts", "src/example.sts"], host === undefined),
|
|
392
|
+
},
|
|
393
|
+
{ path: join("src", "macros.sts"), text: macros },
|
|
394
|
+
{ path: join("src", "example.sts"), text: main },
|
|
395
|
+
]),
|
|
396
|
+
notes: Object.freeze([
|
|
397
|
+
host === undefined
|
|
398
|
+
? "No bundler was recognised here, so this project is set up for the command line: `sweetener build -p sweetener.json` expands into TypeScript you can compile or run."
|
|
399
|
+
: `Detected ${host.name}.`,
|
|
400
|
+
install,
|
|
401
|
+
host === undefined
|
|
402
|
+
? "Run `sweetener build -p sweetener.json` to expand, or see examples/ for a bundler setup."
|
|
403
|
+
: host.wiring.join("\n"),
|
|
404
|
+
"sweetener.json lists the files to expand. Add your own .sts files to it.",
|
|
405
|
+
"`sweetener build` writes a .d.sts.ts beside each .sts so ordinary TypeScript can import it. Add `*.d.sts.ts` and `*.d.stsx.ts` to .gitignore.",
|
|
406
|
+
"Nothing you already had was modified.",
|
|
407
|
+
]),
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
//# sourceMappingURL=scaffold.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scaffold.js","sourceRoot":"","sources":["../../src/scaffold.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAczC,MAAM,MAAM,GAAG;;;;;;;;;;;;;;;CAed,CAAC;AAEF,MAAM,IAAI,GAAG;;;;;;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
|
+
{"version":3,"file":"source-kind.js","sourceRoot":"","sources":["../../src/source-kind.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type * as ts from "typescript";
|
|
2
|
+
import type { ProjectExpansionProvider } from "./project-command.js";
|
|
3
|
+
export interface StandaloneEmitResult {
|
|
4
|
+
/** Absolute output path to expanded text. */
|
|
5
|
+
readonly outputs: ReadonlyMap<string, string>;
|
|
6
|
+
readonly diagnostics: readonly ts.Diagnostic[];
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Expand files and return the expanded sources, without running TypeScript.
|
|
10
|
+
*
|
|
11
|
+
* This is the config-free path: no `tsconfig.json`, no type checking, and no
|
|
12
|
+
* downlevelling. The output is the expanded source under its ordinary
|
|
13
|
+
* extension, which is what a JavaScript project that only wants macros needs.
|
|
14
|
+
*/
|
|
15
|
+
export declare function expandStandalone(options: {
|
|
16
|
+
readonly fileNames: readonly string[];
|
|
17
|
+
readonly outDir: string;
|
|
18
|
+
readonly expansionProvider?: ProjectExpansionProvider | undefined;
|
|
19
|
+
}): StandaloneEmitResult;
|
|
20
|
+
/** Expand files and write the results under `outDir`. */
|
|
21
|
+
export declare function emitStandalone(options: {
|
|
22
|
+
readonly fileNames: readonly string[];
|
|
23
|
+
readonly outDir: string;
|
|
24
|
+
readonly expansionProvider?: ProjectExpansionProvider | undefined;
|
|
25
|
+
}): StandaloneEmitResult;
|
|
26
|
+
//# sourceMappingURL=standalone-emit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"standalone-emit.d.ts","sourceRoot":"","sources":["../../src/standalone-emit.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,EAAE,MAAM,YAAY,CAAC;AAGtC,OAAO,KAAK,EAEV,wBAAwB,EACzB,MAAM,sBAAsB,CAAC;AAE9B,MAAM,WAAW,oBAAoB;IACnC,6CAA6C;IAC7C,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9C,QAAQ,CAAC,WAAW,EAAE,SAAS,EAAE,CAAC,UAAU,EAAE,CAAC;CAChD;AAgBD;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE;IACxC,QAAQ,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,CAAC;IACtC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,iBAAiB,CAAC,EAAE,wBAAwB,GAAG,SAAS,CAAC;CACnE,GAAG,oBAAoB,CAuBvB;AAED,yDAAyD;AACzD,wBAAgB,cAAc,CAAC,OAAO,EAAE;IACtC,QAAQ,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,CAAC;IACtC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,iBAAiB,CAAC,EAAE,wBAAwB,GAAG,SAAS,CAAC;CACnE,GAAG,oBAAoB,CAOvB"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { mkdirSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { dirname, join, relative, resolve, sep } from "node:path";
|
|
3
|
+
import { loadStandaloneProject } from "./configuration.js";
|
|
4
|
+
import { createDefaultProjectExpansionProvider } from "./default-expansion-provider.js";
|
|
5
|
+
/** Deepest directory containing every input, used to mirror the input tree. */
|
|
6
|
+
function commonDirectory(fileNames) {
|
|
7
|
+
const parts = fileNames.map((fileName) => dirname(fileName).split(sep));
|
|
8
|
+
const first = parts[0];
|
|
9
|
+
if (first === undefined)
|
|
10
|
+
return process.cwd();
|
|
11
|
+
const shared = [];
|
|
12
|
+
for (let index = 0; index < first.length; index += 1) {
|
|
13
|
+
const segment = first[index];
|
|
14
|
+
if (!parts.every((candidate) => candidate[index] === segment))
|
|
15
|
+
break;
|
|
16
|
+
shared.push(segment);
|
|
17
|
+
}
|
|
18
|
+
return shared.join(sep) || sep;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Expand files and return the expanded sources, without running TypeScript.
|
|
22
|
+
*
|
|
23
|
+
* This is the config-free path: no `tsconfig.json`, no type checking, and no
|
|
24
|
+
* downlevelling. The output is the expanded source under its ordinary
|
|
25
|
+
* extension, which is what a JavaScript project that only wants macros needs.
|
|
26
|
+
*/
|
|
27
|
+
export function expandStandalone(options) {
|
|
28
|
+
const fileNames = options.fileNames.map((fileName) => resolve(fileName));
|
|
29
|
+
const provider = options.expansionProvider ?? createDefaultProjectExpansionProvider();
|
|
30
|
+
const project = loadStandaloneProject(fileNames);
|
|
31
|
+
const expanded = provider.expandProject(project);
|
|
32
|
+
const output = Array.isArray(expanded)
|
|
33
|
+
? { files: expanded, diagnostics: Object.freeze([]) }
|
|
34
|
+
: expanded;
|
|
35
|
+
if (output.diagnostics.length > 0)
|
|
36
|
+
return Object.freeze({
|
|
37
|
+
outputs: new Map(),
|
|
38
|
+
diagnostics: Object.freeze([...output.diagnostics]),
|
|
39
|
+
});
|
|
40
|
+
const root = commonDirectory(fileNames);
|
|
41
|
+
const outDir = resolve(options.outDir);
|
|
42
|
+
const outputs = new Map();
|
|
43
|
+
for (const file of output.files)
|
|
44
|
+
outputs.set(join(outDir, relative(root, file.fileName)), file.generated.text);
|
|
45
|
+
return Object.freeze({ outputs, diagnostics: Object.freeze([]) });
|
|
46
|
+
}
|
|
47
|
+
/** Expand files and write the results under `outDir`. */
|
|
48
|
+
export function emitStandalone(options) {
|
|
49
|
+
const result = expandStandalone(options);
|
|
50
|
+
for (const [fileName, text] of result.outputs) {
|
|
51
|
+
mkdirSync(dirname(fileName), { recursive: true });
|
|
52
|
+
writeFileSync(fileName, text, "utf8");
|
|
53
|
+
}
|
|
54
|
+
return result;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=standalone-emit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"standalone-emit.js","sourceRoot":"","sources":["../../src/standalone-emit.ts"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gB,CAAC,OAAO,CAAC,CAAC;IACzC,KAAK,MAAM,CAAC,QAAQ,EAAE,IAAI,CAAC,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;QAC9C,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAClD,aAAa,CAAC,QAAQ,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;IACxC,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sweetener/cli",
|
|
3
|
+
"version": "0.1.0-alpha.0",
|
|
4
|
+
"description": "Sweetener alpha package: cli",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./dist/src/index.d.ts",
|
|
9
|
+
"import": "./dist/src/index.js"
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"bin": {
|
|
13
|
+
"sweetener": "./bin/sweetener.mjs"
|
|
14
|
+
},
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"author": "Jimmy Miller <jimmyhmiller@gmail.com>",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/sweetener-ts/sweetener.git",
|
|
20
|
+
"directory": "packages/cli"
|
|
21
|
+
},
|
|
22
|
+
"homepage": "https://github.com/sweetener-ts/sweetener/tree/main/packages/cli#readme",
|
|
23
|
+
"bugs": {
|
|
24
|
+
"url": "https://github.com/sweetener-ts/sweetener/issues"
|
|
25
|
+
},
|
|
26
|
+
"keywords": [
|
|
27
|
+
"sweetener",
|
|
28
|
+
"macros",
|
|
29
|
+
"typescript",
|
|
30
|
+
"hygienic",
|
|
31
|
+
"syntax",
|
|
32
|
+
"command-line",
|
|
33
|
+
"build",
|
|
34
|
+
"watch"
|
|
35
|
+
],
|
|
36
|
+
"files": [
|
|
37
|
+
"bin",
|
|
38
|
+
"dist"
|
|
39
|
+
],
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@sweetener/compiler": "0.1.0-alpha.0",
|
|
42
|
+
"typescript": "npm:@typescript/typescript6@6.0.2"
|
|
43
|
+
},
|
|
44
|
+
"engines": {
|
|
45
|
+
"node": ">=24"
|
|
46
|
+
},
|
|
47
|
+
"publishConfig": {
|
|
48
|
+
"access": "public"
|
|
49
|
+
}
|
|
50
|
+
}
|