@teambit/scripts 0.0.0-00df84d7db07c10ea89ca52e1dfa26599e0b6049
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/exceptions/index.d.ts +1 -0
- package/dist/exceptions/index.js +20 -0
- package/dist/exceptions/index.js.map +1 -0
- package/dist/exceptions/script-not-found.d.ts +6 -0
- package/dist/exceptions/script-not-found.js +23 -0
- package/dist/exceptions/script-not-found.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +48 -0
- package/dist/index.js.map +1 -0
- package/dist/preview-1760387564381.js +7 -0
- package/dist/script-definition.d.ts +12 -0
- package/dist/script-definition.js +3 -0
- package/dist/script-definition.js.map +1 -0
- package/dist/script.cmd.d.ts +20 -0
- package/dist/script.cmd.js +40 -0
- package/dist/script.cmd.js.map +1 -0
- package/dist/scripts.aspect.d.ts +2 -0
- package/dist/scripts.aspect.js +18 -0
- package/dist/scripts.aspect.js.map +1 -0
- package/dist/scripts.d.ts +12 -0
- package/dist/scripts.js +34 -0
- package/dist/scripts.js.map +1 -0
- package/dist/scripts.main.runtime.d.ts +41 -0
- package/dist/scripts.main.runtime.js +284 -0
- package/dist/scripts.main.runtime.js.map +1 -0
- package/dist/scripts.service.d.ts +18 -0
- package/dist/scripts.service.js +53 -0
- package/dist/scripts.service.js.map +1 -0
- package/exceptions/index.ts +1 -0
- package/exceptions/script-not-found.ts +10 -0
- package/index.ts +8 -0
- package/package.json +45 -0
- package/script-definition.ts +16 -0
- package/script.cmd.ts +40 -0
- package/scripts.aspect.ts +5 -0
- package/scripts.main.runtime.ts +255 -0
- package/scripts.service.ts +54 -0
- package/scripts.ts +32 -0
- package/types/asset.d.ts +29 -0
- package/types/style.d.ts +42 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ScriptNotFound } from './script-not-found';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "ScriptNotFound", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _scriptNotFound().ScriptNotFound;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
function _scriptNotFound() {
|
|
13
|
+
const data = require("./script-not-found");
|
|
14
|
+
_scriptNotFound = function () {
|
|
15
|
+
return data;
|
|
16
|
+
};
|
|
17
|
+
return data;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_scriptNotFound","data","require"],"sources":["index.ts"],"sourcesContent":["export { ScriptNotFound } from './script-not-found';\n"],"mappings":";;;;;;;;;;;AAAA,SAAAA,gBAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,eAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA","ignoreList":[]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ScriptNotFound = void 0;
|
|
7
|
+
function _bitError() {
|
|
8
|
+
const data = require("@teambit/bit-error");
|
|
9
|
+
_bitError = function () {
|
|
10
|
+
return data;
|
|
11
|
+
};
|
|
12
|
+
return data;
|
|
13
|
+
}
|
|
14
|
+
class ScriptNotFound extends _bitError().BitError {
|
|
15
|
+
constructor(scriptName, envId) {
|
|
16
|
+
super(`script "${scriptName}" was not found in environment "${envId}"`);
|
|
17
|
+
this.scriptName = scriptName;
|
|
18
|
+
this.envId = envId;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.ScriptNotFound = ScriptNotFound;
|
|
22
|
+
|
|
23
|
+
//# sourceMappingURL=script-not-found.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_bitError","data","require","ScriptNotFound","BitError","constructor","scriptName","envId","exports"],"sources":["script-not-found.ts"],"sourcesContent":["import { BitError } from '@teambit/bit-error';\n\nexport class ScriptNotFound extends BitError {\n constructor(\n readonly scriptName: string,\n readonly envId: string\n ) {\n super(`script \"${scriptName}\" was not found in environment \"${envId}\"`);\n }\n}\n"],"mappings":";;;;;;AAAA,SAAAA,UAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,SAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEO,MAAME,cAAc,SAASC,oBAAQ,CAAC;EAC3CC,WAAWA,CACAC,UAAkB,EAClBC,KAAa,EACtB;IACA,KAAK,CAAC,WAAWD,UAAU,mCAAmCC,KAAK,GAAG,CAAC;IAAC,KAH/DD,UAAkB,GAAlBA,UAAkB;IAAA,KAClBC,KAAa,GAAbA,KAAa;EAGxB;AACF;AAACC,OAAA,CAAAL,cAAA,GAAAA,cAAA","ignoreList":[]}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ScriptsAspect } from './scripts.aspect';
|
|
2
|
+
export type { ScriptsMain } from './scripts.main.runtime';
|
|
3
|
+
export { Scripts } from './scripts';
|
|
4
|
+
export type { ScriptHandler, ScriptDefinition, ScriptsMap } from './script-definition';
|
|
5
|
+
export { ScriptNotFound } from './exceptions';
|
|
6
|
+
export default ScriptsAspect;
|
|
7
|
+
export { ScriptsAspect };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "ScriptNotFound", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _exceptions().ScriptNotFound;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "Scripts", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _scripts2().Scripts;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "ScriptsAspect", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _scripts().ScriptsAspect;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
exports.default = void 0;
|
|
25
|
+
function _scripts() {
|
|
26
|
+
const data = require("./scripts.aspect");
|
|
27
|
+
_scripts = function () {
|
|
28
|
+
return data;
|
|
29
|
+
};
|
|
30
|
+
return data;
|
|
31
|
+
}
|
|
32
|
+
function _scripts2() {
|
|
33
|
+
const data = require("./scripts");
|
|
34
|
+
_scripts2 = function () {
|
|
35
|
+
return data;
|
|
36
|
+
};
|
|
37
|
+
return data;
|
|
38
|
+
}
|
|
39
|
+
function _exceptions() {
|
|
40
|
+
const data = require("./exceptions");
|
|
41
|
+
_exceptions = function () {
|
|
42
|
+
return data;
|
|
43
|
+
};
|
|
44
|
+
return data;
|
|
45
|
+
}
|
|
46
|
+
var _default = exports.default = _scripts().ScriptsAspect;
|
|
47
|
+
|
|
48
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_scripts","data","require","_scripts2","_exceptions","_default","exports","default","ScriptsAspect"],"sources":["index.ts"],"sourcesContent":["import { ScriptsAspect } from './scripts.aspect';\n\nexport type { ScriptsMain } from './scripts.main.runtime';\nexport { Scripts } from './scripts';\nexport type { ScriptHandler, ScriptDefinition, ScriptsMap } from './script-definition';\nexport { ScriptNotFound } from './exceptions';\nexport default ScriptsAspect;\nexport { ScriptsAspect };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAAA,SAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,QAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAGA,SAAAE,UAAA;EAAA,MAAAF,IAAA,GAAAC,OAAA;EAAAC,SAAA,YAAAA,CAAA;IAAA,OAAAF,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAG,YAAA;EAAA,MAAAH,IAAA,GAAAC,OAAA;EAAAE,WAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAA8C,IAAAI,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAC/BC,wBAAa","ignoreList":[]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Component } from '@teambit/component';
|
|
2
|
+
export interface ScriptExecuteContext {
|
|
3
|
+
components: Component[];
|
|
4
|
+
}
|
|
5
|
+
export type ScriptHandler = string | ((context?: ScriptExecuteContext) => void | Promise<void>);
|
|
6
|
+
export interface ScriptDefinition {
|
|
7
|
+
name: string;
|
|
8
|
+
handler: ScriptHandler;
|
|
9
|
+
}
|
|
10
|
+
export interface ScriptsMap {
|
|
11
|
+
[scriptName: string]: ScriptHandler;
|
|
12
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["script-definition.ts"],"sourcesContent":["import type { Component } from '@teambit/component';\n\nexport interface ScriptExecuteContext {\n components: Component[];\n}\n\nexport type ScriptHandler = string | ((context?: ScriptExecuteContext) => void | Promise<void>);\n\nexport interface ScriptDefinition {\n name: string;\n handler: ScriptHandler;\n}\n\nexport interface ScriptsMap {\n [scriptName: string]: ScriptHandler;\n}\n"],"mappings":"","ignoreList":[]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Command, CommandOptions } from '@teambit/cli';
|
|
2
|
+
import type { ScriptsMain } from './scripts.main.runtime';
|
|
3
|
+
export type ScriptOptions = {
|
|
4
|
+
list?: boolean;
|
|
5
|
+
};
|
|
6
|
+
export declare class ScriptCmd implements Command {
|
|
7
|
+
private scripts;
|
|
8
|
+
name: string;
|
|
9
|
+
description: string;
|
|
10
|
+
extendedDescription: string;
|
|
11
|
+
arguments: {
|
|
12
|
+
name: string;
|
|
13
|
+
description: string;
|
|
14
|
+
}[];
|
|
15
|
+
alias: string;
|
|
16
|
+
group: string;
|
|
17
|
+
options: CommandOptions;
|
|
18
|
+
constructor(scripts: ScriptsMain);
|
|
19
|
+
report(args: string[], options: ScriptOptions): Promise<string>;
|
|
20
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ScriptCmd = void 0;
|
|
7
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
8
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
9
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
10
|
+
class ScriptCmd {
|
|
11
|
+
constructor(scripts) {
|
|
12
|
+
this.scripts = scripts;
|
|
13
|
+
_defineProperty(this, "name", 'script [script-name]');
|
|
14
|
+
_defineProperty(this, "description", 'run a script defined by the environment');
|
|
15
|
+
_defineProperty(this, "extendedDescription", `executes custom scripts defined by component environments.
|
|
16
|
+
scripts can be shell commands or JavaScript functions defined in env.scripts().
|
|
17
|
+
runs the script for all components grouped by their environment.
|
|
18
|
+
use --list to see all available scripts.`);
|
|
19
|
+
_defineProperty(this, "arguments", [{
|
|
20
|
+
name: 'script-name',
|
|
21
|
+
description: 'the name of the script to run (e.g., "generate-svg", "pre-snap")'
|
|
22
|
+
}]);
|
|
23
|
+
_defineProperty(this, "alias", '');
|
|
24
|
+
_defineProperty(this, "group", 'development');
|
|
25
|
+
_defineProperty(this, "options", [['l', 'list', 'list all available scripts from all environments']]);
|
|
26
|
+
}
|
|
27
|
+
async report(args, options) {
|
|
28
|
+
const [scriptName] = args;
|
|
29
|
+
if (options.list) {
|
|
30
|
+
return this.scripts.listAllScripts();
|
|
31
|
+
}
|
|
32
|
+
if (!scriptName) {
|
|
33
|
+
throw new Error('script name is required. Use --list to see available scripts.');
|
|
34
|
+
}
|
|
35
|
+
return this.scripts.runScript(scriptName);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.ScriptCmd = ScriptCmd;
|
|
39
|
+
|
|
40
|
+
//# sourceMappingURL=script.cmd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["ScriptCmd","constructor","scripts","_defineProperty","name","description","report","args","options","scriptName","list","listAllScripts","Error","runScript","exports"],"sources":["script.cmd.ts"],"sourcesContent":["import type { Command, CommandOptions } from '@teambit/cli';\nimport type { ScriptsMain } from './scripts.main.runtime';\n\nexport type ScriptOptions = {\n list?: boolean;\n};\n\nexport class ScriptCmd implements Command {\n name = 'script [script-name]';\n description = 'run a script defined by the environment';\n extendedDescription = `executes custom scripts defined by component environments.\nscripts can be shell commands or JavaScript functions defined in env.scripts().\nruns the script for all components grouped by their environment.\nuse --list to see all available scripts.`;\n arguments = [\n {\n name: 'script-name',\n description: 'the name of the script to run (e.g., \"generate-svg\", \"pre-snap\")',\n },\n ];\n alias = '';\n group = 'development';\n options = [['l', 'list', 'list all available scripts from all environments']] as CommandOptions;\n\n constructor(private scripts: ScriptsMain) {}\n\n async report(args: string[], options: ScriptOptions): Promise<string> {\n const [scriptName] = args;\n\n if (options.list) {\n return this.scripts.listAllScripts();\n }\n\n if (!scriptName) {\n throw new Error('script name is required. Use --list to see available scripts.');\n }\n\n return this.scripts.runScript(scriptName);\n }\n}\n"],"mappings":";;;;;;;;;AAOO,MAAMA,SAAS,CAAoB;EAiBxCC,WAAWA,CAASC,OAAoB,EAAE;IAAA,KAAtBA,OAAoB,GAApBA,OAAoB;IAAAC,eAAA,eAhBjC,sBAAsB;IAAAA,eAAA,sBACf,yCAAyC;IAAAA,eAAA,8BACjC;AACxB;AACA;AACA,yCAAyC;IAAAA,eAAA,oBAC3B,CACV;MACEC,IAAI,EAAE,aAAa;MACnBC,WAAW,EAAE;IACf,CAAC,CACF;IAAAF,eAAA,gBACO,EAAE;IAAAA,eAAA,gBACF,aAAa;IAAAA,eAAA,kBACX,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,kDAAkD,CAAC,CAAC;EAElC;EAE3C,MAAMG,MAAMA,CAACC,IAAc,EAAEC,OAAsB,EAAmB;IACpE,MAAM,CAACC,UAAU,CAAC,GAAGF,IAAI;IAEzB,IAAIC,OAAO,CAACE,IAAI,EAAE;MAChB,OAAO,IAAI,CAACR,OAAO,CAACS,cAAc,CAAC,CAAC;IACtC;IAEA,IAAI,CAACF,UAAU,EAAE;MACf,MAAM,IAAIG,KAAK,CAAC,+DAA+D,CAAC;IAClF;IAEA,OAAO,IAAI,CAACV,OAAO,CAACW,SAAS,CAACJ,UAAU,CAAC;EAC3C;AACF;AAACK,OAAA,CAAAd,SAAA,GAAAA,SAAA","ignoreList":[]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ScriptsAspect = void 0;
|
|
7
|
+
function _harmony() {
|
|
8
|
+
const data = require("@teambit/harmony");
|
|
9
|
+
_harmony = function () {
|
|
10
|
+
return data;
|
|
11
|
+
};
|
|
12
|
+
return data;
|
|
13
|
+
}
|
|
14
|
+
const ScriptsAspect = exports.ScriptsAspect = _harmony().Aspect.create({
|
|
15
|
+
id: 'teambit.workspace/scripts'
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
//# sourceMappingURL=scripts.aspect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_harmony","data","require","ScriptsAspect","exports","Aspect","create","id"],"sources":["scripts.aspect.ts"],"sourcesContent":["import { Aspect } from '@teambit/harmony';\n\nexport const ScriptsAspect = Aspect.create({\n id: 'teambit.workspace/scripts',\n});\n"],"mappings":";;;;;;AAAA,SAAAA,SAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,QAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEO,MAAME,aAAa,GAAAC,OAAA,CAAAD,aAAA,GAAGE,iBAAM,CAACC,MAAM,CAAC;EACzCC,EAAE,EAAE;AACN,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { EnvHandler } from '@teambit/envs';
|
|
2
|
+
import type { ScriptHandler, ScriptsMap } from './script-definition';
|
|
3
|
+
export declare class Scripts {
|
|
4
|
+
private scriptsMap;
|
|
5
|
+
constructor(scriptsMap: ScriptsMap);
|
|
6
|
+
static from(scripts: ScriptsMap): EnvHandler<Scripts>;
|
|
7
|
+
get(name: string): ScriptHandler | undefined;
|
|
8
|
+
has(name: string): boolean;
|
|
9
|
+
list(): string[];
|
|
10
|
+
getAll(): ScriptsMap;
|
|
11
|
+
isEmpty(): boolean;
|
|
12
|
+
}
|
package/dist/scripts.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Scripts = void 0;
|
|
7
|
+
class Scripts {
|
|
8
|
+
constructor(scriptsMap) {
|
|
9
|
+
this.scriptsMap = scriptsMap;
|
|
10
|
+
}
|
|
11
|
+
static from(scripts) {
|
|
12
|
+
return _context => {
|
|
13
|
+
return new Scripts(scripts);
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
get(name) {
|
|
17
|
+
return this.scriptsMap[name];
|
|
18
|
+
}
|
|
19
|
+
has(name) {
|
|
20
|
+
return name in this.scriptsMap;
|
|
21
|
+
}
|
|
22
|
+
list() {
|
|
23
|
+
return Object.keys(this.scriptsMap);
|
|
24
|
+
}
|
|
25
|
+
getAll() {
|
|
26
|
+
return this.scriptsMap;
|
|
27
|
+
}
|
|
28
|
+
isEmpty() {
|
|
29
|
+
return this.list().length === 0;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.Scripts = Scripts;
|
|
33
|
+
|
|
34
|
+
//# sourceMappingURL=scripts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Scripts","constructor","scriptsMap","from","scripts","_context","get","name","has","list","Object","keys","getAll","isEmpty","length","exports"],"sources":["scripts.ts"],"sourcesContent":["import type { EnvContext, EnvHandler } from '@teambit/envs';\nimport type { ScriptHandler, ScriptsMap } from './script-definition';\n\nexport class Scripts {\n constructor(private scriptsMap: ScriptsMap) {}\n\n static from(scripts: ScriptsMap): EnvHandler<Scripts> {\n return (_context: EnvContext) => {\n return new Scripts(scripts);\n };\n }\n\n get(name: string): ScriptHandler | undefined {\n return this.scriptsMap[name];\n }\n\n has(name: string): boolean {\n return name in this.scriptsMap;\n }\n\n list(): string[] {\n return Object.keys(this.scriptsMap);\n }\n\n getAll(): ScriptsMap {\n return this.scriptsMap;\n }\n\n isEmpty(): boolean {\n return this.list().length === 0;\n }\n}\n"],"mappings":";;;;;;AAGO,MAAMA,OAAO,CAAC;EACnBC,WAAWA,CAASC,UAAsB,EAAE;IAAA,KAAxBA,UAAsB,GAAtBA,UAAsB;EAAG;EAE7C,OAAOC,IAAIA,CAACC,OAAmB,EAAuB;IACpD,OAAQC,QAAoB,IAAK;MAC/B,OAAO,IAAIL,OAAO,CAACI,OAAO,CAAC;IAC7B,CAAC;EACH;EAEAE,GAAGA,CAACC,IAAY,EAA6B;IAC3C,OAAO,IAAI,CAACL,UAAU,CAACK,IAAI,CAAC;EAC9B;EAEAC,GAAGA,CAACD,IAAY,EAAW;IACzB,OAAOA,IAAI,IAAI,IAAI,CAACL,UAAU;EAChC;EAEAO,IAAIA,CAAA,EAAa;IACf,OAAOC,MAAM,CAACC,IAAI,CAAC,IAAI,CAACT,UAAU,CAAC;EACrC;EAEAU,MAAMA,CAAA,EAAe;IACnB,OAAO,IAAI,CAACV,UAAU;EACxB;EAEAW,OAAOA,CAAA,EAAY;IACjB,OAAO,IAAI,CAACJ,IAAI,CAAC,CAAC,CAACK,MAAM,KAAK,CAAC;EACjC;AACF;AAACC,OAAA,CAAAf,OAAA,GAAAA,OAAA","ignoreList":[]}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { CLIMain } from '@teambit/cli';
|
|
2
|
+
import { ComponentMain } from '@teambit/component';
|
|
3
|
+
import type { EnvsMain } from '@teambit/envs';
|
|
4
|
+
import type { Logger, LoggerMain } from '@teambit/logger';
|
|
5
|
+
import type { Workspace } from '@teambit/workspace';
|
|
6
|
+
export interface ScriptsConfig {
|
|
7
|
+
envs?: string[];
|
|
8
|
+
}
|
|
9
|
+
export declare class ScriptsMain {
|
|
10
|
+
private workspace;
|
|
11
|
+
private envs;
|
|
12
|
+
private logger;
|
|
13
|
+
private componentAspect;
|
|
14
|
+
private config;
|
|
15
|
+
constructor(workspace: Workspace, envs: EnvsMain, logger: Logger, componentAspect: ComponentMain, config: ScriptsConfig);
|
|
16
|
+
private getConfigErrorMessage;
|
|
17
|
+
/**
|
|
18
|
+
* Run a script for all components
|
|
19
|
+
*/
|
|
20
|
+
runScript(scriptName: string): Promise<string>;
|
|
21
|
+
/**
|
|
22
|
+
* List all available scripts from all environments
|
|
23
|
+
*/
|
|
24
|
+
listAllScripts(): Promise<string>;
|
|
25
|
+
/**
|
|
26
|
+
* Check if an env is allowed to run scripts based on config
|
|
27
|
+
* Supports exact match with or without version
|
|
28
|
+
*/
|
|
29
|
+
private isEnvAllowed;
|
|
30
|
+
private getComponents;
|
|
31
|
+
private groupComponentsByEnv;
|
|
32
|
+
private getScriptsFromEnv;
|
|
33
|
+
private executeScript;
|
|
34
|
+
private executeShellCommand;
|
|
35
|
+
private executeFunction;
|
|
36
|
+
static slots: never[];
|
|
37
|
+
static dependencies: import("@teambit/harmony").Aspect[];
|
|
38
|
+
static runtime: import("@teambit/harmony").RuntimeDefinition;
|
|
39
|
+
static provider([cli, workspace, envs, componentAspect, loggerMain]: [CLIMain, Workspace, EnvsMain, ComponentMain, LoggerMain], config: ScriptsConfig): Promise<ScriptsMain>;
|
|
40
|
+
}
|
|
41
|
+
export default ScriptsMain;
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = exports.ScriptsMain = void 0;
|
|
7
|
+
function _cli() {
|
|
8
|
+
const data = require("@teambit/cli");
|
|
9
|
+
_cli = function () {
|
|
10
|
+
return data;
|
|
11
|
+
};
|
|
12
|
+
return data;
|
|
13
|
+
}
|
|
14
|
+
function _component() {
|
|
15
|
+
const data = require("@teambit/component");
|
|
16
|
+
_component = function () {
|
|
17
|
+
return data;
|
|
18
|
+
};
|
|
19
|
+
return data;
|
|
20
|
+
}
|
|
21
|
+
function _envs() {
|
|
22
|
+
const data = require("@teambit/envs");
|
|
23
|
+
_envs = function () {
|
|
24
|
+
return data;
|
|
25
|
+
};
|
|
26
|
+
return data;
|
|
27
|
+
}
|
|
28
|
+
function _logger() {
|
|
29
|
+
const data = require("@teambit/logger");
|
|
30
|
+
_logger = function () {
|
|
31
|
+
return data;
|
|
32
|
+
};
|
|
33
|
+
return data;
|
|
34
|
+
}
|
|
35
|
+
function _workspace() {
|
|
36
|
+
const data = require("@teambit/workspace");
|
|
37
|
+
_workspace = function () {
|
|
38
|
+
return data;
|
|
39
|
+
};
|
|
40
|
+
return data;
|
|
41
|
+
}
|
|
42
|
+
function _chalk() {
|
|
43
|
+
const data = _interopRequireDefault(require("chalk"));
|
|
44
|
+
_chalk = function () {
|
|
45
|
+
return data;
|
|
46
|
+
};
|
|
47
|
+
return data;
|
|
48
|
+
}
|
|
49
|
+
function _lodash() {
|
|
50
|
+
const data = require("lodash");
|
|
51
|
+
_lodash = function () {
|
|
52
|
+
return data;
|
|
53
|
+
};
|
|
54
|
+
return data;
|
|
55
|
+
}
|
|
56
|
+
function _child_process() {
|
|
57
|
+
const data = require("child_process");
|
|
58
|
+
_child_process = function () {
|
|
59
|
+
return data;
|
|
60
|
+
};
|
|
61
|
+
return data;
|
|
62
|
+
}
|
|
63
|
+
function _scripts() {
|
|
64
|
+
const data = require("./scripts.aspect");
|
|
65
|
+
_scripts = function () {
|
|
66
|
+
return data;
|
|
67
|
+
};
|
|
68
|
+
return data;
|
|
69
|
+
}
|
|
70
|
+
function _scripts2() {
|
|
71
|
+
const data = require("./scripts.service");
|
|
72
|
+
_scripts2 = function () {
|
|
73
|
+
return data;
|
|
74
|
+
};
|
|
75
|
+
return data;
|
|
76
|
+
}
|
|
77
|
+
function _script() {
|
|
78
|
+
const data = require("./script.cmd");
|
|
79
|
+
_script = function () {
|
|
80
|
+
return data;
|
|
81
|
+
};
|
|
82
|
+
return data;
|
|
83
|
+
}
|
|
84
|
+
function _exceptions() {
|
|
85
|
+
const data = require("./exceptions");
|
|
86
|
+
_exceptions = function () {
|
|
87
|
+
return data;
|
|
88
|
+
};
|
|
89
|
+
return data;
|
|
90
|
+
}
|
|
91
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
92
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
93
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
94
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
95
|
+
class ScriptsMain {
|
|
96
|
+
constructor(workspace, envs, logger, componentAspect, config) {
|
|
97
|
+
this.workspace = workspace;
|
|
98
|
+
this.envs = envs;
|
|
99
|
+
this.logger = logger;
|
|
100
|
+
this.componentAspect = componentAspect;
|
|
101
|
+
this.config = config;
|
|
102
|
+
}
|
|
103
|
+
getConfigErrorMessage() {
|
|
104
|
+
return _chalk().default.yellow('no envs configured. Add to workspace.jsonc:\n' + '{\n' + ' "teambit.workspace/scripts": {\n' + ' "envs": ["your-scope/your-env"]\n' + ' }\n' + '}');
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Run a script for all components
|
|
109
|
+
*/
|
|
110
|
+
async runScript(scriptName) {
|
|
111
|
+
// Filter envs based on config
|
|
112
|
+
const allowedEnvs = this.config.envs || [];
|
|
113
|
+
if (allowedEnvs.length === 0) {
|
|
114
|
+
return this.getConfigErrorMessage();
|
|
115
|
+
}
|
|
116
|
+
const components = await this.getComponents();
|
|
117
|
+
if (!components.length) {
|
|
118
|
+
return _chalk().default.yellow('no components found');
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// Group components by environment, filtering only configured envs
|
|
122
|
+
const componentsByEnv = this.groupComponentsByEnv(components, allowedEnvs);
|
|
123
|
+
const results = [];
|
|
124
|
+
for (const [envId, envComponents] of Object.entries(componentsByEnv)) {
|
|
125
|
+
const env = this.envs.getEnvDefinitionByStringId(envId);
|
|
126
|
+
if (!env) continue;
|
|
127
|
+
const scripts = this.getScriptsFromEnv(env);
|
|
128
|
+
if (!scripts) continue;
|
|
129
|
+
if (!scripts.has(scriptName)) {
|
|
130
|
+
throw new (_exceptions().ScriptNotFound)(scriptName, envId);
|
|
131
|
+
}
|
|
132
|
+
const handler = scripts.get(scriptName);
|
|
133
|
+
if (!handler) continue;
|
|
134
|
+
const title = _chalk().default.green(`\nRunning script "${scriptName}" for ${envComponents.length} component(s) with env ${envId}:`);
|
|
135
|
+
results.push(title);
|
|
136
|
+
const result = await this.executeScript(handler, envComponents);
|
|
137
|
+
results.push(result);
|
|
138
|
+
}
|
|
139
|
+
return results.join('\n');
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* List all available scripts from all environments
|
|
144
|
+
*/
|
|
145
|
+
async listAllScripts() {
|
|
146
|
+
// Filter envs based on config
|
|
147
|
+
const allowedEnvs = this.config.envs || [];
|
|
148
|
+
if (allowedEnvs.length === 0) {
|
|
149
|
+
return this.getConfigErrorMessage();
|
|
150
|
+
}
|
|
151
|
+
const components = await this.getComponents();
|
|
152
|
+
if (!components.length) {
|
|
153
|
+
return _chalk().default.yellow('no components found');
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// Group components by environment, filtering only configured envs
|
|
157
|
+
const componentsByEnv = this.groupComponentsByEnv(components, allowedEnvs);
|
|
158
|
+
const results = [];
|
|
159
|
+
let foundAnyScripts = false;
|
|
160
|
+
for (const [envId, envComponents] of Object.entries(componentsByEnv)) {
|
|
161
|
+
const env = this.envs.getEnvDefinitionByStringId(envId);
|
|
162
|
+
if (!env) continue;
|
|
163
|
+
const scripts = this.getScriptsFromEnv(env);
|
|
164
|
+
if (!scripts || scripts.isEmpty()) {
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
if (!foundAnyScripts) {
|
|
168
|
+
results.push(_chalk().default.green('Available scripts:\n'));
|
|
169
|
+
foundAnyScripts = true;
|
|
170
|
+
}
|
|
171
|
+
results.push(_chalk().default.cyan(`\nEnvironment: ${envId}`));
|
|
172
|
+
results.push(_chalk().default.gray(` (used by ${envComponents.length} component(s))`));
|
|
173
|
+
const scriptsList = scripts.list();
|
|
174
|
+
scriptsList.forEach(scriptName => {
|
|
175
|
+
const handler = scripts.get(scriptName);
|
|
176
|
+
const handlerStr = typeof handler === 'function' ? _chalk().default.gray('[function]') : _chalk().default.white(handler);
|
|
177
|
+
results.push(` ${_chalk().default.bold(scriptName)}: ${handlerStr}`);
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
if (!foundAnyScripts) {
|
|
181
|
+
return _chalk().default.yellow('no scripts defined in the configured environments');
|
|
182
|
+
}
|
|
183
|
+
return results.join('\n');
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Check if an env is allowed to run scripts based on config
|
|
188
|
+
* Supports exact match with or without version
|
|
189
|
+
*/
|
|
190
|
+
isEnvAllowed(envId, allowedEnvs) {
|
|
191
|
+
return allowedEnvs.some(allowedEnv => {
|
|
192
|
+
// Exact match (with version): "my-scope/my-env@1.0.0" === "my-scope/my-env@1.0.0"
|
|
193
|
+
if (envId === allowedEnv) return true;
|
|
194
|
+
|
|
195
|
+
// If config has no version, match env without version part
|
|
196
|
+
// Config: "my-scope/my-env" should match "my-scope/my-env@1.0.0"
|
|
197
|
+
if (!allowedEnv.includes('@') && envId.startsWith(allowedEnv + '@')) {
|
|
198
|
+
return true;
|
|
199
|
+
}
|
|
200
|
+
return false;
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
async getComponents() {
|
|
204
|
+
const host = this.componentAspect.getHost();
|
|
205
|
+
if (!host) throw new Error('workspace not found');
|
|
206
|
+
return host.list();
|
|
207
|
+
}
|
|
208
|
+
groupComponentsByEnv(components, allowedEnvs) {
|
|
209
|
+
const grouped = (0, _lodash().groupBy)(components, component => {
|
|
210
|
+
const env = this.envs.getOrCalculateEnv(component);
|
|
211
|
+
return env.id;
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
// If allowedEnvs is provided, filter out envs not in the list
|
|
215
|
+
if (allowedEnvs && allowedEnvs.length > 0) {
|
|
216
|
+
const filtered = {};
|
|
217
|
+
for (const [envId, envComponents] of Object.entries(grouped)) {
|
|
218
|
+
if (this.isEnvAllowed(envId, allowedEnvs)) {
|
|
219
|
+
filtered[envId] = envComponents;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
return filtered;
|
|
223
|
+
}
|
|
224
|
+
return grouped;
|
|
225
|
+
}
|
|
226
|
+
getScriptsFromEnv(env) {
|
|
227
|
+
if (!env.env.getScripts) return undefined;
|
|
228
|
+
return env.env.getScripts();
|
|
229
|
+
}
|
|
230
|
+
async executeScript(handler, components) {
|
|
231
|
+
if (typeof handler === 'string') {
|
|
232
|
+
// Execute shell command
|
|
233
|
+
return this.executeShellCommand(handler);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// Execute function
|
|
237
|
+
return this.executeFunction(handler, components);
|
|
238
|
+
}
|
|
239
|
+
executeShellCommand(command) {
|
|
240
|
+
try {
|
|
241
|
+
const output = (0, _child_process().execSync)(command, {
|
|
242
|
+
cwd: this.workspace.path,
|
|
243
|
+
encoding: 'utf-8',
|
|
244
|
+
stdio: 'pipe'
|
|
245
|
+
});
|
|
246
|
+
return _chalk().default.white(output);
|
|
247
|
+
} catch (error) {
|
|
248
|
+
const errorMsg = error.stderr || error.message || 'unknown error';
|
|
249
|
+
return _chalk().default.red(`Error executing script: ${errorMsg}`);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
async executeFunction(handler, components) {
|
|
253
|
+
try {
|
|
254
|
+
const context = {
|
|
255
|
+
components
|
|
256
|
+
};
|
|
257
|
+
await handler(context);
|
|
258
|
+
return _chalk().default.green('✓ Script function executed successfully');
|
|
259
|
+
} catch (error) {
|
|
260
|
+
return _chalk().default.red(`Error executing script function: ${error.message}`);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
static async provider([cli, workspace, envs, componentAspect, loggerMain], config) {
|
|
264
|
+
const logger = loggerMain.createLogger(_scripts().ScriptsAspect.id);
|
|
265
|
+
const scriptsService = new (_scripts2().ScriptsService)();
|
|
266
|
+
const scriptsMain = new ScriptsMain(workspace, envs, logger, componentAspect, config);
|
|
267
|
+
|
|
268
|
+
// Register service with envs
|
|
269
|
+
envs.registerService(scriptsService);
|
|
270
|
+
|
|
271
|
+
// Register CLI command
|
|
272
|
+
const scriptCmd = new (_script().ScriptCmd)(scriptsMain);
|
|
273
|
+
cli.register(scriptCmd);
|
|
274
|
+
return scriptsMain;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
exports.ScriptsMain = ScriptsMain;
|
|
278
|
+
_defineProperty(ScriptsMain, "slots", []);
|
|
279
|
+
_defineProperty(ScriptsMain, "dependencies", [_cli().CLIAspect, _workspace().WorkspaceAspect, _envs().EnvsAspect, _component().ComponentAspect, _logger().LoggerAspect]);
|
|
280
|
+
_defineProperty(ScriptsMain, "runtime", _cli().MainRuntime);
|
|
281
|
+
_scripts().ScriptsAspect.addRuntime(ScriptsMain);
|
|
282
|
+
var _default = exports.default = ScriptsMain;
|
|
283
|
+
|
|
284
|
+
//# sourceMappingURL=scripts.main.runtime.js.map
|