@teambit/scripts 0.0.0-e42bf10dc161cd9ecae46d4cb0f8d14531cf6939
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 +2 -0
- package/dist/exceptions/index.js +33 -0
- package/dist/exceptions/index.js.map +1 -0
- package/dist/exceptions/no-scripts-defined.d.ts +5 -0
- package/dist/exceptions/no-scripts-defined.js +22 -0
- package/dist/exceptions/no-scripts-defined.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 +54 -0
- package/dist/index.js.map +1 -0
- package/dist/preview-1759774855436.js +7 -0
- package/dist/script-definition.d.ts +8 -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 +43 -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 +11 -0
- package/dist/scripts.js +32 -0
- package/dist/scripts.js.map +1 -0
- package/dist/scripts.main.runtime.d.ts +37 -0
- package/dist/scripts.main.runtime.js +243 -0
- package/dist/scripts.main.runtime.js.map +1 -0
- package/dist/scripts.service.d.ts +18 -0
- package/dist/scripts.service.js +54 -0
- package/dist/scripts.service.js.map +1 -0
- package/exceptions/index.ts +2 -0
- package/exceptions/no-scripts-defined.ts +7 -0
- package/exceptions/script-not-found.ts +10 -0
- package/index.ts +8 -0
- package/package.json +45 -0
- package/script-definition.ts +10 -0
- package/script.cmd.ts +44 -0
- package/scripts.aspect.ts +5 -0
- package/scripts.main.runtime.ts +200 -0
- package/scripts.service.ts +55 -0
- package/scripts.ts +29 -0
- package/types/asset.d.ts +29 -0
- package/types/style.d.ts +42 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "NoScriptsDefined", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _noScriptsDefined().NoScriptsDefined;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "ScriptNotFound", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _scriptNotFound().ScriptNotFound;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
function _scriptNotFound() {
|
|
19
|
+
const data = require("./script-not-found");
|
|
20
|
+
_scriptNotFound = function () {
|
|
21
|
+
return data;
|
|
22
|
+
};
|
|
23
|
+
return data;
|
|
24
|
+
}
|
|
25
|
+
function _noScriptsDefined() {
|
|
26
|
+
const data = require("./no-scripts-defined");
|
|
27
|
+
_noScriptsDefined = function () {
|
|
28
|
+
return data;
|
|
29
|
+
};
|
|
30
|
+
return data;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_scriptNotFound","data","require","_noScriptsDefined"],"sources":["index.ts"],"sourcesContent":["export { ScriptNotFound } from './script-not-found';\nexport { NoScriptsDefined } from './no-scripts-defined';\n"],"mappings":";;;;;;;;;;;;;;;;;AAAA,SAAAA,gBAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,eAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAE,kBAAA;EAAA,MAAAF,IAAA,GAAAC,OAAA;EAAAC,iBAAA,YAAAA,CAAA;IAAA,OAAAF,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA","ignoreList":[]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.NoScriptsDefined = 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 NoScriptsDefined extends _bitError().BitError {
|
|
15
|
+
constructor(envId) {
|
|
16
|
+
super(`no scripts are defined in environment "${envId}"`);
|
|
17
|
+
this.envId = envId;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.NoScriptsDefined = NoScriptsDefined;
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=no-scripts-defined.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_bitError","data","require","NoScriptsDefined","BitError","constructor","envId","exports"],"sources":["no-scripts-defined.ts"],"sourcesContent":["import { BitError } from '@teambit/bit-error';\n\nexport class NoScriptsDefined extends BitError {\n constructor(readonly envId: string) {\n super(`no scripts are defined 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,gBAAgB,SAASC,oBAAQ,CAAC;EAC7CC,WAAWA,CAAUC,KAAa,EAAE;IAClC,KAAK,CAAC,0CAA0CA,KAAK,GAAG,CAAC;IAAC,KADvCA,KAAa,GAAbA,KAAa;EAElC;AACF;AAACC,OAAA,CAAAJ,gBAAA,GAAAA,gBAAA","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, NoScriptsDefined } from './exceptions';
|
|
6
|
+
export default ScriptsAspect;
|
|
7
|
+
export { ScriptsAspect };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "NoScriptsDefined", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _exceptions().NoScriptsDefined;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "ScriptNotFound", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _exceptions().ScriptNotFound;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "Scripts", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _scripts2().Scripts;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "ScriptsAspect", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return _scripts().ScriptsAspect;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
exports.default = void 0;
|
|
31
|
+
function _scripts() {
|
|
32
|
+
const data = require("./scripts.aspect");
|
|
33
|
+
_scripts = function () {
|
|
34
|
+
return data;
|
|
35
|
+
};
|
|
36
|
+
return data;
|
|
37
|
+
}
|
|
38
|
+
function _scripts2() {
|
|
39
|
+
const data = require("./scripts");
|
|
40
|
+
_scripts2 = function () {
|
|
41
|
+
return data;
|
|
42
|
+
};
|
|
43
|
+
return data;
|
|
44
|
+
}
|
|
45
|
+
function _exceptions() {
|
|
46
|
+
const data = require("./exceptions");
|
|
47
|
+
_exceptions = function () {
|
|
48
|
+
return data;
|
|
49
|
+
};
|
|
50
|
+
return data;
|
|
51
|
+
}
|
|
52
|
+
var _default = exports.default = _scripts().ScriptsAspect;
|
|
53
|
+
|
|
54
|
+
//# 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, NoScriptsDefined } 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;AAAgE,IAAAI,QAAA,GAAAC,OAAA,CAAAC,OAAA,GACjDC,wBAAa","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["script-definition.ts"],"sourcesContent":["export type ScriptHandler = string | (() => 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,43 @@
|
|
|
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] [pattern]');
|
|
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
|
+
when no pattern is specified, 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
|
+
name: 'pattern',
|
|
24
|
+
description: 'component pattern (optional, runs on all components if not specified)'
|
|
25
|
+
}]);
|
|
26
|
+
_defineProperty(this, "alias", '');
|
|
27
|
+
_defineProperty(this, "group", 'development');
|
|
28
|
+
_defineProperty(this, "options", [['l', 'list', 'list all available scripts from all environments']]);
|
|
29
|
+
}
|
|
30
|
+
async report(args, options) {
|
|
31
|
+
const [scriptName, pattern] = args;
|
|
32
|
+
if (options.list) {
|
|
33
|
+
return this.scripts.listAllScripts(pattern);
|
|
34
|
+
}
|
|
35
|
+
if (!scriptName) {
|
|
36
|
+
throw new Error('script name is required. Use --list to see available scripts.');
|
|
37
|
+
}
|
|
38
|
+
return this.scripts.runScript(scriptName, pattern);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.ScriptCmd = ScriptCmd;
|
|
42
|
+
|
|
43
|
+
//# sourceMappingURL=script.cmd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["ScriptCmd","constructor","scripts","_defineProperty","name","description","report","args","options","scriptName","pattern","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] [pattern]';\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().\nwhen no pattern is specified, runs 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 name: 'pattern',\n description: 'component pattern (optional, runs on all components if not specified)',\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, pattern] = args;\n\n if (options.list) {\n return this.scripts.listAllScripts(pattern);\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, pattern);\n }\n}\n"],"mappings":";;;;;;;;;AAOO,MAAMA,SAAS,CAAoB;EAqBxCC,WAAWA,CAASC,OAAoB,EAAE;IAAA,KAAtBA,OAAoB,GAApBA,OAAoB;IAAAC,eAAA,eApBjC,gCAAgC;IAAAA,eAAA,sBACzB,yCAAyC;IAAAA,eAAA,8BACjC;AACxB;AACA;AACA,yCAAyC;IAAAA,eAAA,oBAC3B,CACV;MACEC,IAAI,EAAE,aAAa;MACnBC,WAAW,EAAE;IACf,CAAC,EACD;MACED,IAAI,EAAE,SAAS;MACfC,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,EAAEC,OAAO,CAAC,GAAGH,IAAI;IAElC,IAAIC,OAAO,CAACG,IAAI,EAAE;MAChB,OAAO,IAAI,CAACT,OAAO,CAACU,cAAc,CAACF,OAAO,CAAC;IAC7C;IAEA,IAAI,CAACD,UAAU,EAAE;MACf,MAAM,IAAII,KAAK,CAAC,+DAA+D,CAAC;IAClF;IAEA,OAAO,IAAI,CAACX,OAAO,CAACY,SAAS,CAACL,UAAU,EAAEC,OAAO,CAAC;EACpD;AACF;AAACK,OAAA,CAAAf,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,11 @@
|
|
|
1
|
+
import type { ScriptHandler, ScriptsMap } from './script-definition';
|
|
2
|
+
export declare class Scripts {
|
|
3
|
+
private scriptsMap;
|
|
4
|
+
constructor(scriptsMap: ScriptsMap);
|
|
5
|
+
static from(scripts: ScriptsMap): Scripts;
|
|
6
|
+
get(name: string): ScriptHandler | undefined;
|
|
7
|
+
has(name: string): boolean;
|
|
8
|
+
list(): string[];
|
|
9
|
+
getAll(): ScriptsMap;
|
|
10
|
+
isEmpty(): boolean;
|
|
11
|
+
}
|
package/dist/scripts.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
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 new Scripts(scripts);
|
|
13
|
+
}
|
|
14
|
+
get(name) {
|
|
15
|
+
return this.scriptsMap[name];
|
|
16
|
+
}
|
|
17
|
+
has(name) {
|
|
18
|
+
return name in this.scriptsMap;
|
|
19
|
+
}
|
|
20
|
+
list() {
|
|
21
|
+
return Object.keys(this.scriptsMap);
|
|
22
|
+
}
|
|
23
|
+
getAll() {
|
|
24
|
+
return this.scriptsMap;
|
|
25
|
+
}
|
|
26
|
+
isEmpty() {
|
|
27
|
+
return this.list().length === 0;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.Scripts = Scripts;
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=scripts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Scripts","constructor","scriptsMap","from","scripts","get","name","has","list","Object","keys","getAll","isEmpty","length","exports"],"sources":["scripts.ts"],"sourcesContent":["import type { ScriptHandler, ScriptsMap } from './script-definition';\n\nexport class Scripts {\n constructor(private scriptsMap: ScriptsMap) {}\n\n static from(scripts: ScriptsMap): Scripts {\n return new Scripts(scripts);\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":";;;;;;AAEO,MAAMA,OAAO,CAAC;EACnBC,WAAWA,CAASC,UAAsB,EAAE;IAAA,KAAxBA,UAAsB,GAAtBA,UAAsB;EAAG;EAE7C,OAAOC,IAAIA,CAACC,OAAmB,EAAW;IACxC,OAAO,IAAIJ,OAAO,CAACI,OAAO,CAAC;EAC7B;EAEAC,GAAGA,CAACC,IAAY,EAA6B;IAC3C,OAAO,IAAI,CAACJ,UAAU,CAACI,IAAI,CAAC;EAC9B;EAEAC,GAAGA,CAACD,IAAY,EAAW;IACzB,OAAOA,IAAI,IAAI,IAAI,CAACJ,UAAU;EAChC;EAEAM,IAAIA,CAAA,EAAa;IACf,OAAOC,MAAM,CAACC,IAAI,CAAC,IAAI,CAACR,UAAU,CAAC;EACrC;EAEAS,MAAMA,CAAA,EAAe;IACnB,OAAO,IAAI,CAACT,UAAU;EACxB;EAEAU,OAAOA,CAAA,EAAY;IACjB,OAAO,IAAI,CAACJ,IAAI,CAAC,CAAC,CAACK,MAAM,KAAK,CAAC;EACjC;AACF;AAACC,OAAA,CAAAd,OAAA,GAAAA,OAAA","ignoreList":[]}
|
|
@@ -0,0 +1,37 @@
|
|
|
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 declare class ScriptsMain {
|
|
7
|
+
private workspace;
|
|
8
|
+
private envs;
|
|
9
|
+
private logger;
|
|
10
|
+
private componentAspect;
|
|
11
|
+
constructor(workspace: Workspace, envs: EnvsMain, logger: Logger, componentAspect: ComponentMain);
|
|
12
|
+
/**
|
|
13
|
+
* Run a script for components matching the pattern
|
|
14
|
+
*/
|
|
15
|
+
runScript(scriptName: string, pattern?: string): Promise<string>;
|
|
16
|
+
/**
|
|
17
|
+
* List all available scripts from all environments
|
|
18
|
+
*/
|
|
19
|
+
listAllScripts(pattern?: string): Promise<string>;
|
|
20
|
+
private getComponents;
|
|
21
|
+
private groupComponentsByEnv;
|
|
22
|
+
private getScriptsFromEnv;
|
|
23
|
+
private executeScript;
|
|
24
|
+
private executeShellCommand;
|
|
25
|
+
private executeFunction;
|
|
26
|
+
static slots: never[];
|
|
27
|
+
static dependencies: import("@teambit/harmony").Aspect[];
|
|
28
|
+
static runtime: import("@teambit/harmony").RuntimeDefinition;
|
|
29
|
+
static provider([cli, workspace, envs, componentAspect, loggerMain]: [
|
|
30
|
+
CLIMain,
|
|
31
|
+
Workspace,
|
|
32
|
+
EnvsMain,
|
|
33
|
+
ComponentMain,
|
|
34
|
+
LoggerMain
|
|
35
|
+
]): Promise<ScriptsMain>;
|
|
36
|
+
}
|
|
37
|
+
export default ScriptsMain;
|
|
@@ -0,0 +1,243 @@
|
|
|
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) {
|
|
97
|
+
this.workspace = workspace;
|
|
98
|
+
this.envs = envs;
|
|
99
|
+
this.logger = logger;
|
|
100
|
+
this.componentAspect = componentAspect;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Run a script for components matching the pattern
|
|
105
|
+
*/
|
|
106
|
+
async runScript(scriptName, pattern) {
|
|
107
|
+
const components = await this.getComponents(pattern);
|
|
108
|
+
if (!components.length) {
|
|
109
|
+
return _chalk().default.yellow('no components found');
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Group components by environment
|
|
113
|
+
const componentsByEnv = this.groupComponentsByEnv(components);
|
|
114
|
+
const results = [];
|
|
115
|
+
for (const [envId, envComponents] of Object.entries(componentsByEnv)) {
|
|
116
|
+
const env = this.envs.getEnvDefinitionByStringId(envId);
|
|
117
|
+
if (!env) {
|
|
118
|
+
this.logger.console(_chalk().default.yellow(`env ${envId} not found, skipping`));
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
const scripts = this.getScriptsFromEnv(env);
|
|
122
|
+
if (!scripts) {
|
|
123
|
+
this.logger.console(_chalk().default.yellow(`env ${envId} has no scripts defined, skipping`));
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
if (!scripts.has(scriptName)) {
|
|
127
|
+
throw new (_exceptions().ScriptNotFound)(scriptName, envId);
|
|
128
|
+
}
|
|
129
|
+
const handler = scripts.get(scriptName);
|
|
130
|
+
if (!handler) continue;
|
|
131
|
+
const title = _chalk().default.green(`\nRunning script "${scriptName}" for ${envComponents.length} component(s) with env ${envId}:`);
|
|
132
|
+
results.push(title);
|
|
133
|
+
const result = await this.executeScript(handler, envComponents);
|
|
134
|
+
results.push(result);
|
|
135
|
+
}
|
|
136
|
+
return results.join('\n');
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* List all available scripts from all environments
|
|
141
|
+
*/
|
|
142
|
+
async listAllScripts(pattern) {
|
|
143
|
+
const components = await this.getComponents(pattern);
|
|
144
|
+
if (!components.length) {
|
|
145
|
+
return _chalk().default.yellow('no components found');
|
|
146
|
+
}
|
|
147
|
+
const componentsByEnv = this.groupComponentsByEnv(components);
|
|
148
|
+
const results = [];
|
|
149
|
+
results.push(_chalk().default.green('Available scripts:\n'));
|
|
150
|
+
for (const [envId, envComponents] of Object.entries(componentsByEnv)) {
|
|
151
|
+
const env = this.envs.getEnvDefinitionByStringId(envId);
|
|
152
|
+
if (!env) continue;
|
|
153
|
+
const scripts = this.getScriptsFromEnv(env);
|
|
154
|
+
if (!scripts || scripts.isEmpty()) {
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
results.push(_chalk().default.cyan(`\nEnvironment: ${envId}`));
|
|
158
|
+
results.push(_chalk().default.gray(` (used by ${envComponents.length} component(s))`));
|
|
159
|
+
const scriptsList = scripts.list();
|
|
160
|
+
scriptsList.forEach(scriptName => {
|
|
161
|
+
const handler = scripts.get(scriptName);
|
|
162
|
+
const handlerStr = typeof handler === 'function' ? _chalk().default.gray('[function]') : _chalk().default.white(handler);
|
|
163
|
+
results.push(` ${_chalk().default.bold(scriptName)}: ${handlerStr}`);
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
return results.join('\n');
|
|
167
|
+
}
|
|
168
|
+
async getComponents(pattern) {
|
|
169
|
+
if (!pattern) {
|
|
170
|
+
// Get all components
|
|
171
|
+
const host = this.componentAspect.getHost();
|
|
172
|
+
if (!host) throw new Error('workspace not found');
|
|
173
|
+
return host.list();
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// Resolve components by pattern
|
|
177
|
+
const componentIds = await this.workspace.resolveMultipleComponentIds([pattern]);
|
|
178
|
+
const filteredIds = await this.workspace.filterIds(componentIds);
|
|
179
|
+
return this.workspace.getMany(filteredIds);
|
|
180
|
+
}
|
|
181
|
+
groupComponentsByEnv(components) {
|
|
182
|
+
const grouped = (0, _lodash().groupBy)(components, component => {
|
|
183
|
+
const env = this.envs.getOrCalculateEnv(component);
|
|
184
|
+
return env.id;
|
|
185
|
+
});
|
|
186
|
+
return grouped;
|
|
187
|
+
}
|
|
188
|
+
getScriptsFromEnv(env) {
|
|
189
|
+
if (!env.env.getScripts) return undefined;
|
|
190
|
+
return env.env.getScripts();
|
|
191
|
+
}
|
|
192
|
+
async executeScript(handler, components) {
|
|
193
|
+
if (typeof handler === 'string') {
|
|
194
|
+
// Execute shell command
|
|
195
|
+
return this.executeShellCommand(handler);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// Execute function
|
|
199
|
+
return this.executeFunction(handler, components);
|
|
200
|
+
}
|
|
201
|
+
executeShellCommand(command) {
|
|
202
|
+
try {
|
|
203
|
+
const output = (0, _child_process().execSync)(command, {
|
|
204
|
+
cwd: this.workspace.path,
|
|
205
|
+
encoding: 'utf-8',
|
|
206
|
+
stdio: 'pipe'
|
|
207
|
+
});
|
|
208
|
+
return _chalk().default.white(output);
|
|
209
|
+
} catch (error) {
|
|
210
|
+
const errorMsg = error.stderr || error.message || 'unknown error';
|
|
211
|
+
return _chalk().default.red(`Error executing script: ${errorMsg}`);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
async executeFunction(handler, _components) {
|
|
215
|
+
try {
|
|
216
|
+
await handler();
|
|
217
|
+
return _chalk().default.green('✓ Script function executed successfully');
|
|
218
|
+
} catch (error) {
|
|
219
|
+
return _chalk().default.red(`Error executing script function: ${error.message}`);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
static async provider([cli, workspace, envs, componentAspect, loggerMain]) {
|
|
223
|
+
const logger = loggerMain.createLogger(_scripts().ScriptsAspect.id);
|
|
224
|
+
const scriptsService = new (_scripts2().ScriptsService)();
|
|
225
|
+
const scriptsMain = new ScriptsMain(workspace, envs, logger, componentAspect);
|
|
226
|
+
|
|
227
|
+
// Register service with envs
|
|
228
|
+
envs.registerService(scriptsService);
|
|
229
|
+
|
|
230
|
+
// Register CLI command
|
|
231
|
+
const scriptCmd = new (_script().ScriptCmd)(scriptsMain);
|
|
232
|
+
cli.register(scriptCmd);
|
|
233
|
+
return scriptsMain;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
exports.ScriptsMain = ScriptsMain;
|
|
237
|
+
_defineProperty(ScriptsMain, "slots", []);
|
|
238
|
+
_defineProperty(ScriptsMain, "dependencies", [_cli().CLIAspect, _workspace().WorkspaceAspect, _envs().EnvsAspect, _component().ComponentAspect, _logger().LoggerAspect]);
|
|
239
|
+
_defineProperty(ScriptsMain, "runtime", _cli().MainRuntime);
|
|
240
|
+
_scripts().ScriptsAspect.addRuntime(ScriptsMain);
|
|
241
|
+
var _default = exports.default = ScriptsMain;
|
|
242
|
+
|
|
243
|
+
//# sourceMappingURL=scripts.main.runtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_cli","data","require","_component","_envs","_logger","_workspace","_chalk","_interopRequireDefault","_lodash","_child_process","_scripts","_scripts2","_script","_exceptions","e","__esModule","default","_defineProperty","r","t","_toPropertyKey","Object","defineProperty","value","enumerable","configurable","writable","i","_toPrimitive","Symbol","toPrimitive","call","TypeError","String","Number","ScriptsMain","constructor","workspace","envs","logger","componentAspect","runScript","scriptName","pattern","components","getComponents","length","chalk","yellow","componentsByEnv","groupComponentsByEnv","results","envId","envComponents","entries","env","getEnvDefinitionByStringId","console","scripts","getScriptsFromEnv","has","ScriptNotFound","handler","get","title","green","push","result","executeScript","join","listAllScripts","isEmpty","cyan","gray","scriptsList","list","forEach","handlerStr","white","bold","host","getHost","Error","componentIds","resolveMultipleComponentIds","filteredIds","filterIds","getMany","grouped","groupBy","component","getOrCalculateEnv","id","getScripts","undefined","executeShellCommand","executeFunction","command","output","execSync","cwd","path","encoding","stdio","error","errorMsg","stderr","message","red","_components","provider","cli","loggerMain","createLogger","ScriptsAspect","scriptsService","ScriptsService","scriptsMain","registerService","scriptCmd","ScriptCmd","register","exports","CLIAspect","WorkspaceAspect","EnvsAspect","ComponentAspect","LoggerAspect","MainRuntime","addRuntime","_default"],"sources":["scripts.main.runtime.ts"],"sourcesContent":["import { CLIAspect, CLIMain, MainRuntime } from '@teambit/cli';\nimport type { Component } from '@teambit/component';\nimport { ComponentAspect, ComponentMain } from '@teambit/component';\nimport type { EnvsMain, EnvDefinition } from '@teambit/envs';\nimport { EnvsAspect } from '@teambit/envs';\nimport type { Logger, LoggerMain } from '@teambit/logger';\nimport { LoggerAspect } from '@teambit/logger';\nimport type { Workspace } from '@teambit/workspace';\nimport { WorkspaceAspect } from '@teambit/workspace';\nimport chalk from 'chalk';\nimport { groupBy } from 'lodash';\nimport { execSync } from 'child_process';\nimport { ScriptsAspect } from './scripts.aspect';\nimport { ScriptsService } from './scripts.service';\nimport { ScriptCmd } from './script.cmd';\nimport { ScriptNotFound } from './exceptions';\nimport type { Scripts } from './scripts';\nimport type { ScriptHandler } from './script-definition';\n\nexport class ScriptsMain {\n constructor(\n private workspace: Workspace,\n private envs: EnvsMain,\n private logger: Logger,\n private componentAspect: ComponentMain\n ) {}\n\n /**\n * Run a script for components matching the pattern\n */\n async runScript(scriptName: string, pattern?: string): Promise<string> {\n const components = await this.getComponents(pattern);\n if (!components.length) {\n return chalk.yellow('no components found');\n }\n\n // Group components by environment\n const componentsByEnv = this.groupComponentsByEnv(components);\n const results: string[] = [];\n\n for (const [envId, envComponents] of Object.entries(componentsByEnv)) {\n const env = this.envs.getEnvDefinitionByStringId(envId);\n if (!env) {\n this.logger.console(chalk.yellow(`env ${envId} not found, skipping`));\n continue;\n }\n\n const scripts = this.getScriptsFromEnv(env);\n if (!scripts) {\n this.logger.console(chalk.yellow(`env ${envId} has no scripts defined, skipping`));\n continue;\n }\n\n if (!scripts.has(scriptName)) {\n throw new ScriptNotFound(scriptName, envId);\n }\n\n const handler = scripts.get(scriptName);\n if (!handler) continue;\n\n const title = chalk.green(\n `\\nRunning script \"${scriptName}\" for ${envComponents.length} component(s) with env ${envId}:`\n );\n results.push(title);\n\n const result = await this.executeScript(handler, envComponents);\n results.push(result);\n }\n\n return results.join('\\n');\n }\n\n /**\n * List all available scripts from all environments\n */\n async listAllScripts(pattern?: string): Promise<string> {\n const components = await this.getComponents(pattern);\n if (!components.length) {\n return chalk.yellow('no components found');\n }\n\n const componentsByEnv = this.groupComponentsByEnv(components);\n const results: string[] = [];\n\n results.push(chalk.green('Available scripts:\\n'));\n\n for (const [envId, envComponents] of Object.entries(componentsByEnv)) {\n const env = this.envs.getEnvDefinitionByStringId(envId);\n if (!env) continue;\n\n const scripts = this.getScriptsFromEnv(env);\n if (!scripts || scripts.isEmpty()) {\n continue;\n }\n\n results.push(chalk.cyan(`\\nEnvironment: ${envId}`));\n results.push(chalk.gray(` (used by ${envComponents.length} component(s))`));\n\n const scriptsList = scripts.list();\n scriptsList.forEach((scriptName) => {\n const handler = scripts.get(scriptName);\n const handlerStr = typeof handler === 'function' ? chalk.gray('[function]') : chalk.white(handler as string);\n results.push(` ${chalk.bold(scriptName)}: ${handlerStr}`);\n });\n }\n\n return results.join('\\n');\n }\n\n private async getComponents(pattern?: string): Promise<Component[]> {\n if (!pattern) {\n // Get all components\n const host = this.componentAspect.getHost();\n if (!host) throw new Error('workspace not found');\n return host.list();\n }\n\n // Resolve components by pattern\n const componentIds = await this.workspace.resolveMultipleComponentIds([pattern]);\n const filteredIds = await this.workspace.filterIds(componentIds);\n return this.workspace.getMany(filteredIds);\n }\n\n private groupComponentsByEnv(components: Component[]): Record<string, Component[]> {\n const grouped = groupBy(components, (component) => {\n const env = this.envs.getOrCalculateEnv(component);\n return env.id;\n });\n return grouped;\n }\n\n private getScriptsFromEnv(env: EnvDefinition): Scripts | undefined {\n if (!env.env.getScripts) return undefined;\n return env.env.getScripts();\n }\n\n private async executeScript(handler: ScriptHandler, components: Component[]): Promise<string> {\n if (typeof handler === 'string') {\n // Execute shell command\n return this.executeShellCommand(handler);\n }\n\n // Execute function\n return this.executeFunction(handler, components);\n }\n\n private executeShellCommand(command: string): string {\n try {\n const output = execSync(command, {\n cwd: this.workspace.path,\n encoding: 'utf-8',\n stdio: 'pipe',\n });\n return chalk.white(output);\n } catch (error: any) {\n const errorMsg = error.stderr || error.message || 'unknown error';\n return chalk.red(`Error executing script: ${errorMsg}`);\n }\n }\n\n private async executeFunction(handler: () => void | Promise<void>, _components: Component[]): Promise<string> {\n try {\n await handler();\n return chalk.green('✓ Script function executed successfully');\n } catch (error: any) {\n return chalk.red(`Error executing script function: ${error.message}`);\n }\n }\n\n static slots = [];\n\n static dependencies = [CLIAspect, WorkspaceAspect, EnvsAspect, ComponentAspect, LoggerAspect];\n\n static runtime = MainRuntime;\n\n static async provider([cli, workspace, envs, componentAspect, loggerMain]: [\n CLIMain,\n Workspace,\n EnvsMain,\n ComponentMain,\n LoggerMain,\n ]) {\n const logger = loggerMain.createLogger(ScriptsAspect.id);\n const scriptsService = new ScriptsService();\n const scriptsMain = new ScriptsMain(workspace, envs, logger, componentAspect);\n\n // Register service with envs\n envs.registerService(scriptsService);\n\n // Register CLI command\n const scriptCmd = new ScriptCmd(scriptsMain);\n cli.register(scriptCmd);\n\n return scriptsMain;\n }\n}\n\nScriptsAspect.addRuntime(ScriptsMain);\n\nexport default ScriptsMain;\n"],"mappings":";;;;;;AAAA,SAAAA,KAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,IAAA,YAAAA,CAAA;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AG,CAAC,oCAAoCJ,KAAK,CAACG,OAAO,EAAE,CAAC;IACvE;EACF;EAQA,aAAaG,QAAQA,CAAC,CAACC,GAAG,EAAE1E,SAAS,EAAEC,IAAI,EAAEE,eAAe,EAAEwE,UAAU,CAMvE,EAAE;IACD,MAAMzE,MAAM,GAAGyE,UAAU,CAACC,YAAY,CAACC,wBAAa,CAACtB,EAAE,CAAC;IACxD,MAAMuB,cAAc,GAAG,KAAIC,0BAAc,EAAC,CAAC;IAC3C,MAAMC,WAAW,GAAG,IAAIlF,WAAW,CAACE,SAAS,EAAEC,IAAI,EAAEC,MAAM,EAAEC,eAAe,CAAC;;IAE7E;IACAF,IAAI,CAACgF,eAAe,CAACH,cAAc,CAAC;;IAEpC;IACA,MAAMI,SAAS,GAAG,KAAIC,mBAAS,EAACH,WAAW,CAAC;IAC5CN,GAAG,CAACU,QAAQ,CAACF,SAAS,CAAC;IAEvB,OAAOF,WAAW;EACpB;AACF;AAACK,OAAA,CAAAvF,WAAA,GAAAA,WAAA;AAAAlB,eAAA,CAhLYkB,WAAW,WAsJP,EAAE;AAAAlB,eAAA,CAtJNkB,WAAW,kBAwJA,CAACwF,gBAAS,EAAEC,4BAAe,EAAEC,kBAAU,EAAEC,4BAAe,EAAEC,sBAAY,CAAC;AAAA9G,eAAA,CAxJlFkB,WAAW,aA0JL6F,kBAAW;AAwB9Bd,wBAAa,CAACe,UAAU,CAAC9F,WAAW,CAAC;AAAC,IAAA+F,QAAA,GAAAR,OAAA,CAAA1G,OAAA,GAEvBmB,WAAW","ignoreList":[]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { EnvService, EnvDefinition, Env, EnvContext, ServiceTransformationMap } from '@teambit/envs';
|
|
2
|
+
import type { Scripts } from './scripts';
|
|
3
|
+
import type { ScriptsMap } from './script-definition';
|
|
4
|
+
export type ScriptsDescriptor = {
|
|
5
|
+
id: string;
|
|
6
|
+
displayName: string;
|
|
7
|
+
scripts: ScriptsMap;
|
|
8
|
+
};
|
|
9
|
+
type ScriptsTransformationMap = ServiceTransformationMap & {
|
|
10
|
+
getScripts: () => Scripts;
|
|
11
|
+
};
|
|
12
|
+
export declare class ScriptsService implements EnvService<{}, ScriptsDescriptor> {
|
|
13
|
+
name: string;
|
|
14
|
+
render(env: EnvDefinition): Promise<string>;
|
|
15
|
+
getDescriptor(env: EnvDefinition): Promise<ScriptsDescriptor | undefined>;
|
|
16
|
+
transform(env: Env, context: EnvContext): ScriptsTransformationMap | undefined;
|
|
17
|
+
}
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ScriptsService = void 0;
|
|
7
|
+
function _chalk() {
|
|
8
|
+
const data = _interopRequireDefault(require("chalk"));
|
|
9
|
+
_chalk = function () {
|
|
10
|
+
return data;
|
|
11
|
+
};
|
|
12
|
+
return data;
|
|
13
|
+
}
|
|
14
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
|
+
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; }
|
|
16
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
17
|
+
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); }
|
|
18
|
+
class ScriptsService {
|
|
19
|
+
constructor() {
|
|
20
|
+
_defineProperty(this, "name", 'Scripts');
|
|
21
|
+
}
|
|
22
|
+
async render(env) {
|
|
23
|
+
const descriptor = await this.getDescriptor(env);
|
|
24
|
+
if (!descriptor || Object.keys(descriptor.scripts).length === 0) {
|
|
25
|
+
return '';
|
|
26
|
+
}
|
|
27
|
+
const title = _chalk().default.green('available scripts:');
|
|
28
|
+
const scriptsList = Object.entries(descriptor.scripts).map(([name, handler]) => {
|
|
29
|
+
const handlerStr = typeof handler === 'function' ? _chalk().default.gray('[function]') : _chalk().default.cyan(handler);
|
|
30
|
+
return ` ${_chalk().default.bold(name)}: ${handlerStr}`;
|
|
31
|
+
}).join('\n');
|
|
32
|
+
return `${title}\n${scriptsList}`;
|
|
33
|
+
}
|
|
34
|
+
async getDescriptor(env) {
|
|
35
|
+
if (!env.env.getScripts) return undefined;
|
|
36
|
+
const scripts = env.env.getScripts();
|
|
37
|
+
if (!scripts) return undefined;
|
|
38
|
+
return {
|
|
39
|
+
id: this.name,
|
|
40
|
+
displayName: this.name,
|
|
41
|
+
scripts: scripts.getAll()
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
transform(env, context) {
|
|
45
|
+
if (!(env !== null && env !== void 0 && env.scripts)) return undefined;
|
|
46
|
+
const scriptsObj = env.scripts()(context);
|
|
47
|
+
return {
|
|
48
|
+
getScripts: () => scriptsObj
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.ScriptsService = ScriptsService;
|
|
53
|
+
|
|
54
|
+
//# sourceMappingURL=scripts.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_chalk","data","_interopRequireDefault","require","e","__esModule","default","_defineProperty","r","t","_toPropertyKey","Object","defineProperty","value","enumerable","configurable","writable","i","_toPrimitive","Symbol","toPrimitive","call","TypeError","String","Number","ScriptsService","constructor","render","env","descriptor","getDescriptor","keys","scripts","length","title","chalk","green","scriptsList","entries","map","name","handler","handlerStr","gray","cyan","bold","join","getScripts","undefined","id","displayName","getAll","transform","context","scriptsObj","exports"],"sources":["scripts.service.ts"],"sourcesContent":["import type { EnvService, EnvDefinition, Env, EnvContext, ServiceTransformationMap } from '@teambit/envs';\nimport chalk from 'chalk';\nimport type { Scripts } from './scripts';\nimport type { ScriptsMap } from './script-definition';\n\nexport type ScriptsDescriptor = {\n id: string;\n displayName: string;\n scripts: ScriptsMap;\n};\n\ntype ScriptsTransformationMap = ServiceTransformationMap & {\n getScripts: () => Scripts;\n};\n\nexport class ScriptsService implements EnvService<{}, ScriptsDescriptor> {\n name = 'Scripts';\n\n async render(env: EnvDefinition) {\n const descriptor = await this.getDescriptor(env);\n if (!descriptor || Object.keys(descriptor.scripts).length === 0) {\n return '';\n }\n\n const title = chalk.green('available scripts:');\n const scriptsList = Object.entries(descriptor.scripts)\n .map(([name, handler]) => {\n const handlerStr = typeof handler === 'function' ? chalk.gray('[function]') : chalk.cyan(handler);\n return ` ${chalk.bold(name)}: ${handlerStr}`;\n })\n .join('\\n');\n\n return `${title}\\n${scriptsList}`;\n }\n\n async getDescriptor(env: EnvDefinition): Promise<ScriptsDescriptor | undefined> {\n if (!env.env.getScripts) return undefined;\n const scripts = env.env.getScripts();\n if (!scripts) return undefined;\n\n return {\n id: this.name,\n displayName: this.name,\n scripts: scripts.getAll(),\n };\n }\n\n transform(env: Env, context: EnvContext): ScriptsTransformationMap | undefined {\n if (!env?.scripts) return undefined;\n const scriptsObj = env.scripts()(context);\n return {\n getScripts: () => scriptsObj,\n };\n }\n}\n"],"mappings":";;;;;;AACA,SAAAA,OAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,MAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAA0B,SAAAC,uBAAAE,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAAA,SAAAG,gBAAAH,CAAA,EAAAI,CAAA,EAAAC,CAAA,YAAAD,CAAA,GAAAE,cAAA,CAAAF,CAAA,MAAAJ,CAAA,GAAAO,MAAA,CAAAC,cAAA,CAAAR,CAAA,EAAAI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,KAAKN,gBAAK,CAACU,IAAI,CAACL,IAAI,CAAC,KAAKE,UAAU,EAAE;IAC/C,CAAC,CAAC,CACDI,IAAI,CAAC,IAAI,CAAC;IAEb,OAAO,GAAGZ,KAAK,KAAKG,WAAW,EAAE;EACnC;EAEA,MAAMP,aAAaA,CAACF,GAAkB,EAA0C;IAC9E,IAAI,CAACA,GAAG,CAACA,GAAG,CAACmB,UAAU,EAAE,OAAOC,SAAS;IACzC,MAAMhB,OAAO,GAAGJ,GAAG,CAACA,GAAG,CAACmB,UAAU,CAAC,CAAC;IACpC,IAAI,CAACf,OAAO,EAAE,OAAOgB,SAAS;IAE9B,OAAO;MACLC,EAAE,EAAE,IAAI,CAACT,IAAI;MACbU,WAAW,EAAE,IAAI,CAACV,IAAI;MACtBR,OAAO,EAAEA,OAAO,CAACmB,MAAM,CAAC;IAC1B,CAAC;EACH;EAEAC,SAASA,CAACxB,GAAQ,EAAEyB,OAAmB,EAAwC;IAC7E,IAAI,EAACzB,GAAG,aAAHA,GAAG,eAAHA,GAAG,CAAEI,OAAO,GAAE,OAAOgB,SAAS;IACnC,MAAMM,UAAU,GAAG1B,GAAG,CAACI,OAAO,CAAC,CAAC,CAACqB,OAAO,CAAC;IACzC,OAAO;MACLN,UAAU,EAAEA,CAAA,KAAMO;IACpB,CAAC;EACH;AACF;AAACC,OAAA,CAAA9B,cAAA,GAAAA,cAAA","ignoreList":[]}
|
package/index.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ScriptsAspect } from './scripts.aspect';
|
|
2
|
+
|
|
3
|
+
export type { ScriptsMain } from './scripts.main.runtime';
|
|
4
|
+
export { Scripts } from './scripts';
|
|
5
|
+
export type { ScriptHandler, ScriptDefinition, ScriptsMap } from './script-definition';
|
|
6
|
+
export { ScriptNotFound, NoScriptsDefined } from './exceptions';
|
|
7
|
+
export default ScriptsAspect;
|
|
8
|
+
export { ScriptsAspect };
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@teambit/scripts",
|
|
3
|
+
"version": "0.0.0-e42bf10dc161cd9ecae46d4cb0f8d14531cf6939",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"componentId": {
|
|
6
|
+
"name": "scripts",
|
|
7
|
+
"version": "e42bf10dc161cd9ecae46d4cb0f8d14531cf6939",
|
|
8
|
+
"scope": "teambit.workspace"
|
|
9
|
+
},
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"chalk": "4.1.2",
|
|
12
|
+
"lodash": "4.17.21",
|
|
13
|
+
"core-js": "^3.0.0",
|
|
14
|
+
"@babel/runtime": "7.20.0",
|
|
15
|
+
"@teambit/cli": "0.0.1278",
|
|
16
|
+
"@teambit/harmony": "0.4.7",
|
|
17
|
+
"@teambit/logger": "0.0.1371",
|
|
18
|
+
"@teambit/bit-error": "0.0.404",
|
|
19
|
+
"@teambit/component": "0.0.0-f5221183e7187a764bff514599f7e2fcb249dafd",
|
|
20
|
+
"@teambit/envs": "0.0.0-ab425da5f2765fbfe6a690112d5b4f42b983ea59",
|
|
21
|
+
"@teambit/workspace": "0.0.0-7ce3ec140b36ecc36789b2a369a865f9d2980983"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@types/lodash": "4.14.165",
|
|
25
|
+
"@types/node": "12.20.4",
|
|
26
|
+
"@types/react": "^17.0.8",
|
|
27
|
+
"@types/react-dom": "^17.0.5",
|
|
28
|
+
"@types/jest": "^26.0.0",
|
|
29
|
+
"@types/testing-library__jest-dom": "5.9.5"
|
|
30
|
+
},
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"react": "^16.8.0 || ^17.0.0",
|
|
33
|
+
"react-dom": "^16.8.0 || ^17.0.0"
|
|
34
|
+
},
|
|
35
|
+
"license": "SEE LICENSE IN UNLICENSED",
|
|
36
|
+
"optionalDependencies": {},
|
|
37
|
+
"peerDependenciesMeta": {},
|
|
38
|
+
"exports": {
|
|
39
|
+
"node": {
|
|
40
|
+
"require": "./dist/index.js",
|
|
41
|
+
"import": "./dist/esm.mjs"
|
|
42
|
+
},
|
|
43
|
+
"default": "./dist/index.js"
|
|
44
|
+
}
|
|
45
|
+
}
|
package/script.cmd.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { Command, CommandOptions } from '@teambit/cli';
|
|
2
|
+
import type { ScriptsMain } from './scripts.main.runtime';
|
|
3
|
+
|
|
4
|
+
export type ScriptOptions = {
|
|
5
|
+
list?: boolean;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export class ScriptCmd implements Command {
|
|
9
|
+
name = 'script [script-name] [pattern]';
|
|
10
|
+
description = 'run a script defined by the environment';
|
|
11
|
+
extendedDescription = `executes custom scripts defined by component environments.
|
|
12
|
+
scripts can be shell commands or JavaScript functions defined in env.scripts().
|
|
13
|
+
when no pattern is specified, runs the script for all components grouped by their environment.
|
|
14
|
+
use --list to see all available scripts.`;
|
|
15
|
+
arguments = [
|
|
16
|
+
{
|
|
17
|
+
name: 'script-name',
|
|
18
|
+
description: 'the name of the script to run (e.g., "generate-svg", "pre-snap")',
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
name: 'pattern',
|
|
22
|
+
description: 'component pattern (optional, runs on all components if not specified)',
|
|
23
|
+
},
|
|
24
|
+
];
|
|
25
|
+
alias = '';
|
|
26
|
+
group = 'development';
|
|
27
|
+
options = [['l', 'list', 'list all available scripts from all environments']] as CommandOptions;
|
|
28
|
+
|
|
29
|
+
constructor(private scripts: ScriptsMain) {}
|
|
30
|
+
|
|
31
|
+
async report(args: string[], options: ScriptOptions): Promise<string> {
|
|
32
|
+
const [scriptName, pattern] = args;
|
|
33
|
+
|
|
34
|
+
if (options.list) {
|
|
35
|
+
return this.scripts.listAllScripts(pattern);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (!scriptName) {
|
|
39
|
+
throw new Error('script name is required. Use --list to see available scripts.');
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return this.scripts.runScript(scriptName, pattern);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { CLIAspect, CLIMain, MainRuntime } from '@teambit/cli';
|
|
2
|
+
import type { Component } from '@teambit/component';
|
|
3
|
+
import { ComponentAspect, ComponentMain } from '@teambit/component';
|
|
4
|
+
import type { EnvsMain, EnvDefinition } from '@teambit/envs';
|
|
5
|
+
import { EnvsAspect } from '@teambit/envs';
|
|
6
|
+
import type { Logger, LoggerMain } from '@teambit/logger';
|
|
7
|
+
import { LoggerAspect } from '@teambit/logger';
|
|
8
|
+
import type { Workspace } from '@teambit/workspace';
|
|
9
|
+
import { WorkspaceAspect } from '@teambit/workspace';
|
|
10
|
+
import chalk from 'chalk';
|
|
11
|
+
import { groupBy } from 'lodash';
|
|
12
|
+
import { execSync } from 'child_process';
|
|
13
|
+
import { ScriptsAspect } from './scripts.aspect';
|
|
14
|
+
import { ScriptsService } from './scripts.service';
|
|
15
|
+
import { ScriptCmd } from './script.cmd';
|
|
16
|
+
import { ScriptNotFound } from './exceptions';
|
|
17
|
+
import type { Scripts } from './scripts';
|
|
18
|
+
import type { ScriptHandler } from './script-definition';
|
|
19
|
+
|
|
20
|
+
export class ScriptsMain {
|
|
21
|
+
constructor(
|
|
22
|
+
private workspace: Workspace,
|
|
23
|
+
private envs: EnvsMain,
|
|
24
|
+
private logger: Logger,
|
|
25
|
+
private componentAspect: ComponentMain
|
|
26
|
+
) {}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Run a script for components matching the pattern
|
|
30
|
+
*/
|
|
31
|
+
async runScript(scriptName: string, pattern?: string): Promise<string> {
|
|
32
|
+
const components = await this.getComponents(pattern);
|
|
33
|
+
if (!components.length) {
|
|
34
|
+
return chalk.yellow('no components found');
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Group components by environment
|
|
38
|
+
const componentsByEnv = this.groupComponentsByEnv(components);
|
|
39
|
+
const results: string[] = [];
|
|
40
|
+
|
|
41
|
+
for (const [envId, envComponents] of Object.entries(componentsByEnv)) {
|
|
42
|
+
const env = this.envs.getEnvDefinitionByStringId(envId);
|
|
43
|
+
if (!env) {
|
|
44
|
+
this.logger.console(chalk.yellow(`env ${envId} not found, skipping`));
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const scripts = this.getScriptsFromEnv(env);
|
|
49
|
+
if (!scripts) {
|
|
50
|
+
this.logger.console(chalk.yellow(`env ${envId} has no scripts defined, skipping`));
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (!scripts.has(scriptName)) {
|
|
55
|
+
throw new ScriptNotFound(scriptName, envId);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const handler = scripts.get(scriptName);
|
|
59
|
+
if (!handler) continue;
|
|
60
|
+
|
|
61
|
+
const title = chalk.green(
|
|
62
|
+
`\nRunning script "${scriptName}" for ${envComponents.length} component(s) with env ${envId}:`
|
|
63
|
+
);
|
|
64
|
+
results.push(title);
|
|
65
|
+
|
|
66
|
+
const result = await this.executeScript(handler, envComponents);
|
|
67
|
+
results.push(result);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return results.join('\n');
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* List all available scripts from all environments
|
|
75
|
+
*/
|
|
76
|
+
async listAllScripts(pattern?: string): Promise<string> {
|
|
77
|
+
const components = await this.getComponents(pattern);
|
|
78
|
+
if (!components.length) {
|
|
79
|
+
return chalk.yellow('no components found');
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const componentsByEnv = this.groupComponentsByEnv(components);
|
|
83
|
+
const results: string[] = [];
|
|
84
|
+
|
|
85
|
+
results.push(chalk.green('Available scripts:\n'));
|
|
86
|
+
|
|
87
|
+
for (const [envId, envComponents] of Object.entries(componentsByEnv)) {
|
|
88
|
+
const env = this.envs.getEnvDefinitionByStringId(envId);
|
|
89
|
+
if (!env) continue;
|
|
90
|
+
|
|
91
|
+
const scripts = this.getScriptsFromEnv(env);
|
|
92
|
+
if (!scripts || scripts.isEmpty()) {
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
results.push(chalk.cyan(`\nEnvironment: ${envId}`));
|
|
97
|
+
results.push(chalk.gray(` (used by ${envComponents.length} component(s))`));
|
|
98
|
+
|
|
99
|
+
const scriptsList = scripts.list();
|
|
100
|
+
scriptsList.forEach((scriptName) => {
|
|
101
|
+
const handler = scripts.get(scriptName);
|
|
102
|
+
const handlerStr = typeof handler === 'function' ? chalk.gray('[function]') : chalk.white(handler as string);
|
|
103
|
+
results.push(` ${chalk.bold(scriptName)}: ${handlerStr}`);
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return results.join('\n');
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
private async getComponents(pattern?: string): Promise<Component[]> {
|
|
111
|
+
if (!pattern) {
|
|
112
|
+
// Get all components
|
|
113
|
+
const host = this.componentAspect.getHost();
|
|
114
|
+
if (!host) throw new Error('workspace not found');
|
|
115
|
+
return host.list();
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Resolve components by pattern
|
|
119
|
+
const componentIds = await this.workspace.resolveMultipleComponentIds([pattern]);
|
|
120
|
+
const filteredIds = await this.workspace.filterIds(componentIds);
|
|
121
|
+
return this.workspace.getMany(filteredIds);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
private groupComponentsByEnv(components: Component[]): Record<string, Component[]> {
|
|
125
|
+
const grouped = groupBy(components, (component) => {
|
|
126
|
+
const env = this.envs.getOrCalculateEnv(component);
|
|
127
|
+
return env.id;
|
|
128
|
+
});
|
|
129
|
+
return grouped;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
private getScriptsFromEnv(env: EnvDefinition): Scripts | undefined {
|
|
133
|
+
if (!env.env.getScripts) return undefined;
|
|
134
|
+
return env.env.getScripts();
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
private async executeScript(handler: ScriptHandler, components: Component[]): Promise<string> {
|
|
138
|
+
if (typeof handler === 'string') {
|
|
139
|
+
// Execute shell command
|
|
140
|
+
return this.executeShellCommand(handler);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// Execute function
|
|
144
|
+
return this.executeFunction(handler, components);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
private executeShellCommand(command: string): string {
|
|
148
|
+
try {
|
|
149
|
+
const output = execSync(command, {
|
|
150
|
+
cwd: this.workspace.path,
|
|
151
|
+
encoding: 'utf-8',
|
|
152
|
+
stdio: 'pipe',
|
|
153
|
+
});
|
|
154
|
+
return chalk.white(output);
|
|
155
|
+
} catch (error: any) {
|
|
156
|
+
const errorMsg = error.stderr || error.message || 'unknown error';
|
|
157
|
+
return chalk.red(`Error executing script: ${errorMsg}`);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
private async executeFunction(handler: () => void | Promise<void>, _components: Component[]): Promise<string> {
|
|
162
|
+
try {
|
|
163
|
+
await handler();
|
|
164
|
+
return chalk.green('✓ Script function executed successfully');
|
|
165
|
+
} catch (error: any) {
|
|
166
|
+
return chalk.red(`Error executing script function: ${error.message}`);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
static slots = [];
|
|
171
|
+
|
|
172
|
+
static dependencies = [CLIAspect, WorkspaceAspect, EnvsAspect, ComponentAspect, LoggerAspect];
|
|
173
|
+
|
|
174
|
+
static runtime = MainRuntime;
|
|
175
|
+
|
|
176
|
+
static async provider([cli, workspace, envs, componentAspect, loggerMain]: [
|
|
177
|
+
CLIMain,
|
|
178
|
+
Workspace,
|
|
179
|
+
EnvsMain,
|
|
180
|
+
ComponentMain,
|
|
181
|
+
LoggerMain,
|
|
182
|
+
]) {
|
|
183
|
+
const logger = loggerMain.createLogger(ScriptsAspect.id);
|
|
184
|
+
const scriptsService = new ScriptsService();
|
|
185
|
+
const scriptsMain = new ScriptsMain(workspace, envs, logger, componentAspect);
|
|
186
|
+
|
|
187
|
+
// Register service with envs
|
|
188
|
+
envs.registerService(scriptsService);
|
|
189
|
+
|
|
190
|
+
// Register CLI command
|
|
191
|
+
const scriptCmd = new ScriptCmd(scriptsMain);
|
|
192
|
+
cli.register(scriptCmd);
|
|
193
|
+
|
|
194
|
+
return scriptsMain;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
ScriptsAspect.addRuntime(ScriptsMain);
|
|
199
|
+
|
|
200
|
+
export default ScriptsMain;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { EnvService, EnvDefinition, Env, EnvContext, ServiceTransformationMap } from '@teambit/envs';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import type { Scripts } from './scripts';
|
|
4
|
+
import type { ScriptsMap } from './script-definition';
|
|
5
|
+
|
|
6
|
+
export type ScriptsDescriptor = {
|
|
7
|
+
id: string;
|
|
8
|
+
displayName: string;
|
|
9
|
+
scripts: ScriptsMap;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
type ScriptsTransformationMap = ServiceTransformationMap & {
|
|
13
|
+
getScripts: () => Scripts;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export class ScriptsService implements EnvService<{}, ScriptsDescriptor> {
|
|
17
|
+
name = 'Scripts';
|
|
18
|
+
|
|
19
|
+
async render(env: EnvDefinition) {
|
|
20
|
+
const descriptor = await this.getDescriptor(env);
|
|
21
|
+
if (!descriptor || Object.keys(descriptor.scripts).length === 0) {
|
|
22
|
+
return '';
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const title = chalk.green('available scripts:');
|
|
26
|
+
const scriptsList = Object.entries(descriptor.scripts)
|
|
27
|
+
.map(([name, handler]) => {
|
|
28
|
+
const handlerStr = typeof handler === 'function' ? chalk.gray('[function]') : chalk.cyan(handler);
|
|
29
|
+
return ` ${chalk.bold(name)}: ${handlerStr}`;
|
|
30
|
+
})
|
|
31
|
+
.join('\n');
|
|
32
|
+
|
|
33
|
+
return `${title}\n${scriptsList}`;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async getDescriptor(env: EnvDefinition): Promise<ScriptsDescriptor | undefined> {
|
|
37
|
+
if (!env.env.getScripts) return undefined;
|
|
38
|
+
const scripts = env.env.getScripts();
|
|
39
|
+
if (!scripts) return undefined;
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
id: this.name,
|
|
43
|
+
displayName: this.name,
|
|
44
|
+
scripts: scripts.getAll(),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
transform(env: Env, context: EnvContext): ScriptsTransformationMap | undefined {
|
|
49
|
+
if (!env?.scripts) return undefined;
|
|
50
|
+
const scriptsObj = env.scripts()(context);
|
|
51
|
+
return {
|
|
52
|
+
getScripts: () => scriptsObj,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
}
|
package/scripts.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { ScriptHandler, ScriptsMap } from './script-definition';
|
|
2
|
+
|
|
3
|
+
export class Scripts {
|
|
4
|
+
constructor(private scriptsMap: ScriptsMap) {}
|
|
5
|
+
|
|
6
|
+
static from(scripts: ScriptsMap): Scripts {
|
|
7
|
+
return new Scripts(scripts);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
get(name: string): ScriptHandler | undefined {
|
|
11
|
+
return this.scriptsMap[name];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
has(name: string): boolean {
|
|
15
|
+
return name in this.scriptsMap;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
list(): string[] {
|
|
19
|
+
return Object.keys(this.scriptsMap);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
getAll(): ScriptsMap {
|
|
23
|
+
return this.scriptsMap;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
isEmpty(): boolean {
|
|
27
|
+
return this.list().length === 0;
|
|
28
|
+
}
|
|
29
|
+
}
|
package/types/asset.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
declare module '*.png' {
|
|
2
|
+
const value: any;
|
|
3
|
+
export = value;
|
|
4
|
+
}
|
|
5
|
+
declare module '*.svg' {
|
|
6
|
+
import type { FunctionComponent, SVGProps } from 'react';
|
|
7
|
+
|
|
8
|
+
export const ReactComponent: FunctionComponent<SVGProps<SVGSVGElement> & { title?: string }>;
|
|
9
|
+
const src: string;
|
|
10
|
+
export default src;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// @TODO Gilad
|
|
14
|
+
declare module '*.jpg' {
|
|
15
|
+
const value: any;
|
|
16
|
+
export = value;
|
|
17
|
+
}
|
|
18
|
+
declare module '*.jpeg' {
|
|
19
|
+
const value: any;
|
|
20
|
+
export = value;
|
|
21
|
+
}
|
|
22
|
+
declare module '*.gif' {
|
|
23
|
+
const value: any;
|
|
24
|
+
export = value;
|
|
25
|
+
}
|
|
26
|
+
declare module '*.bmp' {
|
|
27
|
+
const value: any;
|
|
28
|
+
export = value;
|
|
29
|
+
}
|
package/types/style.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
declare module '*.module.css' {
|
|
2
|
+
const classes: { readonly [key: string]: string };
|
|
3
|
+
export default classes;
|
|
4
|
+
}
|
|
5
|
+
declare module '*.module.scss' {
|
|
6
|
+
const classes: { readonly [key: string]: string };
|
|
7
|
+
export default classes;
|
|
8
|
+
}
|
|
9
|
+
declare module '*.module.sass' {
|
|
10
|
+
const classes: { readonly [key: string]: string };
|
|
11
|
+
export default classes;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
declare module '*.module.less' {
|
|
15
|
+
const classes: { readonly [key: string]: string };
|
|
16
|
+
export default classes;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
declare module '*.less' {
|
|
20
|
+
const classes: { readonly [key: string]: string };
|
|
21
|
+
export default classes;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
declare module '*.css' {
|
|
25
|
+
const classes: { readonly [key: string]: string };
|
|
26
|
+
export default classes;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
declare module '*.sass' {
|
|
30
|
+
const classes: { readonly [key: string]: string };
|
|
31
|
+
export default classes;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
declare module '*.scss' {
|
|
35
|
+
const classes: { readonly [key: string]: string };
|
|
36
|
+
export default classes;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
declare module '*.mdx' {
|
|
40
|
+
const component: any;
|
|
41
|
+
export default component;
|
|
42
|
+
}
|