@enspirit/emb 0.0.9 → 0.1.1
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 +50 -28
- package/dist/src/cli/abstract/BaseCommand.d.ts +6 -0
- package/dist/src/cli/abstract/BaseCommand.js +33 -0
- package/dist/src/cli/abstract/FlavouredCommand.d.ts +2 -1
- package/dist/src/cli/abstract/FlavouredCommand.js +4 -3
- package/dist/src/cli/abstract/index.d.ts +1 -0
- package/dist/src/cli/abstract/index.js +1 -0
- package/dist/src/cli/commands/clean.d.ts +2 -2
- package/dist/src/cli/commands/clean.js +7 -6
- package/dist/src/cli/commands/components/index.d.ts +5 -4
- package/dist/src/cli/commands/components/index.js +13 -15
- package/dist/src/cli/commands/config/print.d.ts +2 -2
- package/dist/src/cli/commands/containers/index.d.ts +2 -2
- package/dist/src/cli/commands/containers/index.js +3 -3
- package/dist/src/cli/commands/containers/prune.d.ts +2 -2
- package/dist/src/cli/commands/containers/prune.js +2 -2
- package/dist/src/cli/commands/images/delete.d.ts +2 -2
- package/dist/src/cli/commands/images/delete.js +3 -2
- package/dist/src/cli/commands/images/index.d.ts +2 -2
- package/dist/src/cli/commands/images/index.js +3 -3
- package/dist/src/cli/commands/images/prune.d.ts +2 -2
- package/dist/src/cli/commands/images/prune.js +3 -2
- package/dist/src/cli/commands/{components → resources}/build.d.ts +3 -3
- package/dist/src/cli/commands/{components → resources}/build.js +11 -10
- package/dist/src/cli/commands/resources/index.d.ts +9 -0
- package/dist/src/cli/commands/resources/index.js +28 -0
- package/dist/src/cli/commands/tasks/index.d.ts +2 -2
- package/dist/src/cli/commands/tasks/index.js +4 -4
- package/dist/src/cli/commands/tasks/run.d.ts +2 -2
- package/dist/src/cli/commands/tasks/run.js +12 -5
- package/dist/src/cli/commands/up.js +5 -4
- package/dist/src/cli/hooks/init.js +1 -26
- package/dist/src/cli/utils.d.ts +1 -0
- package/dist/src/cli/utils.js +26 -0
- package/dist/src/config/convert.d.ts +2 -4
- package/dist/src/config/convert.js +12 -35
- package/dist/src/config/index.d.ts +3 -4
- package/dist/src/config/index.js +2 -3
- package/dist/src/config/schema.d.ts +71 -46
- package/dist/src/config/schema.json +187 -97
- package/dist/src/config/types.d.ts +13 -46
- package/dist/src/config/types.js +1 -1
- package/dist/src/config/validation.d.ts +3 -3
- package/dist/src/config/validation.js +12 -9
- package/dist/src/context.d.ts +1 -1
- package/dist/src/context.js +1 -0
- package/dist/src/docker/images/index.d.ts +0 -1
- package/dist/src/docker/images/index.js +0 -1
- package/dist/src/docker/index.d.ts +1 -1
- package/dist/src/docker/index.js +1 -1
- package/dist/src/docker/operations/containers/ExecContainerOperation.js +2 -1
- package/dist/src/docker/operations/images/BuildImageOperation.d.ts +7 -8
- package/dist/src/docker/operations/images/BuildImageOperation.js +16 -10
- package/dist/src/docker/resources/DockerImageResource.js +62 -0
- package/dist/src/docker/resources/index.d.ts +1 -0
- package/dist/src/docker/resources/index.js +1 -0
- package/dist/src/docker/utils.d.ts +1 -7
- package/dist/src/docker/utils.js +3 -7
- package/dist/src/errors.d.ts +9 -6
- package/dist/src/errors.js +15 -9
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.js +2 -0
- package/dist/src/monorepo/component.d.ts +14 -21
- package/dist/src/monorepo/component.js +40 -63
- package/dist/src/monorepo/config.d.ts +13 -15
- package/dist/src/monorepo/config.js +15 -46
- package/dist/src/monorepo/index.d.ts +1 -0
- package/dist/src/monorepo/index.js +1 -0
- package/dist/src/monorepo/monorepo.d.ts +13 -10
- package/dist/src/monorepo/monorepo.js +77 -19
- package/dist/src/monorepo/operations/components/index.d.ts +0 -1
- package/dist/src/monorepo/operations/components/index.js +0 -1
- package/dist/src/monorepo/operations/fs/CreateFileOperation.d.ts +11 -0
- package/dist/src/monorepo/operations/fs/CreateFileOperation.js +31 -0
- package/dist/src/monorepo/operations/fs/index.d.ts +1 -0
- package/dist/src/monorepo/operations/fs/index.js +1 -0
- package/dist/src/monorepo/operations/index.d.ts +1 -0
- package/dist/src/monorepo/operations/index.js +1 -0
- package/dist/src/monorepo/operations/resources/BuildResourcesOperation.d.ts +27 -0
- package/dist/src/monorepo/operations/resources/BuildResourcesOperation.js +146 -0
- package/dist/src/monorepo/operations/tasks/RunTasksOperation.js +1 -1
- package/dist/src/monorepo/plugins/{ComponentDiscoverPlugin.d.ts → AutoDockerPlugin.d.ts} +4 -4
- package/dist/src/monorepo/plugins/AutoDockerPlugin.js +46 -0
- package/dist/src/monorepo/plugins/EmbfileLoaderPlugin.js +12 -2
- package/dist/src/monorepo/plugins/index.d.ts +1 -1
- package/dist/src/monorepo/plugins/index.js +3 -3
- package/dist/src/monorepo/resources/FileResource.d.ts +1 -0
- package/dist/src/monorepo/resources/FileResource.js +13 -0
- package/dist/src/monorepo/resources/ResourceFactory.d.ts +23 -0
- package/dist/src/monorepo/resources/ResourceFactory.js +16 -0
- package/dist/src/monorepo/resources/index.d.ts +1 -0
- package/dist/src/monorepo/resources/index.js +1 -0
- package/dist/src/monorepo/store/index.d.ts +1 -1
- package/dist/src/monorepo/store/index.js +10 -2
- package/dist/src/monorepo/taskManagerFactory.d.ts +2 -2
- package/dist/src/monorepo/taskManagerFactory.js +1 -2
- package/dist/src/monorepo/types.d.ts +18 -5
- package/dist/src/monorepo/utils/{findRunOrder.d.ts → EMBCollection.d.ts} +3 -9
- package/dist/src/monorepo/utils/EMBCollection.js +101 -0
- package/dist/src/monorepo/utils/graph.d.ts +15 -0
- package/dist/src/monorepo/utils/graph.js +84 -0
- package/dist/src/monorepo/utils/index.d.ts +7 -1
- package/dist/src/monorepo/utils/index.js +14 -1
- package/dist/src/monorepo/utils/types.d.ts +2 -0
- package/dist/src/monorepo/utils/types.js +1 -0
- package/dist/src/operations/abstract/AbstractOperation.d.ts +3 -1
- package/dist/src/operations/abstract/AbstractOperation.js +3 -0
- package/dist/src/operations/types.d.ts +1 -1
- package/dist/src/prerequisites/GitPrerequisitePlugin.d.ts +1 -2
- package/dist/src/prerequisites/GitPrerequisitePlugin.js +3 -3
- package/dist/src/prerequisites/types.d.ts +2 -2
- package/dist/src/utils/TemplateExpander.d.ts +2 -1
- package/dist/src/utils/TemplateExpander.js +3 -1
- package/oclif.manifest.json +126 -89
- package/package.json +7 -2
- package/dist/src/docker/images/buildImage.d.ts +0 -19
- package/dist/src/docker/images/buildImage.js +0 -64
- package/dist/src/docker/types.d.ts +0 -14
- package/dist/src/monorepo/operations/components/BuildComponentsOperation.d.ts +0 -23
- package/dist/src/monorepo/operations/components/BuildComponentsOperation.js +0 -157
- package/dist/src/monorepo/plugins/ComponentDiscoverPlugin.js +0 -44
- package/dist/src/monorepo/project.d.ts +0 -6
- package/dist/src/monorepo/project.js +0 -8
- package/dist/src/monorepo/utils/findRunOrder.js +0 -165
- /package/dist/src/docker/{types.js → resources/DockerImageResource.d.ts} +0 -0
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { stat, statfs } from 'node:fs/promises';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import pMap from 'p-map';
|
|
4
|
+
import { GitPrerequisitePlugin } from '../../prerequisites/index.js';
|
|
5
|
+
import { ResourceFactory, } from '../../monorepo/resources/ResourceFactory.js';
|
|
6
|
+
import { BuildImageOperation } from '../operations/index.js';
|
|
7
|
+
const DockerImageOpFactory = async ({ config, component, monorepo }) => {
|
|
8
|
+
const fromConfig = (config.params || {});
|
|
9
|
+
const context = fromConfig.context
|
|
10
|
+
? fromConfig.context[0] === '/'
|
|
11
|
+
? monorepo.join(fromConfig.context)
|
|
12
|
+
: component.join(fromConfig.context)
|
|
13
|
+
: monorepo.join(component.rootDir);
|
|
14
|
+
// Ensure the folder exists
|
|
15
|
+
await statfs(context);
|
|
16
|
+
const plugin = new GitPrerequisitePlugin();
|
|
17
|
+
const sources = await plugin.collect(context);
|
|
18
|
+
const buildParams = {
|
|
19
|
+
context,
|
|
20
|
+
dockerfile: fromConfig.dockerfile || 'Dockerfile',
|
|
21
|
+
src: sources.map((s) => s.path),
|
|
22
|
+
buildArgs: fromConfig.buildArgs || {},
|
|
23
|
+
tag: [monorepo.name, fromConfig.tag || component.name].join('/'),
|
|
24
|
+
labels: {
|
|
25
|
+
...fromConfig.labels,
|
|
26
|
+
'emb/project': monorepo.name,
|
|
27
|
+
'emb/component': component.name,
|
|
28
|
+
'emb/flavor': monorepo.currentFlavor,
|
|
29
|
+
},
|
|
30
|
+
target: fromConfig.target,
|
|
31
|
+
};
|
|
32
|
+
const lastUpdatedInfo = async (sources) => {
|
|
33
|
+
const stats = await pMap(sources, async (s) => {
|
|
34
|
+
const stats = await stat(join(context, s.path));
|
|
35
|
+
return {
|
|
36
|
+
time: stats.mtime,
|
|
37
|
+
path: s.path,
|
|
38
|
+
};
|
|
39
|
+
}, { concurrency: 30 });
|
|
40
|
+
if (stats.length === 0) {
|
|
41
|
+
return 0;
|
|
42
|
+
}
|
|
43
|
+
return stats.reduce((last, entry) => {
|
|
44
|
+
return last.time > entry.time ? last : entry;
|
|
45
|
+
}, stats[0]);
|
|
46
|
+
};
|
|
47
|
+
return {
|
|
48
|
+
async mustBuild(sentinel) {
|
|
49
|
+
const lastUpdated = await lastUpdatedInfo(sources);
|
|
50
|
+
if (!sentinel) {
|
|
51
|
+
return lastUpdated;
|
|
52
|
+
}
|
|
53
|
+
return lastUpdated && lastUpdated.time.getTime() > sentinel.mtime
|
|
54
|
+
? lastUpdated
|
|
55
|
+
: undefined;
|
|
56
|
+
},
|
|
57
|
+
input: await monorepo.expand(buildParams),
|
|
58
|
+
operation: new BuildImageOperation(),
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
// Bring better abstraction and register as part of the plugin initialization
|
|
62
|
+
ResourceFactory.register('docker/image', DockerImageOpFactory);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import './DockerImageResource.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import './DockerImageResource.js';
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const shortId: (id: string) => string;
|
|
3
|
-
/**
|
|
4
|
-
* This is too naive and will need better logic to ensure
|
|
5
|
-
* we take care of flavors etc
|
|
6
|
-
*/
|
|
7
|
-
export declare const getSentinelFile: (component: Component) => string;
|
|
1
|
+
export declare const shortId: (id?: string) => string;
|
package/dist/src/docker/utils.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
export const shortId = (id) => {
|
|
2
|
+
if (!id) {
|
|
3
|
+
return '';
|
|
4
|
+
}
|
|
2
5
|
return id.slice(0, 12);
|
|
3
6
|
};
|
|
4
|
-
/**
|
|
5
|
-
* This is too naive and will need better logic to ensure
|
|
6
|
-
* we take care of flavors etc
|
|
7
|
-
*/
|
|
8
|
-
export const getSentinelFile = (component) => {
|
|
9
|
-
return `sentinels/docker/build/${component.name}.built`;
|
|
10
|
-
};
|
package/dist/src/errors.d.ts
CHANGED
|
@@ -41,17 +41,20 @@ export declare class CliError extends EMBError {
|
|
|
41
41
|
*/
|
|
42
42
|
ref?: string | undefined);
|
|
43
43
|
}
|
|
44
|
-
export declare class
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
export declare class AmbiguousReferenceError extends EMBError {
|
|
45
|
+
ref: string;
|
|
46
|
+
matches: string[];
|
|
47
|
+
constructor(msg: string, ref: string, matches: string[]);
|
|
47
48
|
}
|
|
48
49
|
export declare class UnkownReferenceError extends EMBError {
|
|
49
|
-
|
|
50
|
+
ref: string;
|
|
51
|
+
constructor(msg: string, ref: string);
|
|
50
52
|
}
|
|
51
|
-
export declare class
|
|
53
|
+
export declare class ItemCollisionsError extends EMBError {
|
|
52
54
|
collisions: Array<string>;
|
|
53
55
|
constructor(msg: string, collisions: Array<string>);
|
|
54
56
|
}
|
|
55
57
|
export declare class CircularDependencyError extends EMBError {
|
|
56
|
-
|
|
58
|
+
readonly deps: Array<Array<string>>;
|
|
59
|
+
constructor(msg: string, deps: Array<Array<string>>);
|
|
57
60
|
}
|
package/dist/src/errors.js
CHANGED
|
@@ -40,27 +40,33 @@ export class CliError extends EMBError {
|
|
|
40
40
|
this.ref = ref;
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
|
-
export class
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
43
|
+
export class AmbiguousReferenceError extends EMBError {
|
|
44
|
+
ref;
|
|
45
|
+
matches;
|
|
46
|
+
constructor(msg, ref, matches) {
|
|
47
|
+
super('AMBIGUOUS_TASK', msg);
|
|
48
|
+
this.ref = ref;
|
|
49
|
+
this.matches = matches;
|
|
48
50
|
}
|
|
49
51
|
}
|
|
50
52
|
export class UnkownReferenceError extends EMBError {
|
|
51
|
-
|
|
53
|
+
ref;
|
|
54
|
+
constructor(msg, ref) {
|
|
52
55
|
super('UNKNOWN_REF', msg);
|
|
56
|
+
this.ref = ref;
|
|
53
57
|
}
|
|
54
58
|
}
|
|
55
|
-
export class
|
|
59
|
+
export class ItemCollisionsError extends EMBError {
|
|
56
60
|
collisions;
|
|
57
61
|
constructor(msg, collisions) {
|
|
58
|
-
super('
|
|
62
|
+
super('ITEM_COLLISIONS', msg);
|
|
59
63
|
this.collisions = collisions;
|
|
60
64
|
}
|
|
61
65
|
}
|
|
62
66
|
export class CircularDependencyError extends EMBError {
|
|
63
|
-
|
|
67
|
+
deps;
|
|
68
|
+
constructor(msg, deps) {
|
|
64
69
|
super('CIRCULAR_DEPS', msg);
|
|
70
|
+
this.deps = deps;
|
|
65
71
|
}
|
|
66
72
|
}
|
package/dist/src/index.d.ts
CHANGED
package/dist/src/index.js
CHANGED
|
@@ -1,24 +1,17 @@
|
|
|
1
|
-
import { ComponentConfig } from '../config/
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
protected _config: ComponentConfig;
|
|
1
|
+
import { ComponentConfig, ComponentFlavorConfig } from '../config/schema.js';
|
|
2
|
+
import { ComponentFlavors, Monorepo, Resources, Tasks } from './index.js';
|
|
3
|
+
export declare class Component implements ComponentConfig {
|
|
4
|
+
readonly name: string;
|
|
5
|
+
readonly config: ComponentConfig;
|
|
7
6
|
protected monorepo: Monorepo;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
get name(): string;
|
|
18
|
-
get rootdir(): string;
|
|
19
|
-
get tasks(): Array<TaskInfo>;
|
|
20
|
-
cloneWith(config: Partial<ComponentConfig>): Component;
|
|
21
|
-
getPrerequisites(): Promise<Array<FilePrerequisite>>;
|
|
7
|
+
readonly rootDir: string;
|
|
8
|
+
readonly tasks: Tasks;
|
|
9
|
+
readonly resources: Resources;
|
|
10
|
+
readonly flavors: ComponentFlavors;
|
|
11
|
+
constructor(name: string, config: ComponentConfig, monorepo: Monorepo);
|
|
12
|
+
flavor(name: string, mustExist?: boolean): ComponentFlavorConfig;
|
|
13
|
+
cloneWith(config: Partial<ComponentConfig>): ComponentConfig;
|
|
14
|
+
toJSON(): ComponentConfig;
|
|
15
|
+
withFlavor(name: string): Component;
|
|
22
16
|
join(path: string): string;
|
|
23
|
-
toDockerBuild(): Promise<DockerComponentBuild>;
|
|
24
17
|
}
|
|
@@ -1,77 +1,54 @@
|
|
|
1
|
-
import
|
|
1
|
+
import jsonpatch from 'fast-json-patch';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
|
-
import {
|
|
3
|
+
import { toIdentifedHash, } from './index.js';
|
|
4
4
|
export class Component {
|
|
5
|
-
|
|
5
|
+
name;
|
|
6
|
+
config;
|
|
6
7
|
monorepo;
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
rootDir;
|
|
9
|
+
tasks;
|
|
10
|
+
resources;
|
|
11
|
+
flavors;
|
|
12
|
+
constructor(name, config, monorepo) {
|
|
13
|
+
this.name = name;
|
|
14
|
+
this.config = config;
|
|
9
15
|
this.monorepo = monorepo;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
get imageTag() {
|
|
24
|
-
return this.monorepo.defaults.docker?.tag || 'latest';
|
|
25
|
-
}
|
|
26
|
-
get labels() {
|
|
27
|
-
return {
|
|
28
|
-
'emb/component': this.name,
|
|
29
|
-
...this._config.docker?.labels,
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
get name() {
|
|
33
|
-
return this.config.name;
|
|
34
|
-
}
|
|
35
|
-
get rootdir() {
|
|
36
|
-
return this.monorepo.join(this.context || this.name);
|
|
37
|
-
}
|
|
38
|
-
get tasks() {
|
|
39
|
-
return (this.config.tasks || [])?.map((t) => {
|
|
40
|
-
return {
|
|
41
|
-
...t,
|
|
42
|
-
component: this.name,
|
|
43
|
-
id: `${this.name}:${t.name}`,
|
|
44
|
-
};
|
|
45
|
-
});
|
|
16
|
+
this.rootDir = config.rootDir || name;
|
|
17
|
+
this.tasks = toIdentifedHash(config.tasks || {}, this.name);
|
|
18
|
+
this.resources = toIdentifedHash(
|
|
19
|
+
// Due to the schema.json -> typescript conversion weirdness
|
|
20
|
+
config.resources || {}, this.name);
|
|
21
|
+
this.flavors = toIdentifedHash(config.flavors || {}, this.name);
|
|
22
|
+
}
|
|
23
|
+
flavor(name, mustExist = true) {
|
|
24
|
+
const flavor = this.flavors[name];
|
|
25
|
+
if (!flavor && mustExist) {
|
|
26
|
+
throw new Error(`Unknown flavor: ${name}`);
|
|
27
|
+
}
|
|
28
|
+
return flavor;
|
|
46
29
|
}
|
|
47
30
|
cloneWith(config) {
|
|
48
|
-
return new Component({
|
|
31
|
+
return new Component(this.name, {
|
|
49
32
|
...this.config,
|
|
50
33
|
...config,
|
|
51
34
|
}, this.monorepo);
|
|
52
35
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
36
|
+
toJSON() {
|
|
37
|
+
return structuredClone(this.config);
|
|
38
|
+
}
|
|
39
|
+
withFlavor(name) {
|
|
40
|
+
const original = this.toJSON();
|
|
41
|
+
const patches = this.flavor(name).patches || [];
|
|
42
|
+
const errors = jsonpatch.validate(patches, original);
|
|
43
|
+
if (errors) {
|
|
44
|
+
throw new Error('Invalid patch(es) detected');
|
|
45
|
+
}
|
|
46
|
+
const patched = patches.reduce((doc, patch, index) => {
|
|
47
|
+
return jsonpatch.applyReducer(doc, patch, index);
|
|
48
|
+
}, original);
|
|
49
|
+
return new Component(this.name, patched, this.monorepo);
|
|
57
50
|
}
|
|
58
51
|
join(path) {
|
|
59
|
-
return this.monorepo.join(this.
|
|
60
|
-
}
|
|
61
|
-
async toDockerBuild() {
|
|
62
|
-
return {
|
|
63
|
-
buildArgs: await this.monorepo.expand(deepmerge()(this.monorepo.defaults.docker?.buildArgs || {}, this.config.docker?.buildArgs || {})),
|
|
64
|
-
context: this.rootdir,
|
|
65
|
-
dockerfile: this.config.docker?.dockerfile || 'Dockerfile',
|
|
66
|
-
labels: deepmerge()({
|
|
67
|
-
...this.monorepo.defaults.docker?.labels,
|
|
68
|
-
}, this.labels),
|
|
69
|
-
name: this.imageName,
|
|
70
|
-
prerequisites: await this.getPrerequisites(),
|
|
71
|
-
tag: this.imageTag
|
|
72
|
-
? await this.monorepo.expand(this.imageTag)
|
|
73
|
-
: 'latest',
|
|
74
|
-
target: this.config.docker?.target || this.monorepo.defaults?.docker?.target,
|
|
75
|
-
};
|
|
52
|
+
return this.monorepo.join(join(this.rootDir, path));
|
|
76
53
|
}
|
|
77
54
|
}
|
|
@@ -1,19 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { ProjectFlavors, Tasks } from '../index.js';
|
|
2
|
+
import { ComponentConfig, DefaultsConfig, PluginConfig, ProjectConfig, ProjectFlavorConfig, UserConfig } from '../config/index.js';
|
|
3
|
+
export declare class MonorepoConfig implements UserConfig {
|
|
4
|
+
project: ProjectConfig;
|
|
5
|
+
defaults: DefaultsConfig;
|
|
5
6
|
env: Record<string, string>;
|
|
6
|
-
flavors:
|
|
7
|
+
flavors: ProjectFlavors;
|
|
7
8
|
plugins: Array<PluginConfig>;
|
|
8
|
-
project: IProjectConfig;
|
|
9
9
|
vars: Record<string, unknown>;
|
|
10
|
-
tasks:
|
|
11
|
-
|
|
12
|
-
constructor(config:
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
with(overrides: Partial<IMonorepoConfig>): MonorepoConfig;
|
|
18
|
-
withFlavor(name: string): MonorepoConfig;
|
|
10
|
+
tasks: Tasks;
|
|
11
|
+
components: Record<string, ComponentConfig>;
|
|
12
|
+
constructor(config: UserConfig);
|
|
13
|
+
component(id: string): ComponentConfig;
|
|
14
|
+
flavor(name: string): ProjectFlavorConfig;
|
|
15
|
+
toJSON(): Required<UserConfig>;
|
|
16
|
+
with(overrides: Partial<UserConfig>): MonorepoConfig;
|
|
19
17
|
}
|
|
@@ -1,84 +1,53 @@
|
|
|
1
|
+
import { toIdentifedHash } from '../index.js';
|
|
1
2
|
import deepMerge from '@fastify/deepmerge';
|
|
2
|
-
import { deepMergeArray } from '../utils/index.js';
|
|
3
3
|
export class MonorepoConfig {
|
|
4
|
-
|
|
5
|
-
currentFlavor;
|
|
6
|
-
//
|
|
4
|
+
project;
|
|
7
5
|
defaults;
|
|
8
6
|
env;
|
|
9
7
|
flavors;
|
|
10
8
|
plugins;
|
|
11
|
-
project;
|
|
12
9
|
vars;
|
|
13
10
|
tasks;
|
|
14
|
-
|
|
11
|
+
components;
|
|
15
12
|
constructor(config) {
|
|
16
|
-
this._components = config.components.reduce((map, cmp) => {
|
|
17
|
-
map.set(cmp.name, cmp);
|
|
18
|
-
return map;
|
|
19
|
-
}, new Map());
|
|
20
13
|
this.defaults = config.defaults || {};
|
|
21
14
|
this.project = config.project;
|
|
22
15
|
this.vars = config.vars || {};
|
|
23
|
-
this.flavors = config.flavors ||
|
|
16
|
+
this.flavors = config.flavors || {};
|
|
24
17
|
this.env = config.env || {};
|
|
25
18
|
this.plugins = config.plugins || [];
|
|
26
|
-
this.tasks = config.tasks ||
|
|
27
|
-
this.
|
|
19
|
+
this.tasks = toIdentifedHash(config.tasks || {}, 'global');
|
|
20
|
+
this.components = config.components || {};
|
|
28
21
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
component(name) {
|
|
33
|
-
const config = this.components.find((c) => c.name === name);
|
|
22
|
+
component(id) {
|
|
23
|
+
const config = this.components[id];
|
|
34
24
|
if (!config) {
|
|
35
|
-
throw new Error(`Unknown component ${
|
|
25
|
+
throw new Error(`Unknown component ${id}`);
|
|
36
26
|
}
|
|
37
27
|
return config;
|
|
38
28
|
}
|
|
39
29
|
flavor(name) {
|
|
40
|
-
const flavor = this.flavors
|
|
30
|
+
const flavor = this.flavors[name];
|
|
41
31
|
if (!flavor) {
|
|
42
32
|
throw new Error(`Unknown flavor: ${name}`);
|
|
43
33
|
}
|
|
44
34
|
return flavor;
|
|
45
35
|
}
|
|
46
36
|
toJSON() {
|
|
47
|
-
return {
|
|
48
|
-
currentFlavor: this.currentFlavor,
|
|
37
|
+
return structuredClone({
|
|
49
38
|
components: this.components,
|
|
50
39
|
defaults: this.defaults,
|
|
51
40
|
env: this.env,
|
|
52
41
|
flavors: this.flavors,
|
|
53
42
|
plugins: this.plugins,
|
|
54
43
|
project: this.project,
|
|
55
|
-
vars: this.vars,
|
|
56
44
|
tasks: this.tasks,
|
|
57
|
-
|
|
45
|
+
vars: this.vars,
|
|
46
|
+
});
|
|
58
47
|
}
|
|
59
48
|
with(overrides) {
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
...overrides,
|
|
63
|
-
components: deepMerge({
|
|
64
|
-
mergeArray() {
|
|
65
|
-
// Merge components by identifying them by name
|
|
66
|
-
return (target, source) => deepMergeArray(target, source, (item) => {
|
|
67
|
-
return item.name;
|
|
68
|
-
});
|
|
69
|
-
},
|
|
70
|
-
})(this.components, overrides?.components || []),
|
|
71
|
-
defaults: deepMerge()(this.defaults || {}, overrides.defaults || {}),
|
|
72
|
-
env: deepMerge()(this.env, overrides?.env || {}),
|
|
73
|
-
project: deepMerge()(this.project, overrides?.project || {}),
|
|
74
|
-
vars: deepMerge()(this.vars, overrides?.vars || {}),
|
|
75
|
-
};
|
|
49
|
+
const oldConfig = this.toJSON();
|
|
50
|
+
const newConfig = deepMerge()(oldConfig, overrides);
|
|
76
51
|
return new MonorepoConfig(newConfig);
|
|
77
52
|
}
|
|
78
|
-
withFlavor(name) {
|
|
79
|
-
return this.with({
|
|
80
|
-
...this.flavor(name),
|
|
81
|
-
currentFlavor: name,
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
53
|
}
|
|
@@ -3,6 +3,7 @@ export * from './config.js';
|
|
|
3
3
|
export * from './monorepo.js';
|
|
4
4
|
export * from './operations/index.js';
|
|
5
5
|
export * from './plugins/index.js';
|
|
6
|
+
export * from './resources/index.js';
|
|
6
7
|
export * from './store/index.js';
|
|
7
8
|
export * from './taskManagerFactory.js';
|
|
8
9
|
export * from './types.js';
|
|
@@ -3,6 +3,7 @@ export * from './config.js';
|
|
|
3
3
|
export * from './monorepo.js';
|
|
4
4
|
export * from './operations/index.js';
|
|
5
5
|
export * from './plugins/index.js';
|
|
6
|
+
export * from './resources/index.js';
|
|
6
7
|
export * from './store/index.js';
|
|
7
8
|
export * from './taskManagerFactory.js';
|
|
8
9
|
export * from './types.js';
|
|
@@ -1,26 +1,29 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { UserConfig } from '../config/types.js';
|
|
2
2
|
import { IOperation } from '../operations/index.js';
|
|
3
3
|
import { TemplateExpander } from '../utils/index.js';
|
|
4
4
|
import { Component } from './component.js';
|
|
5
5
|
import { EMBStore } from './store/index.js';
|
|
6
|
-
import { TaskInfo } from './types.js';
|
|
6
|
+
import { ResourceInfo, TaskInfo } from './types.js';
|
|
7
7
|
export declare class Monorepo {
|
|
8
|
+
private defaultFlavor;
|
|
8
9
|
private _config;
|
|
9
10
|
private _store;
|
|
10
11
|
private initialized;
|
|
11
|
-
constructor(config:
|
|
12
|
-
get
|
|
13
|
-
get
|
|
14
|
-
get
|
|
15
|
-
get flavors(): string[];
|
|
12
|
+
constructor(config: UserConfig, defaultFlavor?: string);
|
|
13
|
+
get config(): UserConfig;
|
|
14
|
+
get defaults(): import("../config/types.js").DefaultsConfig;
|
|
15
|
+
get flavors(): import("./types.js").ProjectFlavors;
|
|
16
16
|
get name(): string;
|
|
17
17
|
get rootDir(): string;
|
|
18
18
|
get currentFlavor(): string;
|
|
19
19
|
get store(): EMBStore;
|
|
20
|
-
get
|
|
21
|
-
get vars(): Record<string, unknown>;
|
|
20
|
+
get components(): Component[];
|
|
22
21
|
component(name: string): Component;
|
|
22
|
+
get tasks(): TaskInfo[];
|
|
23
23
|
task(nameOrId: string): TaskInfo;
|
|
24
|
+
get resources(): Array<ResourceInfo>;
|
|
25
|
+
resource(nameOrId: string): ResourceInfo;
|
|
26
|
+
get vars(): Record<string, unknown>;
|
|
24
27
|
expand(str: string, expander?: TemplateExpander): Promise<string>;
|
|
25
28
|
expand<R extends Record<string, unknown>>(record: R, expander?: TemplateExpander): Promise<R>;
|
|
26
29
|
private installStore;
|
|
@@ -28,5 +31,5 @@ export declare class Monorepo {
|
|
|
28
31
|
init(): Promise<Monorepo>;
|
|
29
32
|
join(...paths: string[]): string;
|
|
30
33
|
run<I, O>(operation: IOperation<I, O>, args: I): Promise<O>;
|
|
31
|
-
withFlavor(
|
|
34
|
+
withFlavor(flavorName: string): Promise<Monorepo>;
|
|
32
35
|
}
|