soma-core 1.0.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.
Files changed (78) hide show
  1. package/app/api/page/route.ts +97 -0
  2. package/app/globals.css +3 -0
  3. package/app/layout.tsx +18 -0
  4. package/app/page.tsx +129 -0
  5. package/bin/soma.cjs +2 -0
  6. package/core/base/SomaApi.ts +14 -0
  7. package/core/base/SomaDict.ts +168 -0
  8. package/core/base/SomaEntity.ts +41 -0
  9. package/core/base/SomaHttpClient.ts +126 -0
  10. package/core/base/SomaLocaleOnlyPageRoot.ts +4 -0
  11. package/core/base/SomaPageRootBase.ts +54 -0
  12. package/core/base/SomaValidator.ts +147 -0
  13. package/core/base/index.ts +7 -0
  14. package/core/compiler/full-manifest-builder.ts +43 -0
  15. package/core/compiler/manifest-compiler.ts +237 -0
  16. package/core/compiler/route-builder.ts +31 -0
  17. package/core/compiler/soma-precompile.ts +48 -0
  18. package/core/compiler/soma-webpack-loader.js +35 -0
  19. package/core/compiler/vite-plugin-soma.ts +73 -0
  20. package/core/container/SomaContainerAdapter.ts +169 -0
  21. package/core/diagnostics/SomaDiagnostics.ts +186 -0
  22. package/core/engine/asset-resolver.ts +67 -0
  23. package/core/engine/dom-renderer.ts +366 -0
  24. package/core/engine/event-engine.ts +287 -0
  25. package/core/engine/lis.ts +60 -0
  26. package/core/engine/reactive-proxy.ts +225 -0
  27. package/core/engine/render-engine.ts +264 -0
  28. package/core/engine/runtime-builder.ts +100 -0
  29. package/core/engine/scope-resolver.ts +252 -0
  30. package/core/engine/soma-bootstrap.ts +244 -0
  31. package/core/index.ts +6 -0
  32. package/core/infra/auth/IAuthService.ts +13 -0
  33. package/core/infra/auth/TokenAuthService.ts +98 -0
  34. package/core/infra/cache/ICache.ts +13 -0
  35. package/core/infra/cache/MemoryCache.ts +95 -0
  36. package/core/infra/cache/ServerFileCache.ts +123 -0
  37. package/core/infra/config/IConfig.ts +9 -0
  38. package/core/infra/config/SomaConfig.ts +85 -0
  39. package/core/infra/event-bus/IEventBus.ts +9 -0
  40. package/core/infra/event-bus/SomaEventBus.ts +53 -0
  41. package/core/infra/http/IHttpClient.ts +21 -0
  42. package/core/infra/http/SomaHttpService.ts +141 -0
  43. package/core/infra/i18n/DefaultI18n.ts +41 -0
  44. package/core/infra/i18n/II18n.ts +7 -0
  45. package/core/infra/logger/ConsoleLogger.ts +81 -0
  46. package/core/infra/logger/ILogger.ts +19 -0
  47. package/core/infra/notify/DefaultNotifyService.ts +31 -0
  48. package/core/infra/notify/INotifyService.ts +14 -0
  49. package/core/infra/permission/IPermission.ts +10 -0
  50. package/core/infra/permission/SomaPermission.ts +48 -0
  51. package/core/infra/router/IRouter.ts +19 -0
  52. package/core/infra/router/SomaRouter.ts +66 -0
  53. package/core/infra/storage/IStorageService.ts +7 -0
  54. package/core/infra/storage/MemoryStorageService.ts +53 -0
  55. package/core/infra/timer/ITimer.ts +9 -0
  56. package/core/infra/timer/SomaTimer.ts +118 -0
  57. package/core/middleware/SomaMiddlewareChain.ts +29 -0
  58. package/core/parser/pipeline-parser.ts +276 -0
  59. package/core/parser/ui-config-parser.ts +336 -0
  60. package/core/parser/yaml-loader.ts +36 -0
  61. package/core/router/RouteHandler.ts +93 -0
  62. package/core/runtime/SomaSnapshotStore.ts +98 -0
  63. package/core/scheduler/SomaScheduler.ts +190 -0
  64. package/core/types/domain.types.ts +88 -0
  65. package/core/types/engine.types.ts +35 -0
  66. package/core/types/event.types.ts +57 -0
  67. package/core/types/keyboard.types.ts +18 -0
  68. package/core/types/manifest.types.ts +30 -0
  69. package/core/types/scheduler.types.ts +10 -0
  70. package/core/types/ui-config.types.ts +89 -0
  71. package/core/validation/contract-validator.ts +465 -0
  72. package/dist/cli/soma.js +49 -0
  73. package/global.d.ts +14 -0
  74. package/next.config.js +61 -0
  75. package/package.json +77 -0
  76. package/postcss.config.js +6 -0
  77. package/tailwind.config.ts +21 -0
  78. package/tsconfig.json +35 -0
@@ -0,0 +1,465 @@
1
+ import type { SomaScopeResolver } from '../engine/scope-resolver';
2
+ import type { ParsedEvent } from '../types/event.types';
3
+ import type {
4
+ ExtendedShowValue,
5
+ NestedShowMapping,
6
+ ShowMapping,
7
+ UiConfig,
8
+ } from '../types/ui-config.types';
9
+ import type { SomaDiagnostics } from '../diagnostics/SomaDiagnostics';
10
+
11
+ export interface SomaContractValidationInput {
12
+ container: HTMLElement;
13
+ uiConfig: UiConfig;
14
+ eventConfig: ParsedEvent[];
15
+ resolver: SomaScopeResolver;
16
+ rootInstance: object;
17
+ }
18
+
19
+ export interface SomaContractReport {
20
+ errors: string[];
21
+ warnings: string[];
22
+ anchorIds: string[];
23
+ bindingCount: number;
24
+ eventCount: number;
25
+ }
26
+
27
+ export class SomaContractError extends Error {
28
+ readonly report: SomaContractReport;
29
+
30
+ constructor(report: SomaContractReport) {
31
+ const summary = report.errors[0] ?? 'SOMA contract validation failed';
32
+ super(`[SOMA Contract] ${summary}`);
33
+ this.name = 'SomaContractError';
34
+ this.report = report;
35
+ }
36
+ }
37
+
38
+ export class SomaContractValidator {
39
+ private diagnostics: SomaDiagnostics | null;
40
+
41
+ constructor(diagnostics?: SomaDiagnostics) {
42
+ this.diagnostics = diagnostics ?? null;
43
+ }
44
+
45
+ validate(input: SomaContractValidationInput): SomaContractReport {
46
+ const hostCount = input.container.querySelectorAll('[data-soma-host]').length;
47
+ const { anchors, duplicates } = this.collectAnchorStats(input.container);
48
+ const report: SomaContractReport = {
49
+ errors: [],
50
+ warnings: [],
51
+ anchorIds: [...anchors].sort(),
52
+ bindingCount: 0,
53
+ eventCount: input.eventConfig.length,
54
+ };
55
+
56
+ if (hostCount === 0) {
57
+ this.addError(report, 'container: 缺少 data-soma-host 边界');
58
+ } else if (hostCount > 1) {
59
+ this.addWarning(report, `container: 检测到 ${hostCount} 个 data-soma-host,建议每页仅保留一个宿主边界`);
60
+ }
61
+
62
+ for (const [somaId, count] of duplicates.entries()) {
63
+ this.addError(report, `anchor.${somaId}: 检测到 ${count} 个重复的静态 data-soma-id,绑定会产生歧义`);
64
+ }
65
+
66
+ this.validateShowMapping(
67
+ input.uiConfig.show,
68
+ anchors,
69
+ input.resolver,
70
+ input.rootInstance,
71
+ report,
72
+ 'show',
73
+ );
74
+ this.validateEvents(
75
+ input.eventConfig,
76
+ anchors,
77
+ input.resolver,
78
+ input.rootInstance,
79
+ report,
80
+ );
81
+
82
+ if (report.errors.length > 0) {
83
+ throw new SomaContractError(report);
84
+ }
85
+
86
+ return report;
87
+ }
88
+
89
+ private collectAnchorStats(container: HTMLElement): {
90
+ anchors: Set<string>;
91
+ duplicates: Map<string, number>;
92
+ } {
93
+ const anchors = new Set<string>();
94
+ const counts = new Map<string, number>();
95
+
96
+ const scanNode = (root: HTMLElement | DocumentFragment) => {
97
+ root.querySelectorAll<HTMLElement>('[data-soma-id]').forEach((element) => {
98
+ const somaId = element.getAttribute('data-soma-id');
99
+ if (somaId) {
100
+ anchors.add(somaId);
101
+ counts.set(somaId, (counts.get(somaId) ?? 0) + 1);
102
+ }
103
+ });
104
+ // Also scan inside <template> elements whose content lives in a DocumentFragment
105
+ root.querySelectorAll<HTMLTemplateElement>('template[data-soma-role]').forEach((tmpl) => {
106
+ if (tmpl.content) {
107
+ scanNode(tmpl.content);
108
+ }
109
+ });
110
+ };
111
+
112
+ scanNode(container);
113
+
114
+ const duplicates = new Map<string, number>();
115
+ for (const [somaId, count] of counts.entries()) {
116
+ if (count > 1) {
117
+ duplicates.set(somaId, count);
118
+ }
119
+ }
120
+
121
+ return { anchors, duplicates };
122
+ }
123
+
124
+ private validateShowMapping(
125
+ show: ShowMapping,
126
+ anchors: Set<string>,
127
+ resolver: SomaScopeResolver,
128
+ rootInstance: object,
129
+ report: SomaContractReport,
130
+ basePath: string,
131
+ ): void {
132
+ for (const [rawKey, value] of Object.entries(show)) {
133
+ report.bindingCount += 1;
134
+ const currentPath = `${basePath}.${rawKey}`;
135
+ const somaId = this.extractSomaId(rawKey);
136
+
137
+ if (!anchors.has(somaId)) {
138
+ this.addError(report, `${currentPath}: 缺少 data-soma-id="${somaId}"`);
139
+ }
140
+
141
+ if (typeof value === 'string') {
142
+ this.validateReadablePath(value, currentPath, resolver, rootInstance, report);
143
+ continue;
144
+ }
145
+
146
+ if (this.isNestedShowMapping(value)) {
147
+ this.validateReadablePath(
148
+ value.bind.obj,
149
+ `${currentPath}.bind.obj`,
150
+ resolver,
151
+ rootInstance,
152
+ report,
153
+ );
154
+ this.validateShowMapping(
155
+ value.show,
156
+ anchors,
157
+ resolver,
158
+ rootInstance,
159
+ report,
160
+ `${currentPath}.show`,
161
+ );
162
+ continue;
163
+ }
164
+
165
+ if (this.isExtendedShowValue(value)) {
166
+ if (value.text) {
167
+ this.validateReadablePath(
168
+ value.text,
169
+ `${currentPath}.text`,
170
+ resolver,
171
+ rootInstance,
172
+ report,
173
+ );
174
+ }
175
+ if (value.model) {
176
+ this.validateReadablePath(
177
+ value.model,
178
+ `${currentPath}.model`,
179
+ resolver,
180
+ rootInstance,
181
+ report,
182
+ );
183
+ }
184
+ if (value.when) {
185
+ this.validateReadablePath(
186
+ value.when,
187
+ `${currentPath}.when`,
188
+ resolver,
189
+ rootInstance,
190
+ report,
191
+ );
192
+ }
193
+ if (value.class) {
194
+ for (const [className, expr] of Object.entries(value.class)) {
195
+ this.validateReadablePath(
196
+ expr,
197
+ `${currentPath}.class.${className}`,
198
+ resolver,
199
+ rootInstance,
200
+ report,
201
+ );
202
+ }
203
+ }
204
+ if (value.show) {
205
+ this.validateShowMapping(
206
+ value.show,
207
+ anchors,
208
+ resolver,
209
+ rootInstance,
210
+ report,
211
+ `${currentPath}.show`,
212
+ );
213
+ }
214
+ }
215
+ }
216
+ }
217
+
218
+ private validateEvents(
219
+ events: ParsedEvent[],
220
+ anchors: Set<string>,
221
+ resolver: SomaScopeResolver,
222
+ rootInstance: object,
223
+ report: SomaContractReport,
224
+ ): void {
225
+ const eventKeys = new Set<string>();
226
+
227
+ for (const event of events) {
228
+ const eventKey = `${event.domEvent}:${event.somaId}`;
229
+ if (eventKeys.has(eventKey)) {
230
+ this.addError(report, `event.${eventKey}: 重复声明的事件绑定`);
231
+ } else {
232
+ eventKeys.add(eventKey);
233
+ }
234
+
235
+ if (!anchors.has(event.somaId)) {
236
+ this.addError(report, `event.${eventKey}: 缺少事件源 data-soma-id="${event.somaId}"`);
237
+ }
238
+
239
+ if (event.targetId && event.targetId !== 'self' && !anchors.has(event.targetId)) {
240
+ this.addError(
241
+ report,
242
+ `event.${eventKey}: 缺少交互目标 data-soma-id="${event.targetId}"`,
243
+ );
244
+ }
245
+
246
+ if (event.funcPath) {
247
+ this.validateFunctionPath(
248
+ event.funcPath,
249
+ `event.${eventKey}.funcPath`,
250
+ resolver,
251
+ rootInstance,
252
+ report,
253
+ );
254
+ }
255
+ }
256
+ }
257
+
258
+ private validateReadablePath(
259
+ rawPath: string,
260
+ location: string,
261
+ resolver: SomaScopeResolver,
262
+ rootInstance: object,
263
+ report: SomaContractReport,
264
+ ): void {
265
+ let path = rawPath.trim();
266
+ if (!path) {
267
+ this.addError(report, `${location}: 绑定路径不能为空`);
268
+ return;
269
+ }
270
+
271
+ if (path.startsWith('!')) {
272
+ path = path.slice(1);
273
+ }
274
+
275
+ const segments = path.split('.').filter(Boolean);
276
+ if (segments.length === 0) {
277
+ this.addError(report, `${location}: 绑定路径不能为空`);
278
+ return;
279
+ }
280
+
281
+ const rootToken = segments[0];
282
+
283
+ if (resolver.hasVar(rootToken)) {
284
+ const varPath = resolver.getVarPath(rootToken);
285
+ if (varPath === '') {
286
+ this.validateSegments(rootInstance, segments.slice(1), location, report);
287
+ }
288
+ return;
289
+ }
290
+
291
+ this.validateSegments(rootInstance, segments, location, report);
292
+ }
293
+
294
+ private validateFunctionPath(
295
+ funcPath: string,
296
+ location: string,
297
+ resolver: SomaScopeResolver,
298
+ rootInstance: object,
299
+ report: SomaContractReport,
300
+ ): void {
301
+ const segments = funcPath.split('.').filter(Boolean);
302
+ if (segments.length < 2) {
303
+ this.addError(report, `${location}: 函数路径至少需要 "对象.方法" 两段`);
304
+ return;
305
+ }
306
+
307
+ const rootToken = segments[0];
308
+ if (resolver.hasVar(rootToken)) {
309
+ const varPath = resolver.getVarPath(rootToken);
310
+ if (varPath === '') {
311
+ try {
312
+ resolver.resolveFunction(funcPath);
313
+ } catch (error) {
314
+ const message = error instanceof Error ? error.message : String(error);
315
+ this.addError(report, `${location}: ${message}`);
316
+ }
317
+ return;
318
+ }
319
+
320
+ const sample = this.resolveAliasSample(rootToken, resolver, rootInstance);
321
+ if (sample === undefined) {
322
+ this.addWarning(
323
+ report,
324
+ `${location}: 别名 "${rootToken}" 当前缺少可验证样本,延迟到运行时校验`,
325
+ );
326
+ return;
327
+ }
328
+
329
+ this.validateFunctionOnTarget(sample, segments.slice(1), location, report, funcPath);
330
+ return;
331
+ }
332
+
333
+ try {
334
+ resolver.resolveFunction(funcPath);
335
+ } catch (error) {
336
+ const message = error instanceof Error ? error.message : String(error);
337
+ this.addError(report, `${location}: ${message}`);
338
+ }
339
+ }
340
+
341
+ private validateSegments(
342
+ rootInstance: object,
343
+ segments: string[],
344
+ location: string,
345
+ report: SomaContractReport,
346
+ ): void {
347
+ if (segments.length === 0) {
348
+ return;
349
+ }
350
+
351
+ let current: any = rootInstance;
352
+ for (let index = 0; index < segments.length; index++) {
353
+ const segment = segments[index];
354
+
355
+ if (current == null) {
356
+ this.addWarning(
357
+ report,
358
+ `${location}: 在 "${segments.slice(0, index).join('.')}" 处遇到空值,延迟到运行时校验`,
359
+ );
360
+ return;
361
+ }
362
+
363
+ if (Array.isArray(current)) {
364
+ this.addWarning(
365
+ report,
366
+ `${location}: "${segments.slice(0, index).join('.')}" 是集合,元素字段延迟到运行时校验`,
367
+ );
368
+ return;
369
+ }
370
+
371
+ if (!(segment in Object(current))) {
372
+ const message = `${location}: 路径 "${segments.slice(0, index + 1).join('.')}" 不存在`;
373
+ if (index === 0) {
374
+ this.addError(report, message);
375
+ } else {
376
+ this.addWarning(report, message);
377
+ }
378
+ return;
379
+ }
380
+
381
+ current = current[segment];
382
+ }
383
+ }
384
+
385
+ private validateFunctionOnTarget(
386
+ target: any,
387
+ segments: string[],
388
+ location: string,
389
+ report: SomaContractReport,
390
+ funcPath: string,
391
+ ): void {
392
+ let current = target;
393
+
394
+ for (let index = 0; index < segments.length; index++) {
395
+ if (current == null) {
396
+ this.addWarning(report, `${location}: "${funcPath}" 在运行时可能为空对象`);
397
+ return;
398
+ }
399
+
400
+ if (Array.isArray(current)) {
401
+ if (current.length === 0) {
402
+ this.addWarning(report, `${location}: "${funcPath}" 对应集合为空,延迟到运行时校验`);
403
+ return;
404
+ }
405
+ current = current[0];
406
+ }
407
+
408
+ const segment = segments[index];
409
+ if (!(segment in Object(current))) {
410
+ this.addError(
411
+ report,
412
+ `${location}: 函数路径 "${funcPath}" 缺少属性 "${segment}"`,
413
+ );
414
+ return;
415
+ }
416
+
417
+ const next = current[segment];
418
+ if (index === segments.length - 1 && typeof next !== 'function') {
419
+ this.addError(report, `${location}: "${funcPath}" 不是可调用函数`);
420
+ return;
421
+ }
422
+
423
+ current = next;
424
+ }
425
+ }
426
+
427
+ private resolveAliasSample(
428
+ alias: string,
429
+ resolver: SomaScopeResolver,
430
+ rootInstance: object,
431
+ ): any {
432
+ const varPath = resolver.getVarPath(alias);
433
+ if (varPath === undefined) return undefined;
434
+ if (!varPath) return rootInstance;
435
+
436
+ const resolved = resolver.readFromRoot(varPath);
437
+ if (Array.isArray(resolved)) {
438
+ return resolved[0];
439
+ }
440
+ return resolved;
441
+ }
442
+
443
+ private extractSomaId(rawKey: string): string {
444
+ const [somaId] = rawKey.split('@');
445
+ return somaId;
446
+ }
447
+
448
+ private isNestedShowMapping(value: unknown): value is NestedShowMapping {
449
+ return typeof value === 'object' && value !== null && 'bind' in value && 'show' in value;
450
+ }
451
+
452
+ private isExtendedShowValue(value: unknown): value is ExtendedShowValue {
453
+ return typeof value === 'object' && value !== null;
454
+ }
455
+
456
+ private addError(report: SomaContractReport, message: string): void {
457
+ report.errors.push(message);
458
+ this.diagnostics?.recordValidation('error', message);
459
+ }
460
+
461
+ private addWarning(report: SomaContractReport, message: string): void {
462
+ report.warnings.push(message);
463
+ this.diagnostics?.recordValidation('warning', message);
464
+ }
465
+ }
@@ -0,0 +1,49 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ const node_child_process_1 = require("node:child_process");
8
+ const node_path_1 = __importDefault(require("node:path"));
9
+ const args = process.argv.slice(2);
10
+ const command = args[0] || 'dev';
11
+ const allowed = ['dev', 'build', 'start'];
12
+ if (!allowed.includes(command)) {
13
+ console.error(`Usage: soma <${allowed.join('|')}> [...next-args]`);
14
+ process.exit(1);
15
+ }
16
+ /** 编译后为 dist/cli/soma.js → 向上两级回到包根(含 core/、package.json) */
17
+ const packageRoot = node_path_1.default.resolve(__dirname, '..', '..');
18
+ function resolveNextBin() {
19
+ try {
20
+ return require.resolve('next/dist/bin/next', { paths: [packageRoot] });
21
+ }
22
+ catch {
23
+ try {
24
+ return require.resolve('next/dist/bin/next', {
25
+ paths: [node_path_1.default.join(packageRoot, '..')],
26
+ });
27
+ }
28
+ catch {
29
+ return null;
30
+ }
31
+ }
32
+ }
33
+ const nextBin = resolveNextBin();
34
+ if (!nextBin) {
35
+ console.error('[soma] 找不到 next,请在 soma-core 包内安装依赖。');
36
+ process.exit(1);
37
+ }
38
+ /** 在宿主根执行 CLI;子进程仅注入 SOMA_HOST_DIR */
39
+ const hostDir = node_path_1.default.resolve(process.cwd());
40
+ const nextArgs = [nextBin, command, ...args.slice(1)];
41
+ const child = (0, node_child_process_1.spawnSync)(process.execPath, nextArgs, {
42
+ cwd: packageRoot,
43
+ stdio: 'inherit',
44
+ env: {
45
+ ...process.env,
46
+ SOMA_HOST_DIR: hostDir,
47
+ },
48
+ });
49
+ process.exit(child.status === null ? 1 : child.status);
package/global.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ declare module '*.html' {
2
+ const content: string;
3
+ export default content;
4
+ }
5
+
6
+ declare module '*.yaml' {
7
+ const content: string;
8
+ export default content;
9
+ }
10
+
11
+ declare module '*.yml' {
12
+ const content: string;
13
+ export default content;
14
+ }
package/next.config.js ADDED
@@ -0,0 +1,61 @@
1
+ /** @type {import('next').NextConfig} */
2
+ const path = require('path');
3
+
4
+ const rawHostDir = process.env.SOMA_HOST_DIR;
5
+ if (!rawHostDir || !String(rawHostDir).trim()) {
6
+ throw new Error(
7
+ '[soma-core] 请设置 SOMA_HOST_DIR(宿主应用根)。通过 `npx soma` 或由 npm scripts 写入。',
8
+ );
9
+ }
10
+ const hostDir = path.resolve(rawHostDir);
11
+
12
+ const nextConfig = {
13
+ experimental: {
14
+ externalDir: true,
15
+ },
16
+
17
+ webpack: (config) => {
18
+ config.resolve.alias['@core'] = path.resolve(__dirname, 'core');
19
+ config.resolve.alias['@soma-host'] = hostDir;
20
+
21
+ config.module.rules.push(
22
+ {
23
+ test: /_(ui|event)\.ya?ml$/,
24
+ type: 'javascript/auto',
25
+ use: [
26
+ { loader: path.resolve(__dirname, 'core/compiler/soma-webpack-loader.js') },
27
+ ],
28
+ },
29
+ {
30
+ test: /\.(config|locale)\.ya?ml$/,
31
+ type: 'javascript/auto',
32
+ use: [
33
+ { loader: path.resolve(__dirname, 'core/compiler/soma-webpack-loader.js') },
34
+ ],
35
+ },
36
+ { test: /\.html$/, type: 'asset/source' },
37
+ {
38
+ test: /\.ya?ml$/,
39
+ exclude: /_(ui|event)\.ya?ml$|\.(config|locale)\.ya?ml$/,
40
+ type: 'asset/source',
41
+ },
42
+ { test: /\.md$/, type: 'asset/source' },
43
+ );
44
+ return config;
45
+ },
46
+
47
+ async rewrites() {
48
+ return [
49
+ {
50
+ source: '/:path*.html',
51
+ destination: '/',
52
+ },
53
+ {
54
+ source: '/:path((?!api|_next|favicon\\.ico)(?![^/]*\\.[a-zA-Z0-9]+$).*)',
55
+ destination: '/',
56
+ },
57
+ ];
58
+ },
59
+ };
60
+
61
+ module.exports = nextConfig;
package/package.json ADDED
@@ -0,0 +1,77 @@
1
+ {
2
+ "name": "soma-core",
3
+ "version": "1.0.0",
4
+ "description": "SOMA — Semantic Oriented Modular Architecture. A declarative frontend framework runtime built on Next.js 14+ App Router.",
5
+ "keywords": ["soma", "declarative-ui", "nextjs", "framework", "modular-architecture"],
6
+ "license": "MIT",
7
+ "author": "ivan <228268157@qq.com>",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+http://43.163.120.58:3000/ivan/soma.git",
11
+ "directory": "soma-core"
12
+ },
13
+ "main": "./core/index.ts",
14
+ "types": "./core/index.ts",
15
+ "bin": {
16
+ "soma": "bin/soma.cjs"
17
+ },
18
+ "exports": {
19
+ ".": "./core/index.ts",
20
+ "./base": "./core/base/index.ts"
21
+ },
22
+ "files": [
23
+ "bin/soma.cjs",
24
+ "core/",
25
+ "app/",
26
+ "dist/",
27
+ "next.config.js",
28
+ "tailwind.config.ts",
29
+ "postcss.config.js",
30
+ "tsconfig.json",
31
+ "global.d.ts"
32
+ ],
33
+ "engines": {
34
+ "node": ">=18.0.0"
35
+ },
36
+ "scripts": {
37
+ "build:cli": "tsc -p tsconfig.cli.json",
38
+ "dev": "cross-env SOMA_HOST_DIR=../app-demo next dev",
39
+ "build": "cross-env SOMA_HOST_DIR=../app-demo next build",
40
+ "start": "cross-env SOMA_HOST_DIR=../app-demo next start",
41
+ "lint": "next lint",
42
+ "test": "cross-env SOMA_HOST_DIR=../app-demo vitest run",
43
+ "test:watch": "cross-env SOMA_HOST_DIR=../app-demo vitest",
44
+ "typecheck": "tsc --noEmit",
45
+ "prepublishOnly": "npm run build:cli"
46
+ },
47
+ "dependencies": {
48
+ "dompurify": "^3.0.9",
49
+ "js-yaml": "^4.1.0",
50
+ "reflect-metadata": "^0.2.1"
51
+ },
52
+ "peerDependencies": {
53
+ "next": ">=14.0.0",
54
+ "react": ">=18.0.0",
55
+ "react-dom": ">=18.0.0"
56
+ },
57
+ "devDependencies": {
58
+ "@playwright/test": "^1.59.1",
59
+ "@types/dompurify": "^3.0.5",
60
+ "@types/js-yaml": "^4.0.9",
61
+ "@types/node": "^20.11.0",
62
+ "@types/react": "^18.3.0",
63
+ "@types/react-dom": "^18.3.0",
64
+ "@vitest/coverage-v8": "^3.2.4",
65
+ "autoprefixer": "^10.4.17",
66
+ "cross-env": "^7.0.3",
67
+ "jsdom": "^26.1.0",
68
+ "next": "^14.2.0",
69
+ "playwright": "^1.59.1",
70
+ "postcss": "^8.4.33",
71
+ "react": "^18.3.0",
72
+ "react-dom": "^18.3.0",
73
+ "tailwindcss": "^3.4.1",
74
+ "typescript": "^5.3.3",
75
+ "vitest": "^3.2.4"
76
+ }
77
+ }
@@ -0,0 +1,6 @@
1
+ module.exports = {
2
+ plugins: {
3
+ tailwindcss: {},
4
+ autoprefixer: {},
5
+ },
6
+ };
@@ -0,0 +1,21 @@
1
+ import type { Config } from 'tailwindcss';
2
+ import path from 'path';
3
+
4
+ if (!process.env.SOMA_HOST_DIR) {
5
+ throw new Error('[soma-core] tailwind: SOMA_HOST_DIR 未设置');
6
+ }
7
+ const hostDir = path.resolve(process.env.SOMA_HOST_DIR);
8
+
9
+ const config: Config = {
10
+ content: [
11
+ './app/**/*.{js,ts,jsx,tsx,mdx}',
12
+ './core/**/*.{js,ts,jsx,tsx}',
13
+ path.resolve(hostDir, 'html/**/*.html'),
14
+ ],
15
+ theme: {
16
+ extend: {},
17
+ },
18
+ plugins: [],
19
+ };
20
+
21
+ export default config;