monorise 1.7.0-dev.9 → 1.7.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/cli/cli.js +143 -131
- package/dist/cli/cli.js.map +1 -1
- package/dist/core/index.d.ts +2 -0
- package/dist/core/index.js +141 -51
- package/dist/core/index.js.map +1 -1
- package/dist/sst/components/analytics.d.ts.map +1 -1
- package/dist/sst/components/monorise-core.d.ts.map +1 -1
- package/dist/sst/components/single-table.d.ts +1 -0
- package/dist/sst/components/single-table.d.ts.map +1 -1
- package/dist/sst/index.js +37 -35
- package/dist/sst/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cli/cli.js
CHANGED
|
@@ -2,19 +2,21 @@
|
|
|
2
2
|
|
|
3
3
|
// cli.ts
|
|
4
4
|
import "tsx";
|
|
5
|
-
import
|
|
6
|
-
import
|
|
5
|
+
import fs3 from "fs";
|
|
6
|
+
import path3 from "path";
|
|
7
7
|
import { execSync } from "child_process";
|
|
8
8
|
import chokidar from "chokidar";
|
|
9
9
|
|
|
10
10
|
// commands/utils/analytics-manifest.ts
|
|
11
11
|
import { createHash } from "crypto";
|
|
12
|
+
import fs from "fs";
|
|
13
|
+
import path from "path";
|
|
12
14
|
var lowerKebabCase = /^[a-z]+(?:-[a-z]+)*$/;
|
|
13
15
|
function normalizeSqlIdentifier(name) {
|
|
14
16
|
const normalized = name.replace(/([a-z0-9])([A-Z])/g, "$1_$2").replace(/[^a-zA-Z0-9]+/g, "_").replace(/^_+|_+$/g, "").toLowerCase();
|
|
15
17
|
return /^[a-z_]/.test(normalized) ? normalized : `_${normalized}`;
|
|
16
18
|
}
|
|
17
|
-
function athenaType(schema,
|
|
19
|
+
function athenaType(schema, path4) {
|
|
18
20
|
let current = schema;
|
|
19
21
|
for (; ; ) {
|
|
20
22
|
const typeName = current._def?.typeName;
|
|
@@ -63,7 +65,7 @@ function athenaType(schema, path3) {
|
|
|
63
65
|
return "json";
|
|
64
66
|
}
|
|
65
67
|
}
|
|
66
|
-
function columns(schema,
|
|
68
|
+
function columns(schema, path4) {
|
|
67
69
|
let objectSchema = schema;
|
|
68
70
|
while (!objectSchema.shape && objectSchema._def?.typeName === "ZodEffects") {
|
|
69
71
|
const innerSchema = objectSchema._def.schema;
|
|
@@ -77,14 +79,14 @@ function columns(schema, path3) {
|
|
|
77
79
|
const existing = names.get(name);
|
|
78
80
|
if (existing) {
|
|
79
81
|
throw new Error(
|
|
80
|
-
`Analytics column identifier collision in ${
|
|
82
|
+
`Analytics column identifier collision in ${path4}: ${existing} and ${sourceName} both normalize to ${name}.`
|
|
81
83
|
);
|
|
82
84
|
}
|
|
83
85
|
names.set(name, sourceName);
|
|
84
86
|
return {
|
|
85
87
|
name,
|
|
86
88
|
sourceName,
|
|
87
|
-
type: athenaType(field, `${
|
|
89
|
+
type: athenaType(field, `${path4}.${sourceName}`)
|
|
88
90
|
};
|
|
89
91
|
});
|
|
90
92
|
}
|
|
@@ -134,11 +136,29 @@ function validateSchemaEvolution(previous, next) {
|
|
|
134
136
|
}
|
|
135
137
|
}
|
|
136
138
|
}
|
|
139
|
+
function writeAnalyticsManifest(monoriseOutputDir, configs) {
|
|
140
|
+
const analyticsManifestPath = path.join(monoriseOutputDir, "analytics-manifest.json");
|
|
141
|
+
const manifest = createAnalyticsManifest(configs);
|
|
142
|
+
if (manifest.unnamedMutuals.length) {
|
|
143
|
+
console.warn(
|
|
144
|
+
`Skipping unnamed mutual analytics datasets: ${manifest.unnamedMutuals.join(", ")}.`
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
if (fs.existsSync(analyticsManifestPath)) {
|
|
148
|
+
validateSchemaEvolution(
|
|
149
|
+
JSON.parse(fs.readFileSync(analyticsManifestPath, "utf8")),
|
|
150
|
+
manifest
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
fs.writeFileSync(analyticsManifestPath, `${JSON.stringify(manifest, null, 2)}
|
|
154
|
+
`);
|
|
155
|
+
}
|
|
137
156
|
function createAnalyticsManifest(configs) {
|
|
138
157
|
const datasets = [];
|
|
139
158
|
const unnamedMutuals = /* @__PURE__ */ new Set();
|
|
140
159
|
const identifiers = /* @__PURE__ */ new Map();
|
|
141
160
|
const mutuals = /* @__PURE__ */ new Set();
|
|
161
|
+
const mutualPairs = /* @__PURE__ */ new Map();
|
|
142
162
|
const addDataset = (kind, name, schema, mutualEntities) => {
|
|
143
163
|
if (!lowerKebabCase.test(name)) {
|
|
144
164
|
throw new Error(
|
|
@@ -198,11 +218,20 @@ function createAnalyticsManifest(configs) {
|
|
|
198
218
|
}
|
|
199
219
|
if (mutuals.has(mutual)) continue;
|
|
200
220
|
mutuals.add(mutual);
|
|
221
|
+
const entities = mutual.entities ?? [config.name, field.entityType];
|
|
222
|
+
const pair = [...entities].sort().join("::");
|
|
223
|
+
const existing = mutualPairs.get(pair);
|
|
224
|
+
if (existing) {
|
|
225
|
+
throw new Error(
|
|
226
|
+
`Analytics mutual ${mutual.name} conflicts with ${existing}: both use the ${pair} entity pair.`
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
mutualPairs.set(pair, mutual.name);
|
|
201
230
|
addDataset(
|
|
202
231
|
"mutual",
|
|
203
232
|
mutual.name,
|
|
204
233
|
mutual.mutualDataSchema,
|
|
205
|
-
|
|
234
|
+
entities
|
|
206
235
|
);
|
|
207
236
|
}
|
|
208
237
|
}
|
|
@@ -218,15 +247,15 @@ function createAnalyticsManifest(configs) {
|
|
|
218
247
|
import { fileURLToPath } from "url";
|
|
219
248
|
|
|
220
249
|
// commands/utils/detect-package.ts
|
|
221
|
-
import
|
|
222
|
-
import
|
|
250
|
+
import fs2 from "fs";
|
|
251
|
+
import path2 from "path";
|
|
223
252
|
function detectCombinedPackage(startDir) {
|
|
224
253
|
let dir = startDir;
|
|
225
254
|
while (true) {
|
|
226
|
-
if (
|
|
255
|
+
if (fs2.existsSync(path2.join(dir, "node_modules", "monorise"))) {
|
|
227
256
|
return true;
|
|
228
257
|
}
|
|
229
|
-
const parent =
|
|
258
|
+
const parent = path2.dirname(dir);
|
|
230
259
|
if (parent === dir) break;
|
|
231
260
|
dir = parent;
|
|
232
261
|
}
|
|
@@ -255,10 +284,10 @@ var ROOT_TSCONFIG_TEMPLATE = {
|
|
|
255
284
|
|
|
256
285
|
// cli.ts
|
|
257
286
|
var __filename = fileURLToPath(import.meta.url);
|
|
258
|
-
var __dirname =
|
|
259
|
-
var TEMPLATES_DIR =
|
|
287
|
+
var __dirname = path3.dirname(__filename);
|
|
288
|
+
var TEMPLATES_DIR = path3.join(__dirname, "templates", "files");
|
|
260
289
|
function readTemplate(filename) {
|
|
261
|
-
return
|
|
290
|
+
return fs3.readFileSync(path3.join(TEMPLATES_DIR, filename), "utf-8");
|
|
262
291
|
}
|
|
263
292
|
function kebabToCamel(str) {
|
|
264
293
|
return str.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
|
|
@@ -271,19 +300,19 @@ function execCommand(command, cwd, stdio = "inherit") {
|
|
|
271
300
|
execSync(command, { cwd, stdio });
|
|
272
301
|
}
|
|
273
302
|
async function generateConfigFile(configDir, monoriseOutputDir, projectRoot) {
|
|
274
|
-
const configOutputPath =
|
|
303
|
+
const configOutputPath = path3.join(monoriseOutputDir, "config.ts");
|
|
275
304
|
const initialConfigContent = `
|
|
276
305
|
export enum Entity {}
|
|
277
306
|
export default {};
|
|
278
307
|
`;
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
308
|
+
fs3.writeFileSync(configOutputPath, initialConfigContent);
|
|
309
|
+
fs3.writeFileSync(
|
|
310
|
+
path3.join(monoriseOutputDir, "index.ts"),
|
|
282
311
|
`export * from './config';
|
|
283
312
|
export { default } from './config';
|
|
284
313
|
`
|
|
285
314
|
);
|
|
286
|
-
const files =
|
|
315
|
+
const files = fs3.readdirSync(configDir).filter((file) => file.endsWith(".ts") && file !== "index.ts");
|
|
287
316
|
const names = /* @__PURE__ */ new Set();
|
|
288
317
|
const nameRegex = /^[a-z]+(-[a-z]+)*$/;
|
|
289
318
|
const imports = [];
|
|
@@ -295,10 +324,10 @@ export { default } from './config';
|
|
|
295
324
|
const allowedEntityEntries = [];
|
|
296
325
|
const entityWithEmailAuthEntries = [];
|
|
297
326
|
const analyticsConfigs = [];
|
|
298
|
-
const relativePathToConfigDir =
|
|
327
|
+
const relativePathToConfigDir = path3.relative(monoriseOutputDir, configDir);
|
|
299
328
|
const importPathPrefix = relativePathToConfigDir ? `${relativePathToConfigDir}/` : "./";
|
|
300
329
|
for (const file of files) {
|
|
301
|
-
const fullPath =
|
|
330
|
+
const fullPath = path3.join(configDir, file);
|
|
302
331
|
const module = await import(fullPath);
|
|
303
332
|
const config = module.default;
|
|
304
333
|
if (!nameRegex.test(config.name)) {
|
|
@@ -392,28 +421,11 @@ const config = {
|
|
|
392
421
|
export default config;
|
|
393
422
|
${moduleAugmentations}
|
|
394
423
|
`;
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
monoriseOutputDir,
|
|
398
|
-
"analytics-manifest.json"
|
|
399
|
-
);
|
|
400
|
-
const manifest = createAnalyticsManifest(analyticsConfigs);
|
|
401
|
-
if (manifest.unnamedMutuals.length) {
|
|
402
|
-
console.warn(
|
|
403
|
-
`Skipping unnamed mutual analytics datasets: ${manifest.unnamedMutuals.join(", ")}.`
|
|
404
|
-
);
|
|
405
|
-
}
|
|
406
|
-
if (fs2.existsSync(analyticsManifestPath)) {
|
|
407
|
-
validateSchemaEvolution(
|
|
408
|
-
JSON.parse(fs2.readFileSync(analyticsManifestPath, "utf8")),
|
|
409
|
-
manifest
|
|
410
|
-
);
|
|
411
|
-
}
|
|
412
|
-
fs2.writeFileSync(analyticsManifestPath, `${JSON.stringify(manifest, null, 2)}
|
|
413
|
-
`);
|
|
424
|
+
fs3.writeFileSync(configOutputPath, configOutputContent);
|
|
425
|
+
writeAnalyticsManifest(monoriseOutputDir, analyticsConfigs);
|
|
414
426
|
console.log("Successfully generated config.ts!");
|
|
415
|
-
const indexOutputPath =
|
|
416
|
-
|
|
427
|
+
const indexOutputPath = path3.join(monoriseOutputDir, "index.ts");
|
|
428
|
+
fs3.writeFileSync(
|
|
417
429
|
indexOutputPath,
|
|
418
430
|
`export * from './config';
|
|
419
431
|
export { default } from './config';
|
|
@@ -423,21 +435,21 @@ export { default } from './config';
|
|
|
423
435
|
return configOutputPath;
|
|
424
436
|
}
|
|
425
437
|
async function generateHandleFile(monoriseConfig, projectRoot, monoriseOutputDir) {
|
|
426
|
-
const handleOutputPath =
|
|
438
|
+
const handleOutputPath = path3.join(monoriseOutputDir, "handle.ts");
|
|
427
439
|
const customRoutesPath = monoriseConfig.customRoutes;
|
|
428
440
|
let routesImportLine = "";
|
|
429
441
|
let appHandlerPayload = "{}";
|
|
430
442
|
if (customRoutesPath) {
|
|
431
|
-
const absoluteCustomRoutesPath =
|
|
443
|
+
const absoluteCustomRoutesPath = path3.resolve(
|
|
432
444
|
projectRoot,
|
|
433
445
|
customRoutesPath
|
|
434
446
|
);
|
|
435
|
-
if (!
|
|
447
|
+
if (!fs3.existsSync(absoluteCustomRoutesPath) && !fs3.existsSync(`${absoluteCustomRoutesPath}.ts`) && !fs3.existsSync(`${absoluteCustomRoutesPath}.js`)) {
|
|
436
448
|
throw new Error(
|
|
437
449
|
`Custom routes file not found: '${absoluteCustomRoutesPath}'. Please ensure 'customRoutes' in monorise.config.ts points to a valid file.`
|
|
438
450
|
);
|
|
439
451
|
}
|
|
440
|
-
let relativePathToRoutes =
|
|
452
|
+
let relativePathToRoutes = path3.relative(
|
|
441
453
|
monoriseOutputDir,
|
|
442
454
|
absoluteCustomRoutesPath
|
|
443
455
|
);
|
|
@@ -469,30 +481,30 @@ export const tagHandler = coreFactory.tagProcessor;
|
|
|
469
481
|
export const treeHandler = coreFactory.prejoinProcessor;
|
|
470
482
|
export const appHandler = coreFactory.appHandler(${appHandlerPayload});
|
|
471
483
|
`;
|
|
472
|
-
|
|
484
|
+
fs3.writeFileSync(handleOutputPath, combinedContent);
|
|
473
485
|
console.log("Successfully generated handle.ts!");
|
|
474
486
|
return handleOutputPath;
|
|
475
487
|
}
|
|
476
488
|
async function generateFiles(rootPath) {
|
|
477
|
-
const baseDir = rootPath ?
|
|
478
|
-
const configFilePathTS =
|
|
479
|
-
const configFilePathJS =
|
|
489
|
+
const baseDir = rootPath ? path3.resolve(rootPath) : process.cwd();
|
|
490
|
+
const configFilePathTS = path3.join(baseDir, "monorise.config.ts");
|
|
491
|
+
const configFilePathJS = path3.join(baseDir, "monorise.config.js");
|
|
480
492
|
let configFilePath;
|
|
481
|
-
if (
|
|
493
|
+
if (fs3.existsSync(configFilePathTS)) {
|
|
482
494
|
configFilePath = configFilePathTS;
|
|
483
|
-
} else if (
|
|
495
|
+
} else if (fs3.existsSync(configFilePathJS)) {
|
|
484
496
|
configFilePath = configFilePathJS;
|
|
485
497
|
} else {
|
|
486
498
|
throw new Error(
|
|
487
499
|
"Neither monorise.config.ts nor monorise.config.js found in the root of the project."
|
|
488
500
|
);
|
|
489
501
|
}
|
|
490
|
-
const projectRoot =
|
|
502
|
+
const projectRoot = path3.dirname(configFilePath);
|
|
491
503
|
const monoriseConfigModule = await import(configFilePath);
|
|
492
504
|
const monoriseConfig = monoriseConfigModule.default;
|
|
493
|
-
const configDir =
|
|
494
|
-
const monoriseOutputDir =
|
|
495
|
-
|
|
505
|
+
const configDir = path3.resolve(projectRoot, monoriseConfig.configDir);
|
|
506
|
+
const monoriseOutputDir = path3.join(projectRoot, ".monorise");
|
|
507
|
+
fs3.mkdirSync(monoriseOutputDir, { recursive: true });
|
|
496
508
|
await generateConfigFile(configDir, monoriseOutputDir, projectRoot);
|
|
497
509
|
await generateHandleFile(monoriseConfig, projectRoot, monoriseOutputDir);
|
|
498
510
|
return configDir;
|
|
@@ -550,29 +562,29 @@ async function runInitCommand(rootPath) {
|
|
|
550
562
|
let projectName = "my-app";
|
|
551
563
|
let projectRoot;
|
|
552
564
|
if (rootPath) {
|
|
553
|
-
projectRoot =
|
|
554
|
-
projectName =
|
|
565
|
+
projectRoot = path3.resolve(rootPath);
|
|
566
|
+
projectName = path3.basename(projectRoot);
|
|
555
567
|
} else {
|
|
556
568
|
const args = process.argv.slice(2);
|
|
557
569
|
const nameIndex = args.indexOf("--name");
|
|
558
570
|
if (nameIndex > -1 && args[nameIndex + 1]) {
|
|
559
571
|
projectName = args[nameIndex + 1];
|
|
560
572
|
}
|
|
561
|
-
projectRoot =
|
|
573
|
+
projectRoot = path3.resolve(projectName);
|
|
562
574
|
}
|
|
563
575
|
console.log(`
|
|
564
576
|
\u{1F680} Creating Monorise project: ${projectName}
|
|
565
577
|
`);
|
|
566
|
-
if (
|
|
578
|
+
if (fs3.existsSync(projectRoot)) {
|
|
567
579
|
console.error(`Error: Directory ${projectName} already exists.`);
|
|
568
580
|
process.exit(1);
|
|
569
581
|
}
|
|
570
582
|
console.log("\u{1F4C1} Creating project structure...");
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
583
|
+
fs3.mkdirSync(projectRoot, { recursive: true });
|
|
584
|
+
fs3.mkdirSync(path3.join(projectRoot, "apps"), { recursive: true });
|
|
585
|
+
fs3.mkdirSync(path3.join(projectRoot, "services", "core"), { recursive: true });
|
|
586
|
+
fs3.mkdirSync(path3.join(projectRoot, "monorise", "configs"), { recursive: true });
|
|
587
|
+
fs3.mkdirSync(path3.join(projectRoot, "monorise", "mutuals"), { recursive: true });
|
|
576
588
|
console.log("\u{1F4E6} Initializing root package.json...");
|
|
577
589
|
const rootPackageJson = {
|
|
578
590
|
name: projectName,
|
|
@@ -581,21 +593,21 @@ async function runInitCommand(rootPath) {
|
|
|
581
593
|
private: true,
|
|
582
594
|
workspaces: ["apps/*", "services/*"]
|
|
583
595
|
};
|
|
584
|
-
|
|
585
|
-
|
|
596
|
+
fs3.writeFileSync(
|
|
597
|
+
path3.join(projectRoot, "package.json"),
|
|
586
598
|
JSON.stringify(rootPackageJson, null, 2)
|
|
587
599
|
);
|
|
588
600
|
console.log("\u2699\uFE0F Creating root tsconfig.json...");
|
|
589
|
-
|
|
590
|
-
|
|
601
|
+
fs3.writeFileSync(
|
|
602
|
+
path3.join(projectRoot, "tsconfig.json"),
|
|
591
603
|
JSON.stringify(ROOT_TSCONFIG_TEMPLATE, null, 2)
|
|
592
604
|
);
|
|
593
605
|
console.log("\n\u{1F4F1} Creating Next.js app in apps/web...");
|
|
594
|
-
const nextAppDir =
|
|
606
|
+
const nextAppDir = path3.join(projectRoot, "apps", "web");
|
|
595
607
|
try {
|
|
596
608
|
execCommand(
|
|
597
609
|
`npx create-next-app@latest web --typescript --tailwind --eslint --app --no-src-dir --import-alias "#/*" --no-turbopack --yes`,
|
|
598
|
-
|
|
610
|
+
path3.join(projectRoot, "apps")
|
|
599
611
|
);
|
|
600
612
|
} catch (error) {
|
|
601
613
|
console.error("Failed to create Next.js app:", error);
|
|
@@ -616,28 +628,28 @@ async function runInitCommand(rootPath) {
|
|
|
616
628
|
process.exit(1);
|
|
617
629
|
}
|
|
618
630
|
console.log("\u2699\uFE0F Creating monorise.config.ts...");
|
|
619
|
-
|
|
620
|
-
|
|
631
|
+
fs3.writeFileSync(
|
|
632
|
+
path3.join(projectRoot, "monorise.config.ts"),
|
|
621
633
|
readTemplate("monorise.config.ts")
|
|
622
634
|
);
|
|
623
635
|
console.log("\u{1F517} Creating team-membership mutual config...");
|
|
624
|
-
|
|
625
|
-
|
|
636
|
+
fs3.writeFileSync(
|
|
637
|
+
path3.join(projectRoot, "monorise", "mutuals", "team-membership.ts"),
|
|
626
638
|
readTemplate("team-membership.mutual.ts")
|
|
627
639
|
);
|
|
628
640
|
console.log("\u{1F464} Creating starter User entity...");
|
|
629
|
-
|
|
630
|
-
|
|
641
|
+
fs3.writeFileSync(
|
|
642
|
+
path3.join(projectRoot, "monorise", "configs", "user.ts"),
|
|
631
643
|
readTemplate("user-entity.ts")
|
|
632
644
|
);
|
|
633
645
|
console.log("\u{1F465} Creating starter Team entity...");
|
|
634
|
-
|
|
635
|
-
|
|
646
|
+
fs3.writeFileSync(
|
|
647
|
+
path3.join(projectRoot, "monorise", "configs", "team.ts"),
|
|
636
648
|
readTemplate("team-entity.ts")
|
|
637
649
|
);
|
|
638
650
|
console.log("\u{1F527} Creating services/core/routes.ts...");
|
|
639
|
-
|
|
640
|
-
|
|
651
|
+
fs3.writeFileSync(
|
|
652
|
+
path3.join(projectRoot, "services", "core", "routes.ts"),
|
|
641
653
|
readTemplate("core-routes.ts")
|
|
642
654
|
);
|
|
643
655
|
const servicesPackageJson = {
|
|
@@ -645,13 +657,13 @@ async function runInitCommand(rootPath) {
|
|
|
645
657
|
version: "0.0.0",
|
|
646
658
|
type: "module"
|
|
647
659
|
};
|
|
648
|
-
|
|
649
|
-
|
|
660
|
+
fs3.writeFileSync(
|
|
661
|
+
path3.join(projectRoot, "services", "core", "package.json"),
|
|
650
662
|
JSON.stringify(servicesPackageJson, null, 2)
|
|
651
663
|
);
|
|
652
664
|
console.log("\u2699\uFE0F Creating sst.config.ts with Monorise...");
|
|
653
|
-
const sstConfigPath =
|
|
654
|
-
|
|
665
|
+
const sstConfigPath = path3.join(projectRoot, "sst.config.ts");
|
|
666
|
+
fs3.writeFileSync(sstConfigPath, readTemplate("sst.config.ts").replace("{{PROJECT_NAME}}", projectName));
|
|
655
667
|
console.log("\n\u2601\uFE0F Installing SST providers...");
|
|
656
668
|
try {
|
|
657
669
|
execCommand("npx sst install", projectRoot);
|
|
@@ -659,63 +671,63 @@ async function runInitCommand(rootPath) {
|
|
|
659
671
|
console.warn("Warning: SST install failed, continuing anyway...");
|
|
660
672
|
}
|
|
661
673
|
console.log("\u{1F4C4} Creating example page in apps/web...");
|
|
662
|
-
const webSrcAppDir =
|
|
663
|
-
const webAppDir =
|
|
664
|
-
const pagePath =
|
|
674
|
+
const webSrcAppDir = path3.join(projectRoot, "apps", "web", "src", "app");
|
|
675
|
+
const webAppDir = path3.join(projectRoot, "apps", "web", "app");
|
|
676
|
+
const pagePath = fs3.existsSync(webSrcAppDir) ? path3.join(webSrcAppDir, "page.tsx") : fs3.existsSync(webAppDir) ? path3.join(webAppDir, "page.tsx") : null;
|
|
665
677
|
if (pagePath) {
|
|
666
678
|
try {
|
|
667
|
-
|
|
668
|
-
console.log(`Created example page at ${
|
|
679
|
+
fs3.writeFileSync(pagePath, readTemplate("example-page.tsx"));
|
|
680
|
+
console.log(`Created example page at ${path3.relative(projectRoot, pagePath)}`);
|
|
669
681
|
} catch (error) {
|
|
670
682
|
console.warn("Warning: Could not create example page:", error);
|
|
671
683
|
}
|
|
672
684
|
} else {
|
|
673
685
|
console.warn("Warning: Could not find apps/web/src/app or apps/web/app directory");
|
|
674
686
|
}
|
|
675
|
-
const webRoot =
|
|
687
|
+
const webRoot = fs3.existsSync(webSrcAppDir) ? path3.join(projectRoot, "apps", "web", "src") : fs3.existsSync(webAppDir) ? path3.join(projectRoot, "apps", "web") : null;
|
|
676
688
|
if (webRoot) {
|
|
677
|
-
const appDir =
|
|
678
|
-
|
|
679
|
-
|
|
689
|
+
const appDir = fs3.existsSync(webSrcAppDir) ? webSrcAppDir : webAppDir;
|
|
690
|
+
fs3.mkdirSync(path3.join(webRoot, "components", "ui"), { recursive: true });
|
|
691
|
+
fs3.mkdirSync(path3.join(webRoot, "lib"), { recursive: true });
|
|
680
692
|
console.log("\u{1F310} Creating global components...");
|
|
681
|
-
|
|
682
|
-
|
|
693
|
+
fs3.writeFileSync(
|
|
694
|
+
path3.join(webRoot, "components", "global-initializer.tsx"),
|
|
683
695
|
readTemplate("global-initializer.tsx")
|
|
684
696
|
);
|
|
685
|
-
|
|
686
|
-
|
|
697
|
+
fs3.writeFileSync(
|
|
698
|
+
path3.join(webRoot, "components", "global-loader.tsx"),
|
|
687
699
|
readTemplate("global-loader.tsx")
|
|
688
700
|
);
|
|
689
701
|
console.log("\u{1F527} Creating lib/utils.ts...");
|
|
690
|
-
|
|
691
|
-
|
|
702
|
+
fs3.writeFileSync(
|
|
703
|
+
path3.join(webRoot, "lib", "utils.ts"),
|
|
692
704
|
readTemplate("lib-utils.ts")
|
|
693
705
|
);
|
|
694
706
|
console.log("\u{1F3A8} Creating shadcn UI components...");
|
|
695
|
-
|
|
696
|
-
|
|
707
|
+
fs3.writeFileSync(
|
|
708
|
+
path3.join(webRoot, "components", "ui", "button.tsx"),
|
|
697
709
|
readTemplate("ui-button.tsx")
|
|
698
710
|
);
|
|
699
|
-
|
|
700
|
-
|
|
711
|
+
fs3.writeFileSync(
|
|
712
|
+
path3.join(webRoot, "components", "ui", "card.tsx"),
|
|
701
713
|
readTemplate("ui-card.tsx")
|
|
702
714
|
);
|
|
703
|
-
|
|
704
|
-
|
|
715
|
+
fs3.writeFileSync(
|
|
716
|
+
path3.join(webRoot, "components", "ui", "input.tsx"),
|
|
705
717
|
readTemplate("ui-input.tsx")
|
|
706
718
|
);
|
|
707
|
-
|
|
708
|
-
|
|
719
|
+
fs3.writeFileSync(
|
|
720
|
+
path3.join(webRoot, "components", "ui", "label.tsx"),
|
|
709
721
|
readTemplate("ui-label.tsx")
|
|
710
722
|
);
|
|
711
723
|
console.log("\u{1F3A8} Setting up shadcn globals.css...");
|
|
712
|
-
const globalsCssPath =
|
|
713
|
-
|
|
724
|
+
const globalsCssPath = path3.join(appDir, "globals.css");
|
|
725
|
+
fs3.writeFileSync(globalsCssPath, readTemplate("globals.css"));
|
|
714
726
|
console.log("\u{1F4D0} Updating layout.tsx with global components...");
|
|
715
|
-
const layoutPath =
|
|
716
|
-
if (
|
|
727
|
+
const layoutPath = path3.join(appDir, "layout.tsx");
|
|
728
|
+
if (fs3.existsSync(layoutPath)) {
|
|
717
729
|
try {
|
|
718
|
-
let layoutContent =
|
|
730
|
+
let layoutContent = fs3.readFileSync(layoutPath, "utf8");
|
|
719
731
|
const globalImports = `import GlobalInitializer from '#/components/global-initializer';
|
|
720
732
|
import GlobalLoader from '#/components/global-loader';`;
|
|
721
733
|
const lastImportIndex = layoutContent.lastIndexOf("import ");
|
|
@@ -728,14 +740,14 @@ import GlobalLoader from '#/components/global-loader';`;
|
|
|
728
740
|
<GlobalInitializer />
|
|
729
741
|
<GlobalLoader />`
|
|
730
742
|
);
|
|
731
|
-
|
|
743
|
+
fs3.writeFileSync(layoutPath, layoutContent);
|
|
732
744
|
} catch (error) {
|
|
733
745
|
console.warn("Warning: Could not update layout.tsx:", error);
|
|
734
746
|
}
|
|
735
747
|
}
|
|
736
|
-
const postcssPath =
|
|
737
|
-
if (
|
|
738
|
-
|
|
748
|
+
const postcssPath = path3.join(projectRoot, "apps", "web", "postcss.config.mjs");
|
|
749
|
+
if (fs3.existsSync(postcssPath)) {
|
|
750
|
+
fs3.writeFileSync(
|
|
739
751
|
postcssPath,
|
|
740
752
|
`const config = {
|
|
741
753
|
plugins: {
|
|
@@ -748,23 +760,23 @@ export default config;
|
|
|
748
760
|
);
|
|
749
761
|
}
|
|
750
762
|
console.log("\u{1F500} Creating API proxy routes...");
|
|
751
|
-
const apiDir =
|
|
752
|
-
const catchAllDir =
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
763
|
+
const apiDir = path3.join(appDir, "api");
|
|
764
|
+
const catchAllDir = path3.join(apiDir, "[...proxy]");
|
|
765
|
+
fs3.mkdirSync(catchAllDir, { recursive: true });
|
|
766
|
+
fs3.writeFileSync(
|
|
767
|
+
path3.join(apiDir, "proxy-request.ts"),
|
|
756
768
|
readTemplate("proxy-request.ts")
|
|
757
769
|
);
|
|
758
|
-
|
|
759
|
-
|
|
770
|
+
fs3.writeFileSync(
|
|
771
|
+
path3.join(catchAllDir, "route.ts"),
|
|
760
772
|
readTemplate("proxy-route.ts")
|
|
761
773
|
);
|
|
762
774
|
}
|
|
763
775
|
console.log("\u2699\uFE0F Updating apps/web tsconfig.json...");
|
|
764
|
-
const webTsconfigPath =
|
|
765
|
-
if (
|
|
776
|
+
const webTsconfigPath = path3.join(projectRoot, "apps", "web", "tsconfig.json");
|
|
777
|
+
if (fs3.existsSync(webTsconfigPath)) {
|
|
766
778
|
try {
|
|
767
|
-
const webTsconfigContent =
|
|
779
|
+
const webTsconfigContent = fs3.readFileSync(webTsconfigPath, "utf8");
|
|
768
780
|
const webTsconfig = JSON.parse(webTsconfigContent);
|
|
769
781
|
if (!webTsconfig.compilerOptions) {
|
|
770
782
|
webTsconfig.compilerOptions = {};
|
|
@@ -775,9 +787,9 @@ export default config;
|
|
|
775
787
|
webTsconfig.compilerOptions.paths["#/shared/*"] = ["../../shared/*"];
|
|
776
788
|
webTsconfig.compilerOptions.paths["#/monorise/*"] = ["../../.monorise/*"];
|
|
777
789
|
webTsconfig.compilerOptions.paths["#/monorise"] = ["../../.monorise/index"];
|
|
778
|
-
const hasSrcDir =
|
|
790
|
+
const hasSrcDir = fs3.existsSync(path3.join(projectRoot, "apps", "web", "src"));
|
|
779
791
|
webTsconfig.compilerOptions.paths["#/*"] = [hasSrcDir ? "./src/*" : "./*"];
|
|
780
|
-
|
|
792
|
+
fs3.writeFileSync(webTsconfigPath, JSON.stringify(webTsconfig, null, 2));
|
|
781
793
|
} catch (error) {
|
|
782
794
|
console.warn("Warning: Could not update apps/web tsconfig.json:", error);
|
|
783
795
|
}
|
|
@@ -804,7 +816,7 @@ export default config;
|
|
|
804
816
|
console.log(` \u2022 Edit your data model \u2192 monorise/configs/user.ts`);
|
|
805
817
|
console.log(` (Add fields like phone, role, status to the User entity)`);
|
|
806
818
|
console.log(
|
|
807
|
-
` \u2022 Build your UI \u2192 ${pagePath ?
|
|
819
|
+
` \u2022 Build your UI \u2192 ${pagePath ? path3.relative(projectRoot, pagePath) : "apps/web/app/page.tsx"}`
|
|
808
820
|
);
|
|
809
821
|
console.log(` (React components using useEntities and createEntity)`);
|
|
810
822
|
console.log(` \u2022 Add backend logic \u2192 services/core/routes.ts`);
|
|
@@ -823,7 +835,7 @@ async function runDevCommand(configDir, rootPath) {
|
|
|
823
835
|
console.log(`Watching for changes in ${configDir}...`);
|
|
824
836
|
const watcher = chokidar.watch(configDir, {
|
|
825
837
|
ignored: (watchedPath) => {
|
|
826
|
-
const fileName =
|
|
838
|
+
const fileName = path3.basename(watchedPath);
|
|
827
839
|
return fileName === "index.ts" || // Old name, still ignore in case it exists
|
|
828
840
|
fileName === "config.ts" || // Generated config file
|
|
829
841
|
fileName === "processors.ts" || // Generated processors file
|