@teambit/scripts 0.0.0-d02046e0c06f3c0cf1554595df1188b64d99650f → 0.0.0-d4e793c7e477fb55c174145d50300d4e1daf6372

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,24 +93,33 @@ 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);
@@ -133,14 +142,21 @@ class ScriptsMain {
133
142
  /**
134
143
  * List all available scripts from all environments
135
144
  */
136
- async listAllScripts(pattern) {
137
- 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();
138
152
  if (!components.length) {
139
153
  return _chalk().default.yellow('no components found');
140
154
  }
141
- const componentsByEnv = this.groupComponentsByEnv(components);
155
+
156
+ // Group components by environment, filtering only configured envs
157
+ const componentsByEnv = this.groupComponentsByEnv(components, allowedEnvs);
142
158
  const results = [];
143
- results.push(_chalk().default.green('Available scripts:\n'));
159
+ let foundAnyScripts = false;
144
160
  for (const [envId, envComponents] of Object.entries(componentsByEnv)) {
145
161
  const env = this.envs.getEnvDefinitionByStringId(envId);
146
162
  if (!env) continue;
@@ -148,6 +164,10 @@ class ScriptsMain {
148
164
  if (!scripts || scripts.isEmpty()) {
149
165
  continue;
150
166
  }
167
+ if (!foundAnyScripts) {
168
+ results.push(_chalk().default.green('Available scripts:\n'));
169
+ foundAnyScripts = true;
170
+ }
151
171
  results.push(_chalk().default.cyan(`\nEnvironment: ${envId}`));
152
172
  results.push(_chalk().default.gray(` (used by ${envComponents.length} component(s))`));
153
173
  const scriptsList = scripts.list();
@@ -157,26 +177,50 @@ class ScriptsMain {
157
177
  results.push(` ${_chalk().default.bold(scriptName)}: ${handlerStr}`);
158
178
  });
159
179
  }
180
+ if (!foundAnyScripts) {
181
+ return _chalk().default.yellow('no scripts defined in the configured environments');
182
+ }
160
183
  return results.join('\n');
161
184
  }
162
- async getComponents(pattern) {
163
- if (!pattern) {
164
- // Get all components
165
- const host = this.componentAspect.getHost();
166
- if (!host) throw new Error('workspace not found');
167
- return host.list();
168
- }
169
185
 
170
- // Resolve components by pattern
171
- const componentIds = await this.workspace.resolveMultipleComponentIds([pattern]);
172
- const filteredIds = await this.workspace.filterIds(componentIds);
173
- 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
+ });
174
202
  }
175
- groupComponentsByEnv(components) {
203
+ async getComponents() {
204
+ const host = this.componentAspect.getHost();
205
+ if (!host) throw new Error('workspace not found');
206
+ return host.list();
207
+ }
208
+ groupComponentsByEnv(components, allowedEnvs) {
176
209
  const grouped = (0, _lodash().groupBy)(components, component => {
177
210
  const env = this.envs.getOrCalculateEnv(component);
178
211
  return env.id;
179
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
+ }
180
224
  return grouped;
181
225
  }
182
226
  getScriptsFromEnv(env) {
@@ -205,18 +249,21 @@ class ScriptsMain {
205
249
  return _chalk().default.red(`Error executing script: ${errorMsg}`);
206
250
  }
207
251
  }
208
- async executeFunction(handler, _components) {
252
+ async executeFunction(handler, components) {
209
253
  try {
210
- await handler();
254
+ const context = {
255
+ components
256
+ };
257
+ await handler(context);
211
258
  return _chalk().default.green('✓ Script function executed successfully');
212
259
  } catch (error) {
213
260
  return _chalk().default.red(`Error executing script function: ${error.message}`);
214
261
  }
215
262
  }
216
- static async provider([cli, workspace, envs, componentAspect, loggerMain]) {
263
+ static async provider([cli, workspace, envs, componentAspect, loggerMain], config) {
217
264
  const logger = loggerMain.createLogger(_scripts().ScriptsAspect.id);
218
265
  const scriptsService = new (_scripts2().ScriptsService)();
219
- const scriptsMain = new ScriptsMain(workspace, envs, logger, componentAspect);
266
+ const scriptsMain = new ScriptsMain(workspace, envs, logger, componentAspect, config);
220
267
 
221
268
  // Register service with envs
222
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","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) 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(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,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,OAAAN,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAQ,QAAA;EAAA,MAAAR,IAAA,GAAAC,OA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_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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ACvB,EAAE,CAAC;IACxD,MAAMwB,cAAc,GAAG,KAAIC,0BAAc,EAAC,CAAC;IAC3C,MAAMC,WAAW,GAAG,IAAIrF,WAAW,CAACE,SAAS,EAAEC,IAAI,EAAEC,MAAM,EAAEC,eAAe,EAAEC,MAAM,CAAC;;IAErF;IACAH,IAAI,CAACmF,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,CAAA1F,WAAA,GAAAA,WAAA;AAAAlB,eAAA,CAnOYkB,WAAW,WA4MP,EAAE;AAAAlB,eAAA,CA5MNkB,WAAW,kBA8MA,CAAC2F,gBAAS,EAAEC,4BAAe,EAAEC,kBAAU,EAAEC,4BAAe,EAAEC,sBAAY,CAAC;AAAAjH,eAAA,CA9MlFkB,WAAW,aAgNLgG,kBAAW;AAqB9Bd,wBAAa,CAACe,UAAU,CAACjG,WAAW,CAAC;AAAC,IAAAkG,QAAA,GAAAR,OAAA,CAAA7G,OAAA,GAEvBmB,WAAW","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,24 +1,25 @@
1
1
  {
2
2
  "name": "@teambit/scripts",
3
- "version": "0.0.0-d02046e0c06f3c0cf1554595df1188b64d99650f",
3
+ "version": "0.0.0-d4e793c7e477fb55c174145d50300d4e1daf6372",
4
+ "homepage": "https://bit.cloud/teambit/workspace/scripts",
4
5
  "main": "dist/index.js",
5
6
  "componentId": {
7
+ "scope": "teambit.workspace",
6
8
  "name": "scripts",
7
- "version": "d02046e0c06f3c0cf1554595df1188b64d99650f",
8
- "scope": "teambit.workspace"
9
+ "version": "d4e793c7e477fb55c174145d50300d4e1daf6372"
9
10
  },
10
11
  "dependencies": {
11
12
  "chalk": "4.1.2",
12
13
  "lodash": "4.17.21",
13
14
  "core-js": "^3.0.0",
14
15
  "@babel/runtime": "7.20.0",
15
- "@teambit/cli": "0.0.1279",
16
+ "@teambit/cli": "0.0.1282",
16
17
  "@teambit/harmony": "0.4.7",
17
- "@teambit/logger": "0.0.1372",
18
+ "@teambit/logger": "0.0.1375",
18
19
  "@teambit/bit-error": "0.0.404",
19
- "@teambit/component": "0.0.0-869123be50382f9d3771ccfe9eb93d3762065382",
20
- "@teambit/envs": "0.0.0-0436f381fa536c01138924fdd58782e50088e1ed",
21
- "@teambit/workspace": "0.0.0-e45964b04d6624c23f2e38a1e45122ef1040d8c4"
20
+ "@teambit/component": "0.0.0-fcd5175d046df1dc3698e485fe298c4d7009481b",
21
+ "@teambit/envs": "0.0.0-79756bf03cd89fde9ee1f79bae188ab6f02578ff",
22
+ "@teambit/workspace": "0.0.0-acab97b325a044691ea8659b60e9f167f0109728"
22
23
  },
23
24
  "devDependencies": {
24
25
  "@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,27 +15,49 @@ 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)) {
@@ -67,16 +89,22 @@ export class ScriptsMain {
67
89
  /**
68
90
  * List all available scripts from all environments
69
91
  */
70
- async listAllScripts(pattern?: string): Promise<string> {
71
- 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();
72
100
  if (!components.length) {
73
101
  return chalk.yellow('no components found');
74
102
  }
75
103
 
76
- const componentsByEnv = this.groupComponentsByEnv(components);
104
+ // Group components by environment, filtering only configured envs
105
+ const componentsByEnv = this.groupComponentsByEnv(components, allowedEnvs);
77
106
  const results: string[] = [];
78
-
79
- results.push(chalk.green('Available scripts:\n'));
107
+ let foundAnyScripts = false;
80
108
 
81
109
  for (const [envId, envComponents] of Object.entries(componentsByEnv)) {
82
110
  const env = this.envs.getEnvDefinitionByStringId(envId);
@@ -87,6 +115,11 @@ export class ScriptsMain {
87
115
  continue;
88
116
  }
89
117
 
118
+ if (!foundAnyScripts) {
119
+ results.push(chalk.green('Available scripts:\n'));
120
+ foundAnyScripts = true;
121
+ }
122
+
90
123
  results.push(chalk.cyan(`\nEnvironment: ${envId}`));
91
124
  results.push(chalk.gray(` (used by ${envComponents.length} component(s))`));
92
125
 
@@ -98,28 +131,55 @@ export class ScriptsMain {
98
131
  });
99
132
  }
100
133
 
134
+ if (!foundAnyScripts) {
135
+ return chalk.yellow('no scripts defined in the configured environments');
136
+ }
137
+
101
138
  return results.join('\n');
102
139
  }
103
140
 
104
- private async getComponents(pattern?: string): Promise<Component[]> {
105
- if (!pattern) {
106
- // Get all components
107
- const host = this.componentAspect.getHost();
108
- if (!host) throw new Error('workspace not found');
109
- return host.list();
110
- }
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
+ }
155
+
156
+ return false;
157
+ });
158
+ }
111
159
 
112
- // Resolve components by pattern
113
- const componentIds = await this.workspace.resolveMultipleComponentIds([pattern]);
114
- const filteredIds = await this.workspace.filterIds(componentIds);
115
- return this.workspace.getMany(filteredIds);
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();
116
164
  }
117
165
 
118
- private groupComponentsByEnv(components: Component[]): Record<string, Component[]> {
166
+ private groupComponentsByEnv(components: Component[], allowedEnvs?: string[]): Record<string, Component[]> {
119
167
  const grouped = groupBy(components, (component) => {
120
168
  const env = this.envs.getOrCalculateEnv(component);
121
169
  return env.id;
122
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
+
123
183
  return grouped;
124
184
  }
125
185
 
@@ -152,9 +212,13 @@ export class ScriptsMain {
152
212
  }
153
213
  }
154
214
 
155
- 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> {
156
219
  try {
157
- await handler();
220
+ const context: ScriptExecuteContext = { components };
221
+ await handler(context);
158
222
  return chalk.green('✓ Script function executed successfully');
159
223
  } catch (error: any) {
160
224
  return chalk.red(`Error executing script function: ${error.message}`);
@@ -167,16 +231,13 @@ export class ScriptsMain {
167
231
 
168
232
  static runtime = MainRuntime;
169
233
 
170
- static async provider([cli, workspace, envs, componentAspect, loggerMain]: [
171
- CLIMain,
172
- Workspace,
173
- EnvsMain,
174
- ComponentMain,
175
- LoggerMain,
176
- ]) {
234
+ static async provider(
235
+ [cli, workspace, envs, componentAspect, loggerMain]: [CLIMain, Workspace, EnvsMain, ComponentMain, LoggerMain],
236
+ config: ScriptsConfig
237
+ ) {
177
238
  const logger = loggerMain.createLogger(ScriptsAspect.id);
178
239
  const scriptsService = new ScriptsService();
179
- const scriptsMain = new ScriptsMain(workspace, envs, logger, componentAspect);
240
+ const scriptsMain = new ScriptsMain(workspace, envs, logger, componentAspect, config);
180
241
 
181
242
  // Register service with envs
182
243
  envs.registerService(scriptsService);
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
- }