monorise 2.0.0-dev.1 → 2.0.0-dev.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.
- package/dist/base/index.d.ts +126 -1
- package/dist/base/index.js +168 -1
- package/dist/base/index.js.map +1 -1
- package/dist/cli/cli.js +226 -123
- package/dist/cli/cli.js.map +1 -1
- package/dist/core/index.d.ts +110 -21
- package/dist/core/index.js +601 -82
- package/dist/core/index.js.map +1 -1
- package/dist/index.d.ts +19 -0
- package/dist/react/actions/core.action.d.ts +24 -70
- package/dist/react/actions/core.action.d.ts.map +1 -1
- package/dist/react/actions/websocket.action.d.ts.map +1 -1
- package/dist/react/index.d.ts +47 -138
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +141 -40
- package/dist/react/index.js.map +1 -1
- package/dist/react/lib/search.d.ts +29 -0
- package/dist/react/lib/search.d.ts.map +1 -0
- package/dist/react/services/core.service.d.ts.map +1 -1
- package/dist/react/types/api.type.d.ts +12 -0
- package/dist/react/types/api.type.d.ts.map +1 -1
- package/dist/react/types/monorise.type.d.ts +1 -0
- package/dist/react/types/monorise.type.d.ts.map +1 -1
- package/dist/sst/components/monorise-core.d.ts +1 -0
- package/dist/sst/components/monorise-core.d.ts.map +1 -1
- package/dist/sst/index.js +66 -1
- package/dist/sst/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cli/cli.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
// cli.ts
|
|
4
4
|
import "tsx";
|
|
5
|
-
import
|
|
6
|
-
import
|
|
5
|
+
import fs5 from "fs";
|
|
6
|
+
import path5 from "path";
|
|
7
7
|
import { execSync } from "child_process";
|
|
8
8
|
import chokidar from "chokidar";
|
|
9
9
|
|
|
@@ -16,7 +16,7 @@ function normalizeSqlIdentifier(name) {
|
|
|
16
16
|
const normalized = name.replace(/([a-z0-9])([A-Z])/g, "$1_$2").replace(/[^a-zA-Z0-9]+/g, "_").replace(/^_+|_+$/g, "").toLowerCase();
|
|
17
17
|
return /^[a-z_]/.test(normalized) ? normalized : `_${normalized}`;
|
|
18
18
|
}
|
|
19
|
-
function athenaType(schema,
|
|
19
|
+
function athenaType(schema, path6) {
|
|
20
20
|
let current = schema;
|
|
21
21
|
for (; ; ) {
|
|
22
22
|
const typeName = current._def?.typeName;
|
|
@@ -65,7 +65,7 @@ function athenaType(schema, path5) {
|
|
|
65
65
|
return "json";
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
|
-
function columns(schema,
|
|
68
|
+
function columns(schema, path6) {
|
|
69
69
|
let objectSchema = schema;
|
|
70
70
|
while (!objectSchema.shape && objectSchema._def?.typeName === "ZodEffects") {
|
|
71
71
|
const innerSchema = objectSchema._def.schema;
|
|
@@ -79,14 +79,14 @@ function columns(schema, path5) {
|
|
|
79
79
|
const existing = names.get(name);
|
|
80
80
|
if (existing) {
|
|
81
81
|
throw new Error(
|
|
82
|
-
`Analytics column identifier collision in ${
|
|
82
|
+
`Analytics column identifier collision in ${path6}: ${existing} and ${sourceName} both normalize to ${name}.`
|
|
83
83
|
);
|
|
84
84
|
}
|
|
85
85
|
names.set(name, sourceName);
|
|
86
86
|
return {
|
|
87
87
|
name,
|
|
88
88
|
sourceName,
|
|
89
|
-
type: athenaType(field, `${
|
|
89
|
+
type: athenaType(field, `${path6}.${sourceName}`)
|
|
90
90
|
};
|
|
91
91
|
});
|
|
92
92
|
}
|
|
@@ -107,16 +107,35 @@ function endpoints(entities) {
|
|
|
107
107
|
function fingerprint(datasets) {
|
|
108
108
|
return createHash("sha256").update(JSON.stringify(datasets)).digest("hex");
|
|
109
109
|
}
|
|
110
|
+
var typeChangeAdvice = "Analytics columns can't change type in place: add a field with a name this dataset has never used. If this project has never deployed analytics, delete .monorise/analytics-manifest.json and run the generator again.";
|
|
110
111
|
function validateSchemaEvolution(previous, next) {
|
|
112
|
+
const warnings = [];
|
|
113
|
+
const removedColumns = {};
|
|
114
|
+
for (const [identifier, columns2] of Object.entries(
|
|
115
|
+
previous.removedColumns ?? {}
|
|
116
|
+
)) {
|
|
117
|
+
removedColumns[identifier] = [...columns2];
|
|
118
|
+
}
|
|
119
|
+
const remember = (identifier, columns2) => {
|
|
120
|
+
const known = removedColumns[identifier] ?? [];
|
|
121
|
+
removedColumns[identifier] = [
|
|
122
|
+
...known,
|
|
123
|
+
...columns2.filter(
|
|
124
|
+
(column) => !known.some((existing) => existing.name === column.name)
|
|
125
|
+
)
|
|
126
|
+
];
|
|
127
|
+
};
|
|
111
128
|
const nextDatasets = new Map(
|
|
112
129
|
next.datasets.map((dataset) => [dataset.identifier, dataset])
|
|
113
130
|
);
|
|
114
131
|
for (const previousDataset of previous.datasets) {
|
|
115
132
|
const nextDataset = nextDatasets.get(previousDataset.identifier);
|
|
116
133
|
if (!nextDataset) {
|
|
117
|
-
|
|
118
|
-
`Analytics dataset ${previousDataset.name} was removed.
|
|
134
|
+
warnings.push(
|
|
135
|
+
`Analytics dataset ${previousDataset.name} was removed. If analytics is deployed, the next deploy drops its raw table; its S3 data and curated tables are kept.`
|
|
119
136
|
);
|
|
137
|
+
remember(previousDataset.identifier, previousDataset.columns);
|
|
138
|
+
continue;
|
|
120
139
|
}
|
|
121
140
|
const nextColumns = new Map(
|
|
122
141
|
nextDataset.columns.map((column) => [column.name, column])
|
|
@@ -124,17 +143,38 @@ function validateSchemaEvolution(previous, next) {
|
|
|
124
143
|
for (const previousColumn of previousDataset.columns) {
|
|
125
144
|
const nextColumn = nextColumns.get(previousColumn.name);
|
|
126
145
|
if (!nextColumn) {
|
|
127
|
-
|
|
128
|
-
`Analytics field ${previousDataset.name}.${previousColumn.sourceName} was removed or renamed.
|
|
146
|
+
warnings.push(
|
|
147
|
+
`Analytics field ${previousDataset.name}.${previousColumn.sourceName} was removed or renamed. Its column stays: new history records leave it empty, and in the current table existing rows keep their last value. A renamed field starts a new column.`
|
|
129
148
|
);
|
|
149
|
+
remember(previousDataset.identifier, [previousColumn]);
|
|
150
|
+
continue;
|
|
130
151
|
}
|
|
131
152
|
if (nextColumn.type !== previousColumn.type) {
|
|
132
153
|
throw new Error(
|
|
133
|
-
`Analytics field ${previousDataset.name}.${previousColumn.sourceName} changed from ${previousColumn.type} to ${nextColumn.type}.
|
|
154
|
+
`Analytics field ${previousDataset.name}.${previousColumn.sourceName} changed from ${previousColumn.type} to ${nextColumn.type}. ${typeChangeAdvice}`
|
|
134
155
|
);
|
|
135
156
|
}
|
|
136
157
|
}
|
|
137
158
|
}
|
|
159
|
+
for (const nextDataset of next.datasets) {
|
|
160
|
+
const removed = removedColumns[nextDataset.identifier];
|
|
161
|
+
if (!removed) continue;
|
|
162
|
+
for (const column of nextDataset.columns) {
|
|
163
|
+
const old = removed.find((candidate) => candidate.name === column.name);
|
|
164
|
+
if (!old) continue;
|
|
165
|
+
if (old.type !== column.type) {
|
|
166
|
+
throw new Error(
|
|
167
|
+
`Analytics field ${nextDataset.name}.${column.sourceName} was removed earlier as ${old.type}, and its column still has that type, so it can't come back as ${column.type}. ${typeChangeAdvice}`
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
const stillRemoved = removed.filter(
|
|
172
|
+
(old) => !nextDataset.columns.some((column) => column.name === old.name)
|
|
173
|
+
);
|
|
174
|
+
if (stillRemoved.length) removedColumns[nextDataset.identifier] = stillRemoved;
|
|
175
|
+
else delete removedColumns[nextDataset.identifier];
|
|
176
|
+
}
|
|
177
|
+
return { warnings, removedColumns };
|
|
138
178
|
}
|
|
139
179
|
function writeAnalyticsManifest(monoriseOutputDir, configs) {
|
|
140
180
|
const analyticsManifestPath = path.join(monoriseOutputDir, "analytics-manifest.json");
|
|
@@ -144,13 +184,17 @@ function writeAnalyticsManifest(monoriseOutputDir, configs) {
|
|
|
144
184
|
`Skipping unnamed mutual analytics datasets: ${manifest.unnamedMutuals.join(", ")}.`
|
|
145
185
|
);
|
|
146
186
|
}
|
|
187
|
+
let removedColumns = {};
|
|
147
188
|
if (fs.existsSync(analyticsManifestPath)) {
|
|
148
|
-
validateSchemaEvolution(
|
|
189
|
+
const evolution = validateSchemaEvolution(
|
|
149
190
|
JSON.parse(fs.readFileSync(analyticsManifestPath, "utf8")),
|
|
150
191
|
manifest
|
|
151
192
|
);
|
|
193
|
+
for (const warning of evolution.warnings) console.warn(warning);
|
|
194
|
+
removedColumns = evolution.removedColumns;
|
|
152
195
|
}
|
|
153
|
-
|
|
196
|
+
const written = Object.keys(removedColumns).length ? { ...manifest, removedColumns } : manifest;
|
|
197
|
+
fs.writeFileSync(analyticsManifestPath, `${JSON.stringify(written, null, 2)}
|
|
154
198
|
`);
|
|
155
199
|
}
|
|
156
200
|
function createAnalyticsManifest(configs) {
|
|
@@ -384,6 +428,51 @@ function detectCombinedPackage(startDir) {
|
|
|
384
428
|
return false;
|
|
385
429
|
}
|
|
386
430
|
|
|
431
|
+
// commands/utils/search-manifest.ts
|
|
432
|
+
import fs4 from "fs";
|
|
433
|
+
import { createRequire as createRequire2 } from "module";
|
|
434
|
+
import path4 from "path";
|
|
435
|
+
import { pathToFileURL as pathToFileURL2 } from "url";
|
|
436
|
+
function searchDefaultsDeclaration(defaults) {
|
|
437
|
+
return `const SearchDefaults = ${JSON.stringify(defaults ?? {})};`;
|
|
438
|
+
}
|
|
439
|
+
async function loadProjectBase(projectRoot) {
|
|
440
|
+
const name = detectCombinedPackage(projectRoot) ? "monorise/base" : "../base/index.js";
|
|
441
|
+
const require3 = createRequire2(path4.join(projectRoot, "package.json"));
|
|
442
|
+
const base = await import(pathToFileURL2(require3.resolve(name)).href);
|
|
443
|
+
if (typeof base.searchConfigHash !== "function") {
|
|
444
|
+
throw new Error(
|
|
445
|
+
`'search' needs a newer ${name}: this version doesn't support the search index.`
|
|
446
|
+
);
|
|
447
|
+
}
|
|
448
|
+
return base;
|
|
449
|
+
}
|
|
450
|
+
async function writeSearchManifest(monoriseOutputDir, projectRoot, configs, defaults) {
|
|
451
|
+
const manifestPath = path4.join(monoriseOutputDir, "search-manifest.json");
|
|
452
|
+
const indexed = configs.filter((config) => config.search);
|
|
453
|
+
if (!indexed.length) {
|
|
454
|
+
fs4.rmSync(manifestPath, { force: true });
|
|
455
|
+
return;
|
|
456
|
+
}
|
|
457
|
+
const base = await loadProjectBase(projectRoot);
|
|
458
|
+
if (defaults !== void 0) {
|
|
459
|
+
base.validateSearchSettings(defaults, "monorise.config.ts");
|
|
460
|
+
}
|
|
461
|
+
const manifest = {
|
|
462
|
+
version: 1,
|
|
463
|
+
entities: Object.fromEntries(
|
|
464
|
+
indexed.map((config) => [
|
|
465
|
+
config.name,
|
|
466
|
+
base.searchConfigHash(
|
|
467
|
+
base.resolveSearchConfig(config.search, defaults)
|
|
468
|
+
)
|
|
469
|
+
])
|
|
470
|
+
)
|
|
471
|
+
};
|
|
472
|
+
fs4.writeFileSync(manifestPath, `${JSON.stringify(manifest, null, 2)}
|
|
473
|
+
`);
|
|
474
|
+
}
|
|
475
|
+
|
|
387
476
|
// templates/root-tsconfig.ts
|
|
388
477
|
var ROOT_TSCONFIG_TEMPLATE = {
|
|
389
478
|
compilerOptions: {
|
|
@@ -406,10 +495,10 @@ var ROOT_TSCONFIG_TEMPLATE = {
|
|
|
406
495
|
|
|
407
496
|
// cli.ts
|
|
408
497
|
var __filename = fileURLToPath(import.meta.url);
|
|
409
|
-
var __dirname =
|
|
410
|
-
var TEMPLATES_DIR =
|
|
498
|
+
var __dirname = path5.dirname(__filename);
|
|
499
|
+
var TEMPLATES_DIR = path5.join(__dirname, "templates", "files");
|
|
411
500
|
function readTemplate(filename) {
|
|
412
|
-
return
|
|
501
|
+
return fs5.readFileSync(path5.join(TEMPLATES_DIR, filename), "utf-8");
|
|
413
502
|
}
|
|
414
503
|
function kebabToCamel(str) {
|
|
415
504
|
return str.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
|
|
@@ -421,20 +510,20 @@ function execCommand(command, cwd, stdio = "inherit") {
|
|
|
421
510
|
console.log(`Running: ${command}`);
|
|
422
511
|
execSync(command, { cwd, stdio });
|
|
423
512
|
}
|
|
424
|
-
async function generateConfigFile(configDir, monoriseOutputDir, projectRoot) {
|
|
425
|
-
const configOutputPath =
|
|
513
|
+
async function generateConfigFile(configDir, monoriseOutputDir, projectRoot, searchDefaults) {
|
|
514
|
+
const configOutputPath = path5.join(monoriseOutputDir, "config.ts");
|
|
426
515
|
const initialConfigContent = `
|
|
427
516
|
export enum Entity {}
|
|
428
517
|
export default {};
|
|
429
518
|
`;
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
519
|
+
fs5.writeFileSync(configOutputPath, initialConfigContent);
|
|
520
|
+
fs5.writeFileSync(
|
|
521
|
+
path5.join(monoriseOutputDir, "index.ts"),
|
|
433
522
|
`export * from './config';
|
|
434
523
|
export { default } from './config';
|
|
435
524
|
`
|
|
436
525
|
);
|
|
437
|
-
const files =
|
|
526
|
+
const files = fs5.readdirSync(configDir).filter((file) => file.endsWith(".ts") && file !== "index.ts");
|
|
438
527
|
const names = /* @__PURE__ */ new Set();
|
|
439
528
|
const nameRegex = /^[a-z]+(-[a-z]+)*$/;
|
|
440
529
|
const imports = [];
|
|
@@ -447,10 +536,11 @@ export { default } from './config';
|
|
|
447
536
|
const entityWithEmailAuthEntries = [];
|
|
448
537
|
const analyticsConfigs = [];
|
|
449
538
|
const apiKeyTypeEntities = [];
|
|
450
|
-
const
|
|
539
|
+
const searchConfigs = [];
|
|
540
|
+
const relativePathToConfigDir = path5.relative(monoriseOutputDir, configDir);
|
|
451
541
|
const importPathPrefix = relativePathToConfigDir ? `${relativePathToConfigDir}/` : "./";
|
|
452
542
|
for (const file of files) {
|
|
453
|
-
const fullPath =
|
|
543
|
+
const fullPath = path5.join(configDir, file);
|
|
454
544
|
const module = await import(fullPath);
|
|
455
545
|
const config = module.default;
|
|
456
546
|
if (!nameRegex.test(config.name)) {
|
|
@@ -463,6 +553,7 @@ export { default } from './config';
|
|
|
463
553
|
}
|
|
464
554
|
names.add(config.name);
|
|
465
555
|
analyticsConfigs.push(config);
|
|
556
|
+
searchConfigs.push(config);
|
|
466
557
|
const fileName = file.replace(/\.ts$/, "");
|
|
467
558
|
const variableName = kebabToCamel(fileName);
|
|
468
559
|
imports.push(
|
|
@@ -529,11 +620,14 @@ const AllowedEntityTypes = [
|
|
|
529
620
|
|
|
530
621
|
const EmailAuthEnabledEntities: Entity[] = [${entityWithEmailAuthEntries.join(", ")}];
|
|
531
622
|
|
|
623
|
+
${searchDefaultsDeclaration(searchDefaults)}
|
|
624
|
+
|
|
532
625
|
export {
|
|
533
626
|
EntityConfig,
|
|
534
627
|
FormSchema,
|
|
535
628
|
AllowedEntityTypes,
|
|
536
629
|
EmailAuthEnabledEntities,
|
|
630
|
+
SearchDefaults,
|
|
537
631
|
};
|
|
538
632
|
|
|
539
633
|
const config = {
|
|
@@ -541,16 +635,23 @@ const config = {
|
|
|
541
635
|
FormSchema,
|
|
542
636
|
AllowedEntityTypes,
|
|
543
637
|
EmailAuthEnabledEntities,
|
|
638
|
+
SearchDefaults,
|
|
544
639
|
};
|
|
545
640
|
|
|
546
641
|
export default config;
|
|
547
642
|
${moduleAugmentations}
|
|
548
643
|
`;
|
|
549
|
-
|
|
644
|
+
fs5.writeFileSync(configOutputPath, configOutputContent);
|
|
550
645
|
writeAnalyticsManifest(monoriseOutputDir, analyticsConfigs);
|
|
646
|
+
await writeSearchManifest(
|
|
647
|
+
monoriseOutputDir,
|
|
648
|
+
projectRoot,
|
|
649
|
+
searchConfigs,
|
|
650
|
+
searchDefaults
|
|
651
|
+
);
|
|
551
652
|
console.log("Successfully generated config.ts!");
|
|
552
|
-
const indexOutputPath =
|
|
553
|
-
|
|
653
|
+
const indexOutputPath = path5.join(monoriseOutputDir, "index.ts");
|
|
654
|
+
fs5.writeFileSync(
|
|
554
655
|
indexOutputPath,
|
|
555
656
|
`export * from './config';
|
|
556
657
|
export { default } from './config';
|
|
@@ -560,21 +661,21 @@ export { default } from './config';
|
|
|
560
661
|
return configOutputPath;
|
|
561
662
|
}
|
|
562
663
|
async function generateHandleFile(monoriseConfig, projectRoot, monoriseOutputDir, apiKeysPath) {
|
|
563
|
-
const handleOutputPath =
|
|
664
|
+
const handleOutputPath = path5.join(monoriseOutputDir, "handle.ts");
|
|
564
665
|
const customRoutesPath = monoriseConfig.customRoutes;
|
|
565
666
|
let routesImportLine = "";
|
|
566
667
|
let appHandlerPayload = "{}";
|
|
567
668
|
if (customRoutesPath) {
|
|
568
|
-
const absoluteCustomRoutesPath =
|
|
669
|
+
const absoluteCustomRoutesPath = path5.resolve(
|
|
569
670
|
projectRoot,
|
|
570
671
|
customRoutesPath
|
|
571
672
|
);
|
|
572
|
-
if (!
|
|
673
|
+
if (!fs5.existsSync(absoluteCustomRoutesPath) && !fs5.existsSync(`${absoluteCustomRoutesPath}.ts`) && !fs5.existsSync(`${absoluteCustomRoutesPath}.js`)) {
|
|
573
674
|
throw new Error(
|
|
574
675
|
`Custom routes file not found: '${absoluteCustomRoutesPath}'. Please ensure 'customRoutes' in monorise.config.ts points to a valid file.`
|
|
575
676
|
);
|
|
576
677
|
}
|
|
577
|
-
let relativePathToRoutes =
|
|
678
|
+
let relativePathToRoutes = path5.relative(
|
|
578
679
|
monoriseOutputDir,
|
|
579
680
|
absoluteCustomRoutesPath
|
|
580
681
|
);
|
|
@@ -600,6 +701,7 @@ ${routesImportLine ? `${routesImportLine}
|
|
|
600
701
|
` : ""}const coreFactory = new CoreFactory(${apiKeyPolicies.coreFactoryArg});
|
|
601
702
|
|
|
602
703
|
export const replicationHandler = coreFactory.replicationProcessor;
|
|
704
|
+
export const searchReindexHandler = coreFactory.searchReindexProcessor;
|
|
603
705
|
export const analyticsHandler = coreFactory.analyticsProcessor;
|
|
604
706
|
export const analyticsBackfillHandler = coreFactory.analyticsBackfillProcessor;
|
|
605
707
|
export const analyticsMaterializationHandler = analyticsMaterializationProcessor(analyticsManifest);
|
|
@@ -617,30 +719,30 @@ export const wsDisconnect = coreFactory.wsDisconnect;
|
|
|
617
719
|
export const wsDefault = coreFactory.wsDefault;
|
|
618
720
|
export const wsBroadcast = coreFactory.wsBroadcast;
|
|
619
721
|
`;
|
|
620
|
-
|
|
722
|
+
fs5.writeFileSync(handleOutputPath, combinedContent);
|
|
621
723
|
console.log("Successfully generated handle.ts!");
|
|
622
724
|
return handleOutputPath;
|
|
623
725
|
}
|
|
624
726
|
async function generateFiles(rootPath) {
|
|
625
|
-
const baseDir = rootPath ?
|
|
626
|
-
const configFilePathTS =
|
|
627
|
-
const configFilePathJS =
|
|
727
|
+
const baseDir = rootPath ? path5.resolve(rootPath) : process.cwd();
|
|
728
|
+
const configFilePathTS = path5.join(baseDir, "monorise.config.ts");
|
|
729
|
+
const configFilePathJS = path5.join(baseDir, "monorise.config.js");
|
|
628
730
|
let configFilePath;
|
|
629
|
-
if (
|
|
731
|
+
if (fs5.existsSync(configFilePathTS)) {
|
|
630
732
|
configFilePath = configFilePathTS;
|
|
631
|
-
} else if (
|
|
733
|
+
} else if (fs5.existsSync(configFilePathJS)) {
|
|
632
734
|
configFilePath = configFilePathJS;
|
|
633
735
|
} else {
|
|
634
736
|
throw new Error(
|
|
635
737
|
"Neither monorise.config.ts nor monorise.config.js found in the root of the project."
|
|
636
738
|
);
|
|
637
739
|
}
|
|
638
|
-
const projectRoot =
|
|
740
|
+
const projectRoot = path5.dirname(configFilePath);
|
|
639
741
|
const monoriseConfigModule = await import(configFilePath);
|
|
640
742
|
const monoriseConfig = monoriseConfigModule.default;
|
|
641
|
-
const configDir =
|
|
642
|
-
const monoriseOutputDir =
|
|
643
|
-
|
|
743
|
+
const configDir = path5.resolve(projectRoot, monoriseConfig.configDir);
|
|
744
|
+
const monoriseOutputDir = path5.join(projectRoot, ".monorise");
|
|
745
|
+
fs5.mkdirSync(monoriseOutputDir, { recursive: true });
|
|
644
746
|
const apiKeysPath = resolveApiKeysPath(
|
|
645
747
|
projectRoot,
|
|
646
748
|
monoriseConfig.apiKeys,
|
|
@@ -649,14 +751,15 @@ async function generateFiles(rootPath) {
|
|
|
649
751
|
const configOutputPath = await generateConfigFile(
|
|
650
752
|
configDir,
|
|
651
753
|
monoriseOutputDir,
|
|
652
|
-
projectRoot
|
|
754
|
+
projectRoot,
|
|
755
|
+
monoriseConfig.search
|
|
653
756
|
);
|
|
654
757
|
if (apiKeysPath) {
|
|
655
758
|
const policies = await validateApiKeyPoliciesFile(
|
|
656
759
|
apiKeysPath,
|
|
657
760
|
configOutputPath
|
|
658
761
|
);
|
|
659
|
-
|
|
762
|
+
fs5.appendFileSync(
|
|
660
763
|
configOutputPath,
|
|
661
764
|
routePermissionDeclarations(policies, [
|
|
662
765
|
detectCombinedPackage(projectRoot) ? "monorise/base" : "../base/index.js"
|
|
@@ -727,29 +830,29 @@ async function runInitCommand(rootPath) {
|
|
|
727
830
|
let projectName = "my-app";
|
|
728
831
|
let projectRoot;
|
|
729
832
|
if (rootPath) {
|
|
730
|
-
projectRoot =
|
|
731
|
-
projectName =
|
|
833
|
+
projectRoot = path5.resolve(rootPath);
|
|
834
|
+
projectName = path5.basename(projectRoot);
|
|
732
835
|
} else {
|
|
733
836
|
const args = process.argv.slice(2);
|
|
734
837
|
const nameIndex = args.indexOf("--name");
|
|
735
838
|
if (nameIndex > -1 && args[nameIndex + 1]) {
|
|
736
839
|
projectName = args[nameIndex + 1];
|
|
737
840
|
}
|
|
738
|
-
projectRoot =
|
|
841
|
+
projectRoot = path5.resolve(projectName);
|
|
739
842
|
}
|
|
740
843
|
console.log(`
|
|
741
844
|
\u{1F680} Creating Monorise project: ${projectName}
|
|
742
845
|
`);
|
|
743
|
-
if (
|
|
846
|
+
if (fs5.existsSync(projectRoot)) {
|
|
744
847
|
console.error(`Error: Directory ${projectName} already exists.`);
|
|
745
848
|
process.exit(1);
|
|
746
849
|
}
|
|
747
850
|
console.log("\u{1F4C1} Creating project structure...");
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
851
|
+
fs5.mkdirSync(projectRoot, { recursive: true });
|
|
852
|
+
fs5.mkdirSync(path5.join(projectRoot, "apps"), { recursive: true });
|
|
853
|
+
fs5.mkdirSync(path5.join(projectRoot, "services", "core"), { recursive: true });
|
|
854
|
+
fs5.mkdirSync(path5.join(projectRoot, "monorise", "configs"), { recursive: true });
|
|
855
|
+
fs5.mkdirSync(path5.join(projectRoot, "monorise", "mutuals"), { recursive: true });
|
|
753
856
|
console.log("\u{1F4E6} Initializing root package.json...");
|
|
754
857
|
const rootPackageJson = {
|
|
755
858
|
name: projectName,
|
|
@@ -758,21 +861,21 @@ async function runInitCommand(rootPath) {
|
|
|
758
861
|
private: true,
|
|
759
862
|
workspaces: ["apps/*", "services/*"]
|
|
760
863
|
};
|
|
761
|
-
|
|
762
|
-
|
|
864
|
+
fs5.writeFileSync(
|
|
865
|
+
path5.join(projectRoot, "package.json"),
|
|
763
866
|
JSON.stringify(rootPackageJson, null, 2)
|
|
764
867
|
);
|
|
765
868
|
console.log("\u2699\uFE0F Creating root tsconfig.json...");
|
|
766
|
-
|
|
767
|
-
|
|
869
|
+
fs5.writeFileSync(
|
|
870
|
+
path5.join(projectRoot, "tsconfig.json"),
|
|
768
871
|
JSON.stringify(ROOT_TSCONFIG_TEMPLATE, null, 2)
|
|
769
872
|
);
|
|
770
873
|
console.log("\n\u{1F4F1} Creating Next.js app in apps/web...");
|
|
771
|
-
const nextAppDir =
|
|
874
|
+
const nextAppDir = path5.join(projectRoot, "apps", "web");
|
|
772
875
|
try {
|
|
773
876
|
execCommand(
|
|
774
877
|
`npx create-next-app@latest web --typescript --tailwind --eslint --app --no-src-dir --import-alias "#/*" --no-turbopack --yes`,
|
|
775
|
-
|
|
878
|
+
path5.join(projectRoot, "apps")
|
|
776
879
|
);
|
|
777
880
|
} catch (error) {
|
|
778
881
|
console.error("Failed to create Next.js app:", error);
|
|
@@ -793,32 +896,32 @@ async function runInitCommand(rootPath) {
|
|
|
793
896
|
process.exit(1);
|
|
794
897
|
}
|
|
795
898
|
console.log("\u2699\uFE0F Creating monorise.config.ts...");
|
|
796
|
-
|
|
797
|
-
|
|
899
|
+
fs5.writeFileSync(
|
|
900
|
+
path5.join(projectRoot, "monorise.config.ts"),
|
|
798
901
|
readTemplate("monorise.config.ts")
|
|
799
902
|
);
|
|
800
|
-
|
|
801
|
-
|
|
903
|
+
fs5.writeFileSync(
|
|
904
|
+
path5.join(projectRoot, "monorise", "api-keys.ts"),
|
|
802
905
|
readTemplate("api-keys.ts")
|
|
803
906
|
);
|
|
804
907
|
console.log("\u{1F517} Creating team-membership mutual config...");
|
|
805
|
-
|
|
806
|
-
|
|
908
|
+
fs5.writeFileSync(
|
|
909
|
+
path5.join(projectRoot, "monorise", "mutuals", "team-membership.ts"),
|
|
807
910
|
readTemplate("team-membership.mutual.ts")
|
|
808
911
|
);
|
|
809
912
|
console.log("\u{1F464} Creating starter User entity...");
|
|
810
|
-
|
|
811
|
-
|
|
913
|
+
fs5.writeFileSync(
|
|
914
|
+
path5.join(projectRoot, "monorise", "configs", "user.ts"),
|
|
812
915
|
readTemplate("user-entity.ts")
|
|
813
916
|
);
|
|
814
917
|
console.log("\u{1F465} Creating starter Team entity...");
|
|
815
|
-
|
|
816
|
-
|
|
918
|
+
fs5.writeFileSync(
|
|
919
|
+
path5.join(projectRoot, "monorise", "configs", "team.ts"),
|
|
817
920
|
readTemplate("team-entity.ts")
|
|
818
921
|
);
|
|
819
922
|
console.log("\u{1F527} Creating services/core/routes.ts...");
|
|
820
|
-
|
|
821
|
-
|
|
923
|
+
fs5.writeFileSync(
|
|
924
|
+
path5.join(projectRoot, "services", "core", "routes.ts"),
|
|
822
925
|
readTemplate("core-routes.ts")
|
|
823
926
|
);
|
|
824
927
|
const servicesPackageJson = {
|
|
@@ -826,13 +929,13 @@ async function runInitCommand(rootPath) {
|
|
|
826
929
|
version: "0.0.0",
|
|
827
930
|
type: "module"
|
|
828
931
|
};
|
|
829
|
-
|
|
830
|
-
|
|
932
|
+
fs5.writeFileSync(
|
|
933
|
+
path5.join(projectRoot, "services", "core", "package.json"),
|
|
831
934
|
JSON.stringify(servicesPackageJson, null, 2)
|
|
832
935
|
);
|
|
833
936
|
console.log("\u2699\uFE0F Creating sst.config.ts with Monorise...");
|
|
834
|
-
const sstConfigPath =
|
|
835
|
-
|
|
937
|
+
const sstConfigPath = path5.join(projectRoot, "sst.config.ts");
|
|
938
|
+
fs5.writeFileSync(sstConfigPath, readTemplate("sst.config.ts").replace("{{PROJECT_NAME}}", projectName));
|
|
836
939
|
console.log("\n\u2601\uFE0F Installing SST providers...");
|
|
837
940
|
try {
|
|
838
941
|
execCommand("npx sst install", projectRoot);
|
|
@@ -840,63 +943,63 @@ async function runInitCommand(rootPath) {
|
|
|
840
943
|
console.warn("Warning: SST install failed, continuing anyway...");
|
|
841
944
|
}
|
|
842
945
|
console.log("\u{1F4C4} Creating example page in apps/web...");
|
|
843
|
-
const webSrcAppDir =
|
|
844
|
-
const webAppDir =
|
|
845
|
-
const pagePath =
|
|
946
|
+
const webSrcAppDir = path5.join(projectRoot, "apps", "web", "src", "app");
|
|
947
|
+
const webAppDir = path5.join(projectRoot, "apps", "web", "app");
|
|
948
|
+
const pagePath = fs5.existsSync(webSrcAppDir) ? path5.join(webSrcAppDir, "page.tsx") : fs5.existsSync(webAppDir) ? path5.join(webAppDir, "page.tsx") : null;
|
|
846
949
|
if (pagePath) {
|
|
847
950
|
try {
|
|
848
|
-
|
|
849
|
-
console.log(`Created example page at ${
|
|
951
|
+
fs5.writeFileSync(pagePath, readTemplate("example-page.tsx"));
|
|
952
|
+
console.log(`Created example page at ${path5.relative(projectRoot, pagePath)}`);
|
|
850
953
|
} catch (error) {
|
|
851
954
|
console.warn("Warning: Could not create example page:", error);
|
|
852
955
|
}
|
|
853
956
|
} else {
|
|
854
957
|
console.warn("Warning: Could not find apps/web/src/app or apps/web/app directory");
|
|
855
958
|
}
|
|
856
|
-
const webRoot =
|
|
959
|
+
const webRoot = fs5.existsSync(webSrcAppDir) ? path5.join(projectRoot, "apps", "web", "src") : fs5.existsSync(webAppDir) ? path5.join(projectRoot, "apps", "web") : null;
|
|
857
960
|
if (webRoot) {
|
|
858
|
-
const appDir =
|
|
859
|
-
|
|
860
|
-
|
|
961
|
+
const appDir = fs5.existsSync(webSrcAppDir) ? webSrcAppDir : webAppDir;
|
|
962
|
+
fs5.mkdirSync(path5.join(webRoot, "components", "ui"), { recursive: true });
|
|
963
|
+
fs5.mkdirSync(path5.join(webRoot, "lib"), { recursive: true });
|
|
861
964
|
console.log("\u{1F310} Creating global components...");
|
|
862
|
-
|
|
863
|
-
|
|
965
|
+
fs5.writeFileSync(
|
|
966
|
+
path5.join(webRoot, "components", "global-initializer.tsx"),
|
|
864
967
|
readTemplate("global-initializer.tsx")
|
|
865
968
|
);
|
|
866
|
-
|
|
867
|
-
|
|
969
|
+
fs5.writeFileSync(
|
|
970
|
+
path5.join(webRoot, "components", "global-loader.tsx"),
|
|
868
971
|
readTemplate("global-loader.tsx")
|
|
869
972
|
);
|
|
870
973
|
console.log("\u{1F527} Creating lib/utils.ts...");
|
|
871
|
-
|
|
872
|
-
|
|
974
|
+
fs5.writeFileSync(
|
|
975
|
+
path5.join(webRoot, "lib", "utils.ts"),
|
|
873
976
|
readTemplate("lib-utils.ts")
|
|
874
977
|
);
|
|
875
978
|
console.log("\u{1F3A8} Creating shadcn UI components...");
|
|
876
|
-
|
|
877
|
-
|
|
979
|
+
fs5.writeFileSync(
|
|
980
|
+
path5.join(webRoot, "components", "ui", "button.tsx"),
|
|
878
981
|
readTemplate("ui-button.tsx")
|
|
879
982
|
);
|
|
880
|
-
|
|
881
|
-
|
|
983
|
+
fs5.writeFileSync(
|
|
984
|
+
path5.join(webRoot, "components", "ui", "card.tsx"),
|
|
882
985
|
readTemplate("ui-card.tsx")
|
|
883
986
|
);
|
|
884
|
-
|
|
885
|
-
|
|
987
|
+
fs5.writeFileSync(
|
|
988
|
+
path5.join(webRoot, "components", "ui", "input.tsx"),
|
|
886
989
|
readTemplate("ui-input.tsx")
|
|
887
990
|
);
|
|
888
|
-
|
|
889
|
-
|
|
991
|
+
fs5.writeFileSync(
|
|
992
|
+
path5.join(webRoot, "components", "ui", "label.tsx"),
|
|
890
993
|
readTemplate("ui-label.tsx")
|
|
891
994
|
);
|
|
892
995
|
console.log("\u{1F3A8} Setting up shadcn globals.css...");
|
|
893
|
-
const globalsCssPath =
|
|
894
|
-
|
|
996
|
+
const globalsCssPath = path5.join(appDir, "globals.css");
|
|
997
|
+
fs5.writeFileSync(globalsCssPath, readTemplate("globals.css"));
|
|
895
998
|
console.log("\u{1F4D0} Updating layout.tsx with global components...");
|
|
896
|
-
const layoutPath =
|
|
897
|
-
if (
|
|
999
|
+
const layoutPath = path5.join(appDir, "layout.tsx");
|
|
1000
|
+
if (fs5.existsSync(layoutPath)) {
|
|
898
1001
|
try {
|
|
899
|
-
let layoutContent =
|
|
1002
|
+
let layoutContent = fs5.readFileSync(layoutPath, "utf8");
|
|
900
1003
|
const globalImports = `import GlobalInitializer from '#/components/global-initializer';
|
|
901
1004
|
import GlobalLoader from '#/components/global-loader';`;
|
|
902
1005
|
const lastImportIndex = layoutContent.lastIndexOf("import ");
|
|
@@ -909,14 +1012,14 @@ import GlobalLoader from '#/components/global-loader';`;
|
|
|
909
1012
|
<GlobalInitializer />
|
|
910
1013
|
<GlobalLoader />`
|
|
911
1014
|
);
|
|
912
|
-
|
|
1015
|
+
fs5.writeFileSync(layoutPath, layoutContent);
|
|
913
1016
|
} catch (error) {
|
|
914
1017
|
console.warn("Warning: Could not update layout.tsx:", error);
|
|
915
1018
|
}
|
|
916
1019
|
}
|
|
917
|
-
const postcssPath =
|
|
918
|
-
if (
|
|
919
|
-
|
|
1020
|
+
const postcssPath = path5.join(projectRoot, "apps", "web", "postcss.config.mjs");
|
|
1021
|
+
if (fs5.existsSync(postcssPath)) {
|
|
1022
|
+
fs5.writeFileSync(
|
|
920
1023
|
postcssPath,
|
|
921
1024
|
`const config = {
|
|
922
1025
|
plugins: {
|
|
@@ -929,31 +1032,31 @@ export default config;
|
|
|
929
1032
|
);
|
|
930
1033
|
}
|
|
931
1034
|
console.log("\u{1F500} Creating API proxy routes...");
|
|
932
|
-
const coreApiDir =
|
|
933
|
-
const proxyDir =
|
|
934
|
-
const ticketDir =
|
|
1035
|
+
const coreApiDir = path5.join(appDir, "api", "core");
|
|
1036
|
+
const proxyDir = path5.join(coreApiDir, "[...path]");
|
|
1037
|
+
const ticketDir = path5.join(
|
|
935
1038
|
coreApiDir,
|
|
936
1039
|
"ws",
|
|
937
1040
|
"ticket",
|
|
938
1041
|
"[entityType]",
|
|
939
1042
|
"[entityId]"
|
|
940
1043
|
);
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
1044
|
+
fs5.mkdirSync(proxyDir, { recursive: true });
|
|
1045
|
+
fs5.mkdirSync(ticketDir, { recursive: true });
|
|
1046
|
+
fs5.writeFileSync(
|
|
1047
|
+
path5.join(proxyDir, "route.ts"),
|
|
945
1048
|
readTemplate("proxy-route.ts")
|
|
946
1049
|
);
|
|
947
|
-
|
|
948
|
-
|
|
1050
|
+
fs5.writeFileSync(
|
|
1051
|
+
path5.join(ticketDir, "route.ts"),
|
|
949
1052
|
readTemplate("ws-ticket-route.ts")
|
|
950
1053
|
);
|
|
951
1054
|
}
|
|
952
1055
|
console.log("\u2699\uFE0F Updating apps/web tsconfig.json...");
|
|
953
|
-
const webTsconfigPath =
|
|
954
|
-
if (
|
|
1056
|
+
const webTsconfigPath = path5.join(projectRoot, "apps", "web", "tsconfig.json");
|
|
1057
|
+
if (fs5.existsSync(webTsconfigPath)) {
|
|
955
1058
|
try {
|
|
956
|
-
const webTsconfigContent =
|
|
1059
|
+
const webTsconfigContent = fs5.readFileSync(webTsconfigPath, "utf8");
|
|
957
1060
|
const webTsconfig = JSON.parse(webTsconfigContent);
|
|
958
1061
|
if (!webTsconfig.compilerOptions) {
|
|
959
1062
|
webTsconfig.compilerOptions = {};
|
|
@@ -963,10 +1066,10 @@ export default config;
|
|
|
963
1066
|
}
|
|
964
1067
|
webTsconfig.compilerOptions.paths["#/shared/*"] = ["../../shared/*"];
|
|
965
1068
|
webTsconfig.compilerOptions.paths["#/monorise/*"] = ["../../.monorise/*"];
|
|
966
|
-
webTsconfig.compilerOptions.paths["#/monorise"] = ["../../.monorise/
|
|
967
|
-
const hasSrcDir =
|
|
1069
|
+
webTsconfig.compilerOptions.paths["#/monorise"] = ["../../.monorise/config"];
|
|
1070
|
+
const hasSrcDir = fs5.existsSync(path5.join(projectRoot, "apps", "web", "src"));
|
|
968
1071
|
webTsconfig.compilerOptions.paths["#/*"] = [hasSrcDir ? "./src/*" : "./*"];
|
|
969
|
-
|
|
1072
|
+
fs5.writeFileSync(webTsconfigPath, JSON.stringify(webTsconfig, null, 2));
|
|
970
1073
|
} catch (error) {
|
|
971
1074
|
console.warn("Warning: Could not update apps/web tsconfig.json:", error);
|
|
972
1075
|
}
|
|
@@ -993,7 +1096,7 @@ export default config;
|
|
|
993
1096
|
console.log(` \u2022 Edit your data model \u2192 monorise/configs/user.ts`);
|
|
994
1097
|
console.log(` (Add fields like phone, role, status to the User entity)`);
|
|
995
1098
|
console.log(
|
|
996
|
-
` \u2022 Build your UI \u2192 ${pagePath ?
|
|
1099
|
+
` \u2022 Build your UI \u2192 ${pagePath ? path5.relative(projectRoot, pagePath) : "apps/web/app/page.tsx"}`
|
|
997
1100
|
);
|
|
998
1101
|
console.log(` (React components using useEntities and createEntity)`);
|
|
999
1102
|
console.log(` \u2022 Add backend logic \u2192 services/core/routes.ts`);
|
|
@@ -1015,7 +1118,7 @@ async function runDevCommand({ configDir, apiKeysFile: apiKeysFile2 }, rootPath)
|
|
|
1015
1118
|
const watched = apiKeysFile2 ? [configDir, apiKeysFile2] : configDir;
|
|
1016
1119
|
const watcher = chokidar.watch(watched, {
|
|
1017
1120
|
ignored: (watchedPath) => {
|
|
1018
|
-
const fileName =
|
|
1121
|
+
const fileName = path5.basename(watchedPath);
|
|
1019
1122
|
return fileName === "index.ts" || // Old name, still ignore in case it exists
|
|
1020
1123
|
fileName === "config.ts" || // Generated config file
|
|
1021
1124
|
fileName === "processors.ts" || // Generated processors file
|