@reckona/create-mreact-app 0.0.65 → 0.0.67

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/index.js CHANGED
@@ -1,14 +1,14 @@
1
1
  import { mkdir, readdir, readFile, writeFile } from "node:fs/promises";
2
2
  import { basename, dirname, join, relative, resolve } from "node:path";
3
3
  const internalPackageVersions = {
4
- "@reckona/mreact-auth": "^0.0.65",
5
- "@reckona/mreact-devtools": "^0.0.65",
6
- "@reckona/mreact-forms": "^0.0.65",
7
- "@reckona/mreact": "^0.0.65",
8
- "@reckona/mreact-query": "^0.0.65",
9
- "@reckona/mreact-reactive-core": "^0.0.65",
4
+ "@reckona/mreact-auth": "^0.0.67",
5
+ "@reckona/mreact-devtools": "^0.0.67",
6
+ "@reckona/mreact-forms": "^0.0.67",
7
+ "@reckona/mreact": "^0.0.67",
8
+ "@reckona/mreact-query": "^0.0.67",
9
+ "@reckona/mreact-reactive-core": "^0.0.67",
10
10
  "@reckona/mreact-reactive-dom": "^0.0.51",
11
- "@reckona/mreact-router": "^0.0.65",
11
+ "@reckona/mreact-router": "^0.0.67",
12
12
  "@reckona/mreact-test-utils": "^0.0.51",
13
13
  };
14
14
  const currentMreactVersion = internalPackageVersions["@reckona/mreact"].replace(/^\^/, "");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reckona/create-mreact-app",
3
- "version": "0.0.65",
3
+ "version": "0.0.67",
4
4
  "description": "Project scaffolder for mreact app-router applications.",
5
5
  "keywords": [
6
6
  "cli",
@@ -27,7 +27,8 @@
27
27
  "dist/**/*.js",
28
28
  "dist/**/*.js.map",
29
29
  "dist/**/*.d.ts",
30
- "dist/**/*.d.ts.map"
30
+ "dist/**/*.d.ts.map",
31
+ "src/**/*"
31
32
  ],
32
33
  "type": "module",
33
34
  "sideEffects": false,
@@ -0,0 +1,305 @@
1
+ import {
2
+ createMreactAppTemplates,
3
+ type CreateMreactAppDeployTarget,
4
+ type CreateMreactAppPackageManager,
5
+ type CreateMreactAppTemplate,
6
+ } from "./index.js";
7
+
8
+ export interface CreateMreactAppCreateCliOptions {
9
+ command: "create";
10
+ deploy?: CreateMreactAppDeployTarget | undefined;
11
+ directory: string;
12
+ help?: boolean | undefined;
13
+ packageManager: CreateMreactAppPackageManager;
14
+ srcDir: boolean;
15
+ template: CreateMreactAppTemplate;
16
+ }
17
+
18
+ export interface CreateMreactAppUpgradeCliOptions {
19
+ command: "upgrade";
20
+ directory: string;
21
+ dryRun?: boolean | undefined;
22
+ fromVersion?: string | undefined;
23
+ help?: boolean | undefined;
24
+ targetVersion?: string | undefined;
25
+ }
26
+
27
+ export type CreateMreactAppCliOptions =
28
+ | CreateMreactAppCreateCliOptions
29
+ | CreateMreactAppUpgradeCliOptions;
30
+
31
+ export function parseCreateMreactAppCliArgs(args: readonly string[]): CreateMreactAppCliOptions {
32
+ if (args[0] === "upgrade") {
33
+ return parseUpgradeArgs(args.slice(1));
34
+ }
35
+
36
+ const directories: string[] = [];
37
+ let template: CreateMreactAppTemplate = "app-router";
38
+ let packageManager: CreateMreactAppPackageManager = "pnpm";
39
+ let deploy: CreateMreactAppDeployTarget | undefined;
40
+ let srcDir = false;
41
+
42
+ for (let index = 0; index < args.length; index += 1) {
43
+ const arg = args[index];
44
+
45
+ if (arg === "--") {
46
+ directories.push(...args.slice(index + 1));
47
+ break;
48
+ }
49
+
50
+ if (arg === "--help" || arg === "-h") {
51
+ return {
52
+ command: "create",
53
+ deploy,
54
+ directory: directories[0] ?? "mreact-app",
55
+ help: true,
56
+ packageManager,
57
+ srcDir,
58
+ template,
59
+ };
60
+ }
61
+
62
+ if (arg === "--template") {
63
+ template = parseTemplate(readOptionValue(args, index, "template"));
64
+ index += 1;
65
+ continue;
66
+ }
67
+
68
+ if (arg?.startsWith("--template=")) {
69
+ template = parseTemplate(arg.slice("--template=".length));
70
+ continue;
71
+ }
72
+
73
+ if (arg === "--pm" || arg === "--package-manager") {
74
+ packageManager = parsePackageManager(readOptionValue(args, index, "package manager"));
75
+ index += 1;
76
+ continue;
77
+ }
78
+
79
+ if (arg?.startsWith("--pm=")) {
80
+ packageManager = parsePackageManager(arg.slice("--pm=".length));
81
+ continue;
82
+ }
83
+
84
+ if (arg?.startsWith("--package-manager=")) {
85
+ packageManager = parsePackageManager(arg.slice("--package-manager=".length));
86
+ continue;
87
+ }
88
+
89
+ if (arg === "--deploy") {
90
+ deploy = parseDeployTarget(readOptionValue(args, index, "deploy target"));
91
+ index += 1;
92
+ continue;
93
+ }
94
+
95
+ if (arg?.startsWith("--deploy=")) {
96
+ deploy = parseDeployTarget(arg.slice("--deploy=".length));
97
+ continue;
98
+ }
99
+
100
+ if (arg === "--src-dir") {
101
+ srcDir = true;
102
+ continue;
103
+ }
104
+
105
+ if (arg?.startsWith("-")) {
106
+ throw new Error(`Unknown option ${arg}.`);
107
+ }
108
+
109
+ if (arg !== undefined) {
110
+ directories.push(arg);
111
+ }
112
+ }
113
+
114
+ if (directories.length > 1) {
115
+ throw new Error(`Expected one target directory, received ${directories.length}.`);
116
+ }
117
+
118
+ return {
119
+ command: "create",
120
+ deploy,
121
+ directory: directories[0] ?? "mreact-app",
122
+ packageManager,
123
+ srcDir,
124
+ template,
125
+ };
126
+ }
127
+
128
+ export function createMreactAppHelpText(): string {
129
+ return [
130
+ "Usage:",
131
+ " create-mreact-app [directory] [options]",
132
+ " create-mreact-app upgrade [directory] [options]",
133
+ "",
134
+ "Options:",
135
+ ` --template <name> Template to generate: ${createMreactAppTemplates.join(", ")}. Default: app-router.`,
136
+ " --pm, --package-manager <pm> Package manager for generated scripts: pnpm, npm, or bun. Default: pnpm.",
137
+ " --deploy <target> Add deploy files: container or aws-lambda.",
138
+ " --src-dir Generate routes under src/app instead of app.",
139
+ " -h, --help Show this help message.",
140
+ "",
141
+ "Upgrade options:",
142
+ " --dry-run Report dependency and codemod changes without writing package.json.",
143
+ " --from <version> Version the project is upgrading from.",
144
+ " --to <version> Target mreact package version. Default: current create-mreact-app version.",
145
+ "",
146
+ "Examples:",
147
+ " create-mreact-app my-app",
148
+ " create-mreact-app my-app --template app-router-tailwind --src-dir",
149
+ " create-mreact-app my-app --deploy container",
150
+ " create-mreact-app my-app --deploy aws-lambda",
151
+ " create-mreact-app upgrade --dry-run",
152
+ ].join("\n");
153
+ }
154
+
155
+ export function createMreactAppSuccessText(options: {
156
+ directory: string;
157
+ displayDirectory: string;
158
+ packageManager: CreateMreactAppPackageManager;
159
+ template: CreateMreactAppTemplate;
160
+ }): string {
161
+ const installCommand =
162
+ options.packageManager === "npm"
163
+ ? "npm install"
164
+ : options.packageManager === "bun"
165
+ ? "bun install"
166
+ : "pnpm install";
167
+ const devCommand =
168
+ options.packageManager === "npm"
169
+ ? "npm run dev"
170
+ : options.packageManager === "bun"
171
+ ? "bun run dev"
172
+ : "pnpm dev";
173
+ const dashboardNote =
174
+ options.template === "dashboard"
175
+ ? ["", "Demo account:", " demo@example.com / kanban1234"]
176
+ : [];
177
+
178
+ return [
179
+ `Created mreact app in ${options.directory} (template: ${options.template})`,
180
+ "",
181
+ "Next steps:",
182
+ ` cd ${options.displayDirectory}`,
183
+ ` ${installCommand}`,
184
+ ` ${devCommand}`,
185
+ "",
186
+ "Then open http://localhost:3001/.",
187
+ ...dashboardNote,
188
+ ].join("\n");
189
+ }
190
+
191
+ function parseUpgradeArgs(args: readonly string[]): CreateMreactAppUpgradeCliOptions {
192
+ const directories: string[] = [];
193
+ let dryRun = false;
194
+ let fromVersion: string | undefined;
195
+ let targetVersion: string | undefined;
196
+
197
+ for (let index = 0; index < args.length; index += 1) {
198
+ const arg = args[index];
199
+
200
+ if (arg === "--") {
201
+ directories.push(...args.slice(index + 1));
202
+ break;
203
+ }
204
+
205
+ if (arg === "--help" || arg === "-h") {
206
+ return {
207
+ command: "upgrade",
208
+ directory: directories[0] ?? ".",
209
+ dryRun,
210
+ fromVersion,
211
+ help: true,
212
+ targetVersion,
213
+ };
214
+ }
215
+
216
+ if (arg === "--dry-run") {
217
+ dryRun = true;
218
+ continue;
219
+ }
220
+
221
+ if (arg === "--from") {
222
+ fromVersion = readOptionValue(args, index, "from version");
223
+ index += 1;
224
+ continue;
225
+ }
226
+
227
+ if (arg?.startsWith("--from=")) {
228
+ fromVersion = arg.slice("--from=".length);
229
+ continue;
230
+ }
231
+
232
+ if (arg === "--to") {
233
+ targetVersion = readOptionValue(args, index, "target version");
234
+ index += 1;
235
+ continue;
236
+ }
237
+
238
+ if (arg?.startsWith("--to=")) {
239
+ targetVersion = arg.slice("--to=".length);
240
+ continue;
241
+ }
242
+
243
+ if (arg?.startsWith("-")) {
244
+ throw new Error(`Unknown option ${arg}.`);
245
+ }
246
+
247
+ if (arg !== undefined) {
248
+ directories.push(arg);
249
+ }
250
+ }
251
+
252
+ if (directories.length > 1) {
253
+ throw new Error(`Expected one target directory, received ${directories.length}.`);
254
+ }
255
+
256
+ return {
257
+ command: "upgrade",
258
+ directory: directories[0] ?? ".",
259
+ dryRun,
260
+ fromVersion,
261
+ targetVersion,
262
+ };
263
+ }
264
+
265
+ function readOptionValue(args: readonly string[], index: number, name: string): string {
266
+ const value = args[index + 1];
267
+
268
+ if (value === undefined || value.startsWith("-")) {
269
+ throw new Error(`Missing value for ${name}.`);
270
+ }
271
+
272
+ return value;
273
+ }
274
+
275
+ function parseTemplate(value: string | undefined): CreateMreactAppTemplate {
276
+ if (
277
+ value === "basic" ||
278
+ value === "app-router" ||
279
+ value === "app-router-tailwind" ||
280
+ value === "cloudflare" ||
281
+ value === "dashboard"
282
+ ) {
283
+ return value;
284
+ }
285
+
286
+ throw new Error(
287
+ `Unknown template ${JSON.stringify(value)}. Available templates: ${createMreactAppTemplates.join(", ")}`,
288
+ );
289
+ }
290
+
291
+ function parsePackageManager(value: string | undefined): CreateMreactAppPackageManager {
292
+ if (value === "pnpm" || value === "npm" || value === "bun") {
293
+ return value;
294
+ }
295
+
296
+ throw new Error(`Unknown package manager ${JSON.stringify(value)}. Use pnpm, npm, or bun.`);
297
+ }
298
+
299
+ function parseDeployTarget(value: string | undefined): CreateMreactAppDeployTarget {
300
+ if (value === "aws-lambda" || value === "container") {
301
+ return value;
302
+ }
303
+
304
+ throw new Error(`Unknown deploy target ${JSON.stringify(value)}. Use aws-lambda or container.`);
305
+ }
package/src/cli.ts ADDED
@@ -0,0 +1,57 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { resolve } from "node:path";
4
+ import {
5
+ createMreactAppHelpText,
6
+ createMreactAppSuccessText,
7
+ parseCreateMreactAppCliArgs,
8
+ } from "./cli-args.js";
9
+ import { createMreactApp, upgradeMreactApp } from "./index.js";
10
+
11
+ try {
12
+ const options = parseCreateMreactAppCliArgs(process.argv.slice(2));
13
+ if (options.help === true) {
14
+ console.log(createMreactAppHelpText());
15
+ process.exit(0);
16
+ }
17
+
18
+ if (options.command === "upgrade") {
19
+ const result = await upgradeMreactApp({
20
+ directory: resolve(options.directory),
21
+ dryRun: options.dryRun,
22
+ fromVersion: options.fromVersion,
23
+ targetVersion: options.targetVersion,
24
+ });
25
+
26
+ console.log(
27
+ result.changed
28
+ ? `Updated ${result.updatedDependencies.length} mreact dependency range(s).`
29
+ : "No mreact dependency ranges needed updating.",
30
+ );
31
+ if (result.codemods.length > 0) {
32
+ console.log(`Codemods: ${result.codemods.map((codemod) => codemod.id).join(", ")}`);
33
+ }
34
+ process.exit(0);
35
+ }
36
+
37
+ const result = await createMreactApp({
38
+ deploy: options.deploy,
39
+ directory: resolve(options.directory),
40
+ name: options.directory,
41
+ packageManager: options.packageManager,
42
+ srcDir: options.srcDir,
43
+ template: options.template,
44
+ });
45
+
46
+ console.log(
47
+ createMreactAppSuccessText({
48
+ directory: result.directory,
49
+ displayDirectory: options.directory,
50
+ packageManager: result.packageManager,
51
+ template: result.template,
52
+ }),
53
+ );
54
+ } catch (error) {
55
+ console.error(error instanceof Error ? error.message : String(error));
56
+ process.exitCode = 1;
57
+ }