@teambit/scripts 0.0.0-e42bf10dc161cd9ecae46d4cb0f8d14531cf6939 → 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1 @@
1
1
  export { ScriptNotFound } from './script-not-found';
2
- export { NoScriptsDefined } from './no-scripts-defined';
@@ -3,12 +3,6 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- Object.defineProperty(exports, "NoScriptsDefined", {
7
- enumerable: true,
8
- get: function () {
9
- return _noScriptsDefined().NoScriptsDefined;
10
- }
11
- });
12
6
  Object.defineProperty(exports, "ScriptNotFound", {
13
7
  enumerable: true,
14
8
  get: function () {
@@ -22,12 +16,5 @@ function _scriptNotFound() {
22
16
  };
23
17
  return data;
24
18
  }
25
- function _noScriptsDefined() {
26
- const data = require("./no-scripts-defined");
27
- _noScriptsDefined = function () {
28
- return data;
29
- };
30
- return data;
31
- }
32
19
 
33
20
  //# sourceMappingURL=index.js.map
@@ -1 +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":[]}
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":[]}
package/dist/index.d.ts CHANGED
@@ -2,6 +2,6 @@ import { ScriptsAspect } from './scripts.aspect';
2
2
  export type { ScriptsMain } from './scripts.main.runtime';
3
3
  export { Scripts } from './scripts';
4
4
  export type { ScriptHandler, ScriptDefinition, ScriptsMap } from './script-definition';
5
- export { ScriptNotFound, NoScriptsDefined } from './exceptions';
5
+ export { ScriptNotFound } from './exceptions';
6
6
  export default ScriptsAspect;
7
7
  export { ScriptsAspect };
package/dist/index.js CHANGED
@@ -3,12 +3,6 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- Object.defineProperty(exports, "NoScriptsDefined", {
7
- enumerable: true,
8
- get: function () {
9
- return _exceptions().NoScriptsDefined;
10
- }
11
- });
12
6
  Object.defineProperty(exports, "ScriptNotFound", {
13
7
  enumerable: true,
14
8
  get: function () {
package/dist/index.js.map CHANGED
@@ -1 +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":[]}
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":[]}
@@ -1,4 +1,8 @@
1
- export type ScriptHandler = string | (() => void | Promise<void>);
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>);
2
6
  export interface ScriptDefinition {
3
7
  name: string;
4
8
  handler: ScriptHandler;
@@ -1 +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":[]}
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":[]}
@@ -10,32 +10,29 @@ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e =
10
10
  class ScriptCmd {
11
11
  constructor(scripts) {
12
12
  this.scripts = scripts;
13
- _defineProperty(this, "name", 'script [script-name] [pattern]');
13
+ _defineProperty(this, "name", 'script [script-name]');
14
14
  _defineProperty(this, "description", 'run a script defined by the environment');
15
15
  _defineProperty(this, "extendedDescription", `executes custom scripts defined by component environments.
16
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.
17
+ runs the script for all components grouped by their environment.
18
18
  use --list to see all available scripts.`);
19
19
  _defineProperty(this, "arguments", [{
20
20
  name: 'script-name',
21
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
22
  }]);
26
23
  _defineProperty(this, "alias", '');
27
24
  _defineProperty(this, "group", 'development');
28
25
  _defineProperty(this, "options", [['l', 'list', 'list all available scripts from all environments']]);
29
26
  }
30
27
  async report(args, options) {
31
- const [scriptName, pattern] = args;
28
+ const [scriptName] = args;
32
29
  if (options.list) {
33
- return this.scripts.listAllScripts(pattern);
30
+ return this.scripts.listAllScripts();
34
31
  }
35
32
  if (!scriptName) {
36
33
  throw new Error('script name is required. Use --list to see available scripts.');
37
34
  }
38
- return this.scripts.runScript(scriptName, pattern);
35
+ return this.scripts.runScript(scriptName);
39
36
  }
40
37
  }
41
38
  exports.ScriptCmd = ScriptCmd;
@@ -1 +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":[]}
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":[]}
package/dist/scripts.d.ts CHANGED
@@ -1,8 +1,9 @@
1
+ import type { EnvHandler } from '@teambit/envs';
1
2
  import type { ScriptHandler, ScriptsMap } from './script-definition';
2
3
  export declare class Scripts {
3
4
  private scriptsMap;
4
5
  constructor(scriptsMap: ScriptsMap);
5
- static from(scripts: ScriptsMap): Scripts;
6
+ static from(scripts: ScriptsMap): EnvHandler<Scripts>;
6
7
  get(name: string): ScriptHandler | undefined;
7
8
  has(name: string): boolean;
8
9
  list(): string[];
package/dist/scripts.js CHANGED
@@ -9,7 +9,9 @@ class Scripts {
9
9
  this.scriptsMap = scriptsMap;
10
10
  }
11
11
  static from(scripts) {
12
- return new Scripts(scripts);
12
+ return _context => {
13
+ return new Scripts(scripts);
14
+ };
13
15
  }
14
16
  get(name) {
15
17
  return this.scriptsMap[name];
@@ -1 +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":[]}
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":[]}
@@ -3,20 +3,30 @@ import { ComponentMain } from '@teambit/component';
3
3
  import type { EnvsMain } from '@teambit/envs';
4
4
  import type { Logger, LoggerMain } from '@teambit/logger';
5
5
  import type { Workspace } from '@teambit/workspace';
6
+ export interface ScriptsConfig {
7
+ envs?: string[];
8
+ }
6
9
  export declare class ScriptsMain {
7
10
  private workspace;
8
11
  private envs;
9
12
  private logger;
10
13
  private componentAspect;
11
- constructor(workspace: Workspace, envs: EnvsMain, logger: Logger, componentAspect: ComponentMain);
14
+ private config;
15
+ constructor(workspace: Workspace, envs: EnvsMain, logger: Logger, componentAspect: ComponentMain, config: ScriptsConfig);
16
+ private getConfigErrorMessage;
12
17
  /**
13
- * Run a script for components matching the pattern
18
+ * Run a script for all components
14
19
  */
15
- runScript(scriptName: string, pattern?: string): Promise<string>;
20
+ runScript(scriptName: string): Promise<string>;
16
21
  /**
17
22
  * List all available scripts from all environments
18
23
  */
19
- listAllScripts(pattern?: string): Promise<string>;
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;
20
30
  private getComponents;
21
31
  private groupComponentsByEnv;
22
32
  private getScriptsFromEnv;
@@ -26,12 +36,6 @@ export declare class ScriptsMain {
26
36
  static slots: never[];
27
37
  static dependencies: import("@teambit/harmony").Aspect[];
28
38
  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>;
39
+ static provider([cli, workspace, envs, componentAspect, loggerMain]: [CLIMain, Workspace, EnvsMain, ComponentMain, LoggerMain], config: ScriptsConfig): Promise<ScriptsMain>;
36
40
  }
37
41
  export default ScriptsMain;
@@ -93,36 +93,39 @@ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object
93
93
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
94
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
95
  class ScriptsMain {
96
- constructor(workspace, envs, logger, componentAspect) {
96
+ constructor(workspace, envs, logger, componentAspect, config) {
97
97
  this.workspace = workspace;
98
98
  this.envs = envs;
99
99
  this.logger = logger;
100
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' + '}');
101
105
  }
102
106
 
103
107
  /**
104
- * Run a script for components matching the pattern
108
+ * Run a script for all components
105
109
  */
106
- async runScript(scriptName, pattern) {
107
- const components = await this.getComponents(pattern);
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();
108
117
  if (!components.length) {
109
118
  return _chalk().default.yellow('no components found');
110
119
  }
111
120
 
112
- // Group components by environment
113
- const componentsByEnv = this.groupComponentsByEnv(components);
121
+ // Group components by environment, filtering only configured envs
122
+ const componentsByEnv = this.groupComponentsByEnv(components, allowedEnvs);
114
123
  const results = [];
115
124
  for (const [envId, envComponents] of Object.entries(componentsByEnv)) {
116
125
  const env = this.envs.getEnvDefinitionByStringId(envId);
117
- if (!env) {
118
- this.logger.console(_chalk().default.yellow(`env ${envId} not found, skipping`));
119
- continue;
120
- }
126
+ if (!env) continue;
121
127
  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
- }
128
+ if (!scripts) continue;
126
129
  if (!scripts.has(scriptName)) {
127
130
  throw new (_exceptions().ScriptNotFound)(scriptName, envId);
128
131
  }
@@ -139,14 +142,21 @@ class ScriptsMain {
139
142
  /**
140
143
  * List all available scripts from all environments
141
144
  */
142
- async listAllScripts(pattern) {
143
- const components = await this.getComponents(pattern);
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();
144
152
  if (!components.length) {
145
153
  return _chalk().default.yellow('no components found');
146
154
  }
147
- const componentsByEnv = this.groupComponentsByEnv(components);
155
+
156
+ // Group components by environment, filtering only configured envs
157
+ const componentsByEnv = this.groupComponentsByEnv(components, allowedEnvs);
148
158
  const results = [];
149
- results.push(_chalk().default.green('Available scripts:\n'));
159
+ let foundAnyScripts = false;
150
160
  for (const [envId, envComponents] of Object.entries(componentsByEnv)) {
151
161
  const env = this.envs.getEnvDefinitionByStringId(envId);
152
162
  if (!env) continue;
@@ -154,6 +164,10 @@ class ScriptsMain {
154
164
  if (!scripts || scripts.isEmpty()) {
155
165
  continue;
156
166
  }
167
+ if (!foundAnyScripts) {
168
+ results.push(_chalk().default.green('Available scripts:\n'));
169
+ foundAnyScripts = true;
170
+ }
157
171
  results.push(_chalk().default.cyan(`\nEnvironment: ${envId}`));
158
172
  results.push(_chalk().default.gray(` (used by ${envComponents.length} component(s))`));
159
173
  const scriptsList = scripts.list();
@@ -163,26 +177,50 @@ class ScriptsMain {
163
177
  results.push(` ${_chalk().default.bold(scriptName)}: ${handlerStr}`);
164
178
  });
165
179
  }
180
+ if (!foundAnyScripts) {
181
+ return _chalk().default.yellow('no scripts defined in the configured environments');
182
+ }
166
183
  return results.join('\n');
167
184
  }
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
185
 
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);
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();
180
207
  }
181
- groupComponentsByEnv(components) {
208
+ groupComponentsByEnv(components, allowedEnvs) {
182
209
  const grouped = (0, _lodash().groupBy)(components, component => {
183
210
  const env = this.envs.getOrCalculateEnv(component);
184
211
  return env.id;
185
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
+ }
186
224
  return grouped;
187
225
  }
188
226
  getScriptsFromEnv(env) {
@@ -211,18 +249,21 @@ class ScriptsMain {
211
249
  return _chalk().default.red(`Error executing script: ${errorMsg}`);
212
250
  }
213
251
  }
214
- async executeFunction(handler, _components) {
252
+ async executeFunction(handler, components) {
215
253
  try {
216
- await handler();
254
+ const context = {
255
+ components
256
+ };
257
+ await handler(context);
217
258
  return _chalk().default.green('✓ Script function executed successfully');
218
259
  } catch (error) {
219
260
  return _chalk().default.red(`Error executing script function: ${error.message}`);
220
261
  }
221
262
  }
222
- static async provider([cli, workspace, envs, componentAspect, loggerMain]) {
263
+ static async provider([cli, workspace, envs, componentAspect, loggerMain], config) {
223
264
  const logger = loggerMain.createLogger(_scripts().ScriptsAspect.id);
224
265
  const scriptsService = new (_scripts2().ScriptsService)();
225
- const scriptsMain = new ScriptsMain(workspace, envs, logger, componentAspect);
266
+ const scriptsMain = new ScriptsMain(workspace, envs, logger, componentAspect, config);
226
267
 
227
268
  // Register service with envs
228
269
  envs.registerService(scriptsService);
@@ -1 +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;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAE,WAAA;EAAA,MAAAF,IAAA,GAAAC,OAAA;EAAAC,UAAA,YAAAA,CAAA;IAAA,OAAAF,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAG,MAAA;EAAA,MAAAH,IAAA,GAAAC,OAAA;EAAAE,KAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAI,QAAA;EAAA,MAAAJ,IAAA,GAAAC,OAAA;EAAAG,OAAA,YAAAA,CAAA;IAAA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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":[]}
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","config","getConfigErrorMessage","chalk","yellow","runScript","scriptName","allowedEnvs","length","components","getComponents","componentsByEnv","groupComponentsByEnv","results","envId","envComponents","entries","env","getEnvDefinitionByStringId","scripts","getScriptsFromEnv","has","ScriptNotFound","handler","get","title","green","push","result","executeScript","join","listAllScripts","foundAnyScripts","isEmpty","cyan","gray","scriptsList","list","forEach","handlerStr","white","bold","isEnvAllowed","some","allowedEnv","includes","startsWith","host","getHost","Error","grouped","groupBy","component","getOrCalculateEnv","id","filtered","getScripts","undefined","executeShellCommand","executeFunction","command","output","execSync","cwd","path","encoding","stdio","error","errorMsg","stderr","message","red","context","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, ScriptExecuteContext } from './script-definition';\n\nexport interface ScriptsConfig {\n envs?: string[];\n}\n\nexport class ScriptsMain {\n constructor(\n private workspace: Workspace,\n private envs: EnvsMain,\n private logger: Logger,\n private componentAspect: ComponentMain,\n private config: ScriptsConfig\n ) {}\n\n private getConfigErrorMessage(): string {\n return chalk.yellow(\n 'no envs configured. Add to workspace.jsonc:\\n' +\n '{\\n' +\n ' \"teambit.workspace/scripts\": {\\n' +\n ' \"envs\": [\"your-scope/your-env\"]\\n' +\n ' }\\n' +\n '}'\n );\n }\n\n /**\n * Run a script for all components\n */\n async runScript(scriptName: string): Promise<string> {\n // Filter envs based on config\n const allowedEnvs = this.config.envs || [];\n if (allowedEnvs.length === 0) {\n return this.getConfigErrorMessage();\n }\n\n const components = await this.getComponents();\n if (!components.length) {\n return chalk.yellow('no components found');\n }\n\n // Group components by environment, filtering only configured envs\n const componentsByEnv = this.groupComponentsByEnv(components, allowedEnvs);\n const results: string[] = [];\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) continue;\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(): Promise<string> {\n // Filter envs based on config\n const allowedEnvs = this.config.envs || [];\n if (allowedEnvs.length === 0) {\n return this.getConfigErrorMessage();\n }\n\n const components = await this.getComponents();\n if (!components.length) {\n return chalk.yellow('no components found');\n }\n\n // Group components by environment, filtering only configured envs\n const componentsByEnv = this.groupComponentsByEnv(components, allowedEnvs);\n const results: string[] = [];\n let foundAnyScripts = false;\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 if (!foundAnyScripts) {\n results.push(chalk.green('Available scripts:\\n'));\n foundAnyScripts = true;\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 if (!foundAnyScripts) {\n return chalk.yellow('no scripts defined in the configured environments');\n }\n\n return results.join('\\n');\n }\n\n /**\n * Check if an env is allowed to run scripts based on config\n * Supports exact match with or without version\n */\n private isEnvAllowed(envId: string, allowedEnvs: string[]): boolean {\n return allowedEnvs.some((allowedEnv) => {\n // Exact match (with version): \"my-scope/my-env@1.0.0\" === \"my-scope/my-env@1.0.0\"\n if (envId === allowedEnv) return true;\n\n // If config has no version, match env without version part\n // Config: \"my-scope/my-env\" should match \"my-scope/my-env@1.0.0\"\n if (!allowedEnv.includes('@') && envId.startsWith(allowedEnv + '@')) {\n return true;\n }\n\n return false;\n });\n }\n\n private async getComponents(): Promise<Component[]> {\n const host = this.componentAspect.getHost();\n if (!host) throw new Error('workspace not found');\n return host.list();\n }\n\n private groupComponentsByEnv(components: Component[], allowedEnvs?: string[]): Record<string, Component[]> {\n const grouped = groupBy(components, (component) => {\n const env = this.envs.getOrCalculateEnv(component);\n return env.id;\n });\n\n // If allowedEnvs is provided, filter out envs not in the list\n if (allowedEnvs && allowedEnvs.length > 0) {\n const filtered: Record<string, Component[]> = {};\n for (const [envId, envComponents] of Object.entries(grouped)) {\n if (this.isEnvAllowed(envId, allowedEnvs)) {\n filtered[envId] = envComponents;\n }\n }\n return filtered;\n }\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(\n handler: (context?: ScriptExecuteContext) => void | Promise<void>,\n components: Component[]\n ): Promise<string> {\n try {\n const context: ScriptExecuteContext = { components };\n await handler(context);\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(\n [cli, workspace, envs, componentAspect, loggerMain]: [CLIMain, Workspace, EnvsMain, ComponentMain, LoggerMain],\n config: ScriptsConfig\n ) {\n const logger = loggerMain.createLogger(ScriptsAspect.id);\n const scriptsService = new ScriptsService();\n const scriptsMain = new ScriptsMain(workspace, envs, logger, componentAspect, config);\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;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAE,WAAA;EAAA,MAAAF,IAAA,GAAAC,OAAA;EAAAC,UAAA,YAAAA,CAAA;IAAA,OAAAF,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAG,MAAA;EAAA,MAAAH,IAAA,GAAAC,OAAA;EAAAE,KAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAI,QAAA;EAAA,MAAAJ,IAAA,GAAAC,OAAA;EAAAG,OAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAK,WAAA;EAAA,MAAAL,IAAA,GAAAC,OAAA;EAAAI,UAAA,YAAAA,CAAA;IAAA,OAAAL,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAM,OAAA;EAAA,MAAAN,IAAA,GAAAO,sBAAA,CAAAN,OAAA;EAAAK,MAAA,YAAAA,CAAA;IAAA,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CAACe,UAAU,CAACjG,WAAW,CAAC;AAAC,IAAAkG,QAAA,GAAAR,OAAA,CAAA7G,OAAA,GAEvBmB,WAAW","ignoreList":[]}
@@ -43,9 +43,8 @@ class ScriptsService {
43
43
  }
44
44
  transform(env, context) {
45
45
  if (!(env !== null && env !== void 0 && env.scripts)) return undefined;
46
- const scriptsObj = env.scripts()(context);
47
46
  return {
48
- getScripts: () => scriptsObj
47
+ getScripts: () => env.scripts()(context)
49
48
  };
50
49
  }
51
50
  }
@@ -1 +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,CAAA,IAAAK,KAAA,EAAAJ,CAAA,EAAAK,UAAA,MAAAC,YAAA,MAAAC,QAAA,UAAAZ,CAAA,CAAAI,CAAA,IAAAC,CAAA,EAAAL,CAAA;AAAA,SAAAM,eAAAD,CAAA,QAAAQ,CAAA,GAAAC,YAAA,CAAAT,CAAA,uCAAAQ,CAAA,GAAAA,CAAA,GAAAA,CAAA;AAAA,SAAAC,aAAAT,CAAA,EAAAD,CAAA,2BAAAC,CAAA,KAAAA,CAAA,SAAAA,CAAA,MAAAL,CAAA,GAAAK,CAAA,CAAAU,MAAA,CAAAC,WAAA,kBAAAhB,CAAA,QAAAa,CAAA,GAAAb,CAAA,CAAAiB,IAAA,CAAAZ,CAAA,EAAAD,CAAA,uCAAAS,CAAA,SAAAA,CAAA,YAAAK,SAAA,yEAAAd,CAAA,GAAAe,MAAA,GAAAC,MAAA,EAAAf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AEAC,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":[]}
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","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 return {\n getScripts: () => env.scripts()(context),\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,CAAA,IAAAK,KAAA,EAAAJ,CAAA,EAAAK,UAAA,MAAAC,YAAA,MAAAC,QAAA,UAAAZ,CAAA,CAAAI,CAAA,IAAAC,CAAA,EAAAL,CAAA;AAAA,SAAAM,eAAAD,CAAA,QAAAQ,CAAA,GAAAC,YAAA,CAAAT,CAAA,uCAAAQ,CAAA,GAAAA,CAAA,GAAAA,CAAA;AAAA,SAAAC,aAAAT,CAAA,EAAAD,CAAA,2BAAAC,CAAA,KAAAA,CAAA,SAAAA,CAAA,MAAAL,CAAA,GAAAK,CAAA,CAAAU,MAAA,CAAAC,WAAA,kBAAAhB,CAAA,QAAAa,CAAA,GAAAb,CAAA,CAAAiB,IAAA,CAAAZ,CAAA,EAAAD,CAAA,uCAAAS,CAAA,SAAAA,CAAA,YAAAK,SAAA,yEAAAd,CAAA,GAAAe,MAAA,GAAAC,MAAA,EAAAf,CAAA;AAcnB,MAAMgB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AQ,EAAEyB,OAAmB,EAAwC;IAC7E,IAAI,EAACzB,GAAG,aAAHA,GAAG,eAAHA,GAAG,CAAEI,OAAO,GAAE,OAAOgB,SAAS;IACnC,OAAO;MACLD,UAAU,EAAEA,CAAA,KAAMnB,GAAG,CAACI,OAAO,CAAC,CAAC,CAACqB,OAAO;IACzC,CAAC;EACH;AACF;AAACC,OAAA,CAAA7B,cAAA,GAAAA,cAAA","ignoreList":[]}
@@ -1,2 +1 @@
1
1
  export { ScriptNotFound } from './script-not-found';
2
- export { NoScriptsDefined } from './no-scripts-defined';
package/index.ts CHANGED
@@ -3,6 +3,6 @@ import { ScriptsAspect } from './scripts.aspect';
3
3
  export type { ScriptsMain } from './scripts.main.runtime';
4
4
  export { Scripts } from './scripts';
5
5
  export type { ScriptHandler, ScriptDefinition, ScriptsMap } from './script-definition';
6
- export { ScriptNotFound, NoScriptsDefined } from './exceptions';
6
+ export { ScriptNotFound } from './exceptions';
7
7
  export default ScriptsAspect;
8
8
  export { ScriptsAspect };
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@teambit/scripts",
3
- "version": "0.0.0-e42bf10dc161cd9ecae46d4cb0f8d14531cf6939",
3
+ "version": "0.0.1",
4
4
  "main": "dist/index.js",
5
5
  "componentId": {
6
6
  "name": "scripts",
7
- "version": "e42bf10dc161cd9ecae46d4cb0f8d14531cf6939",
7
+ "version": "0.0.1",
8
8
  "scope": "teambit.workspace"
9
9
  },
10
10
  "dependencies": {
@@ -12,13 +12,13 @@
12
12
  "lodash": "4.17.21",
13
13
  "core-js": "^3.0.0",
14
14
  "@babel/runtime": "7.20.0",
15
- "@teambit/cli": "0.0.1278",
15
+ "@teambit/cli": "0.0.1282",
16
16
  "@teambit/harmony": "0.4.7",
17
- "@teambit/logger": "0.0.1371",
17
+ "@teambit/logger": "0.0.1375",
18
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"
19
+ "@teambit/component": "1.0.782",
20
+ "@teambit/envs": "1.0.782",
21
+ "@teambit/workspace": "1.0.782"
22
22
  },
23
23
  "devDependencies": {
24
24
  "@types/lodash": "4.14.165",
@@ -1,4 +1,10 @@
1
- export type ScriptHandler = string | (() => void | Promise<void>);
1
+ import type { Component } from '@teambit/component';
2
+
3
+ export interface ScriptExecuteContext {
4
+ components: Component[];
5
+ }
6
+
7
+ export type ScriptHandler = string | ((context?: ScriptExecuteContext) => void | Promise<void>);
2
8
 
3
9
  export interface ScriptDefinition {
4
10
  name: string;
package/script.cmd.ts CHANGED
@@ -6,21 +6,17 @@ export type ScriptOptions = {
6
6
  };
7
7
 
8
8
  export class ScriptCmd implements Command {
9
- name = 'script [script-name] [pattern]';
9
+ name = 'script [script-name]';
10
10
  description = 'run a script defined by the environment';
11
11
  extendedDescription = `executes custom scripts defined by component environments.
12
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.
13
+ runs the script for all components grouped by their environment.
14
14
  use --list to see all available scripts.`;
15
15
  arguments = [
16
16
  {
17
17
  name: 'script-name',
18
18
  description: 'the name of the script to run (e.g., "generate-svg", "pre-snap")',
19
19
  },
20
- {
21
- name: 'pattern',
22
- description: 'component pattern (optional, runs on all components if not specified)',
23
- },
24
20
  ];
25
21
  alias = '';
26
22
  group = 'development';
@@ -29,16 +25,16 @@ use --list to see all available scripts.`;
29
25
  constructor(private scripts: ScriptsMain) {}
30
26
 
31
27
  async report(args: string[], options: ScriptOptions): Promise<string> {
32
- const [scriptName, pattern] = args;
28
+ const [scriptName] = args;
33
29
 
34
30
  if (options.list) {
35
- return this.scripts.listAllScripts(pattern);
31
+ return this.scripts.listAllScripts();
36
32
  }
37
33
 
38
34
  if (!scriptName) {
39
35
  throw new Error('script name is required. Use --list to see available scripts.');
40
36
  }
41
37
 
42
- return this.scripts.runScript(scriptName, pattern);
38
+ return this.scripts.runScript(scriptName);
43
39
  }
44
40
  }
@@ -15,41 +15,57 @@ import { ScriptsService } from './scripts.service';
15
15
  import { ScriptCmd } from './script.cmd';
16
16
  import { ScriptNotFound } from './exceptions';
17
17
  import type { Scripts } from './scripts';
18
- import type { ScriptHandler } from './script-definition';
18
+ import type { ScriptHandler, ScriptExecuteContext } from './script-definition';
19
+
20
+ export interface ScriptsConfig {
21
+ envs?: string[];
22
+ }
19
23
 
20
24
  export class ScriptsMain {
21
25
  constructor(
22
26
  private workspace: Workspace,
23
27
  private envs: EnvsMain,
24
28
  private logger: Logger,
25
- private componentAspect: ComponentMain
29
+ private componentAspect: ComponentMain,
30
+ private config: ScriptsConfig
26
31
  ) {}
27
32
 
33
+ private getConfigErrorMessage(): string {
34
+ return chalk.yellow(
35
+ 'no envs configured. Add to workspace.jsonc:\n' +
36
+ '{\n' +
37
+ ' "teambit.workspace/scripts": {\n' +
38
+ ' "envs": ["your-scope/your-env"]\n' +
39
+ ' }\n' +
40
+ '}'
41
+ );
42
+ }
43
+
28
44
  /**
29
- * Run a script for components matching the pattern
45
+ * Run a script for all components
30
46
  */
31
- async runScript(scriptName: string, pattern?: string): Promise<string> {
32
- const components = await this.getComponents(pattern);
47
+ async runScript(scriptName: string): Promise<string> {
48
+ // Filter envs based on config
49
+ const allowedEnvs = this.config.envs || [];
50
+ if (allowedEnvs.length === 0) {
51
+ return this.getConfigErrorMessage();
52
+ }
53
+
54
+ const components = await this.getComponents();
33
55
  if (!components.length) {
34
56
  return chalk.yellow('no components found');
35
57
  }
36
58
 
37
- // Group components by environment
38
- const componentsByEnv = this.groupComponentsByEnv(components);
59
+ // Group components by environment, filtering only configured envs
60
+ const componentsByEnv = this.groupComponentsByEnv(components, allowedEnvs);
39
61
  const results: string[] = [];
40
62
 
41
63
  for (const [envId, envComponents] of Object.entries(componentsByEnv)) {
42
64
  const env = this.envs.getEnvDefinitionByStringId(envId);
43
- if (!env) {
44
- this.logger.console(chalk.yellow(`env ${envId} not found, skipping`));
45
- continue;
46
- }
65
+ if (!env) continue;
47
66
 
48
67
  const scripts = this.getScriptsFromEnv(env);
49
- if (!scripts) {
50
- this.logger.console(chalk.yellow(`env ${envId} has no scripts defined, skipping`));
51
- continue;
52
- }
68
+ if (!scripts) continue;
53
69
 
54
70
  if (!scripts.has(scriptName)) {
55
71
  throw new ScriptNotFound(scriptName, envId);
@@ -73,16 +89,22 @@ export class ScriptsMain {
73
89
  /**
74
90
  * List all available scripts from all environments
75
91
  */
76
- async listAllScripts(pattern?: string): Promise<string> {
77
- const components = await this.getComponents(pattern);
92
+ async listAllScripts(): Promise<string> {
93
+ // Filter envs based on config
94
+ const allowedEnvs = this.config.envs || [];
95
+ if (allowedEnvs.length === 0) {
96
+ return this.getConfigErrorMessage();
97
+ }
98
+
99
+ const components = await this.getComponents();
78
100
  if (!components.length) {
79
101
  return chalk.yellow('no components found');
80
102
  }
81
103
 
82
- const componentsByEnv = this.groupComponentsByEnv(components);
104
+ // Group components by environment, filtering only configured envs
105
+ const componentsByEnv = this.groupComponentsByEnv(components, allowedEnvs);
83
106
  const results: string[] = [];
84
-
85
- results.push(chalk.green('Available scripts:\n'));
107
+ let foundAnyScripts = false;
86
108
 
87
109
  for (const [envId, envComponents] of Object.entries(componentsByEnv)) {
88
110
  const env = this.envs.getEnvDefinitionByStringId(envId);
@@ -93,6 +115,11 @@ export class ScriptsMain {
93
115
  continue;
94
116
  }
95
117
 
118
+ if (!foundAnyScripts) {
119
+ results.push(chalk.green('Available scripts:\n'));
120
+ foundAnyScripts = true;
121
+ }
122
+
96
123
  results.push(chalk.cyan(`\nEnvironment: ${envId}`));
97
124
  results.push(chalk.gray(` (used by ${envComponents.length} component(s))`));
98
125
 
@@ -104,28 +131,55 @@ export class ScriptsMain {
104
131
  });
105
132
  }
106
133
 
134
+ if (!foundAnyScripts) {
135
+ return chalk.yellow('no scripts defined in the configured environments');
136
+ }
137
+
107
138
  return results.join('\n');
108
139
  }
109
140
 
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
- }
141
+ /**
142
+ * Check if an env is allowed to run scripts based on config
143
+ * Supports exact match with or without version
144
+ */
145
+ private isEnvAllowed(envId: string, allowedEnvs: string[]): boolean {
146
+ return allowedEnvs.some((allowedEnv) => {
147
+ // Exact match (with version): "my-scope/my-env@1.0.0" === "my-scope/my-env@1.0.0"
148
+ if (envId === allowedEnv) return true;
149
+
150
+ // If config has no version, match env without version part
151
+ // Config: "my-scope/my-env" should match "my-scope/my-env@1.0.0"
152
+ if (!allowedEnv.includes('@') && envId.startsWith(allowedEnv + '@')) {
153
+ return true;
154
+ }
117
155
 
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);
156
+ return false;
157
+ });
158
+ }
159
+
160
+ private async getComponents(): Promise<Component[]> {
161
+ const host = this.componentAspect.getHost();
162
+ if (!host) throw new Error('workspace not found');
163
+ return host.list();
122
164
  }
123
165
 
124
- private groupComponentsByEnv(components: Component[]): Record<string, Component[]> {
166
+ private groupComponentsByEnv(components: Component[], allowedEnvs?: string[]): Record<string, Component[]> {
125
167
  const grouped = groupBy(components, (component) => {
126
168
  const env = this.envs.getOrCalculateEnv(component);
127
169
  return env.id;
128
170
  });
171
+
172
+ // If allowedEnvs is provided, filter out envs not in the list
173
+ if (allowedEnvs && allowedEnvs.length > 0) {
174
+ const filtered: Record<string, Component[]> = {};
175
+ for (const [envId, envComponents] of Object.entries(grouped)) {
176
+ if (this.isEnvAllowed(envId, allowedEnvs)) {
177
+ filtered[envId] = envComponents;
178
+ }
179
+ }
180
+ return filtered;
181
+ }
182
+
129
183
  return grouped;
130
184
  }
131
185
 
@@ -158,9 +212,13 @@ export class ScriptsMain {
158
212
  }
159
213
  }
160
214
 
161
- private async executeFunction(handler: () => void | Promise<void>, _components: Component[]): Promise<string> {
215
+ private async executeFunction(
216
+ handler: (context?: ScriptExecuteContext) => void | Promise<void>,
217
+ components: Component[]
218
+ ): Promise<string> {
162
219
  try {
163
- await handler();
220
+ const context: ScriptExecuteContext = { components };
221
+ await handler(context);
164
222
  return chalk.green('✓ Script function executed successfully');
165
223
  } catch (error: any) {
166
224
  return chalk.red(`Error executing script function: ${error.message}`);
@@ -173,16 +231,13 @@ export class ScriptsMain {
173
231
 
174
232
  static runtime = MainRuntime;
175
233
 
176
- static async provider([cli, workspace, envs, componentAspect, loggerMain]: [
177
- CLIMain,
178
- Workspace,
179
- EnvsMain,
180
- ComponentMain,
181
- LoggerMain,
182
- ]) {
234
+ static async provider(
235
+ [cli, workspace, envs, componentAspect, loggerMain]: [CLIMain, Workspace, EnvsMain, ComponentMain, LoggerMain],
236
+ config: ScriptsConfig
237
+ ) {
183
238
  const logger = loggerMain.createLogger(ScriptsAspect.id);
184
239
  const scriptsService = new ScriptsService();
185
- const scriptsMain = new ScriptsMain(workspace, envs, logger, componentAspect);
240
+ const scriptsMain = new ScriptsMain(workspace, envs, logger, componentAspect, config);
186
241
 
187
242
  // Register service with envs
188
243
  envs.registerService(scriptsService);
@@ -47,9 +47,8 @@ export class ScriptsService implements EnvService<{}, ScriptsDescriptor> {
47
47
 
48
48
  transform(env: Env, context: EnvContext): ScriptsTransformationMap | undefined {
49
49
  if (!env?.scripts) return undefined;
50
- const scriptsObj = env.scripts()(context);
51
50
  return {
52
- getScripts: () => scriptsObj,
51
+ getScripts: () => env.scripts()(context),
53
52
  };
54
53
  }
55
54
  }
package/scripts.ts CHANGED
@@ -1,10 +1,13 @@
1
+ import type { EnvContext, EnvHandler } from '@teambit/envs';
1
2
  import type { ScriptHandler, ScriptsMap } from './script-definition';
2
3
 
3
4
  export class Scripts {
4
5
  constructor(private scriptsMap: ScriptsMap) {}
5
6
 
6
- static from(scripts: ScriptsMap): Scripts {
7
- return new Scripts(scripts);
7
+ static from(scripts: ScriptsMap): EnvHandler<Scripts> {
8
+ return (_context: EnvContext) => {
9
+ return new Scripts(scripts);
10
+ };
8
11
  }
9
12
 
10
13
  get(name: string): ScriptHandler | undefined {
@@ -1,5 +0,0 @@
1
- import { BitError } from '@teambit/bit-error';
2
- export declare class NoScriptsDefined extends BitError {
3
- readonly envId: string;
4
- constructor(envId: string);
5
- }
@@ -1,22 +0,0 @@
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
@@ -1 +0,0 @@
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":[]}
@@ -1,7 +0,0 @@
1
- import { BitError } from '@teambit/bit-error';
2
-
3
- export class NoScriptsDefined extends BitError {
4
- constructor(readonly envId: string) {
5
- super(`no scripts are defined in environment "${envId}"`);
6
- }
7
- }