@lbdudc/linea-core 0.1.0 → 0.1.2
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 +230 -358
- package/dist/analysis/analyze.d.ts +0 -54
- package/dist/analysis/analyze.js +1 -70
- package/dist/analysis/analyze.js.map +1 -1
- package/dist/analysis/runtime.d.ts +4 -73
- package/dist/analysis/runtime.js +7 -100
- package/dist/analysis/runtime.js.map +1 -1
- package/dist/analysis/uvl-text.d.ts +8 -0
- package/dist/analysis/uvl-text.js +70 -0
- package/dist/analysis/uvl-text.js.map +1 -0
- package/dist/assets.d.ts +0 -12
- package/dist/assets.js +0 -25
- package/dist/assets.js.map +1 -1
- package/dist/ci/annotations.d.ts +6 -0
- package/dist/ci/annotations.js +12 -0
- package/dist/ci/annotations.js.map +1 -0
- package/dist/ci/leftovers.d.ts +25 -0
- package/dist/ci/leftovers.js +50 -0
- package/dist/ci/leftovers.js.map +1 -0
- package/dist/ci/pairwise.d.ts +11 -0
- package/dist/ci/pairwise.js +35 -0
- package/dist/ci/pairwise.js.map +1 -0
- package/dist/ci/pipeline.d.ts +18 -0
- package/dist/ci/pipeline.js +26 -0
- package/dist/ci/pipeline.js.map +1 -0
- package/dist/ci/select.d.ts +28 -0
- package/dist/ci/select.js +43 -0
- package/dist/ci/select.js.map +1 -0
- package/dist/ci/validate-specs.d.ts +52 -0
- package/dist/ci/validate-specs.js +212 -0
- package/dist/ci/validate-specs.js.map +1 -0
- package/dist/constants.d.ts +1 -60
- package/dist/constants.js +1 -58
- package/dist/constants.js.map +1 -1
- package/dist/derivation/derive.d.ts +0 -56
- package/dist/derivation/derive.js +21 -72
- package/dist/derivation/derive.js.map +1 -1
- package/dist/derivation/engine.d.ts +10 -42
- package/dist/derivation/engine.js +37 -68
- package/dist/derivation/engine.js.map +1 -1
- package/dist/derivation/selection-error.d.ts +7 -0
- package/dist/derivation/selection-error.js +13 -0
- package/dist/derivation/selection-error.js.map +1 -0
- package/dist/errors.d.ts +19 -47
- package/dist/errors.js +28 -47
- package/dist/errors.js.map +1 -1
- package/dist/feature-model/uvl.d.ts +52 -0
- package/dist/feature-model/uvl.js +191 -0
- package/dist/feature-model/uvl.js.map +1 -0
- package/dist/fs/archive.d.ts +0 -16
- package/dist/fs/archive.js +0 -36
- package/dist/fs/archive.js.map +1 -1
- package/dist/fs/diff.d.ts +0 -30
- package/dist/fs/diff.js +4 -65
- package/dist/fs/diff.js.map +1 -1
- package/dist/fs/format.d.ts +0 -16
- package/dist/fs/format.js +0 -52
- package/dist/fs/format.js.map +1 -1
- package/dist/fs/workspace.d.ts +0 -52
- package/dist/fs/workspace.js +0 -56
- package/dist/fs/workspace.js.map +1 -1
- package/dist/index.d.ts +23 -29
- package/dist/index.js +15 -35
- package/dist/index.js.map +1 -1
- package/dist/internal/guards.d.ts +0 -13
- package/dist/internal/guards.js +0 -13
- package/dist/internal/guards.js.map +1 -1
- package/dist/line/deletion.d.ts +33 -0
- package/dist/line/deletion.js +23 -0
- package/dist/line/deletion.js.map +1 -0
- package/dist/line/platform-files.d.ts +15 -64
- package/dist/line/platform-files.js +18 -94
- package/dist/line/platform-files.js.map +1 -1
- package/dist/line/restoration.d.ts +27 -0
- package/dist/line/restoration.js +27 -0
- package/dist/line/restoration.js.map +1 -0
- package/dist/line/scaffold.d.ts +26 -57
- package/dist/line/scaffold.js +32 -93
- package/dist/line/scaffold.js.map +1 -1
- package/dist/line/templates/core/extra.js +54 -54
- package/dist/line/templates/core/transformation.js +208 -196
- package/dist/line/templates/pipeline/.gitlab-ci.yml +51 -51
- package/dist/line/templates/pipeline/ci/test-client.sh +16 -16
- package/dist/line/templates/pipeline/ci/test-server.sh +16 -16
- package/dist/line/templates/pipeline/github-ci.yml +50 -0
- package/dist/line/templates/pipeline/spl-gitlab-ci.yml +182 -0
- package/dist/modules/configuration/configure.d.ts +52 -0
- package/dist/modules/configuration/configure.js +101 -0
- package/dist/modules/configuration/configure.js.map +1 -0
- package/dist/modules/configuration/constants.d.ts +17 -0
- package/dist/modules/configuration/constants.js +14 -0
- package/dist/modules/configuration/constants.js.map +1 -0
- package/dist/modules/configuration/index.d.ts +6 -0
- package/dist/modules/configuration/index.js +5 -0
- package/dist/modules/configuration/index.js.map +1 -0
- package/dist/modules/configuration/names.d.ts +9 -0
- package/dist/modules/configuration/names.js +7 -0
- package/dist/modules/configuration/names.js.map +1 -0
- package/dist/modules/configuration/selection.d.ts +32 -0
- package/dist/modules/configuration/selection.js +49 -0
- package/dist/modules/configuration/selection.js.map +1 -0
- package/dist/modules/diagnostics.d.ts +2 -0
- package/dist/modules/diagnostics.js +2 -0
- package/dist/modules/diagnostics.js.map +1 -0
- package/dist/modules/index.d.ts +18 -0
- package/dist/modules/index.js +18 -0
- package/dist/modules/index.js.map +1 -0
- package/dist/modules/metamodels/engine.d.ts +93 -0
- package/dist/modules/metamodels/engine.js +10 -0
- package/dist/modules/metamodels/engine.js.map +1 -0
- package/dist/modules/metamodels/files.d.ts +40 -0
- package/dist/modules/metamodels/files.js +58 -0
- package/dist/modules/metamodels/files.js.map +1 -0
- package/dist/modules/metamodels/index.d.ts +8 -0
- package/dist/modules/metamodels/index.js +5 -0
- package/dist/modules/metamodels/index.js.map +1 -0
- package/dist/modules/metamodels/layout.d.ts +23 -0
- package/dist/modules/metamodels/layout.js +29 -0
- package/dist/modules/metamodels/layout.js.map +1 -0
- package/dist/modules/metamodels/offered.d.ts +15 -0
- package/dist/modules/metamodels/offered.js +14 -0
- package/dist/modules/metamodels/offered.js.map +1 -0
- package/dist/modules/metamodels/prepare.d.ts +20 -0
- package/dist/modules/metamodels/prepare.js +155 -0
- package/dist/modules/metamodels/prepare.js.map +1 -0
- package/dist/modules/packages/index.d.ts +4 -0
- package/dist/modules/packages/index.js +4 -0
- package/dist/modules/packages/index.js.map +1 -0
- package/dist/modules/packages/location.d.ts +21 -0
- package/dist/modules/packages/location.js +34 -0
- package/dist/modules/packages/location.js.map +1 -0
- package/dist/modules/packages/manifests.d.ts +33 -0
- package/dist/modules/packages/manifests.js +231 -0
- package/dist/modules/packages/manifests.js.map +1 -0
- package/dist/modules/packages/source.d.ts +34 -0
- package/dist/modules/packages/source.js +128 -0
- package/dist/modules/packages/source.js.map +1 -0
- package/dist/modules/products/check.d.ts +28 -0
- package/dist/modules/products/check.js +61 -0
- package/dist/modules/products/check.js.map +1 -0
- package/dist/modules/products/derive.d.ts +30 -0
- package/dist/modules/products/derive.js +56 -0
- package/dist/modules/products/derive.js.map +1 -0
- package/dist/modules/products/index.d.ts +5 -0
- package/dist/modules/products/index.js +4 -0
- package/dist/modules/products/index.js.map +1 -0
- package/dist/modules/products/seed.d.ts +18 -0
- package/dist/modules/products/seed.js +23 -0
- package/dist/modules/products/seed.js.map +1 -0
- package/dist/modules/registry/catalog.d.ts +64 -0
- package/dist/modules/registry/catalog.js +91 -0
- package/dist/modules/registry/catalog.js.map +1 -0
- package/dist/modules/registry/index.d.ts +5 -0
- package/dist/modules/registry/index.js +4 -0
- package/dist/modules/registry/index.js.map +1 -0
- package/dist/modules/registry/registry.d.ts +34 -0
- package/dist/modules/registry/registry.js +37 -0
- package/dist/modules/registry/registry.js.map +1 -0
- package/dist/modules/registry/routing.d.ts +8 -0
- package/dist/modules/registry/routing.js +23 -0
- package/dist/modules/registry/routing.js.map +1 -0
- package/dist/modules/resolution/closure.d.ts +28 -0
- package/dist/modules/resolution/closure.js +105 -0
- package/dist/modules/resolution/closure.js.map +1 -0
- package/dist/modules/resolution/index.d.ts +4 -0
- package/dist/modules/resolution/index.js +3 -0
- package/dist/modules/resolution/index.js.map +1 -0
- package/dist/modules/resolution/resolve.d.ts +33 -0
- package/dist/modules/resolution/resolve.js +59 -0
- package/dist/modules/resolution/resolve.js.map +1 -0
- package/dist/modules/resolution/resolvers.d.ts +23 -0
- package/dist/modules/resolution/resolvers.js +34 -0
- package/dist/modules/resolution/resolvers.js.map +1 -0
- package/dist/modules/spl/check.d.ts +25 -0
- package/dist/modules/spl/check.js +21 -0
- package/dist/modules/spl/check.js.map +1 -0
- package/dist/modules/spl/cip.d.ts +67 -0
- package/dist/modules/spl/cip.js +98 -0
- package/dist/modules/spl/cip.js.map +1 -0
- package/dist/modules/spl/feature-model.d.ts +39 -0
- package/dist/modules/spl/feature-model.js +106 -0
- package/dist/modules/spl/feature-model.js.map +1 -0
- package/dist/modules/spl/index.d.ts +6 -0
- package/dist/modules/spl/index.js +4 -0
- package/dist/modules/spl/index.js.map +1 -0
- package/dist/modules/spl/platform.d.ts +49 -0
- package/dist/modules/spl/platform.js +316 -0
- package/dist/modules/spl/platform.js.map +1 -0
- package/dist/modules/types.d.ts +132 -0
- package/dist/modules/types.js +2 -0
- package/dist/modules/types.js.map +1 -0
- package/dist/product/engine-spec.d.ts +0 -16
- package/dist/product/engine-spec.js +4 -50
- package/dist/product/engine-spec.js.map +1 -1
- package/dist/product/spec.d.ts +0 -82
- package/dist/product/spec.js +0 -79
- package/dist/product/spec.js.map +1 -1
- package/dist/product/version.d.ts +0 -23
- package/dist/product/version.js +0 -28
- package/dist/product/version.js.map +1 -1
- package/dist/products-index/products-index.d.ts +0 -165
- package/dist/products-index/products-index.js +0 -176
- package/dist/products-index/products-index.js.map +1 -1
- package/dist/workspace/context.d.ts +25 -0
- package/dist/workspace/context.js +43 -0
- package/dist/workspace/context.js.map +1 -0
- package/dist/workspace/gitExclude.d.ts +2 -0
- package/dist/workspace/gitExclude.js +19 -0
- package/dist/workspace/gitExclude.js.map +1 -0
- package/dist/workspace/host.d.ts +14 -0
- package/dist/workspace/host.js +13 -0
- package/dist/workspace/host.js.map +1 -0
- package/dist/workspace/index.d.ts +12 -0
- package/dist/workspace/index.js +12 -0
- package/dist/workspace/index.js.map +1 -0
- package/dist/workspace/local.d.ts +81 -0
- package/dist/workspace/local.js +287 -0
- package/dist/workspace/local.js.map +1 -0
- package/dist/workspace/modular.d.ts +95 -0
- package/dist/workspace/modular.js +301 -0
- package/dist/workspace/modular.js.map +1 -0
- package/dist/workspace/operations.d.ts +35 -0
- package/dist/workspace/operations.js +57 -0
- package/dist/workspace/operations.js.map +1 -0
- package/dist/workspace/origin.d.ts +20 -0
- package/dist/workspace/origin.js +19 -0
- package/dist/workspace/origin.js.map +1 -0
- package/package.json +82 -67
- package/dist/feature-model/convert.d.ts +0 -35
- package/dist/feature-model/convert.js +0 -47
- package/dist/feature-model/convert.js.map +0 -1
- package/dist/feature-model/engine.d.ts +0 -60
- package/dist/feature-model/engine.js +0 -139
- package/dist/feature-model/engine.js.map +0 -1
- package/dist/feature-model/inspect.d.ts +0 -67
- package/dist/feature-model/inspect.js +0 -113
- package/dist/feature-model/inspect.js.map +0 -1
- package/dist/feature-model/io.d.ts +0 -66
- package/dist/feature-model/io.js +0 -92
- package/dist/feature-model/io.js.map +0 -1
- package/dist/feature-model/parse.d.ts +0 -30
- package/dist/feature-model/parse.js +0 -36
- package/dist/feature-model/parse.js.map +0 -1
- package/dist/feature-model/text.d.ts +0 -54
- package/dist/feature-model/text.js +0 -126
- package/dist/feature-model/text.js.map +0 -1
- package/dist/line/templates/metamodels/dataModel/extra.js +0 -328
- package/dist/line/templates/metamodels/dataModel/transformation.js +0 -211
- package/dist/line/templates/metamodels/sensor/extra.js +0 -36
- package/dist/line/templates/metamodels/sensor/transformation.js +0 -47
- package/dist/selection/selection.d.ts +0 -126
- package/dist/selection/selection.js +0 -152
- package/dist/selection/selection.js.map +0 -1
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { NAME_PATTERN } from '../constants.js';
|
|
4
|
+
import { LineaCoreError, ModuleCheckError, InvalidArgumentError } from '../errors.js';
|
|
5
|
+
import { writeTextFile } from '../fs/workspace.js';
|
|
6
|
+
import {} from '../modules/metamodels/engine.js';
|
|
7
|
+
import { metamodelPath } from '../modules/metamodels/layout.js';
|
|
8
|
+
import { listOfferedModels } from '../modules/metamodels/offered.js';
|
|
9
|
+
import { LOCK_PATH, METAMODEL_MANIFEST_PATH, MODULE_MANIFEST_PATH, SPL_MANIFEST_PATH, parseLock, parseMetamodelManifest, parseModuleManifest, parseSplManifest, serializeLock, serializeSplManifest } from '../modules/packages/manifests.js';
|
|
10
|
+
import { createFsFiles, createFsPackageSource, createMemoryPackageSource, withOverlay } from '../modules/packages/source.js';
|
|
11
|
+
import { checkProduct } from '../modules/products/check.js';
|
|
12
|
+
import { deriveModularProduct, deriveModularProductToZip } from '../modules/products/derive.js';
|
|
13
|
+
import { seedProductModels } from '../modules/products/seed.js';
|
|
14
|
+
import { resolveSpl } from '../modules/resolution/resolve.js';
|
|
15
|
+
import { checkSpl } from '../modules/spl/check.js';
|
|
16
|
+
import {} from '../modules/types.js';
|
|
17
|
+
import {} from '../product/spec.js';
|
|
18
|
+
import { excludeFromGit } from './gitExclude.js';
|
|
19
|
+
import { createEngine, packageSourceOf } from './host.js';
|
|
20
|
+
import { createLocalLine, COMPOSED_MODEL_PATH } from './local.js';
|
|
21
|
+
import { rootFeatureName } from '../modules/configuration/names.js';
|
|
22
|
+
/**
|
|
23
|
+
* LOCAL mode of a line made of modules. A workspace holds `modules/<name>/` and `metamodels/<name>/` next to the lines; a package
|
|
24
|
+
* is a folder with one version (the one its manifest declares), located as `file:modules/<name>`. A product keeps its models in
|
|
25
|
+
* `<product>/models/<metamodel>.<extension>`.
|
|
26
|
+
*/
|
|
27
|
+
const DIRS = { module: 'modules', metamodel: 'metamodels' };
|
|
28
|
+
const MANIFESTS = { module: MODULE_MANIFEST_PATH, metamodel: METAMODEL_MANIFEST_PATH };
|
|
29
|
+
export const locationOf = (kind, name) => `file:${DIRS[kind]}/${name}`;
|
|
30
|
+
/** A line made of modules: its `spl.json` says so (every line has one: the kind of SPL it is, and what it is made of). */
|
|
31
|
+
export function isModularLine(lineDir) {
|
|
32
|
+
try {
|
|
33
|
+
return parseSplManifest({ content: fs.readFileSync(path.join(lineDir, SPL_MANIFEST_PATH), 'utf8') }).kind === 'modular';
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
export function listLocalPackages(workdir) {
|
|
40
|
+
const found = [];
|
|
41
|
+
for (const kind of ['module', 'metamodel']) {
|
|
42
|
+
const root = path.join(workdir, DIRS[kind]);
|
|
43
|
+
let entries;
|
|
44
|
+
try {
|
|
45
|
+
entries = fs.readdirSync(root, { withFileTypes: true });
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
for (const entry of entries.filter((e) => e.isDirectory()).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
51
|
+
const dir = path.join(root, entry.name);
|
|
52
|
+
try {
|
|
53
|
+
const content = fs.readFileSync(path.join(dir, MANIFESTS[kind]), 'utf8');
|
|
54
|
+
const manifest = kind === 'module' ? parseModuleManifest({ content }) : parseMetamodelManifest({ content });
|
|
55
|
+
found.push({
|
|
56
|
+
kind,
|
|
57
|
+
name: entry.name,
|
|
58
|
+
version: manifest.version,
|
|
59
|
+
location: locationOf(kind, entry.name),
|
|
60
|
+
dir,
|
|
61
|
+
description: manifest.description ?? '',
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
// a folder that is not a (valid) package is not listed
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return found;
|
|
70
|
+
}
|
|
71
|
+
export function createLocalPackage(opts) {
|
|
72
|
+
const { workdir, kind, name, description } = opts;
|
|
73
|
+
if (!NAME_PATTERN.test(name))
|
|
74
|
+
throw new InvalidArgumentError(`"${name}" is not a valid name: use letters, digits, "_", "-" and "." only.`);
|
|
75
|
+
const dir = path.join(workdir, DIRS[kind], name);
|
|
76
|
+
if (fs.existsSync(dir) && fs.readdirSync(dir).length > 0)
|
|
77
|
+
throw new InvalidArgumentError(`"${dir}" already exists and is not empty.`);
|
|
78
|
+
const manifest = kind === 'module'
|
|
79
|
+
? { name, version: '0.1.0', ...(description ? { description } : {}), requires: { modules: {}, metamodels: {} }, offers: {} }
|
|
80
|
+
: { name, version: '0.1.0', ...(description ? { description } : {}), requires: {} };
|
|
81
|
+
writeTextFile({ filePath: path.join(dir, MANIFESTS[kind]), content: `${JSON.stringify(manifest, null, 2)}\n` });
|
|
82
|
+
if (kind === 'module') {
|
|
83
|
+
writeTextFile({ filePath: path.join(dir, '.linea', 'model.uvl'), content: `features\n\t${rootFeatureName({ name, fallback: 'Root' })}\n` });
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
const rule = rootFeatureName({ name, fallback: 'Root' });
|
|
87
|
+
writeTextFile({
|
|
88
|
+
filePath: path.join(dir, metamodelPath({ kind: 'grammar', grammar: name })),
|
|
89
|
+
content: [
|
|
90
|
+
`grammar ${rule}`,
|
|
91
|
+
'',
|
|
92
|
+
`// ${description ?? `${rule}: describe what this metamodel models`}`,
|
|
93
|
+
`entry ${rule}Model: '${name.toLowerCase()}' name=ID? (items+=Item)*;`,
|
|
94
|
+
'',
|
|
95
|
+
"Item: 'item' name=ID;",
|
|
96
|
+
'',
|
|
97
|
+
'terminal ID: /[_a-zA-Z][\\w_-]*/;',
|
|
98
|
+
'hidden terminal WS: /\\s+/;',
|
|
99
|
+
'',
|
|
100
|
+
].join('\n'),
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
return { kind, name, version: '0.1.0', location: locationOf(kind, name), dir, description: description ?? '' };
|
|
104
|
+
}
|
|
105
|
+
export function createLocalModularLine(opts) {
|
|
106
|
+
return createLocalLine({ workdir: opts.workdir, name: opts.name, kind: 'modular' });
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* The feature model the modules of a line compose, kept in the line folder so the plain (synchronous) product operations can validate
|
|
110
|
+
* a feature selection against it. It is refreshed whenever the modules are set or checked; generating always composes anew.
|
|
111
|
+
*/
|
|
112
|
+
function cacheComposedModel(lineDir, featureModel) {
|
|
113
|
+
if (!featureModel)
|
|
114
|
+
return;
|
|
115
|
+
writeTextFile({ filePath: path.join(lineDir, COMPOSED_MODEL_PATH), content: featureModel });
|
|
116
|
+
// a cache of this machine, not part of the SPL: a clone of it must not send it with its changes
|
|
117
|
+
excludeFromGit(lineDir, '.linea/composed-model.uvl');
|
|
118
|
+
}
|
|
119
|
+
function readSpl(lineDir) {
|
|
120
|
+
const splPath = path.join(lineDir, SPL_MANIFEST_PATH);
|
|
121
|
+
if (!fs.existsSync(splPath))
|
|
122
|
+
throw new InvalidArgumentError(`"${lineDir}" is not a line made of modules (no ${SPL_MANIFEST_PATH}).`);
|
|
123
|
+
const spl = parseSplManifest({ content: fs.readFileSync(splPath, 'utf8') });
|
|
124
|
+
const lockPath = path.join(lineDir, LOCK_PATH);
|
|
125
|
+
let lock;
|
|
126
|
+
try {
|
|
127
|
+
lock = fs.existsSync(lockPath) ? parseLock({ content: fs.readFileSync(lockPath, 'utf8') }) : undefined;
|
|
128
|
+
}
|
|
129
|
+
catch {
|
|
130
|
+
lock = undefined; // a lock that cannot be read is made again
|
|
131
|
+
}
|
|
132
|
+
return { spl, lock };
|
|
133
|
+
}
|
|
134
|
+
/** The packages of a line, resolved against the workspace (and pinned by the line's lockfile where it still fits). */
|
|
135
|
+
async function resolveLocalContext(workdir, lineDir, modules) {
|
|
136
|
+
const { spl: saved, lock } = readSpl(lineDir);
|
|
137
|
+
const spl = modules ? { ...saved, modules } : saved;
|
|
138
|
+
const resolved = await resolveSpl({ spl, source: packageSourceOf(createFsPackageSource({ root: workdir })), lock });
|
|
139
|
+
return { resolved, spl, files: createFsFiles({ dir: lineDir }) };
|
|
140
|
+
}
|
|
141
|
+
export async function getLocalLineModules(workdir, lineDir) {
|
|
142
|
+
const { resolved, spl } = await resolveLocalContext(workdir, lineDir);
|
|
143
|
+
return {
|
|
144
|
+
modules: { ...spl.modules },
|
|
145
|
+
packages: [...resolved.modules, ...resolved.metamodels].map((p) => ({
|
|
146
|
+
kind: p.kind,
|
|
147
|
+
name: p.manifest.name,
|
|
148
|
+
version: p.version,
|
|
149
|
+
location: p.location,
|
|
150
|
+
requiredBy: p.requiredBy,
|
|
151
|
+
})),
|
|
152
|
+
featureModelName: spl.name,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
export async function checkLocalLine(workdir, lineDir, modules) {
|
|
156
|
+
const { resolved, files } = await resolveLocalContext(workdir, lineDir, modules);
|
|
157
|
+
const report = await checkSpl({ resolved, spl: files, createEngine });
|
|
158
|
+
if (!modules && report.featureModel)
|
|
159
|
+
cacheComposedModel(lineDir, report.featureModel);
|
|
160
|
+
return { resolved, report };
|
|
161
|
+
}
|
|
162
|
+
/** Sets the modules of a line: resolves and checks them, and writes `spl.json` and the lockfile. Throws `ModuleCheckError` when they do not fit. */
|
|
163
|
+
export async function setLocalLineModules(workdir, lineDir, modules) {
|
|
164
|
+
const { resolved, report } = await checkLocalLine(workdir, lineDir, modules);
|
|
165
|
+
if (!report.ok)
|
|
166
|
+
throw new ModuleCheckError(`The modules do not fit together`, report.diagnostics);
|
|
167
|
+
const { spl } = readSpl(lineDir);
|
|
168
|
+
writeTextFile({ filePath: path.join(lineDir, SPL_MANIFEST_PATH), content: serializeSplManifest({ spl: { ...spl, modules } }) });
|
|
169
|
+
writeTextFile({ filePath: path.join(lineDir, LOCK_PATH), content: serializeLock({ lock: resolved.lock }) });
|
|
170
|
+
cacheComposedModel(lineDir, report.featureModel);
|
|
171
|
+
return { resolved, report };
|
|
172
|
+
}
|
|
173
|
+
// ---------------------------------------------------------------- products
|
|
174
|
+
const MODELS_DIR = path.join('.linea', 'models');
|
|
175
|
+
export function readLocalProductModels(productDir) {
|
|
176
|
+
const dir = path.join(productDir, MODELS_DIR);
|
|
177
|
+
const models = {};
|
|
178
|
+
try {
|
|
179
|
+
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
180
|
+
if (entry.isFile())
|
|
181
|
+
models[entry.name.replace(/\.[^.]+$/, '')] = fs.readFileSync(path.join(dir, entry.name), 'utf8');
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
catch {
|
|
185
|
+
// no models yet
|
|
186
|
+
}
|
|
187
|
+
return models;
|
|
188
|
+
}
|
|
189
|
+
export async function checkLocalProductModels(workdir, lineDir, productDir) {
|
|
190
|
+
const { resolved, files } = await resolveLocalContext(workdir, lineDir);
|
|
191
|
+
const models = readLocalProductModels(productDir);
|
|
192
|
+
const report = await checkProduct({ resolved, spl: files, models, createEngine });
|
|
193
|
+
return {
|
|
194
|
+
metamodels: report.metamodels,
|
|
195
|
+
models,
|
|
196
|
+
offered: await listOfferedModels({ resolved }),
|
|
197
|
+
diagnostics: report.diagnostics,
|
|
198
|
+
ok: report.ok,
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
/** Writes the smallest valid model of each metamodel into a new product of a modular line (does nothing for a plain line). */
|
|
202
|
+
export async function seedLocalProductModels(workdir, lineDir, productDir) {
|
|
203
|
+
const { resolved, files } = await resolveLocalContext(workdir, lineDir);
|
|
204
|
+
const seeded = await seedProductModels({ resolved, spl: files, createEngine });
|
|
205
|
+
const written = [];
|
|
206
|
+
for (const info of seeded.metamodels) {
|
|
207
|
+
const file = path.join(productDir, MODELS_DIR, `${info.name}.${info.extension}`);
|
|
208
|
+
writeTextFile({ filePath: file, content: seeded.models[info.name] ?? '' });
|
|
209
|
+
written.push(path.relative(productDir, file));
|
|
210
|
+
}
|
|
211
|
+
return written;
|
|
212
|
+
}
|
|
213
|
+
export async function deriveLocalModularProduct(workdir, lineDir, productDir, spec, outputDir = productDir) {
|
|
214
|
+
const { resolved, files } = await resolveLocalContext(workdir, lineDir);
|
|
215
|
+
return deriveModularProduct({
|
|
216
|
+
resolved,
|
|
217
|
+
spl: files,
|
|
218
|
+
spec,
|
|
219
|
+
models: readLocalProductModels(productDir),
|
|
220
|
+
createEngine,
|
|
221
|
+
outputDir,
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
export async function deriveLocalModularProductZip(workdir, lineDir, productDir, spec) {
|
|
225
|
+
const { resolved, files } = await resolveLocalContext(workdir, lineDir);
|
|
226
|
+
return deriveModularProductToZip({
|
|
227
|
+
resolved,
|
|
228
|
+
spl: files,
|
|
229
|
+
spec,
|
|
230
|
+
models: readLocalProductModels(productDir),
|
|
231
|
+
createEngine,
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
// ---------------------------------------------------------------- one package
|
|
235
|
+
const CHECK_LOCATION = 'memory:check';
|
|
236
|
+
/**
|
|
237
|
+
* Checks a package of the workspace on its own, as the registry does before it publishes it: what it needs is resolved, and everything
|
|
238
|
+
* is composed. A metamodel is only ever used through a module, so it is checked through one made up for the purpose.
|
|
239
|
+
*/
|
|
240
|
+
export async function checkLocalPackage(workdir, kind, name) {
|
|
241
|
+
const location = locationOf(kind, name);
|
|
242
|
+
const pkg = listLocalPackages(workdir).find((p) => p.kind === kind && p.name === name);
|
|
243
|
+
if (!pkg)
|
|
244
|
+
throw new InvalidArgumentError(`No ${kind} "${name}" in ${path.join(workdir, DIRS[kind])}`);
|
|
245
|
+
let source = packageSourceOf(createFsPackageSource({ root: workdir }));
|
|
246
|
+
let spl = { name: 'check', version: '0.0.0', kind: 'modular', metamodels: {}, modules: { [location]: `^${pkg.version}` } };
|
|
247
|
+
if (kind === 'metamodel') {
|
|
248
|
+
const overlay = createMemoryPackageSource({
|
|
249
|
+
packages: {
|
|
250
|
+
[CHECK_LOCATION]: {
|
|
251
|
+
'0.0.0': { '.linea/module.json': JSON.stringify({ name: 'check', version: '0.0.0', requires: { metamodels: { [location]: `^${pkg.version}` } } }) },
|
|
252
|
+
},
|
|
253
|
+
},
|
|
254
|
+
});
|
|
255
|
+
source = withOverlay({ base: source, overlay, locations: new Set([CHECK_LOCATION]) });
|
|
256
|
+
spl = { name: 'check', version: '0.0.0', kind: 'modular', metamodels: {}, modules: { [CHECK_LOCATION]: '0.0.0' } };
|
|
257
|
+
}
|
|
258
|
+
try {
|
|
259
|
+
const resolved = await resolveSpl({ spl, source });
|
|
260
|
+
const report = await checkSpl({ resolved, createEngine, configuration: false });
|
|
261
|
+
return { ok: report.ok, diagnostics: report.diagnostics, resolved: { modules: resolved.modules.length, metamodels: resolved.metamodels.length } };
|
|
262
|
+
}
|
|
263
|
+
catch (e) {
|
|
264
|
+
if (e instanceof ModuleCheckError)
|
|
265
|
+
return { ok: false, diagnostics: e.diagnostics, resolved: { modules: 0, metamodels: 0 } };
|
|
266
|
+
if (!(e instanceof LineaCoreError))
|
|
267
|
+
throw e;
|
|
268
|
+
return { ok: false, diagnostics: [{ severity: 'error', package: location, message: e.message }], resolved: { modules: 0, metamodels: 0 } };
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Takes the newest versions the ranges of an SPL allow, and pins them: the lockfile is made again (for one module and what it brought,
|
|
273
|
+
* with `only`). Nothing is written when the result does not check out. Returns what changed.
|
|
274
|
+
*/
|
|
275
|
+
export async function updateLocalLineLock(workdir, lineDir, only) {
|
|
276
|
+
const { spl, lock } = readSpl(lineDir);
|
|
277
|
+
let keep;
|
|
278
|
+
if (only && lock) {
|
|
279
|
+
const matches = (location) => location === only || location === locationOf('module', only) || location.endsWith(`/${only}`) || location.endsWith(`:${only}`);
|
|
280
|
+
if (!Object.keys(lock.packages).some(matches))
|
|
281
|
+
throw new InvalidArgumentError(`"${only}" is not in the lockfile of this SPL`);
|
|
282
|
+
keep = { ...lock, packages: Object.fromEntries(Object.entries(lock.packages).filter(([location]) => !matches(location))) };
|
|
283
|
+
}
|
|
284
|
+
const resolved = await resolveSpl({ spl, source: packageSourceOf(createFsPackageSource({ root: workdir })), lock: keep });
|
|
285
|
+
const report = await checkSpl({ resolved, spl: createFsFiles({ dir: lineDir }), createEngine });
|
|
286
|
+
if (!report.ok)
|
|
287
|
+
throw new ModuleCheckError('The newest versions do not fit together', report.diagnostics);
|
|
288
|
+
const before = lock?.packages ?? {};
|
|
289
|
+
const after = resolved.lock.packages;
|
|
290
|
+
const changes = [];
|
|
291
|
+
for (const location of [...new Set([...Object.keys(before), ...Object.keys(after)])].sort()) {
|
|
292
|
+
const from = before[location]?.version;
|
|
293
|
+
const to = after[location]?.version;
|
|
294
|
+
if (from !== to)
|
|
295
|
+
changes.push({ location, ...(from ? { from } : {}), ...(to ? { to } : {}) });
|
|
296
|
+
}
|
|
297
|
+
writeTextFile({ filePath: path.join(lineDir, LOCK_PATH), content: serializeLock({ lock: resolved.lock }) });
|
|
298
|
+
cacheComposedModel(lineDir, report.featureModel);
|
|
299
|
+
return { changes, resolved };
|
|
300
|
+
}
|
|
301
|
+
//# sourceMappingURL=modular.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"modular.js","sourceRoot":"","sources":["../../src/workspace/modular.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC9C,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AACrF,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAsB,MAAM,iCAAiC,CAAA;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAA;AAC/D,OAAO,EAAE,iBAAiB,EAAqB,MAAM,kCAAkC,CAAA;AACvF,OAAO,EAAE,SAAS,EAAE,uBAAuB,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,SAAS,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAA;AAC7O,OAAO,EAAE,aAAa,EAAE,qBAAqB,EAAE,yBAAyB,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAA;AAC5H,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAA;AAC3D,OAAO,EAAE,oBAAoB,EAAE,yBAAyB,EAAE,MAAM,+BAA+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,EAAE,OAAO,CAAA;QACtC,MAAM,EAAE,GAAG,KAAK,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;QACnC,IAAI,IAAI,KAAK,EAAE;YAAE,OAAO,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAA;IAC/F,CAAC;IACD,aAAa,CAAC,EAAE,QAAQ,EAAE,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,SAAS,CAAC,EAAE,OAAO,EAAE,aAAa,CAAC,EAAE,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,CAAA;IAC3G,kBAAkB,CAAC,OAAO,EAAE,MAAM,CAAC,YAAY,CAAC,CAAA;IAChD,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAA;AAC9B,CAAC","sourcesContent":["import fs from 'node:fs'\nimport path from 'node:path'\nimport { NAME_PATTERN } from '../constants.js'\nimport { LineaCoreError, ModuleCheckError, InvalidArgumentError } from '../errors.js'\nimport { writeTextFile } from '../fs/workspace.js'\nimport { type MetamodelInfo } from '../modules/metamodels/engine.js'\nimport { metamodelPath } from '../modules/metamodels/layout.js'\nimport { listOfferedModels, type OfferedModel } from '../modules/metamodels/offered.js'\nimport { LOCK_PATH, METAMODEL_MANIFEST_PATH, MODULE_MANIFEST_PATH, SPL_MANIFEST_PATH, parseLock, parseMetamodelManifest, parseModuleManifest, parseSplManifest, serializeLock, serializeSplManifest } from '../modules/packages/manifests.js'\nimport { createFsFiles, createFsPackageSource, createMemoryPackageSource, withOverlay } from '../modules/packages/source.js'\nimport { checkProduct } from '../modules/products/check.js'\nimport { deriveModularProduct, deriveModularProductToZip } from '../modules/products/derive.js'\nimport { seedProductModels } from '../modules/products/seed.js'\nimport { resolveSpl } from '../modules/resolution/resolve.js'\nimport { checkSpl } from '../modules/spl/check.js'\nimport { type PackageKind, type Diagnostic, type Lock, type PackageFiles, type PackageSource, type ResolvedSpl, type SplManifest } from '../modules/types.js'\nimport { type ProductSpec } from '../product/spec.js'\nimport { excludeFromGit } from './gitExclude.js'\nimport { createEngine, packageSourceOf } from './host.js'\nimport { createLocalLine, COMPOSED_MODEL_PATH, type LocalLine } from './local.js'\nimport { rootFeatureName } from '../modules/configuration/names.js'\n\n/**\n * LOCAL mode of a line made of modules. A workspace holds `modules/<name>/` and `metamodels/<name>/` next to the lines; a package\n * is a folder with one version (the one its manifest declares), located as `file:modules/<name>`. A product keeps its models in\n * `<product>/models/<metamodel>.<extension>`.\n */\n\n\nconst DIRS: Record<PackageKind, string> = { module: 'modules', metamodel: 'metamodels' }\nconst MANIFESTS: Record<PackageKind, string> = { module: MODULE_MANIFEST_PATH, metamodel: METAMODEL_MANIFEST_PATH }\n\nexport interface LocalPackage {\n kind: PackageKind\n name: string\n version: string\n location: string\n dir: string\n description: string\n}\n\nexport const locationOf = (kind: PackageKind, name: string): string => `file:${DIRS[kind]}/${name}`\n\n/** A line made of modules: its `spl.json` says so (every line has one: the kind of SPL it is, and what it is made of). */\nexport function isModularLine(lineDir: string): boolean {\n try {\n return parseSplManifest({ content: fs.readFileSync(path.join(lineDir, SPL_MANIFEST_PATH), 'utf8') }).kind === 'modular'\n } catch {\n return false\n }\n}\n\nexport function listLocalPackages(workdir: string): LocalPackage[] {\n const found: LocalPackage[] = []\n for (const kind of ['module', 'metamodel'] as const) {\n const root = path.join(workdir, DIRS[kind])\n let entries: fs.Dirent[]\n try {\n entries = fs.readdirSync(root, { withFileTypes: true })\n } catch {\n continue\n }\n for (const entry of entries.filter((e) => e.isDirectory()).sort((a, b) => a.name.localeCompare(b.name))) {\n const dir = path.join(root, entry.name)\n try {\n const content = fs.readFileSync(path.join(dir, MANIFESTS[kind]), 'utf8')\n const manifest = kind === 'module' ? parseModuleManifest({ content }) : parseMetamodelManifest({ content })\n found.push({\n kind,\n name: entry.name,\n version: manifest.version,\n location: locationOf(kind, entry.name),\n dir,\n description: manifest.description ?? '',\n })\n } catch {\n // a folder that is not a (valid) package is not listed\n }\n }\n }\n return found\n}\n\nexport function createLocalPackage(opts: { workdir: string; kind: PackageKind; name: string; description?: string }): LocalPackage {\n const { workdir, kind, name, description } = opts\n if (!NAME_PATTERN.test(name)) throw new InvalidArgumentError(`\"${name}\" is not a valid name: use letters, digits, \"_\", \"-\" and \".\" only.`)\n const dir = path.join(workdir, DIRS[kind], name)\n if (fs.existsSync(dir) && fs.readdirSync(dir).length > 0) throw new InvalidArgumentError(`\"${dir}\" already exists and is not empty.`)\n\n const manifest =\n kind === 'module'\n ? { name, version: '0.1.0', ...(description ? { description } : {}), requires: { modules: {}, metamodels: {} }, offers: {} }\n : { name, version: '0.1.0', ...(description ? { description } : {}), requires: {} }\n writeTextFile({ filePath: path.join(dir, MANIFESTS[kind]), content: `${JSON.stringify(manifest, null, 2)}\\n` })\n if (kind === 'module') {\n writeTextFile({ filePath: path.join(dir, '.linea', 'model.uvl'), content: `features\\n\\t${rootFeatureName({ name, fallback: 'Root' })}\\n` })\n } else {\n const rule = rootFeatureName({ name, fallback: 'Root' })\n writeTextFile({\n filePath: path.join(dir, metamodelPath({ kind: 'grammar', grammar: name })),\n content: [\n `grammar ${rule}`,\n '',\n `// ${description ?? `${rule}: describe what this metamodel models`}`,\n `entry ${rule}Model: '${name.toLowerCase()}' name=ID? (items+=Item)*;`,\n '',\n \"Item: 'item' name=ID;\",\n '',\n 'terminal ID: /[_a-zA-Z][\\\\w_-]*/;',\n 'hidden terminal WS: /\\\\s+/;',\n '',\n ].join('\\n'),\n })\n }\n return { kind, name, version: '0.1.0', location: locationOf(kind, name), dir, description: description ?? '' }\n}\n\nexport function createLocalModularLine(opts: { workdir: string; name: string }): LocalLine {\n return createLocalLine({ workdir: opts.workdir, name: opts.name, kind: 'modular' })\n}\n\n/**\n * The feature model the modules of a line compose, kept in the line folder so the plain (synchronous) product operations can validate\n * a feature selection against it. It is refreshed whenever the modules are set or checked; generating always composes anew.\n */\nfunction cacheComposedModel(lineDir: string, featureModel: string): void {\n if (!featureModel) return\n writeTextFile({ filePath: path.join(lineDir, COMPOSED_MODEL_PATH), content: featureModel })\n // a cache of this machine, not part of the SPL: a clone of it must not send it with its changes\n excludeFromGit(lineDir, '.linea/composed-model.uvl')\n}\n\nfunction readSpl(lineDir: string): { spl: SplManifest; lock?: Lock } {\n const splPath = path.join(lineDir, SPL_MANIFEST_PATH)\n if (!fs.existsSync(splPath)) throw new InvalidArgumentError(`\"${lineDir}\" is not a line made of modules (no ${SPL_MANIFEST_PATH}).`)\n const spl = parseSplManifest({ content: fs.readFileSync(splPath, 'utf8') })\n const lockPath = path.join(lineDir, LOCK_PATH)\n let lock: Lock | undefined\n try {\n lock = fs.existsSync(lockPath) ? parseLock({ content: fs.readFileSync(lockPath, 'utf8') }) : undefined\n } catch {\n lock = undefined // a lock that cannot be read is made again\n }\n return { spl, lock }\n}\n\nexport interface LocalContext {\n resolved: ResolvedSpl\n spl: SplManifest\n files: PackageFiles\n}\n\n/** The packages of a line, resolved against the workspace (and pinned by the line's lockfile where it still fits). */\nasync function resolveLocalContext(workdir: string, lineDir: string, modules?: Record<string, string>): Promise<LocalContext> {\n const { spl: saved, lock } = readSpl(lineDir)\n const spl: SplManifest = modules ? { ...saved, modules } : saved\n const resolved = await resolveSpl({ spl, source: packageSourceOf(createFsPackageSource({ root: workdir })), lock })\n return { resolved, spl, files: createFsFiles({ dir: lineDir }) }\n}\n\nexport interface LocalModulesView {\n modules: Record<string, string>\n packages: { kind: PackageKind, name: string, version: string, location: string, requiredBy: readonly string[] }[]\n featureModelName: string\n}\n\nexport async function getLocalLineModules(workdir: string, lineDir: string): Promise<LocalModulesView> {\n const { resolved, spl } = await resolveLocalContext(workdir, lineDir)\n return {\n modules: { ...spl.modules },\n packages: [...resolved.modules, ...resolved.metamodels].map((p) => ({\n kind: p.kind,\n name: p.manifest.name,\n version: p.version,\n location: p.location,\n requiredBy: p.requiredBy,\n })),\n featureModelName: spl.name,\n }\n}\n\nexport async function checkLocalLine(workdir: string, lineDir: string, modules?: Record<string, string>): Promise<{ resolved: ResolvedSpl, report: Awaited<ReturnType<typeof checkSpl>> }> {\n const { resolved, files } = await resolveLocalContext(workdir, lineDir, modules)\n const report = await checkSpl({ resolved, spl: files, createEngine })\n if (!modules && report.featureModel) cacheComposedModel(lineDir, report.featureModel)\n return { resolved, report }\n}\n\n/** Sets the modules of a line: resolves and checks them, and writes `spl.json` and the lockfile. Throws `ModuleCheckError` when they do not fit. */\nexport async function setLocalLineModules(workdir: string, lineDir: string, modules: Record<string, string>): Promise<{ resolved: ResolvedSpl, report: Awaited<ReturnType<typeof checkSpl>> }> {\n const { resolved, report } = await checkLocalLine(workdir, lineDir, modules)\n if (!report.ok) throw new ModuleCheckError(`The modules do not fit together`, report.diagnostics)\n const { spl } = readSpl(lineDir)\n writeTextFile({ filePath: path.join(lineDir, SPL_MANIFEST_PATH), content: serializeSplManifest({ spl: { ...spl, modules } }) })\n writeTextFile({ filePath: path.join(lineDir, LOCK_PATH), content: serializeLock({ lock: resolved.lock }) })\n cacheComposedModel(lineDir, report.featureModel)\n return { resolved, report }\n}\n\n// ---------------------------------------------------------------- products\n\nconst MODELS_DIR = path.join('.linea', 'models')\n\nexport function readLocalProductModels(productDir: string): Record<string, string> {\n const dir = path.join(productDir, MODELS_DIR)\n const models: Record<string, string> = {}\n try {\n for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {\n if (entry.isFile()) models[entry.name.replace(/\\.[^.]+$/, '')] = fs.readFileSync(path.join(dir, entry.name), 'utf8')\n }\n } catch {\n // no models yet\n }\n return models\n}\n\nexport interface LocalProductModels {\n metamodels: readonly MetamodelInfo[]\n models: Record<string, string>\n offered: OfferedModel[]\n diagnostics: readonly Diagnostic[]\n ok: boolean\n}\n\nexport async function checkLocalProductModels(workdir: string, lineDir: string, productDir: string): Promise<LocalProductModels> {\n const { resolved, files } = await resolveLocalContext(workdir, lineDir)\n const models = readLocalProductModels(productDir)\n const report = await checkProduct({ resolved, spl: files, models, createEngine })\n return {\n metamodels: report.metamodels,\n models,\n offered: await listOfferedModels({ resolved }),\n diagnostics: report.diagnostics,\n ok: report.ok,\n }\n}\n\n/** Writes the smallest valid model of each metamodel into a new product of a modular line (does nothing for a plain line). */\nexport async function seedLocalProductModels(workdir: string, lineDir: string, productDir: string): Promise<string[]> {\n const { resolved, files } = await resolveLocalContext(workdir, lineDir)\n const seeded = await seedProductModels({ resolved, spl: files, createEngine })\n const written: string[] = []\n for (const info of seeded.metamodels) {\n const file = path.join(productDir, MODELS_DIR, `${info.name}.${info.extension}`)\n writeTextFile({ filePath: file, content: seeded.models[info.name] ?? '' })\n written.push(path.relative(productDir, file))\n }\n return written\n}\n\nexport async function deriveLocalModularProduct(workdir: string, lineDir: string, productDir: string, spec: ProductSpec, outputDir = productDir): ReturnType<typeof deriveModularProduct> {\n const { resolved, files } = await resolveLocalContext(workdir, lineDir)\n return deriveModularProduct({\n resolved,\n spl: files,\n spec,\n models: readLocalProductModels(productDir),\n createEngine,\n outputDir,\n })\n}\n\nexport async function deriveLocalModularProductZip(workdir: string, lineDir: string, productDir: string, spec: ProductSpec): ReturnType<typeof deriveModularProductToZip> {\n const { resolved, files } = await resolveLocalContext(workdir, lineDir)\n return deriveModularProductToZip({\n resolved,\n spl: files,\n spec,\n models: readLocalProductModels(productDir),\n createEngine,\n })\n}\n\n// ---------------------------------------------------------------- one package\n\nconst CHECK_LOCATION = 'memory:check'\n\nexport interface LocalPackageCheck {\n ok: boolean\n diagnostics: readonly Diagnostic[]\n /** what it brings in with it, dependencies first */\n resolved: { modules: number, metamodels: number }\n}\n\n/**\n * Checks a package of the workspace on its own, as the registry does before it publishes it: what it needs is resolved, and everything\n * is composed. A metamodel is only ever used through a module, so it is checked through one made up for the purpose.\n */\nexport async function checkLocalPackage(workdir: string, kind: PackageKind, name: string): Promise<LocalPackageCheck> {\n const location = locationOf(kind, name)\n const pkg = listLocalPackages(workdir).find((p) => p.kind === kind && p.name === name)\n if (!pkg) throw new InvalidArgumentError(`No ${kind} \"${name}\" in ${path.join(workdir, DIRS[kind])}`)\n\n let source: PackageSource = packageSourceOf(createFsPackageSource({ root: workdir }))\n let spl: SplManifest = { name: 'check', version: '0.0.0', kind: 'modular', metamodels: {}, modules: { [location]: `^${pkg.version}` } }\n if (kind === 'metamodel') {\n const overlay = createMemoryPackageSource({\n packages: {\n [CHECK_LOCATION]: {\n '0.0.0': { '.linea/module.json': JSON.stringify({ name: 'check', version: '0.0.0', requires: { metamodels: { [location]: `^${pkg.version}` } } }) },\n },\n },\n })\n source = withOverlay({ base: source, overlay, locations: new Set([CHECK_LOCATION]) })\n spl = { name: 'check', version: '0.0.0', kind: 'modular', metamodels: {}, modules: { [CHECK_LOCATION]: '0.0.0' } }\n }\n try {\n const resolved = await resolveSpl({ spl, source })\n const report = await checkSpl({ resolved, createEngine, configuration: false })\n return { ok: report.ok, diagnostics: report.diagnostics, resolved: { modules: resolved.modules.length, metamodels: resolved.metamodels.length } }\n } catch (e) {\n if (e instanceof ModuleCheckError) return { ok: false, diagnostics: e.diagnostics, resolved: { modules: 0, metamodels: 0 } }\n if (!(e instanceof LineaCoreError)) throw e\n return { ok: false, diagnostics: [{ severity: 'error', package: location, message: e.message }], resolved: { modules: 0, metamodels: 0 } }\n }\n}\n\nexport interface LockChange {\n location: string\n from?: string\n to?: string\n}\n\n/**\n * Takes the newest versions the ranges of an SPL allow, and pins them: the lockfile is made again (for one module and what it brought,\n * with `only`). Nothing is written when the result does not check out. Returns what changed.\n */\nexport async function updateLocalLineLock(workdir: string, lineDir: string, only?: string): Promise<{ changes: LockChange[]; resolved: ResolvedSpl }> {\n const { spl, lock } = readSpl(lineDir)\n let keep: Lock | undefined\n if (only && lock) {\n const matches = (location: string) => location === only || location === locationOf('module', only) || location.endsWith(`/${only}`) || location.endsWith(`:${only}`)\n if (!Object.keys(lock.packages).some(matches)) throw new InvalidArgumentError(`\"${only}\" is not in the lockfile of this SPL`)\n keep = { ...lock, packages: Object.fromEntries(Object.entries(lock.packages).filter(([location]) => !matches(location))) }\n }\n const resolved = await resolveSpl({ spl, source: packageSourceOf(createFsPackageSource({ root: workdir })), lock: keep })\n const report = await checkSpl({ resolved, spl: createFsFiles({ dir: lineDir }), createEngine })\n if (!report.ok) throw new ModuleCheckError('The newest versions do not fit together', report.diagnostics)\n\n const before = lock?.packages ?? {}\n const after = resolved.lock.packages\n const changes: LockChange[] = []\n for (const location of [...new Set([...Object.keys(before), ...Object.keys(after)])].sort()) {\n const from = before[location]?.version\n const to = after[location]?.version\n if (from !== to) changes.push({ location, ...(from ? { from } : {}), ...(to ? { to } : {}) })\n }\n writeTextFile({ filePath: path.join(lineDir, LOCK_PATH), content: serializeLock({ lock: resolved.lock }) })\n cacheComposedModel(lineDir, report.featureModel)\n return { changes, resolved }\n}\n"]}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { ProductSpec } from '../product/spec.js';
|
|
2
|
+
import type { PackageKind } from '../modules/types.js';
|
|
3
|
+
import type { LocalPackage } from './modular.js';
|
|
4
|
+
/** What people do to the things of a workspace, as one call each (the commands that do it only say it in words). */
|
|
5
|
+
export type VersionPart = 'major' | 'minor' | 'patch';
|
|
6
|
+
/** The version after `version`, raising `part` of it. */
|
|
7
|
+
export declare function nextVersion(version: string, part: string): string;
|
|
8
|
+
/** Raises the version in the manifest of a package of the workspace. Returns the version it had and has now. */
|
|
9
|
+
export declare function bumpPackageVersion(opts: {
|
|
10
|
+
dir: string;
|
|
11
|
+
kind: PackageKind;
|
|
12
|
+
part: string;
|
|
13
|
+
}): {
|
|
14
|
+
from: string;
|
|
15
|
+
to: string;
|
|
16
|
+
};
|
|
17
|
+
/** Which SPLs of the workspace use a package of the workspace directly (the modules they name in `spl.json`). */
|
|
18
|
+
export declare function splsUsing(opts: {
|
|
19
|
+
workdir: string;
|
|
20
|
+
pkg: Pick<LocalPackage, 'kind' | 'location'>;
|
|
21
|
+
}): string[];
|
|
22
|
+
/**
|
|
23
|
+
* Adds and removes features of a product's selection. A change that changes nothing (adding what is selected, removing nothing) is not
|
|
24
|
+
* saved, so the product's version does not move. Removing a feature the product does not select is an error.
|
|
25
|
+
*/
|
|
26
|
+
export declare function changeProductFeatures(opts: {
|
|
27
|
+
lineDir: string;
|
|
28
|
+
name: string;
|
|
29
|
+
add?: readonly string[];
|
|
30
|
+
remove?: readonly string[];
|
|
31
|
+
}): {
|
|
32
|
+
features: string[];
|
|
33
|
+
changed: boolean;
|
|
34
|
+
spec: ProductSpec;
|
|
35
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { InvalidArgumentError } from '../errors.js';
|
|
4
|
+
import { incrementVersion } from '../product/version.js';
|
|
5
|
+
import { METAMODEL_MANIFEST_PATH, MODULE_MANIFEST_PATH } from '../modules/packages/manifests.js';
|
|
6
|
+
import { listLocalLines, readLocalProductSpec, updateLocalProduct } from './local.js';
|
|
7
|
+
const MANIFESTS = { module: MODULE_MANIFEST_PATH, metamodel: METAMODEL_MANIFEST_PATH };
|
|
8
|
+
const PARTS = { major: 0, minor: 1, patch: 2 };
|
|
9
|
+
/** The version after `version`, raising `part` of it. */
|
|
10
|
+
export function nextVersion(version, part) {
|
|
11
|
+
if (!(part in PARTS))
|
|
12
|
+
throw new InvalidArgumentError(`Bump "patch", "minor" or "major", not "${part}".`);
|
|
13
|
+
return incrementVersion({ version, index: PARTS[part] });
|
|
14
|
+
}
|
|
15
|
+
/** Raises the version in the manifest of a package of the workspace. Returns the version it had and has now. */
|
|
16
|
+
export function bumpPackageVersion(opts) {
|
|
17
|
+
const file = path.join(opts.dir, MANIFESTS[opts.kind]);
|
|
18
|
+
const manifest = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
19
|
+
const to = nextVersion(manifest.version, opts.part);
|
|
20
|
+
fs.writeFileSync(file, `${JSON.stringify({ ...manifest, version: to }, null, 2)}\n`);
|
|
21
|
+
return { from: manifest.version, to };
|
|
22
|
+
}
|
|
23
|
+
/** Which SPLs of the workspace use a package of the workspace directly (the modules they name in `spl.json`). */
|
|
24
|
+
export function splsUsing(opts) {
|
|
25
|
+
if (opts.pkg.kind !== 'module')
|
|
26
|
+
return [];
|
|
27
|
+
return listLocalLines(opts.workdir)
|
|
28
|
+
.filter((l) => {
|
|
29
|
+
try {
|
|
30
|
+
const spl = JSON.parse(fs.readFileSync(path.join(l.dir, 'spl.json'), 'utf8'));
|
|
31
|
+
return Boolean(spl.modules && opts.pkg.location in spl.modules);
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
})
|
|
37
|
+
.map((l) => l.name);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Adds and removes features of a product's selection. A change that changes nothing (adding what is selected, removing nothing) is not
|
|
41
|
+
* saved, so the product's version does not move. Removing a feature the product does not select is an error.
|
|
42
|
+
*/
|
|
43
|
+
export function changeProductFeatures(opts) {
|
|
44
|
+
const spec = readLocalProductSpec(path.join(opts.lineDir, opts.name));
|
|
45
|
+
const current = (spec.features ?? []).slice();
|
|
46
|
+
const remove = new Set(opts.remove ?? []);
|
|
47
|
+
const absent = [...remove].filter((f) => !current.includes(f));
|
|
48
|
+
if (absent.length)
|
|
49
|
+
throw new InvalidArgumentError(`${opts.name} does not select ${absent.join(', ')}.`);
|
|
50
|
+
const features = [...new Set([...current.filter((f) => !remove.has(f)), ...(opts.add ?? [])])];
|
|
51
|
+
const changed = features.length !== current.length || features.some((f, i) => f !== current[i]);
|
|
52
|
+
if (!changed)
|
|
53
|
+
return { features, changed, spec };
|
|
54
|
+
const { spec: saved } = updateLocalProduct({ lineDir: opts.lineDir, name: opts.name, spec: { ...spec, features } });
|
|
55
|
+
return { features, changed, spec: saved };
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=operations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operations.js","sourceRoot":"","sources":["../../src/workspace/operations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AAGxD,OAAO,EAAE,uBAAuB,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAA;AAChG,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAOrF,MAAM,SAAS,GAAgC,EAAE,MAAM,EAAE,oBAAoB,EAAE,SAAS,EAAE,uBAAuB,EAAE,CAAA;AACnH,MAAM,KAAK,GAAgC,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAA;AAE3E,yDAAyD;AACzD,MAAM,UAAU,WAAW,CAAE,OAAe,EAAE,IAAY;IACxD,IAAI,CAAC,CAAC,IAAI,IAAI,KAAK,CAAC;QAAE,MAAM,IAAI,oBAAoB,CAAC,0CAA0C,IAAI,IAAI,CAAC,CAAA;IACxG,OAAO,gBAAgB,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,IAAmB,CAAC,EAAE,CAAC,CAAA;AACzE,CAAC;AAED,gHAAgH;AAChH,MAAM,UAAU,kBAAkB,CAAE,IAAsD;IACxF,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAA;IACtD,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,MA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Q,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,CAAA;AAC3C,CAAC","sourcesContent":["import fs from 'node:fs'\nimport path from 'node:path'\nimport { InvalidArgumentError } from '../errors.js'\nimport { incrementVersion } from '../product/version.js'\nimport type { ProductSpec } from '../product/spec.js'\nimport type { PackageKind } from '../modules/types.js'\nimport { METAMODEL_MANIFEST_PATH, MODULE_MANIFEST_PATH } from '../modules/packages/manifests.js'\nimport { listLocalLines, readLocalProductSpec, updateLocalProduct } from './local.js'\nimport type { LocalPackage } from './modular.js'\n\n/** What people do to the things of a workspace, as one call each (the commands that do it only say it in words). */\n\nexport type VersionPart = 'major' | 'minor' | 'patch'\n\nconst MANIFESTS: Record<PackageKind, string> = { module: MODULE_MANIFEST_PATH, metamodel: METAMODEL_MANIFEST_PATH }\nconst PARTS: Record<VersionPart, number> = { major: 0, minor: 1, patch: 2 }\n\n/** The version after `version`, raising `part` of it. */\nexport function nextVersion (version: string, part: string): string {\n if (!(part in PARTS)) throw new InvalidArgumentError(`Bump \"patch\", \"minor\" or \"major\", not \"${part}\".`)\n return incrementVersion({ version, index: PARTS[part as VersionPart] })\n}\n\n/** Raises the version in the manifest of a package of the workspace. Returns the version it had and has now. */\nexport function bumpPackageVersion (opts: { dir: string, kind: PackageKind, part: string }): { from: string, to: string } {\n const file = path.join(opts.dir, MANIFESTS[opts.kind])\n const manifest = JSON.parse(fs.readFileSync(file, 'utf8')) as { version: string }\n const to = nextVersion(manifest.version, opts.part)\n fs.writeFileSync(file, `${JSON.stringify({ ...manifest, version: to }, null, 2)}\\n`)\n return { from: manifest.version, to }\n}\n\n/** Which SPLs of the workspace use a package of the workspace directly (the modules they name in `spl.json`). */\nexport function splsUsing (opts: { workdir: string, pkg: Pick<LocalPackage, 'kind' | 'location'> }): string[] {\n if (opts.pkg.kind !== 'module') return []\n return listLocalLines(opts.workdir)\n .filter((l) => {\n try {\n const spl = JSON.parse(fs.readFileSync(path.join(l.dir, 'spl.json'), 'utf8')) as { modules?: Record<string, string> }\n return Boolean(spl.modules && opts.pkg.location in spl.modules)\n } catch {\n return false\n }\n })\n .map((l) => l.name)\n}\n\n/**\n * Adds and removes features of a product's selection. A change that changes nothing (adding what is selected, removing nothing) is not\n * saved, so the product's version does not move. Removing a feature the product does not select is an error.\n */\nexport function changeProductFeatures (opts: { lineDir: string, name: string, add?: readonly string[], remove?: readonly string[] }): { features: string[], changed: boolean, spec: ProductSpec } {\n const spec = readLocalProductSpec(path.join(opts.lineDir, opts.name))\n const current = ((spec as { features?: string[] }).features ?? []).slice()\n const remove = new Set(opts.remove ?? [])\n const absent = [...remove].filter((f) => !current.includes(f))\n if (absent.length) throw new InvalidArgumentError(`${opts.name} does not select ${absent.join(', ')}.`)\n const features = [...new Set([...current.filter((f) => !remove.has(f)), ...(opts.add ?? [])])]\n const changed = features.length !== current.length || features.some((f, i) => f !== current[i])\n if (!changed) return { features, changed, spec }\n const { spec: saved } = updateLocalProduct({ lineDir: opts.lineDir, name: opts.name, spec: { ...spec, features } })\n return { features, changed, spec: saved }\n}\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Where a checkout came from: what `.linea/origin.json` of a cloned SPL, product, module or metamodel says. */
|
|
2
|
+
export interface Origin {
|
|
3
|
+
kind: 'spl' | 'product' | 'module' | 'metamodel';
|
|
4
|
+
name: string;
|
|
5
|
+
provider: 'local' | 'gitlab' | 'github';
|
|
6
|
+
/** the id of the repository on the host (what the API takes) */
|
|
7
|
+
projectId: number | string;
|
|
8
|
+
webUrl: string;
|
|
9
|
+
defaultBranch: string;
|
|
10
|
+
/** an SPL or a product: the LINEA server it was cloned from, and the ids it knows it by */
|
|
11
|
+
server?: string;
|
|
12
|
+
lineId?: string;
|
|
13
|
+
productId?: string;
|
|
14
|
+
/** the LINEA web address of it */
|
|
15
|
+
webUi?: string;
|
|
16
|
+
/** a module or metamodel: where `publish` puts it (the group on GitLab, the owner on GitHub), when that can be told from where it came from */
|
|
17
|
+
publishRoot?: string;
|
|
18
|
+
}
|
|
19
|
+
export declare function writeOrigin(dir: string, origin: Origin): void;
|
|
20
|
+
export declare function readOrigin(dir: string): Origin | undefined;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { excludeFromGit } from './gitExclude.js';
|
|
4
|
+
const ORIGIN_FILE = path.join('.linea', 'origin.json');
|
|
5
|
+
export function writeOrigin(dir, origin) {
|
|
6
|
+
fs.mkdirSync(path.join(dir, '.linea'), { recursive: true });
|
|
7
|
+
fs.writeFileSync(path.join(dir, ORIGIN_FILE), `${JSON.stringify(origin, null, 2)}\n`);
|
|
8
|
+
// it says where the checkout came from, not what it contains: it is not for the repository
|
|
9
|
+
excludeFromGit(dir, '.linea/origin.json');
|
|
10
|
+
}
|
|
11
|
+
export function readOrigin(dir) {
|
|
12
|
+
try {
|
|
13
|
+
return JSON.parse(fs.readFileSync(path.join(dir, ORIGIN_FILE), 'utf8'));
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=origin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"origin.js","sourceRoot":"","sources":["../../src/workspace/origin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAqBhD,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,aAAa,CAAC,CAAA;AAEtD,MAAM,UAAU,WAAW,CAAE,GAAW,EAAE,MAAc;IACtD,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;IAC3D,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,WAAW,CAAC,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAA;IACrF,2FAA2F;IAC3F,cAAc,CAAC,GAAG,EAAE,oBAAoB,CAAC,CAAA;AAC3C,CAAC;AAED,MAAM,UAAU,UAAU,CAAE,GAAW;IACrC,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,WAAW,CAAC,EAAE,MAAM,CAAC,CAAW,CAAA;IACnF,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAA;IAClB,CAAC;AACH,CAAC","sourcesContent":["import fs from 'node:fs'\nimport path from 'node:path'\nimport { excludeFromGit } from './gitExclude.js'\n\n/** Where a checkout came from: what `.linea/origin.json` of a cloned SPL, product, module or metamodel says. */\nexport interface Origin {\n kind: 'spl' | 'product' | 'module' | 'metamodel'\n name: string\n provider: 'local' | 'gitlab' | 'github'\n /** the id of the repository on the host (what the API takes) */\n projectId: number | string\n webUrl: string\n defaultBranch: string\n /** an SPL or a product: the LINEA server it was cloned from, and the ids it knows it by */\n server?: string\n lineId?: string\n productId?: string\n /** the LINEA web address of it */\n webUi?: string\n /** a module or metamodel: where `publish` puts it (the group on GitLab, the owner on GitHub), when that can be told from where it came from */\n publishRoot?: string\n}\n\nconst ORIGIN_FILE = path.join('.linea', 'origin.json')\n\nexport function writeOrigin (dir: string, origin: Origin): void {\n fs.mkdirSync(path.join(dir, '.linea'), { recursive: true })\n fs.writeFileSync(path.join(dir, ORIGIN_FILE), `${JSON.stringify(origin, null, 2)}\\n`)\n // it says where the checkout came from, not what it contains: it is not for the repository\n excludeFromGit(dir, '.linea/origin.json')\n}\n\nexport function readOrigin (dir: string): Origin | undefined {\n try {\n return JSON.parse(fs.readFileSync(path.join(dir, ORIGIN_FILE), 'utf8')) as Origin\n } catch {\n return undefined\n }\n}\n"]}
|