@lbdudc/linea-core 0.1.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/README.md +358 -0
- package/dist/analysis/analyze.d.ts +105 -0
- package/dist/analysis/analyze.js +220 -0
- package/dist/analysis/analyze.js.map +1 -0
- package/dist/analysis/runtime.d.ts +97 -0
- package/dist/analysis/runtime.js +198 -0
- package/dist/analysis/runtime.js.map +1 -0
- package/dist/analysis/wheels/micropip-0.6.0-py3-none-any.whl +0 -0
- package/dist/analysis/wheels/packaging-23.2-py3-none-any.whl +0 -0
- package/dist/assets.d.ts +16 -0
- package/dist/assets.js +36 -0
- package/dist/assets.js.map +1 -0
- package/dist/constants.d.ts +77 -0
- package/dist/constants.js +76 -0
- package/dist/constants.js.map +1 -0
- package/dist/derivation/derive.d.ts +68 -0
- package/dist/derivation/derive.js +115 -0
- package/dist/derivation/derive.js.map +1 -0
- package/dist/derivation/engine.d.ts +48 -0
- package/dist/derivation/engine.js +98 -0
- package/dist/derivation/engine.js.map +1 -0
- package/dist/errors.d.ts +72 -0
- package/dist/errors.js +91 -0
- package/dist/errors.js.map +1 -0
- package/dist/feature-model/convert.d.ts +35 -0
- package/dist/feature-model/convert.js +47 -0
- package/dist/feature-model/convert.js.map +1 -0
- package/dist/feature-model/engine.d.ts +60 -0
- package/dist/feature-model/engine.js +139 -0
- package/dist/feature-model/engine.js.map +1 -0
- package/dist/feature-model/inspect.d.ts +67 -0
- package/dist/feature-model/inspect.js +113 -0
- package/dist/feature-model/inspect.js.map +1 -0
- package/dist/feature-model/io.d.ts +66 -0
- package/dist/feature-model/io.js +92 -0
- package/dist/feature-model/io.js.map +1 -0
- package/dist/feature-model/parse.d.ts +30 -0
- package/dist/feature-model/parse.js +36 -0
- package/dist/feature-model/parse.js.map +1 -0
- package/dist/feature-model/text.d.ts +54 -0
- package/dist/feature-model/text.js +126 -0
- package/dist/feature-model/text.js.map +1 -0
- package/dist/fs/archive.d.ts +23 -0
- package/dist/fs/archive.js +87 -0
- package/dist/fs/archive.js.map +1 -0
- package/dist/fs/diff.d.ts +40 -0
- package/dist/fs/diff.js +155 -0
- package/dist/fs/diff.js.map +1 -0
- package/dist/fs/format.d.ts +21 -0
- package/dist/fs/format.js +111 -0
- package/dist/fs/format.js.map +1 -0
- package/dist/fs/workspace.d.ts +77 -0
- package/dist/fs/workspace.js +103 -0
- package/dist/fs/workspace.js.map +1 -0
- package/dist/index.d.ts +50 -0
- package/dist/index.js +48 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/guards.d.ts +15 -0
- package/dist/internal/guards.js +16 -0
- package/dist/internal/guards.js.map +1 -0
- package/dist/line/platform-files.d.ts +73 -0
- package/dist/line/platform-files.js +112 -0
- package/dist/line/platform-files.js.map +1 -0
- package/dist/line/scaffold.d.ts +88 -0
- package/dist/line/scaffold.js +145 -0
- package/dist/line/scaffold.js.map +1 -0
- package/dist/line/templates/core/extra.js +54 -0
- package/dist/line/templates/core/transformation.js +196 -0
- package/dist/line/templates/metamodels/dataModel/extra.js +328 -0
- package/dist/line/templates/metamodels/dataModel/transformation.js +211 -0
- package/dist/line/templates/metamodels/sensor/extra.js +36 -0
- package/dist/line/templates/metamodels/sensor/transformation.js +47 -0
- package/dist/line/templates/pipeline/.gitlab-ci.yml +51 -0
- package/dist/line/templates/pipeline/ci/test-client.sh +16 -0
- package/dist/line/templates/pipeline/ci/test-server.sh +16 -0
- package/dist/product/engine-spec.d.ts +25 -0
- package/dist/product/engine-spec.js +77 -0
- package/dist/product/engine-spec.js.map +1 -0
- package/dist/product/spec.d.ts +130 -0
- package/dist/product/spec.js +219 -0
- package/dist/product/spec.js.map +1 -0
- package/dist/product/version.d.ts +27 -0
- package/dist/product/version.js +49 -0
- package/dist/product/version.js.map +1 -0
- package/dist/products-index/products-index.d.ts +224 -0
- package/dist/products-index/products-index.js +395 -0
- package/dist/products-index/products-index.js.map +1 -0
- package/dist/selection/selection.d.ts +126 -0
- package/dist/selection/selection.js +152 -0
- package/dist/selection/selection.js.map +1 -0
- package/package.json +67 -0
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Platform files seeded into a brand new line.
|
|
3
|
+
*
|
|
4
|
+
* Migrated from:
|
|
5
|
+
* - `linea/server/src/model/services/templates/PlatformFileFactory.js`
|
|
6
|
+
* (`buildExtraJs`, `buildTransformationJs`)
|
|
7
|
+
* - `linea/server/src/model/services/templates/PipelineFileFactory.js`
|
|
8
|
+
* (`PIPELINE_FILES`)
|
|
9
|
+
*
|
|
10
|
+
* The templates under `src/line/templates/**` are byte-for-byte copies of
|
|
11
|
+
* `linea/server/src/model/services/templates/**`. They are ASSETS, not
|
|
12
|
+
* TypeScript: `scripts/copy-assets.mjs` mirrors them into `dist/` at build time
|
|
13
|
+
* and `resolveAsset` locates them through `import.meta.url`.
|
|
14
|
+
*
|
|
15
|
+
* The monolith reads every template ONCE at module load into a module-level
|
|
16
|
+
* `const`. That is module state, which ADR-014 rules out, so here each call
|
|
17
|
+
* reads from disk. These are a handful of small files read only when a line is
|
|
18
|
+
* created; if it ever mattered, the caller can cache.
|
|
19
|
+
*/
|
|
20
|
+
import fs from 'node:fs';
|
|
21
|
+
import { resolveAsset } from '../assets.js';
|
|
22
|
+
import { InvalidArgumentError } from '../errors.js';
|
|
23
|
+
import { isArray } from '../internal/guards.js';
|
|
24
|
+
/** Metamodels that contribute extra template fragments. */
|
|
25
|
+
const METAMODEL_TEMPLATES = {
|
|
26
|
+
UML: { extra: 'metamodels/dataModel/extra.js', transformation: 'metamodels/dataModel/transformation.js' },
|
|
27
|
+
SENSOR: { extra: 'metamodels/sensor/extra.js', transformation: 'metamodels/sensor/transformation.js' }
|
|
28
|
+
};
|
|
29
|
+
const readTemplate = (...segments) => fs.readFileSync(resolveAsset({ segments: ['line', 'templates', ...segments] }), 'utf8');
|
|
30
|
+
const assertModels = (models) => {
|
|
31
|
+
if (models === undefined)
|
|
32
|
+
return [];
|
|
33
|
+
if (!isArray(models) || models.some((model) => typeof model !== 'string')) {
|
|
34
|
+
throw new InvalidArgumentError('"models" must be an array of strings.');
|
|
35
|
+
}
|
|
36
|
+
return models;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Concatenates the core template with the fragment of each selected metamodel.
|
|
40
|
+
*
|
|
41
|
+
* Verbatim behaviour of `PlatformFileFactory.js:31-39`: the core template first,
|
|
42
|
+
* then `'\n' + fragment` for every model that has one, in the order given.
|
|
43
|
+
* A model with no template — including an unknown name — is skipped silently.
|
|
44
|
+
*/
|
|
45
|
+
const buildFromTemplates = (models, core, kind) => {
|
|
46
|
+
let content = readTemplate(core);
|
|
47
|
+
for (const model of models) {
|
|
48
|
+
const templates = METAMODEL_TEMPLATES[model];
|
|
49
|
+
if (templates !== undefined) {
|
|
50
|
+
content += '\n' + readTemplate(templates[kind]);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return content;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Builds `src/platform/extra.js` for a line.
|
|
57
|
+
*
|
|
58
|
+
* WRITING YOUR OWN `extra.js`: do NOT use `//` line comments. The template
|
|
59
|
+
* processor concatenates this file into the function it builds and then strips
|
|
60
|
+
* every newline from it (`spl-js-engine/src/template-engine/processor.js:28`),
|
|
61
|
+
* so a line comment swallows the rest of that function — including its final
|
|
62
|
+
* `return`. Every annotated file then processes to nothing and, because the
|
|
63
|
+
* engine skips empty output, the derivation produces ZERO files WITHOUT raising
|
|
64
|
+
* an error. Use `/* ... *\/` blocks. Neither the monolith's `core/extra.js` nor
|
|
65
|
+
* its mock LPS uses line comments, for exactly this reason.
|
|
66
|
+
*
|
|
67
|
+
* @param params.models Metamodels chosen for the line, e.g. `['UML']`. Unknown
|
|
68
|
+
* names are ignored, matching the monolith.
|
|
69
|
+
* @returns The file contents: core template plus one fragment per known model.
|
|
70
|
+
* @throws {InvalidArgumentError} when `models` is not an array of strings.
|
|
71
|
+
*/
|
|
72
|
+
export const buildExtraJs = ({ models }) => buildFromTemplates(assertModels(models), 'core/extra.js', 'extra');
|
|
73
|
+
/**
|
|
74
|
+
* Builds `src/platform/transformation.js` for a line.
|
|
75
|
+
*
|
|
76
|
+
* WRITING YOUR OWN `transformation.js`: the same `//` trap described on
|
|
77
|
+
* {@link buildExtraJs} applies here — the processor strips every newline, so a
|
|
78
|
+
* line comment silently swallows the rest of the generated function and the
|
|
79
|
+
* derivation produces ZERO files without raising. Use block comments.
|
|
80
|
+
*
|
|
81
|
+
* @param params.models Metamodels chosen for the line. Unknown names are ignored.
|
|
82
|
+
* @returns The file contents: core template plus one fragment per known model.
|
|
83
|
+
* @throws {InvalidArgumentError} when `models` is not an array of strings.
|
|
84
|
+
*/
|
|
85
|
+
export const buildTransformationJs = ({ models }) => buildFromTemplates(assertModels(models), 'core/transformation.js', 'transformation');
|
|
86
|
+
/**
|
|
87
|
+
* The default CI pipeline files seeded into every new line repository.
|
|
88
|
+
*
|
|
89
|
+
* Migrated from `PipelineFileFactory.js:PIPELINE_FILES`, same paths and same
|
|
90
|
+
* order. A function rather than an exported constant so no module-level state
|
|
91
|
+
* holds the file contents (ADR-014) and so each caller gets its own array.
|
|
92
|
+
*
|
|
93
|
+
* @returns The pipeline files, in the order the monolith creates them.
|
|
94
|
+
*/
|
|
95
|
+
export const getPipelineFiles = () => [
|
|
96
|
+
{
|
|
97
|
+
path: 'src/platform/code/.gitlab-ci.yml',
|
|
98
|
+
content: readTemplate('pipeline/.gitlab-ci.yml'),
|
|
99
|
+
encoding: 'text'
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
path: 'src/platform/code/ci/test-server.sh',
|
|
103
|
+
content: readTemplate('pipeline/ci/test-server.sh'),
|
|
104
|
+
encoding: 'text'
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
path: 'src/platform/code/ci/test-client.sh',
|
|
108
|
+
content: readTemplate('pipeline/ci/test-client.sh'),
|
|
109
|
+
encoding: 'text'
|
|
110
|
+
}
|
|
111
|
+
];
|
|
112
|
+
//# sourceMappingURL=platform-files.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platform-files.js","sourceRoot":"","sources":["../../src/line/platform-files.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAC3C,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAA;AAiB/C,2DAA2D;AAC3D,MAAM,mBAAmB,GAAG;IAC1B,GAAG,EAAE,EAAE,KAAK,EAAE,+BAA+B,EAAE,cAAc,EAAE,wCAAwC,EAAE;IACzG,MAAM,EAAE,EAAE,KAAK,EAAE,4BAA4B,EAAE,cAAc,EAAE,qCAAqC,EAAE;CAC9F,CAAA;AAKV,MAAM,YAAY,GAAG,CAAC,GAAG,QAAkB,EAAU,EAAE,CACrD,EAAE,CAAC,YAAY,CAAC,YAAY,CAAC,EAAE,QAAQ,EAAE,CAAC,MAAM,EAAE,WAAW,EAAE,GAAG,QAAQ,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,CAAA;AAEzF,MAAM,YAAY,GAAG,CAAC,MAAe,EAAqB,EAAE;IAC1D,IAAI,MAAM,KAAK,SAAS;QAAE,OAAO,EAAE,CAAA;IACnC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC,EAAE,CAAC;QAC1E,MAAM,IAAI,oBAAoB,CAAC,uCAAuC,CAAC,CAAA;IACzE,CAAC;IACD,OAAO,MAA2B,CAAA;AACpC,CAAC,CAAA;AAED;;;;;;GAMG;AACH,MAAM,kBAAkB,GAAG,CACzB,MAAyB,EACzB,IAAY,EACZ,IAAgC,EACxB,EAAE;IACV,IAAI,OAAO,GAAG,YAAY,CAAC,IAAI,CAAC,CAAA;IAChC,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,MAAM,SAAS,GAAG,mBAAmB,CAAC,KAAsB,CAE/C,CAAA;QACb,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;YAC5B,OAAO,IAAI,IAAI,GAAG,YAAY,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAA;QACjD,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,EAAE,MAAM,EAAkC,EAAU,EAAE,CACjF,kBAAkB,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,eAAe,EAAE,OAAO,CAAC,CAAA;AAEpE;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,EAAE,MAAM,EAAkC,EAAU,EAAE,CAC1F,kBAAkB,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,wBAAwB,EAAE,gBAAgB,CAAC,CAAA;AAEtF;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAe,EAAE,CAAC;IAChD;QACE,IAAI,EAAE,kCAAkC;QACxC,OAAO,EAAE,YAAY,CAAC,yBAAyB,CAAC;QAChD,QAAQ,EAAE,MAAM;KACjB;IACD;QACE,IAAI,EAAE,qCAAqC;QAC3C,OAAO,EAAE,YAAY,CAAC,4BAA4B,CAAC;QACnD,QAAQ,EAAE,MAAM;KACjB;IACD;QACE,IAAI,EAAE,qCAAqC;QAC3C,OAAO,EAAE,YAAY,CAAC,4BAA4B,CAAC;QACnD,QAAQ,EAAE,MAAM;KACjB;CACF,CAAA","sourcesContent":["/**\r\n * Platform files seeded into a brand new line.\r\n *\r\n * Migrated from:\r\n * - `linea/server/src/model/services/templates/PlatformFileFactory.js`\r\n * (`buildExtraJs`, `buildTransformationJs`)\r\n * - `linea/server/src/model/services/templates/PipelineFileFactory.js`\r\n * (`PIPELINE_FILES`)\r\n *\r\n * The templates under `src/line/templates/**` are byte-for-byte copies of\r\n * `linea/server/src/model/services/templates/**`. They are ASSETS, not\r\n * TypeScript: `scripts/copy-assets.mjs` mirrors them into `dist/` at build time\r\n * and `resolveAsset` locates them through `import.meta.url`.\r\n *\r\n * The monolith reads every template ONCE at module load into a module-level\r\n * `const`. That is module state, which ADR-014 rules out, so here each call\r\n * reads from disk. These are a handful of small files read only when a line is\r\n * created; if it ever mattered, the caller can cache.\r\n */\r\nimport fs from 'node:fs'\r\nimport { resolveAsset } from '../assets.js'\r\nimport { InvalidArgumentError } from '../errors.js'\r\nimport { isArray } from '../internal/guards.js'\r\n\r\n/**\r\n * A file to be written somewhere, described without deciding where.\r\n *\r\n * The pure half of the scaffold API returns these so linea-server can push them\r\n * to GitLab and linea-cli can write them to disk, from the same description.\r\n */\r\nexport interface FileSpec {\r\n /** Repository-relative path, always POSIX (`/`), never absolute. */\r\n readonly path: string\r\n /** File contents. */\r\n readonly content: string\r\n /** How `content` is encoded. Every seeded file is text today. */\r\n readonly encoding: 'text' | 'base64'\r\n}\r\n\r\n/** Metamodels that contribute extra template fragments. */\r\nconst METAMODEL_TEMPLATES = {\r\n UML: { extra: 'metamodels/dataModel/extra.js', transformation: 'metamodels/dataModel/transformation.js' },\r\n SENSOR: { extra: 'metamodels/sensor/extra.js', transformation: 'metamodels/sensor/transformation.js' }\r\n} as const\r\n\r\n/** A metamodel name recognised by the template factory. */\r\nexport type MetamodelName = keyof typeof METAMODEL_TEMPLATES\r\n\r\nconst readTemplate = (...segments: string[]): string =>\r\n fs.readFileSync(resolveAsset({ segments: ['line', 'templates', ...segments] }), 'utf8')\r\n\r\nconst assertModels = (models: unknown): readonly string[] => {\r\n if (models === undefined) return []\r\n if (!isArray(models) || models.some((model) => typeof model !== 'string')) {\r\n throw new InvalidArgumentError('\"models\" must be an array of strings.')\r\n }\r\n return models as readonly string[]\r\n}\r\n\r\n/**\r\n * Concatenates the core template with the fragment of each selected metamodel.\r\n *\r\n * Verbatim behaviour of `PlatformFileFactory.js:31-39`: the core template first,\r\n * then `'\\n' + fragment` for every model that has one, in the order given.\r\n * A model with no template — including an unknown name — is skipped silently.\r\n */\r\nconst buildFromTemplates = (\r\n models: readonly string[],\r\n core: string,\r\n kind: 'extra' | 'transformation'\r\n): string => {\r\n let content = readTemplate(core)\r\n for (const model of models) {\r\n const templates = METAMODEL_TEMPLATES[model as MetamodelName] as\r\n | (typeof METAMODEL_TEMPLATES)[MetamodelName]\r\n | undefined\r\n if (templates !== undefined) {\r\n content += '\\n' + readTemplate(templates[kind])\r\n }\r\n }\r\n return content\r\n}\r\n\r\n/**\r\n * Builds `src/platform/extra.js` for a line.\r\n *\r\n * WRITING YOUR OWN `extra.js`: do NOT use `//` line comments. The template\r\n * processor concatenates this file into the function it builds and then strips\r\n * every newline from it (`spl-js-engine/src/template-engine/processor.js:28`),\r\n * so a line comment swallows the rest of that function — including its final\r\n * `return`. Every annotated file then processes to nothing and, because the\r\n * engine skips empty output, the derivation produces ZERO files WITHOUT raising\r\n * an error. Use `/* ... *\\/` blocks. Neither the monolith's `core/extra.js` nor\r\n * its mock LPS uses line comments, for exactly this reason.\r\n *\r\n * @param params.models Metamodels chosen for the line, e.g. `['UML']`. Unknown\r\n * names are ignored, matching the monolith.\r\n * @returns The file contents: core template plus one fragment per known model.\r\n * @throws {InvalidArgumentError} when `models` is not an array of strings.\r\n */\r\nexport const buildExtraJs = ({ models }: { models?: readonly string[] }): string =>\r\n buildFromTemplates(assertModels(models), 'core/extra.js', 'extra')\r\n\r\n/**\r\n * Builds `src/platform/transformation.js` for a line.\r\n *\r\n * WRITING YOUR OWN `transformation.js`: the same `//` trap described on\r\n * {@link buildExtraJs} applies here — the processor strips every newline, so a\r\n * line comment silently swallows the rest of the generated function and the\r\n * derivation produces ZERO files without raising. Use block comments.\r\n *\r\n * @param params.models Metamodels chosen for the line. Unknown names are ignored.\r\n * @returns The file contents: core template plus one fragment per known model.\r\n * @throws {InvalidArgumentError} when `models` is not an array of strings.\r\n */\r\nexport const buildTransformationJs = ({ models }: { models?: readonly string[] }): string =>\r\n buildFromTemplates(assertModels(models), 'core/transformation.js', 'transformation')\r\n\r\n/**\r\n * The default CI pipeline files seeded into every new line repository.\r\n *\r\n * Migrated from `PipelineFileFactory.js:PIPELINE_FILES`, same paths and same\r\n * order. A function rather than an exported constant so no module-level state\r\n * holds the file contents (ADR-014) and so each caller gets its own array.\r\n *\r\n * @returns The pipeline files, in the order the monolith creates them.\r\n */\r\nexport const getPipelineFiles = (): FileSpec[] => [\r\n {\r\n path: 'src/platform/code/.gitlab-ci.yml',\r\n content: readTemplate('pipeline/.gitlab-ci.yml'),\r\n encoding: 'text'\r\n },\r\n {\r\n path: 'src/platform/code/ci/test-server.sh',\r\n content: readTemplate('pipeline/ci/test-server.sh'),\r\n encoding: 'text'\r\n },\r\n {\r\n path: 'src/platform/code/ci/test-client.sh',\r\n content: readTemplate('pipeline/ci/test-client.sh'),\r\n encoding: 'text'\r\n }\r\n]\r\n"]}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { type FeatureModelType } from '../constants.js';
|
|
2
|
+
import { type FileSpec } from './platform-files.js';
|
|
3
|
+
/**
|
|
4
|
+
* Engine configuration seeded into every new line (`src/platform/config.json`).
|
|
5
|
+
*
|
|
6
|
+
* Verbatim from `LineService.js:48-56`, which is what actually runs when a line
|
|
7
|
+
* is created.
|
|
8
|
+
*
|
|
9
|
+
* KNOWN DISCREPANCY IN THE MONOLITH: the test fixture
|
|
10
|
+
* `linea/server/src/test/mocks/lps/src/platform/config.json` carries a RICHER
|
|
11
|
+
* list — it also declares `dockerfile` and `sh` extensions. The two have drifted
|
|
12
|
+
* apart. `LineService.js` is the source of truth here because it is the code
|
|
13
|
+
* path that creates real lines; the fixture only feeds derivation tests. A line
|
|
14
|
+
* seeded by linea-core therefore will not process `Dockerfile` or `.sh`
|
|
15
|
+
* annotations until someone edits its `config.json`, exactly as today.
|
|
16
|
+
*/
|
|
17
|
+
export declare const DEFAULT_PLATFORM_CONFIG: {
|
|
18
|
+
readonly ignore: readonly ["target", "bower_components", ".gradle", ".project", "bin", "build", ".settings", ".classpath"];
|
|
19
|
+
readonly delimiters: readonly [{
|
|
20
|
+
readonly extension: readonly ["html", "jsp", "xml"];
|
|
21
|
+
readonly start: "<!--%";
|
|
22
|
+
readonly end: "%-->";
|
|
23
|
+
}, {
|
|
24
|
+
readonly extension: readonly ["css", "js", "java", "vue", "g4", "tokens", "gradle", "md", "conf", "gitignore", "properties", "sql", "env", "production"];
|
|
25
|
+
readonly start: "/*%";
|
|
26
|
+
readonly end: "%*/";
|
|
27
|
+
}, {
|
|
28
|
+
readonly extension: readonly ["py"];
|
|
29
|
+
readonly start: "#%";
|
|
30
|
+
readonly end: "%#";
|
|
31
|
+
}, {
|
|
32
|
+
readonly extension: readonly ["json"];
|
|
33
|
+
readonly start: "###<";
|
|
34
|
+
readonly end: ">###";
|
|
35
|
+
}];
|
|
36
|
+
};
|
|
37
|
+
/** Contents of `src/platform/code/.gitignore`, verbatim from `LineService.js:60`. */
|
|
38
|
+
export declare const DEFAULT_CODE_GITIGNORE = "node_modules/\ntarget/\ndist/\n.env\n*.log\n";
|
|
39
|
+
/** What a line scaffold needs to know. */
|
|
40
|
+
export interface LineScaffoldInput {
|
|
41
|
+
/** Line name; becomes the root feature of the seed model. */
|
|
42
|
+
name: string;
|
|
43
|
+
/** Metamodels chosen for the line, e.g. `['UML']`. Unknown names are ignored. */
|
|
44
|
+
models?: readonly string[];
|
|
45
|
+
/** Notation of the seed feature model. Defaults to `'UVL'`. */
|
|
46
|
+
featureModelType?: FeatureModelType;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Computes the files of a brand new line. PURE: reads no working directory and
|
|
50
|
+
* writes nothing.
|
|
51
|
+
*
|
|
52
|
+
* The returned order is the order `createLine` creates them in, and callers
|
|
53
|
+
* should preserve it: model, config, code/.gitignore, extra.js,
|
|
54
|
+
* transformation.js, then the pipeline files.
|
|
55
|
+
*
|
|
56
|
+
* Note the template files themselves ARE read from the package's own asset
|
|
57
|
+
* directory — that is reading linea-core's own installed data, not the caller's
|
|
58
|
+
* working directory, and is what makes the function usable with no filesystem
|
|
59
|
+
* target at all.
|
|
60
|
+
*
|
|
61
|
+
* @param params.name Line name.
|
|
62
|
+
* @param params.models Metamodels chosen for the line.
|
|
63
|
+
* @param params.featureModelType `'UVL'` (default) or `'XML'`.
|
|
64
|
+
* @returns The files to create, in order.
|
|
65
|
+
* @throws {InvalidArgumentError} when `name` is empty or has characters outside
|
|
66
|
+
* `NAME_PATTERN`, or when `featureModelType` is unknown.
|
|
67
|
+
*/
|
|
68
|
+
export declare const buildLineScaffold: ({ name, models, featureModelType }: LineScaffoldInput) => FileSpec[];
|
|
69
|
+
/**
|
|
70
|
+
* Materialises a line scaffold in a directory.
|
|
71
|
+
*
|
|
72
|
+
* The impure counterpart of `buildLineScaffold`, for linea-cli's local mode.
|
|
73
|
+
* Creates `dir` and every parent directory the files need.
|
|
74
|
+
*
|
|
75
|
+
* @param params.dir Target directory (the line's working directory root).
|
|
76
|
+
* @param params.name Line name.
|
|
77
|
+
* @param params.models Metamodels chosen for the line.
|
|
78
|
+
* @param params.featureModelType `'UVL'` (default) or `'XML'`.
|
|
79
|
+
* @returns The resolved directory and the files written.
|
|
80
|
+
* @throws {InvalidArgumentError} for the same reasons as `buildLineScaffold`, or
|
|
81
|
+
* when `dir` is not a non-empty path.
|
|
82
|
+
*/
|
|
83
|
+
export declare const writeLineScaffold: ({ dir, name, models, featureModelType }: LineScaffoldInput & {
|
|
84
|
+
dir: string;
|
|
85
|
+
}) => {
|
|
86
|
+
dir: string;
|
|
87
|
+
files: FileSpec[];
|
|
88
|
+
};
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The initial file tree of a brand new line.
|
|
3
|
+
*
|
|
4
|
+
* Migrated from `linea/server/src/model/services/LineService.js:createLine`
|
|
5
|
+
* (~43-68), keeping ONLY the file construction. Everything around it belongs to
|
|
6
|
+
* linea-server (ADR-003): creating the GitLab group and project, the
|
|
7
|
+
* `createFile` calls, the Mongo transaction and the rollback.
|
|
8
|
+
*
|
|
9
|
+
* The API is split into a PURE half and an IMPURE half on purpose:
|
|
10
|
+
*
|
|
11
|
+
* - `buildLineScaffold` computes the files and touches nothing. linea-server
|
|
12
|
+
* feeds the result straight to `gitlabSession.createFile`, in order, for
|
|
13
|
+
* exact parity with `createLine` — without linea-core ever reaching the
|
|
14
|
+
* network or the disk (ADR-002).
|
|
15
|
+
* - `writeLineScaffold` materialises the same description on disk, which is
|
|
16
|
+
* what linea-cli needs in local mode (ADR-004).
|
|
17
|
+
*
|
|
18
|
+
* They must stay separate: collapsing them would force the GitLab path to write
|
|
19
|
+
* a temporary tree it does not want.
|
|
20
|
+
*/
|
|
21
|
+
import path from 'node:path';
|
|
22
|
+
import { FEATURE_MODEL_TYPES, isFeatureModelType, NAME_PATTERN } from '../constants.js';
|
|
23
|
+
import { InvalidArgumentError } from '../errors.js';
|
|
24
|
+
import { modelToXml } from '../feature-model/engine.js';
|
|
25
|
+
import { parseFeatureModel } from '../feature-model/parse.js';
|
|
26
|
+
import { emptyFeatureModelUvl } from '../feature-model/text.js';
|
|
27
|
+
import { ensureDir, writeTextFile } from '../fs/workspace.js';
|
|
28
|
+
import { buildExtraJs, buildTransformationJs, getPipelineFiles } from './platform-files.js';
|
|
29
|
+
/**
|
|
30
|
+
* Engine configuration seeded into every new line (`src/platform/config.json`).
|
|
31
|
+
*
|
|
32
|
+
* Verbatim from `LineService.js:48-56`, which is what actually runs when a line
|
|
33
|
+
* is created.
|
|
34
|
+
*
|
|
35
|
+
* KNOWN DISCREPANCY IN THE MONOLITH: the test fixture
|
|
36
|
+
* `linea/server/src/test/mocks/lps/src/platform/config.json` carries a RICHER
|
|
37
|
+
* list — it also declares `dockerfile` and `sh` extensions. The two have drifted
|
|
38
|
+
* apart. `LineService.js` is the source of truth here because it is the code
|
|
39
|
+
* path that creates real lines; the fixture only feeds derivation tests. A line
|
|
40
|
+
* seeded by linea-core therefore will not process `Dockerfile` or `.sh`
|
|
41
|
+
* annotations until someone edits its `config.json`, exactly as today.
|
|
42
|
+
*/
|
|
43
|
+
export const DEFAULT_PLATFORM_CONFIG = {
|
|
44
|
+
ignore: ['target', 'bower_components', '.gradle', '.project', 'bin', 'build', '.settings', '.classpath'],
|
|
45
|
+
delimiters: [
|
|
46
|
+
{ extension: ['html', 'jsp', 'xml'], start: '<!--%', end: '%-->' },
|
|
47
|
+
{
|
|
48
|
+
extension: [
|
|
49
|
+
'css', 'js', 'java', 'vue', 'g4', 'tokens', 'gradle', 'md', 'conf',
|
|
50
|
+
'gitignore', 'properties', 'sql', 'env', 'production'
|
|
51
|
+
],
|
|
52
|
+
start: '/*%',
|
|
53
|
+
end: '%*/'
|
|
54
|
+
},
|
|
55
|
+
{ extension: ['py'], start: '#%', end: '%#' },
|
|
56
|
+
{ extension: ['json'], start: '###<', end: '>###' }
|
|
57
|
+
]
|
|
58
|
+
};
|
|
59
|
+
/** Contents of `src/platform/code/.gitignore`, verbatim from `LineService.js:60`. */
|
|
60
|
+
export const DEFAULT_CODE_GITIGNORE = 'node_modules/\ntarget/\ndist/\n.env\n*.log\n';
|
|
61
|
+
/**
|
|
62
|
+
* Computes the files of a brand new line. PURE: reads no working directory and
|
|
63
|
+
* writes nothing.
|
|
64
|
+
*
|
|
65
|
+
* The returned order is the order `createLine` creates them in, and callers
|
|
66
|
+
* should preserve it: model, config, code/.gitignore, extra.js,
|
|
67
|
+
* transformation.js, then the pipeline files.
|
|
68
|
+
*
|
|
69
|
+
* Note the template files themselves ARE read from the package's own asset
|
|
70
|
+
* directory — that is reading linea-core's own installed data, not the caller's
|
|
71
|
+
* working directory, and is what makes the function usable with no filesystem
|
|
72
|
+
* target at all.
|
|
73
|
+
*
|
|
74
|
+
* @param params.name Line name.
|
|
75
|
+
* @param params.models Metamodels chosen for the line.
|
|
76
|
+
* @param params.featureModelType `'UVL'` (default) or `'XML'`.
|
|
77
|
+
* @returns The files to create, in order.
|
|
78
|
+
* @throws {InvalidArgumentError} when `name` is empty or has characters outside
|
|
79
|
+
* `NAME_PATTERN`, or when `featureModelType` is unknown.
|
|
80
|
+
*/
|
|
81
|
+
export const buildLineScaffold = ({ name, models = [], featureModelType = 'UVL' }) => {
|
|
82
|
+
if (typeof name !== 'string' || name === '') {
|
|
83
|
+
throw new InvalidArgumentError('"name" must be a non-empty string.');
|
|
84
|
+
}
|
|
85
|
+
if (!NAME_PATTERN.test(name)) {
|
|
86
|
+
throw new InvalidArgumentError(`Invalid line name ${JSON.stringify(name)}: allowed characters are [a-zA-Z0-9_.-].`);
|
|
87
|
+
}
|
|
88
|
+
if (!isFeatureModelType(featureModelType)) {
|
|
89
|
+
throw new InvalidArgumentError(`Unknown feature model type ${JSON.stringify(featureModelType)}. Use one of ${FEATURE_MODEL_TYPES.join(', ')}.`);
|
|
90
|
+
}
|
|
91
|
+
const uvlContent = emptyFeatureModelUvl({ name });
|
|
92
|
+
const modelFile = featureModelType === 'XML'
|
|
93
|
+
? {
|
|
94
|
+
path: 'src/platform/model.xml',
|
|
95
|
+
content: modelToXml(parseFeatureModel({ content: uvlContent, type: 'UVL' })),
|
|
96
|
+
encoding: 'text'
|
|
97
|
+
}
|
|
98
|
+
: { path: 'src/platform/model.uvl', content: uvlContent, encoding: 'text' };
|
|
99
|
+
return [
|
|
100
|
+
modelFile,
|
|
101
|
+
{
|
|
102
|
+
path: 'src/platform/config.json',
|
|
103
|
+
// JSON.stringify(config, null, 2) — same two-space indentation as the
|
|
104
|
+
// monolith, and no trailing newline, so the committed file matches.
|
|
105
|
+
content: JSON.stringify(DEFAULT_PLATFORM_CONFIG, null, 2),
|
|
106
|
+
encoding: 'text'
|
|
107
|
+
},
|
|
108
|
+
{ path: 'src/platform/code/.gitignore', content: DEFAULT_CODE_GITIGNORE, encoding: 'text' },
|
|
109
|
+
{ path: 'src/platform/extra.js', content: buildExtraJs({ models }), encoding: 'text' },
|
|
110
|
+
{
|
|
111
|
+
path: 'src/platform/transformation.js',
|
|
112
|
+
content: buildTransformationJs({ models }),
|
|
113
|
+
encoding: 'text'
|
|
114
|
+
},
|
|
115
|
+
...getPipelineFiles()
|
|
116
|
+
];
|
|
117
|
+
};
|
|
118
|
+
/**
|
|
119
|
+
* Materialises a line scaffold in a directory.
|
|
120
|
+
*
|
|
121
|
+
* The impure counterpart of `buildLineScaffold`, for linea-cli's local mode.
|
|
122
|
+
* Creates `dir` and every parent directory the files need.
|
|
123
|
+
*
|
|
124
|
+
* @param params.dir Target directory (the line's working directory root).
|
|
125
|
+
* @param params.name Line name.
|
|
126
|
+
* @param params.models Metamodels chosen for the line.
|
|
127
|
+
* @param params.featureModelType `'UVL'` (default) or `'XML'`.
|
|
128
|
+
* @returns The resolved directory and the files written.
|
|
129
|
+
* @throws {InvalidArgumentError} for the same reasons as `buildLineScaffold`, or
|
|
130
|
+
* when `dir` is not a non-empty path.
|
|
131
|
+
*/
|
|
132
|
+
export const writeLineScaffold = ({ dir, name, models = [], featureModelType = 'UVL' }) => {
|
|
133
|
+
if (typeof dir !== 'string' || dir.trim() === '') {
|
|
134
|
+
throw new InvalidArgumentError('"dir" must be a non-empty path.');
|
|
135
|
+
}
|
|
136
|
+
const files = buildLineScaffold({ name, models, featureModelType });
|
|
137
|
+
const root = ensureDir({ dirPath: dir });
|
|
138
|
+
for (const file of files) {
|
|
139
|
+
// FileSpec paths are POSIX and repository-relative; join with the platform
|
|
140
|
+
// separator to land them on disk.
|
|
141
|
+
writeTextFile({ filePath: path.join(root, ...file.path.split('/')), content: file.content });
|
|
142
|
+
}
|
|
143
|
+
return { dir: root, files };
|
|
144
|
+
};
|
|
145
|
+
//# sourceMappingURL=scaffold.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scaffold.js","sourceRo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AAC,IAAI,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,CAAA;IAC9F,CAAC;IAED,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,CAAA;AAC7B,CAAC,CAAA","sourcesContent":["/**\r\n * The initial file tree of a brand new line.\r\n *\r\n * Migrated from `linea/server/src/model/services/LineService.js:createLine`\r\n * (~43-68), keeping ONLY the file construction. Everything around it belongs to\r\n * linea-server (ADR-003): creating the GitLab group and project, the\r\n * `createFile` calls, the Mongo transaction and the rollback.\r\n *\r\n * The API is split into a PURE half and an IMPURE half on purpose:\r\n *\r\n * - `buildLineScaffold` computes the files and touches nothing. linea-server\r\n * feeds the result straight to `gitlabSession.createFile`, in order, for\r\n * exact parity with `createLine` — without linea-core ever reaching the\r\n * network or the disk (ADR-002).\r\n * - `writeLineScaffold` materialises the same description on disk, which is\r\n * what linea-cli needs in local mode (ADR-004).\r\n *\r\n * They must stay separate: collapsing them would force the GitLab path to write\r\n * a temporary tree it does not want.\r\n */\r\nimport path from 'node:path'\r\nimport { FEATURE_MODEL_TYPES, isFeatureModelType, NAME_PATTERN, type FeatureModelType } from '../constants.js'\r\nimport { InvalidArgumentError } from '../errors.js'\r\nimport { modelToXml } from '../feature-model/engine.js'\r\nimport { parseFeatureModel } from '../feature-model/parse.js'\r\nimport { emptyFeatureModelUvl } from '../feature-model/text.js'\r\nimport { ensureDir, writeTextFile } from '../fs/workspace.js'\r\nimport { buildExtraJs, buildTransformationJs, getPipelineFiles, type FileSpec } from './platform-files.js'\r\n\r\n/**\r\n * Engine configuration seeded into every new line (`src/platform/config.json`).\r\n *\r\n * Verbatim from `LineService.js:48-56`, which is what actually runs when a line\r\n * is created.\r\n *\r\n * KNOWN DISCREPANCY IN THE MONOLITH: the test fixture\r\n * `linea/server/src/test/mocks/lps/src/platform/config.json` carries a RICHER\r\n * list — it also declares `dockerfile` and `sh` extensions. The two have drifted\r\n * apart. `LineService.js` is the source of truth here because it is the code\r\n * path that creates real lines; the fixture only feeds derivation tests. A line\r\n * seeded by linea-core therefore will not process `Dockerfile` or `.sh`\r\n * annotations until someone edits its `config.json`, exactly as today.\r\n */\r\nexport const DEFAULT_PLATFORM_CONFIG = {\r\n ignore: ['target', 'bower_components', '.gradle', '.project', 'bin', 'build', '.settings', '.classpath'],\r\n delimiters: [\r\n { extension: ['html', 'jsp', 'xml'], start: '<!--%', end: '%-->' },\r\n {\r\n extension: [\r\n 'css', 'js', 'java', 'vue', 'g4', 'tokens', 'gradle', 'md', 'conf',\r\n 'gitignore', 'properties', 'sql', 'env', 'production'\r\n ],\r\n start: '/*%',\r\n end: '%*/'\r\n },\r\n { extension: ['py'], start: '#%', end: '%#' },\r\n { extension: ['json'], start: '###<', end: '>###' }\r\n ]\r\n} as const\r\n\r\n/** Contents of `src/platform/code/.gitignore`, verbatim from `LineService.js:60`. */\r\nexport const DEFAULT_CODE_GITIGNORE = 'node_modules/\\ntarget/\\ndist/\\n.env\\n*.log\\n'\r\n\r\n/** What a line scaffold needs to know. */\r\nexport interface LineScaffoldInput {\r\n /** Line name; becomes the root feature of the seed model. */\r\n name: string\r\n /** Metamodels chosen for the line, e.g. `['UML']`. Unknown names are ignored. */\r\n models?: readonly string[]\r\n /** Notation of the seed feature model. Defaults to `'UVL'`. */\r\n featureModelType?: FeatureModelType\r\n}\r\n\r\n/**\r\n * Computes the files of a brand new line. PURE: reads no working directory and\r\n * writes nothing.\r\n *\r\n * The returned order is the order `createLine` creates them in, and callers\r\n * should preserve it: model, config, code/.gitignore, extra.js,\r\n * transformation.js, then the pipeline files.\r\n *\r\n * Note the template files themselves ARE read from the package's own asset\r\n * directory — that is reading linea-core's own installed data, not the caller's\r\n * working directory, and is what makes the function usable with no filesystem\r\n * target at all.\r\n *\r\n * @param params.name Line name.\r\n * @param params.models Metamodels chosen for the line.\r\n * @param params.featureModelType `'UVL'` (default) or `'XML'`.\r\n * @returns The files to create, in order.\r\n * @throws {InvalidArgumentError} when `name` is empty or has characters outside\r\n * `NAME_PATTERN`, or when `featureModelType` is unknown.\r\n */\r\nexport const buildLineScaffold = ({\r\n name,\r\n models = [],\r\n featureModelType = 'UVL'\r\n}: LineScaffoldInput): FileSpec[] => {\r\n if (typeof name !== 'string' || name === '') {\r\n throw new InvalidArgumentError('\"name\" must be a non-empty string.')\r\n }\r\n if (!NAME_PATTERN.test(name)) {\r\n throw new InvalidArgumentError(\r\n `Invalid line name ${JSON.stringify(name)}: allowed characters are [a-zA-Z0-9_.-].`\r\n )\r\n }\r\n if (!isFeatureModelType(featureModelType)) {\r\n throw new InvalidArgumentError(\r\n `Unknown feature model type ${JSON.stringify(featureModelType)}. Use one of ${FEATURE_MODEL_TYPES.join(', ')}.`\r\n )\r\n }\r\n\r\n const uvlContent = emptyFeatureModelUvl({ name })\r\n const modelFile: FileSpec = featureModelType === 'XML'\r\n ? {\r\n path: 'src/platform/model.xml',\r\n content: modelToXml(parseFeatureModel({ content: uvlContent, type: 'UVL' })),\r\n encoding: 'text'\r\n }\r\n : { path: 'src/platform/model.uvl', content: uvlContent, encoding: 'text' }\r\n\r\n return [\r\n modelFile,\r\n {\r\n path: 'src/platform/config.json',\r\n // JSON.stringify(config, null, 2) — same two-space indentation as the\r\n // monolith, and no trailing newline, so the committed file matches.\r\n content: JSON.stringify(DEFAULT_PLATFORM_CONFIG, null, 2),\r\n encoding: 'text'\r\n },\r\n { path: 'src/platform/code/.gitignore', content: DEFAULT_CODE_GITIGNORE, encoding: 'text' },\r\n { path: 'src/platform/extra.js', content: buildExtraJs({ models }), encoding: 'text' },\r\n {\r\n path: 'src/platform/transformation.js',\r\n content: buildTransformationJs({ models }),\r\n encoding: 'text'\r\n },\r\n ...getPipelineFiles()\r\n ]\r\n}\r\n\r\n/**\r\n * Materialises a line scaffold in a directory.\r\n *\r\n * The impure counterpart of `buildLineScaffold`, for linea-cli's local mode.\r\n * Creates `dir` and every parent directory the files need.\r\n *\r\n * @param params.dir Target directory (the line's working directory root).\r\n * @param params.name Line name.\r\n * @param params.models Metamodels chosen for the line.\r\n * @param params.featureModelType `'UVL'` (default) or `'XML'`.\r\n * @returns The resolved directory and the files written.\r\n * @throws {InvalidArgumentError} for the same reasons as `buildLineScaffold`, or\r\n * when `dir` is not a non-empty path.\r\n */\r\nexport const writeLineScaffold = ({\r\n dir,\r\n name,\r\n models = [],\r\n featureModelType = 'UVL'\r\n}: LineScaffoldInput & { dir: string }): { dir: string, files: FileSpec[] } => {\r\n if (typeof dir !== 'string' || dir.trim() === '') {\r\n throw new InvalidArgumentError('\"dir\" must be a non-empty path.')\r\n }\r\n const files = buildLineScaffold({ name, models, featureModelType })\r\n const root = ensureDir({ dirPath: dir })\r\n\r\n for (const file of files) {\r\n // FileSpec paths are POSIX and repository-relative; join with the platform\r\n // separator to land them on disk.\r\n writeTextFile({ filePath: path.join(root, ...file.path.split('/')), content: file.content })\r\n }\r\n\r\n return { dir: root, files }\r\n}\r\n"]}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
function pluralize(name) {
|
|
2
|
+
return name + "s";
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
function capitalizeOneWord(word) {
|
|
6
|
+
return word.charAt(0).toUpperCase() + word.slice(1);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function camelToSnakeCase(str) {
|
|
10
|
+
return str[0].toLowerCase() + str.slice(1, str.length).replace(/[A-Z]/g, letter => '_' + letter.toLowerCase());
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function normalizeKebabCase(str) {
|
|
14
|
+
return str
|
|
15
|
+
.replace(/[\s-]+/g, '-')
|
|
16
|
+
.replace(/([a-z])([A-Z])/g, '$1_$2')
|
|
17
|
+
.toLowerCase();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function normalizeSnakeCase(str) {
|
|
21
|
+
return str
|
|
22
|
+
.replace(/[\s-]+/g, '_')
|
|
23
|
+
.replace(/([a-z])([A-Z])/g, '$1_$2')
|
|
24
|
+
.toLowerCase();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function normalizeUrl(str) {
|
|
28
|
+
return str
|
|
29
|
+
.normalize("NFKD")
|
|
30
|
+
.replace(/[\u0300-\u036F]/g, "")
|
|
31
|
+
.trim()
|
|
32
|
+
.replace(/[\s]/g, "-")
|
|
33
|
+
.toLowerCase();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function getDatabaseConfigFromSpec(data, name, defaultValue) {
|
|
37
|
+
var dataBase = data.basicData.database;
|
|
38
|
+
if (dataBase) {
|
|
39
|
+
if (dataBase[name] && dataBase[name] != "") {
|
|
40
|
+
return dataBase[name];
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return defaultValue;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function getExtraConfigFromSpec(data, name, defaultValue) {
|
|
47
|
+
var extra = data.basicData.extra;
|
|
48
|
+
if (extra) {
|
|
49
|
+
if (extra[name] && extra[name] != "") {
|
|
50
|
+
return extra[name];
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return defaultValue;
|
|
54
|
+
}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
module.exports = modelTransformation;
|
|
2
|
+
|
|
3
|
+
var _metamodelProcessors = [];
|
|
4
|
+
|
|
5
|
+
function registerMetamodelProcessor(fn) {
|
|
6
|
+
_metamodelProcessors.push(fn);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function modelTransformation(input) {
|
|
10
|
+
if (input.data && input.data.basicData) return input;
|
|
11
|
+
|
|
12
|
+
let ret = {};
|
|
13
|
+
ret.features = input.features;
|
|
14
|
+
ret.data = {};
|
|
15
|
+
ret.data.basicData = basicData(input.basicData);
|
|
16
|
+
|
|
17
|
+
_metamodelProcessors.forEach(function(processor) {
|
|
18
|
+
processor(ret, input);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
ret.data.gui = gui(ret.features, input.basicData.name);
|
|
22
|
+
ret.data.menus = menus(ret);
|
|
23
|
+
ret.data.statics = statics(input.statics);
|
|
24
|
+
return ret;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function normalize(str, upper) {
|
|
28
|
+
return str
|
|
29
|
+
.normalize("NFKD")
|
|
30
|
+
.replace(/[\u0300-\u036F]/g, "")
|
|
31
|
+
.replace(/[-_]+/g, " ")
|
|
32
|
+
.replace(/[^\w\s]/gi, "")
|
|
33
|
+
.replace(/\s(.)/g, function ($1) {
|
|
34
|
+
return $1.toUpperCase();
|
|
35
|
+
})
|
|
36
|
+
.replace(/\s/g, "")
|
|
37
|
+
.replace(/^(.)/, function ($1) {
|
|
38
|
+
return upper ? $1.toUpperCase() : $1.toLowerCase();
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function basicData(input) {
|
|
43
|
+
return {
|
|
44
|
+
index: {
|
|
45
|
+
component: "STATIC",
|
|
46
|
+
view: "welcome",
|
|
47
|
+
},
|
|
48
|
+
languages: input.languages || [],
|
|
49
|
+
name: input.name,
|
|
50
|
+
packageInfo: {
|
|
51
|
+
artifact: normalize(input.name).toLowerCase(),
|
|
52
|
+
group: input.packageGroup || "com.example",
|
|
53
|
+
},
|
|
54
|
+
database: input.database,
|
|
55
|
+
extra: input.extra,
|
|
56
|
+
SRID: input.SRID,
|
|
57
|
+
version: input.version,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function gui(features, name) {
|
|
62
|
+
const ret = {
|
|
63
|
+
settings: {
|
|
64
|
+
font: { family: "Arial", size: "14px" },
|
|
65
|
+
colorset: ["#fff", "#eee", "#777", "#555", "#577492", "#333", "#222"],
|
|
66
|
+
header: { type: "Text", text: name },
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
if (features.indexOf("GUI_M_Top") !== -1) {
|
|
71
|
+
ret.design = "1";
|
|
72
|
+
} else if (features.indexOf("GUI_M_Left") !== -1) {
|
|
73
|
+
ret.design = "5";
|
|
74
|
+
} else if (features.indexOf("GUI_M_Right") !== -1) {
|
|
75
|
+
ret.design = "6";
|
|
76
|
+
} else {
|
|
77
|
+
ret.design = "4";
|
|
78
|
+
}
|
|
79
|
+
if (features.indexOf("GUI_M_Top") !== -1 && features.indexOf("GUI_M_Left") !== -1) {
|
|
80
|
+
ret.design = "2";
|
|
81
|
+
}
|
|
82
|
+
if (features.indexOf("GUI_M_Top") !== -1 && features.indexOf("GUI_M_Right") !== -1) {
|
|
83
|
+
ret.design = "3";
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return ret;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function statics(input) {
|
|
90
|
+
return input;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function menus(product) {
|
|
94
|
+
const ret = [];
|
|
95
|
+
|
|
96
|
+
switch (product.data.gui.design) {
|
|
97
|
+
case "1": ret.push({ id: "top", elements: [] }); break;
|
|
98
|
+
case "2": ret.push({ id: "top", elements: [] }); ret.push({ id: "left", elements: [] }); break;
|
|
99
|
+
case "3": ret.push({ id: "top", elements: [] }); ret.push({ id: "right", elements: [] }); break;
|
|
100
|
+
case "4": return [];
|
|
101
|
+
case "5": ret.push({ id: "left", elements: [] }); break;
|
|
102
|
+
case "6": ret.push({ id: "right", elements: [] }); break;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (product.data.lists && product.features.indexOf("GUI_Lists") !== -1) {
|
|
106
|
+
ret[0].elements.push(listMenu(product.data.lists));
|
|
107
|
+
}
|
|
108
|
+
ret[0].elements.push(listComponents(product.features));
|
|
109
|
+
|
|
110
|
+
if (product.features.indexOf("UserManagement") !== -1) {
|
|
111
|
+
ret[0].elements.push(listUserManagement(product.features));
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return ret;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function listMenu(lists) {
|
|
118
|
+
return {
|
|
119
|
+
id: "Lists",
|
|
120
|
+
type: "MENU",
|
|
121
|
+
elements: lists.map((l) => ({
|
|
122
|
+
id: l.id,
|
|
123
|
+
type: "VIEW",
|
|
124
|
+
view: { component: "LIST", view: l.id },
|
|
125
|
+
})),
|
|
126
|
+
access: { admin: true, logged: true },
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function listComponents(features) {
|
|
131
|
+
return {
|
|
132
|
+
id: "Components",
|
|
133
|
+
type: "MENU",
|
|
134
|
+
elements: features
|
|
135
|
+
.filter((f) => featureMenu(f, features))
|
|
136
|
+
.map((f) => featureMenu(f, features)),
|
|
137
|
+
access: { admin: true, logged: true },
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function featureMenu(feature, features) {
|
|
142
|
+
// Add cases for your platform's features here
|
|
143
|
+
// Example: case "MY_FEATURE": return view("MY_COMPONENT", "My View");
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function listUserManagement(features) {
|
|
148
|
+
const list = [];
|
|
149
|
+
let aux;
|
|
150
|
+
|
|
151
|
+
if (features.indexOf("UM_Authentication") !== -1) {
|
|
152
|
+
aux = view("USER_MANAGEMENT", "Sign in");
|
|
153
|
+
aux.access = { anonymous: true };
|
|
154
|
+
list.push(aux);
|
|
155
|
+
}
|
|
156
|
+
if (features.indexOf("UM_R_Anonymous") !== -1) {
|
|
157
|
+
aux = view("USER_MANAGEMENT", "Registration");
|
|
158
|
+
aux.access = { anonymous: true };
|
|
159
|
+
list.push(aux);
|
|
160
|
+
}
|
|
161
|
+
if (features.indexOf("UM_UP_ByUser") !== -1) {
|
|
162
|
+
aux = view("USER_MANAGEMENT", "Change password");
|
|
163
|
+
aux.access = { admin: true, logged: true };
|
|
164
|
+
list.push(aux);
|
|
165
|
+
}
|
|
166
|
+
if (features.indexOf("UM_UserProfile") !== -1) {
|
|
167
|
+
aux = view("USER_MANAGEMENT", "Profile details");
|
|
168
|
+
aux.access = { admin: true, logged: true };
|
|
169
|
+
list.push(aux);
|
|
170
|
+
}
|
|
171
|
+
if (features.indexOf("UM_UserSessions") !== -1) {
|
|
172
|
+
aux = view("USER_MANAGEMENT", "Sessions");
|
|
173
|
+
aux.access = { admin: true, logged: true };
|
|
174
|
+
list.push(aux);
|
|
175
|
+
}
|
|
176
|
+
if (features.indexOf("UM_UserCRUD") !== -1) {
|
|
177
|
+
aux = view("USER_MANAGEMENT", "User Management");
|
|
178
|
+
aux.access = { admin: true };
|
|
179
|
+
list.push(aux);
|
|
180
|
+
}
|
|
181
|
+
if (features.indexOf("UM_Authentication") !== -1) {
|
|
182
|
+
aux = view("USER_MANAGEMENT", "Exit");
|
|
183
|
+
aux.access = { admin: true, logged: true };
|
|
184
|
+
list.push(aux);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
return { id: "Account", type: "MENU", elements: list };
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function view(comp, view) {
|
|
191
|
+
return {
|
|
192
|
+
id: view,
|
|
193
|
+
type: "VIEW",
|
|
194
|
+
view: { component: comp, view: view },
|
|
195
|
+
};
|
|
196
|
+
}
|