@alloy-js/create 0.6.1 → 0.6.3

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.
@@ -0,0 +1,13 @@
1
+ {
2
+ "@alloy-js/core": "0.6.3",
3
+ "@alloy-js/typescript": "0.6.3",
4
+ "@alloy-js/babel-plugin": "0.2.0",
5
+ "@babel/cli": "^7.24.7",
6
+ "@babel/preset-typescript": "^7.24.7",
7
+ "@rollup/plugin-babel": "^6.0.4",
8
+ "@rollup/plugin-typescript": "^11.1.6",
9
+ "@types/node": "^20.14.12",
10
+ "concurrently": "^8.2.2",
11
+ "typescript": "^5.7.3",
12
+ "vitest": "^3.0.4"
13
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alloy-js/create",
3
- "version": "0.6.1",
3
+ "version": "0.6.3",
4
4
  "description": "Create an Alloy project with npm init @alloy-js",
5
5
  "main": "./dist/src/index.js",
6
6
  "bin": "./dist/src/index.js",
@@ -8,6 +8,7 @@
8
8
  "author": "brian.terlson@microsoft.com",
9
9
  "license": "MIT",
10
10
  "dependencies": {
11
+ "prompts": "^2.4.2",
11
12
  "@alloy-js/core": "~0.6.0",
12
13
  "@alloy-js/typescript": "~0.6.0"
13
14
  },
@@ -20,16 +21,24 @@
20
21
  "@types/prompts": "^2.4.9",
21
22
  "concurrently": "^8.2.2",
22
23
  "js-yaml": "^4.1.0",
23
- "prompts": "^2.4.2",
24
24
  "typescript": "^5.7.3",
25
25
  "vite": "^6.0.1",
26
26
  "vitest": "^3.0.4",
27
27
  "@alloy-js/babel-plugin": "~0.2.0"
28
28
  },
29
29
  "type": "module",
30
+ "files": [
31
+ "dist",
32
+ "README.md",
33
+ "LICENSE",
34
+ "CHANGELOG.md",
35
+ "package.json",
36
+ "deps.json",
37
+ "deps-versions.json"
38
+ ],
30
39
  "scripts": {
31
40
  "build-src": "babel src -d dist/src --extensions .ts,.tsx",
32
- "build": "tsc -p . && npm run build-src",
41
+ "build": "node scripts/gen-deps.js && tsc -p . && npm run build-src",
33
42
  "clean": "rimraf dist/ .temp/",
34
43
  "test": "vitest run",
35
44
  "test:watch": "vitest -w",
package/babel.config.cjs DELETED
@@ -1,7 +0,0 @@
1
- module.exports = {
2
- sourceMaps: true,
3
- presets: [
4
- "@babel/preset-typescript",
5
- ["@alloy-js/babel-preset"],
6
- ],
7
- };
@@ -1,65 +0,0 @@
1
- import fs from "fs/promises";
2
- import yaml from "js-yaml";
3
- import path from "path";
4
-
5
- async function generateDepsVersions() {
6
- // Get current directory (assuming script is run from package root)
7
- const packageDir = process.cwd();
8
-
9
- // Load package.json
10
- const packageJsonPath = path.join(packageDir, "package.json");
11
- const packageJson = JSON.parse(await fs.readFile(packageJsonPath, "utf8"));
12
- const packageVersion = packageJson.version;
13
-
14
- // Load deps.json
15
- const depsJsonPath = path.join(packageDir, "deps.json");
16
- const depsJson = JSON.parse(await fs.readFile(depsJsonPath, "utf8"));
17
-
18
- // Load workspace yaml for catalog
19
- const workspaceYamlPath = path.join(packageDir, "../../pnpm-workspace.yaml");
20
- const workspaceYaml = yaml.load(await fs.readFile(workspaceYamlPath, "utf8"));
21
- const catalog = workspaceYaml.catalog || {};
22
-
23
- // Generate versions object
24
- const versions = {};
25
-
26
- // Process dependencies
27
- const allDeps = [
28
- ...(depsJson.dependencies || []),
29
- ...(depsJson.devDependencies || []),
30
- ];
31
-
32
- for (const dep of allDeps) {
33
- const packageName = dep.package;
34
-
35
- if (packageName === "@alloy-js/babel-plugin") {
36
- // Special case for @alloy-js/babel-plugin
37
- const babelPluginPath = path.join(
38
- packageDir,
39
- "../babel-plugin-alloy/package.json",
40
- );
41
- const babelPluginJson = JSON.parse(
42
- await fs.readFile(babelPluginPath, "utf8"),
43
- );
44
- versions[packageName] = babelPluginJson.version;
45
- } else if (packageName.startsWith("@alloy-js")) {
46
- versions[packageName] = packageVersion;
47
- } else if (catalog[packageName]) {
48
- versions[packageName] = catalog[packageName];
49
- } else {
50
- console.warn(`Warning: No catalog entry found for ${packageName}`);
51
- }
52
- }
53
-
54
- // Write to deps-versions.json
55
- const outputPath = path.join(packageDir, "deps-versions.json");
56
- await fs.writeFile(outputPath, JSON.stringify(versions, null, 2), "utf8");
57
-
58
- console.log(`Dependencies versions written to ${outputPath}`);
59
- }
60
-
61
- // Execute the function
62
- generateDepsVersions().catch((err) => {
63
- console.error("Error generating dependencies versions:", err);
64
- process.exit(1);
65
- });
package/src/index.tsx DELETED
@@ -1,456 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import {
4
- code,
5
- Output,
6
- render,
7
- Show,
8
- SourceDirectory,
9
- writeOutput,
10
- } from "@alloy-js/core";
11
- import { PackageJsonFile, SourceFile } from "@alloy-js/typescript";
12
- import fs from "fs";
13
- import { parseArgs } from "node:util";
14
- import path from "path";
15
- import prompts from "prompts";
16
-
17
- const displayHelp = () => {
18
- console.log(`
19
- Alloy Project Generator
20
-
21
- Usage:
22
- npm init @alloy-js [options]
23
-
24
- Options:
25
- -h, --help Show this help message
26
- -y Use default values without prompting
27
- --name <name> Package name
28
- --version <version> Package version
29
- --description <desc> Package description
30
- --repository <url> Git repository URL
31
- --keywords <list> Comma-separated list of keywords
32
- --author <name> Author name
33
- --license <license> License type
34
- --library Create a library project
35
- --stc Create a project using string template components
36
- --project Create a general project (default)
37
- `);
38
- };
39
-
40
- function parseCommandLineArgs(): Partial<PackageInfo> & {
41
- help: boolean;
42
- useDefaults: boolean;
43
- } {
44
- const { values } = parseArgs({
45
- options: {
46
- h: { type: "boolean", short: "h" },
47
- help: { type: "boolean" },
48
- y: { type: "boolean" },
49
- name: { type: "string" },
50
- version: { type: "string" },
51
- description: { type: "string" },
52
- main: { type: "string" },
53
- repository: { type: "string" },
54
- keywords: { type: "string" },
55
- author: { type: "string" },
56
- license: { type: "string" },
57
- library: { type: "boolean" },
58
- project: { type: "boolean" },
59
- stc: { type: "boolean" },
60
- },
61
- });
62
-
63
- return {
64
- help: values.h || values.help || false,
65
- useDefaults: values.y || false,
66
- name: values.name,
67
- version: values.version,
68
- description: values.description,
69
- repository: values.repository,
70
- keywords:
71
- values.keywords ?
72
- values.keywords
73
- .split(",")
74
- .map((k: string) => k.trim())
75
- .filter(Boolean)
76
- : undefined,
77
- author: values.author,
78
- license: values.license,
79
- type:
80
- values.library ? "library"
81
- : values.stc ? "stc-project"
82
- : values.project ? "project"
83
- : "project",
84
- };
85
- }
86
-
87
- const calculatePackageName = () => {
88
- const cwd = process.cwd();
89
- const dirName = path.basename(cwd);
90
-
91
- // Clean up directory name to be a valid package name
92
- return dirName
93
- .toLowerCase()
94
- .replace(/[^a-z0-9._-]/g, "-")
95
- .replace(/^[._-]+|[._-]+$/g, "");
96
- };
97
-
98
- interface PackageInfo {
99
- name: string;
100
- version: string;
101
- description: string;
102
- repository: string;
103
- keywords: string[];
104
- author: string;
105
- license: string;
106
- type: "project" | "stc-project" | "library";
107
- }
108
-
109
- // Function to prompt for package information
110
- const promptForPackageInfo = async (
111
- useDefaults: boolean,
112
- cmdArgs: Partial<PackageInfo> = {},
113
- ): Promise<PackageInfo> => {
114
- const defaultName = calculatePackageName();
115
-
116
- if (useDefaults) {
117
- return {
118
- name: cmdArgs.name || defaultName,
119
- version: cmdArgs.version || "1.0.0",
120
- description: cmdArgs.description || "",
121
- repository: cmdArgs.repository || "",
122
- keywords: cmdArgs.keywords || [],
123
- author: cmdArgs.author || "",
124
- license: cmdArgs.license || "ISC",
125
- type: cmdArgs.type || "project",
126
- };
127
- }
128
-
129
- const questions: prompts.PromptObject[] = [];
130
-
131
- if (!cmdArgs.name) {
132
- questions.push({
133
- type: "text",
134
- name: "name",
135
- message: "package name:",
136
- initial: defaultName,
137
- });
138
- }
139
-
140
- if (!cmdArgs.version) {
141
- questions.push({
142
- type: "text",
143
- name: "version",
144
- message: "version:",
145
- initial: "1.0.0",
146
- });
147
- }
148
-
149
- if (!cmdArgs.description) {
150
- questions.push({
151
- type: "text",
152
- name: "description",
153
- message: "description:",
154
- });
155
- }
156
-
157
- if (!cmdArgs.repository) {
158
- questions.push({
159
- type: "text",
160
- name: "repository",
161
- message: "git repository:",
162
- });
163
- }
164
-
165
- if (!cmdArgs.keywords) {
166
- questions.push({
167
- type: "list",
168
- name: "keywords",
169
- message: "keywords (comma separated):",
170
- });
171
- }
172
-
173
- if (!cmdArgs.author) {
174
- questions.push({
175
- type: "text",
176
- name: "author",
177
- message: "author:",
178
- });
179
- }
180
-
181
- if (!cmdArgs.license) {
182
- questions.push({
183
- type: "text",
184
- name: "license",
185
- message: "license:",
186
- initial: "ISC",
187
- });
188
- }
189
-
190
- if (!cmdArgs.type) {
191
- questions.push({
192
- type: "select",
193
- name: "type",
194
- message: "project type:",
195
- choices: [
196
- {
197
- title: "project using jsx templates",
198
- value: "project",
199
- description:
200
- "Use alloy and jsx templates to generate code. Requires a babel transform.",
201
- },
202
- {
203
- title: "project using string template components",
204
- value: "stc-project",
205
- description:
206
- "Use alloy and string templates to generate code. Does not require babel transform.",
207
- },
208
- {
209
- title: "library",
210
- value: "library",
211
- description:
212
- "Create a library of alloy JSX components. Requires a babel transform.",
213
- },
214
- ],
215
- });
216
- }
217
-
218
- const answers =
219
- questions.length > 0 ?
220
- await prompts(questions, {
221
- onCancel: (p) => {
222
- console.log("Operation canceled. No files were generated.");
223
- process.exit(0);
224
- },
225
- })
226
- : {};
227
-
228
- return {
229
- name: cmdArgs.name || answers.name || defaultName,
230
- version: cmdArgs.version || answers.version || "1.0.0",
231
- description: cmdArgs.description || answers.description || "",
232
- repository: cmdArgs.repository || answers.repository || "",
233
- keywords: cmdArgs.keywords || answers.keywords || [],
234
- author: cmdArgs.author || answers.author || "",
235
- license: cmdArgs.license || answers.license || "ISC",
236
- type: cmdArgs.type || answers.type || "project",
237
- };
238
- };
239
-
240
- // Load dependencies and versions from JSON files
241
- const depsFilePath = path.resolve(
242
- path.dirname(import.meta.url.replace("file:", "")),
243
- "../../deps.json",
244
- );
245
- const depsVersionsFilePath = path.resolve(
246
- path.dirname(import.meta.url.replace("file:", "")),
247
- "../../deps-versions.json",
248
- );
249
-
250
- const depsInfo = JSON.parse(fs.readFileSync(depsFilePath, "utf-8"));
251
- const depsVersions = JSON.parse(fs.readFileSync(depsVersionsFilePath, "utf-8"));
252
-
253
- const exports = {
254
- ".": {
255
- import: "./dist/src/index.js",
256
- types: "./dist/src/index.d.ts",
257
- },
258
- "./stc": {
259
- import: "./dist/src/stc.js",
260
- types: "./dist/src/stc.d.ts",
261
- },
262
- };
263
-
264
- const main = async () => {
265
- const cmdArgs = parseCommandLineArgs();
266
-
267
- if (cmdArgs.help) {
268
- displayHelp();
269
- return;
270
- }
271
-
272
- const packageInfo = await promptForPackageInfo(cmdArgs.useDefaults, cmdArgs);
273
-
274
- let scripts: Record<string, string>;
275
-
276
- if (packageInfo.type === "stc-project") {
277
- scripts = {
278
- "build-tsc": "tsc -p .",
279
- build: "npm run build-tsc",
280
- clean: "rimraf dist/ .temp/",
281
- test: "vitest run",
282
- "test:watch": "vitest -w",
283
- "watch-tsc": "tsc -p . --watch",
284
- watch: "npm run watch-tsc",
285
- };
286
- } else {
287
- scripts = {
288
- "build-src": "babel src -d dist/src --extensions .ts,.tsx",
289
- "build-tsc": "tsc -p .",
290
- build: "npm run build-tsc && npm run build-src",
291
- clean: "rimraf dist/ .temp/",
292
- test: "vitest run",
293
- "test:watch": "vitest -w",
294
- "watch-src": "babel src -d dist/src --extensions '.ts,.tsx' --watch",
295
- "watch-tsc": "tsc -p . --watch",
296
- watch:
297
- 'concurrently --kill-others "npm run watch-tsc" "npm run watch-src"',
298
- };
299
- }
300
-
301
- // Map dependencies to their versions with filtering based on project type
302
- const deps = Object.fromEntries(
303
- depsInfo.dependencies
304
- .filter((dep: any) =>
305
- packageInfo.type === "stc-project" ? dep.stc : dep.jsx,
306
- )
307
- .map((dep: any) => [dep.package, depsVersions[dep.package]]),
308
- );
309
-
310
- const devDeps = Object.fromEntries(
311
- depsInfo.devDependencies
312
- .filter((dep: any) =>
313
- packageInfo.type === "stc-project" ? dep.stc : dep.jsx,
314
- )
315
- .map((dep: any) => [dep.package, depsVersions[dep.package]]),
316
- );
317
-
318
- const files = (
319
- <Output>
320
- <PackageJsonFile
321
- type="module"
322
- name={packageInfo.name}
323
- version={packageInfo.version}
324
- description={packageInfo.description}
325
- exports={exports}
326
- dependencies={deps}
327
- devDependencies={devDeps}
328
- license={packageInfo.license}
329
- scripts={scripts}
330
- author={packageInfo.author}
331
- repository={
332
- packageInfo.repository ?
333
- { type: "git", url: packageInfo.repository }
334
- : undefined
335
- }
336
- keywords={packageInfo.keywords}
337
- />
338
- <SourceDirectory path="src">
339
- <SourceDirectory path="components">
340
- <Show when={packageInfo.type === "library"}>
341
- <SourceDirectory path="stc">
342
- <SourceFile path="index.ts">
343
- import * as jsx from "../index.js";
344
- </SourceFile>
345
- </SourceDirectory>
346
- </Show>
347
- <SourceFile path="index.ts">// barrel file for components</SourceFile>
348
- <SourceFile
349
- path={
350
- packageInfo.type === "stc-project" ?
351
- "ExampleComponent.ts"
352
- : "ExampleComponent.tsx"
353
- }
354
- >
355
- {code`
356
- export interface ExampleComponentProps {}
357
-
358
- export function ExampleComponent(props: ExampleComponentProps) {
359
-
360
- }
361
- `}
362
- </SourceFile>
363
- </SourceDirectory>
364
- <SourceFile path="index.ts">
365
- export * from "./components/index.js";
366
- </SourceFile>
367
- </SourceDirectory>
368
- <Show when={packageInfo.type !== "stc-project"}>
369
- <SourceFile path="babel.config.cjs">
370
- {code`
371
- module.exports = {
372
- sourceMaps: true,
373
- presets: [
374
- "@babel/preset-typescript",
375
- ["@alloy-js/babel-preset"],
376
- ],
377
- };
378
- `}
379
- </SourceFile>
380
- </Show>
381
- <SourceFile path="tsconfig.json">
382
- {code`
383
- {
384
- "compilerOptions": {
385
- "lib": ["es2023", "DOM"],
386
- "module": "NodeNext",
387
- "moduleResolution": "NodeNext",
388
- "target": "es2022",
389
- "strict": true,
390
- "skipLibCheck": true,
391
- "isolatedModules": true,
392
- "declaration": true,
393
- "sourceMap": true,
394
- "declarationMap": true,
395
- "composite": true,
396
- "incremental": true,
397
- "outDir": "dist"${
398
- packageInfo.type === "stc-project" ?
399
- ""
400
- : code`
401
- ,
402
- "jsx": "preserve",
403
- "jsxImportSource": "@alloy-js/core",
404
- "emitDeclarationOnly": true
405
- `
406
- }
407
- },
408
- "include": [
409
- "src/**/*.ts",
410
- "test/**/*.ts"${
411
- packageInfo.type === "stc-project" ?
412
- ""
413
- : code`
414
- ,
415
- "src/**/*.tsx",
416
- "test/**/*.tsx",
417
- `
418
- }
419
-
420
- ],
421
- "exclude": ["node_modules", "dist"]
422
- }
423
- `}
424
- </SourceFile>
425
-
426
- <Show when={packageInfo.type !== "stc-project"}>
427
- <SourceFile path="vitest.config.ts">
428
- {code`
429
- import { babel } from "@rollup/plugin-babel";
430
- import { defineConfig } from "vitest/config";
431
-
432
- export default defineConfig({
433
- esbuild: {
434
- jsx: "preserve",
435
- sourcemap: "both",
436
- },
437
- plugins: [
438
- babel({
439
- inputSourceMap: true as any,
440
- sourceMaps: "both",
441
- babelHelpers: "bundled",
442
- extensions: [".ts", ".tsx"],
443
- presets: ["@babel/preset-typescript", ["@alloy-js/babel-preset"]],
444
- }),
445
- ],
446
- });
447
- `}
448
- </SourceFile>
449
- </Show>
450
- </Output>
451
- );
452
- writeOutput(render(files));
453
- };
454
-
455
- // Execute main function
456
- main().catch(console.error);
package/tsconfig.json DELETED
@@ -1,17 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.base.json",
3
- "compilerOptions": {
4
- "emitDeclarationOnly": true,
5
- "declaration": true,
6
- "outDir": "dist"
7
- },
8
- "include": [
9
- "src/**/*.ts",
10
- "src/**/*.tsx",
11
- "test/**/*.ts",
12
- "test/**/*.tsx",
13
- "testing/**/*.ts",
14
- "testing/**/*.d.ts"
15
- ],
16
- "exclude": ["node_modules", "dist"]
17
- }