@teambit/generator 0.0.918 → 0.0.920

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.
@@ -19,7 +19,8 @@ export declare class ComponentGenerator {
19
19
  private envs;
20
20
  private newComponentHelper;
21
21
  private aspectId;
22
- constructor(workspace: Workspace, componentIds: ComponentID[], options: CreateOptions, template: ComponentTemplate, envs: EnvsMain, newComponentHelper: NewComponentHelperMain, aspectId: string);
22
+ private envId?;
23
+ constructor(workspace: Workspace, componentIds: ComponentID[], options: CreateOptions, template: ComponentTemplate, envs: EnvsMain, newComponentHelper: NewComponentHelperMain, aspectId: string, envId?: ComponentID | undefined);
23
24
  generate(): Promise<GenerateResult[]>;
24
25
  private deleteGeneratedComponents;
25
26
  private generateOneComponent;
@@ -71,7 +71,7 @@ function _dataToPersist() {
71
71
  return data;
72
72
  }
73
73
  class ComponentGenerator {
74
- constructor(workspace, componentIds, options, template, envs, newComponentHelper, aspectId) {
74
+ constructor(workspace, componentIds, options, template, envs, newComponentHelper, aspectId, envId) {
75
75
  this.workspace = workspace;
76
76
  this.componentIds = componentIds;
77
77
  this.options = options;
@@ -79,6 +79,7 @@ class ComponentGenerator {
79
79
  this.envs = envs;
80
80
  this.newComponentHelper = newComponentHelper;
81
81
  this.aspectId = aspectId;
82
+ this.envId = envId;
82
83
  }
83
84
  async generate() {
84
85
  const dirsToDeleteIfFailed = [];
@@ -141,10 +142,20 @@ class ComponentGenerator {
141
142
  const envBeforeConfigChanges = this.envs.getEnv(component);
142
143
  let config = this.template.config;
143
144
  if (config && typeof config === 'function') {
144
- config = config({
145
+ var _this$template$config;
146
+ const boundConfig = (_this$template$config = this.template.config) === null || _this$template$config === void 0 ? void 0 : _this$template$config.bind(this.template);
147
+ config = boundConfig({
145
148
  aspectId: this.aspectId
146
149
  });
147
150
  }
151
+ if (!config && this.envId) {
152
+ config = {
153
+ [this.envId.toString()]: {},
154
+ 'teambit.envs/envs': {
155
+ env: this.envId.toStringWithoutVersion()
156
+ }
157
+ };
158
+ }
148
159
  const templateEnv = (_config = config) === null || _config === void 0 ? void 0 : (_config$EnvsAspect$id = _config[_envs().default.id]) === null || _config$EnvsAspect$id === void 0 ? void 0 : _config$EnvsAspect$id.env;
149
160
  if (config && templateEnv && hasEnvConfiguredOriginally) {
150
161
  // remove the env we got from the template.
@@ -1 +1 @@
1
- {"version":3,"names":["ComponentGenerator","constructor","workspace","componentIds","options","template","envs","newComponentHelper","aspectId","generate","dirsToDeleteIfFailed","generateResults","pMapSeries","componentId","componentPath","getNewComponentPath","path","fs","existsSync","join","BitError","hasName","fullName","push","generateOneComponent","err","deleteGeneratedComponents","bitMap","write","dirs","Promise","all","map","dir","absoluteDir","remove","code","name","namePascalCase","camelcase","pascalCase","nameCamelCase","files","generateFiles","mainFile","find","file","isMain","writeComponentFiles","addResults","track","rootDir","relativePath","componentName","defaultScope","scope","triggerOnMultipleComponentsAdd","component","get","hasEnvConfiguredOriginally","hasEnvConfigured","envBeforeConfigChanges","getEnv","config","templateEnv","EnvsAspect","id","env","Object","keys","length","undefined","configWithEnv","addEnvIfProvidedByFlag","setEntireConfig","getEnvData","envFromFlag","envFromTemplate","envId","setBy","envSetBy","userEnv","userEnvId","resolveComponentId","userEnvIdWithPotentialVersion","resolveEnvIdWithPotentialVersionForConfig","toStringWithoutVersion","templateFiles","dataToPersist","DataToPersist","vinylFiles","templateFile","templateFileVinyl","Vinyl","base","contents","Buffer","from","content","AbstractVinyl","fromVinyl","results","v","addManyFiles","addBasePath","persistAllToFS"],"sources":["component-generator.ts"],"sourcesContent":["import Vinyl from 'vinyl';\nimport fs from 'fs-extra';\nimport pMapSeries from 'p-map-series';\nimport path from 'path';\nimport { Workspace } from '@teambit/workspace';\nimport EnvsAspect, { EnvsMain } from '@teambit/envs';\nimport camelcase from 'camelcase';\nimport { BitError } from '@teambit/bit-error';\nimport { PathOsBasedRelative } from '@teambit/legacy/dist/utils/path';\nimport { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';\nimport DataToPersist from '@teambit/legacy/dist/consumer/component/sources/data-to-persist';\nimport { NewComponentHelperMain } from '@teambit/new-component-helper';\nimport { ComponentID } from '@teambit/component-id';\nimport { ComponentTemplate, ComponentFile, ComponentConfig } from './component-template';\nimport { CreateOptions } from './create.cmd';\n\nexport type GenerateResult = { id: ComponentID; dir: string; files: string[]; envId: string; envSetBy: string };\n\nexport class ComponentGenerator {\n constructor(\n private workspace: Workspace,\n private componentIds: ComponentID[],\n private options: CreateOptions,\n private template: ComponentTemplate,\n private envs: EnvsMain,\n private newComponentHelper: NewComponentHelperMain,\n private aspectId: string\n ) {}\n\n async generate(): Promise<GenerateResult[]> {\n const dirsToDeleteIfFailed: string[] = [];\n const generateResults = await pMapSeries(this.componentIds, async (componentId) => {\n try {\n const componentPath = this.newComponentHelper.getNewComponentPath(componentId, this.options.path);\n if (fs.existsSync(path.join(this.workspace.path, componentPath))) {\n throw new BitError(`unable to create a component at \"${componentPath}\", this path already exist`);\n }\n if (await this.workspace.hasName(componentId.fullName)) {\n throw new BitError(\n `unable to create a component \"${componentId.fullName}\", a component with the same name already exist`\n );\n }\n dirsToDeleteIfFailed.push(componentPath);\n return await this.generateOneComponent(componentId, componentPath);\n } catch (err: any) {\n await this.deleteGeneratedComponents(dirsToDeleteIfFailed);\n throw err;\n }\n });\n\n await this.workspace.bitMap.write();\n\n return generateResults;\n }\n\n private async deleteGeneratedComponents(dirs: string[]) {\n await Promise.all(\n dirs.map(async (dir) => {\n const absoluteDir = path.join(this.workspace.path, dir);\n try {\n await fs.remove(absoluteDir);\n } catch (err: any) {\n if (err.code !== 'ENOENT') {\n // if not exist, it's fine\n throw err;\n }\n }\n })\n );\n }\n\n private async generateOneComponent(componentId: ComponentID, componentPath: string): Promise<GenerateResult> {\n const name = componentId.name;\n const namePascalCase = camelcase(name, { pascalCase: true });\n const nameCamelCase = camelcase(name);\n const files = this.template.generateFiles({ name, namePascalCase, nameCamelCase, componentId });\n const mainFile = files.find((file) => file.isMain);\n await this.writeComponentFiles(componentPath, files);\n const addResults = await this.workspace.track({\n rootDir: componentPath,\n mainFile: mainFile?.relativePath,\n componentName: componentId.fullName,\n defaultScope: this.options.scope,\n });\n await this.workspace.triggerOnMultipleComponentsAdd();\n const component = await this.workspace.get(componentId);\n const hasEnvConfiguredOriginally = this.envs.hasEnvConfigured(component);\n const envBeforeConfigChanges = this.envs.getEnv(component);\n\n let config = this.template.config;\n if (config && typeof config === 'function') {\n config = config({ aspectId: this.aspectId });\n }\n\n const templateEnv = config?.[EnvsAspect.id]?.env;\n\n if (config && templateEnv && hasEnvConfiguredOriginally) {\n // remove the env we got from the template.\n delete config[templateEnv];\n delete config[EnvsAspect.id].env;\n if (Object.keys(config[EnvsAspect.id]).length === 0) delete config[EnvsAspect.id];\n if (Object.keys(config).length === 0) config = undefined;\n }\n\n const configWithEnv = await this.addEnvIfProvidedByFlag(config);\n if (configWithEnv) this.workspace.bitMap.setEntireConfig(component.id, configWithEnv);\n\n const getEnvData = () => {\n const envFromFlag = this.options.env; // env entered by the user when running `bit create --env`\n const envFromTemplate = config?.[EnvsAspect.id]?.env;\n if (envFromFlag) {\n return {\n envId: envFromFlag,\n setBy: '--env flag',\n };\n }\n if (envFromTemplate) {\n return {\n envId: envFromTemplate,\n setBy: 'template',\n };\n }\n return {\n envId: envBeforeConfigChanges.id,\n setBy: hasEnvConfiguredOriginally ? 'workspace variants' : '<default>',\n };\n };\n const { envId, setBy } = getEnvData();\n return {\n id: componentId,\n dir: componentPath,\n files: addResults.files,\n envId,\n envSetBy: setBy,\n };\n }\n\n private async addEnvIfProvidedByFlag(config?: ComponentConfig): Promise<ComponentConfig | undefined> {\n const userEnv = this.options.env; // env entered by the user when running `bit create --env`\n const templateEnv = config?.[EnvsAspect.id]?.env;\n if (!userEnv || userEnv === templateEnv) {\n return config;\n }\n config = config || {};\n if (templateEnv) {\n // the component template has an env and the user wants a different env.\n delete config[templateEnv];\n }\n const userEnvId = await this.workspace.resolveComponentId(userEnv);\n const userEnvIdWithPotentialVersion = await this.workspace.resolveEnvIdWithPotentialVersionForConfig(userEnvId);\n config[userEnvIdWithPotentialVersion] = {};\n config[EnvsAspect.id] = config[EnvsAspect.id] || {};\n config[EnvsAspect.id].env = userEnvId.toStringWithoutVersion();\n return config;\n }\n\n /**\n * writes the generated template files to the default directory set in the workspace config\n */\n private async writeComponentFiles(\n componentPath: string,\n templateFiles: ComponentFile[]\n ): Promise<PathOsBasedRelative[]> {\n const dataToPersist = new DataToPersist();\n const vinylFiles = templateFiles.map((templateFile) => {\n const templateFileVinyl = new Vinyl({\n base: componentPath,\n path: path.join(componentPath, templateFile.relativePath),\n contents: Buffer.from(templateFile.content),\n });\n return AbstractVinyl.fromVinyl(templateFileVinyl);\n });\n const results = vinylFiles.map((v) => v.path);\n dataToPersist.addManyFiles(vinylFiles);\n dataToPersist.addBasePath(this.workspace.path);\n await dataToPersist.persistAllToFS();\n return results;\n }\n}\n"],"mappings":";;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAQO,MAAMA,kBAAkB,CAAC;EAC9BC,WAAW,CACDC,SAAoB,EACpBC,YAA2B,EAC3BC,OAAsB,EACtBC,QAA2B,EAC3BC,IAAc,EACdC,kBAA0C,EAC1CC,QAAgB,EACxB;IAAA,KAPQN,SAAoB,GAApBA,SAAoB;IAAA,KACpBC,YAA2B,GAA3BA,YAA2B;IAAA,KAC3BC,OAAsB,GAAtBA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AAyC,CAACH,SAAS,CAAC;IAC/GnB,MAAM,CAACqB,6BAA6B,CAAC,GAAG,CAAC,CAAC;IAC1CrB,MAAM,CAACE,eAAU,CAACC,EAAE,CAAC,GAAGH,MAAM,CAACE,eAAU,CAACC,EAAE,CAAC,IAAI,CAAC,CAAC;IACnDH,MAAM,CAACE,eAAU,CAACC,EAAE,CAAC,CAACC,GAAG,GAAGe,SAAS,CAACI,sBAAsB,EAAE;IAC9D,OAAOvB,MAAM;EACf;;EAEA;AACF;AACA;EACE,MAAcf,mBAAmB,CAC/BlC,aAAqB,EACrByE,aAA8B,EACE;IAChC,MAAMC,aAAa,GAAG,KAAIC,wBAAa,GAAE;IACzC,MAAMC,UAAU,GAAGH,aAAa,CAACvD,GAAG,CAAE2D,YAAY,IAAK;MACrD,MAAMC,iBAAiB,GAAG,KAAIC,gBAAK,EAAC;QAClCC,IAAI,EAAEhF,aAAa;QACnBE,IAAI,EAAEA,eAAI,CAACG,IAAI,CAACL,aAAa,EAAE6E,YAAY,CAACvC,YAAY,CAAC;QACzD2C,QAAQ,EAAEC,MAAM,CAACC,IAAI,CAACN,YAAY,CAACO,OAAO;MAC5C,CAAC,CAAC;MACF,OAAOC,wBAAa,CAACC,SAAS,CAACR,iBAAiB,CAAC;IACnD,CAAC,CAAC;IACF,MAAMS,OAAO,GAAGX,UAAU,CAAC1D,GAAG,CAAEsE,CAAC,IAAKA,CAAC,CAACtF,IAAI,CAAC;IAC7CwE,aAAa,CAACe,YAAY,CAACb,UAAU,CAAC;IACtCF,aAAa,CAACgB,WAAW,CAAC,IAAI,CAACtG,SAAS,CAACc,IAAI,CAAC;IAC9C,MAAMwE,aAAa,CAACiB,cAAc,EAAE;IACpC,OAAOJ,OAAO;EAChB;AACF;AAAC"}
1
+ {"version":3,"names":["ComponentGenerator","constructor","workspace","componentIds","options","template","envs","newComponentHelper","aspectId","envId","generate","dirsToDeleteIfFailed","generateResults","pMapSeries","componentId","componentPath","getNewComponentPath","path","fs","existsSync","join","BitError","hasName","fullName","push","generateOneComponent","err","deleteGeneratedComponents","bitMap","write","dirs","Promise","all","map","dir","absoluteDir","remove","code","name","namePascalCase","camelcase","pascalCase","nameCamelCase","files","generateFiles","mainFile","find","file","isMain","writeComponentFiles","addResults","track","rootDir","relativePath","componentName","defaultScope","scope","triggerOnMultipleComponentsAdd","component","get","hasEnvConfiguredOriginally","hasEnvConfigured","envBeforeConfigChanges","getEnv","config","boundConfig","bind","toString","env","toStringWithoutVersion","templateEnv","EnvsAspect","id","Object","keys","length","undefined","configWithEnv","addEnvIfProvidedByFlag","setEntireConfig","getEnvData","envFromFlag","envFromTemplate","setBy","envSetBy","userEnv","userEnvId","resolveComponentId","userEnvIdWithPotentialVersion","resolveEnvIdWithPotentialVersionForConfig","templateFiles","dataToPersist","DataToPersist","vinylFiles","templateFile","templateFileVinyl","Vinyl","base","contents","Buffer","from","content","AbstractVinyl","fromVinyl","results","v","addManyFiles","addBasePath","persistAllToFS"],"sources":["component-generator.ts"],"sourcesContent":["import Vinyl from 'vinyl';\nimport fs from 'fs-extra';\nimport pMapSeries from 'p-map-series';\nimport path from 'path';\nimport { Workspace } from '@teambit/workspace';\nimport EnvsAspect, { EnvsMain } from '@teambit/envs';\nimport camelcase from 'camelcase';\nimport { BitError } from '@teambit/bit-error';\nimport { PathOsBasedRelative } from '@teambit/legacy/dist/utils/path';\nimport { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';\nimport DataToPersist from '@teambit/legacy/dist/consumer/component/sources/data-to-persist';\nimport { NewComponentHelperMain } from '@teambit/new-component-helper';\nimport { ComponentID } from '@teambit/component-id';\nimport { ComponentTemplate, ComponentFile, ComponentConfig } from './component-template';\nimport { CreateOptions } from './create.cmd';\n\nexport type GenerateResult = { id: ComponentID; dir: string; files: string[]; envId: string; envSetBy: string };\n\nexport class ComponentGenerator {\n constructor(\n private workspace: Workspace,\n private componentIds: ComponentID[],\n private options: CreateOptions,\n private template: ComponentTemplate,\n private envs: EnvsMain,\n private newComponentHelper: NewComponentHelperMain,\n private aspectId: string,\n private envId?: ComponentID\n ) {}\n\n async generate(): Promise<GenerateResult[]> {\n const dirsToDeleteIfFailed: string[] = [];\n const generateResults = await pMapSeries(this.componentIds, async (componentId) => {\n try {\n const componentPath = this.newComponentHelper.getNewComponentPath(componentId, this.options.path);\n if (fs.existsSync(path.join(this.workspace.path, componentPath))) {\n throw new BitError(`unable to create a component at \"${componentPath}\", this path already exist`);\n }\n if (await this.workspace.hasName(componentId.fullName)) {\n throw new BitError(\n `unable to create a component \"${componentId.fullName}\", a component with the same name already exist`\n );\n }\n dirsToDeleteIfFailed.push(componentPath);\n return await this.generateOneComponent(componentId, componentPath);\n } catch (err: any) {\n await this.deleteGeneratedComponents(dirsToDeleteIfFailed);\n throw err;\n }\n });\n\n await this.workspace.bitMap.write();\n\n return generateResults;\n }\n\n private async deleteGeneratedComponents(dirs: string[]) {\n await Promise.all(\n dirs.map(async (dir) => {\n const absoluteDir = path.join(this.workspace.path, dir);\n try {\n await fs.remove(absoluteDir);\n } catch (err: any) {\n if (err.code !== 'ENOENT') {\n // if not exist, it's fine\n throw err;\n }\n }\n })\n );\n }\n\n private async generateOneComponent(componentId: ComponentID, componentPath: string): Promise<GenerateResult> {\n const name = componentId.name;\n const namePascalCase = camelcase(name, { pascalCase: true });\n const nameCamelCase = camelcase(name);\n const files = this.template.generateFiles({ name, namePascalCase, nameCamelCase, componentId });\n const mainFile = files.find((file) => file.isMain);\n await this.writeComponentFiles(componentPath, files);\n const addResults = await this.workspace.track({\n rootDir: componentPath,\n mainFile: mainFile?.relativePath,\n componentName: componentId.fullName,\n defaultScope: this.options.scope,\n });\n await this.workspace.triggerOnMultipleComponentsAdd();\n const component = await this.workspace.get(componentId);\n const hasEnvConfiguredOriginally = this.envs.hasEnvConfigured(component);\n const envBeforeConfigChanges = this.envs.getEnv(component);\n let config = this.template.config;\n if (config && typeof config === 'function') {\n const boundConfig = this.template.config?.bind(this.template);\n config = boundConfig({ aspectId: this.aspectId });\n }\n\n if (!config && this.envId) {\n config = {\n [this.envId.toString()]: {},\n 'teambit.envs/envs': {\n env: this.envId.toStringWithoutVersion(),\n },\n };\n }\n\n const templateEnv = config?.[EnvsAspect.id]?.env;\n\n if (config && templateEnv && hasEnvConfiguredOriginally) {\n // remove the env we got from the template.\n delete config[templateEnv];\n delete config[EnvsAspect.id].env;\n if (Object.keys(config[EnvsAspect.id]).length === 0) delete config[EnvsAspect.id];\n if (Object.keys(config).length === 0) config = undefined;\n }\n\n const configWithEnv = await this.addEnvIfProvidedByFlag(config);\n if (configWithEnv) this.workspace.bitMap.setEntireConfig(component.id, configWithEnv);\n\n const getEnvData = () => {\n const envFromFlag = this.options.env; // env entered by the user when running `bit create --env`\n const envFromTemplate = config?.[EnvsAspect.id]?.env;\n if (envFromFlag) {\n return {\n envId: envFromFlag,\n setBy: '--env flag',\n };\n }\n if (envFromTemplate) {\n return {\n envId: envFromTemplate,\n setBy: 'template',\n };\n }\n return {\n envId: envBeforeConfigChanges.id,\n setBy: hasEnvConfiguredOriginally ? 'workspace variants' : '<default>',\n };\n };\n const { envId, setBy } = getEnvData();\n return {\n id: componentId,\n dir: componentPath,\n files: addResults.files,\n envId,\n envSetBy: setBy,\n };\n }\n\n private async addEnvIfProvidedByFlag(config?: ComponentConfig): Promise<ComponentConfig | undefined> {\n const userEnv = this.options.env; // env entered by the user when running `bit create --env`\n const templateEnv = config?.[EnvsAspect.id]?.env;\n if (!userEnv || userEnv === templateEnv) {\n return config;\n }\n config = config || {};\n if (templateEnv) {\n // the component template has an env and the user wants a different env.\n delete config[templateEnv];\n }\n const userEnvId = await this.workspace.resolveComponentId(userEnv);\n const userEnvIdWithPotentialVersion = await this.workspace.resolveEnvIdWithPotentialVersionForConfig(userEnvId);\n config[userEnvIdWithPotentialVersion] = {};\n config[EnvsAspect.id] = config[EnvsAspect.id] || {};\n config[EnvsAspect.id].env = userEnvId.toStringWithoutVersion();\n return config;\n }\n\n /**\n * writes the generated template files to the default directory set in the workspace config\n */\n private async writeComponentFiles(\n componentPath: string,\n templateFiles: ComponentFile[]\n ): Promise<PathOsBasedRelative[]> {\n const dataToPersist = new DataToPersist();\n const vinylFiles = templateFiles.map((templateFile) => {\n const templateFileVinyl = new Vinyl({\n base: componentPath,\n path: path.join(componentPath, templateFile.relativePath),\n contents: Buffer.from(templateFile.content),\n });\n return AbstractVinyl.fromVinyl(templateFileVinyl);\n });\n const results = vinylFiles.map((v) => v.path);\n dataToPersist.addManyFiles(vinylFiles);\n dataToPersist.addBasePath(this.workspace.path);\n await dataToPersist.persistAllToFS();\n return results;\n }\n}\n"],"mappings":";;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAQO,MAAMA,kBAAkB,CAAC;EAC9BC,WAAW,CACDC,SAAoB,EACpBC,YAA2B,EAC3BC,OAAsB,EACtBC,QAA2B,EAC3BC,IAAc,EACdC,kBAA0C,EAC1CC,QAAgB,EAChBC,KAAmB,EAC3B;IAAA,KARQP,SAAoB,GAApBA,SAAoB;IAAA,KACpBC,YAA2B,GAA3BA,YAA2B;IAAA,KAC3BC,OAAsB,GAAtBA,OAAsB;IAAA,KACtBC,QAA2B,GAA3BA,QAA2B;IAAA,KAC3BC,IAAc,GAAdA,IAAc;IAAA,KACdC,kBAA0C,GAA1CA,kBAA0C;IAAA,KAC1CC,QAAgB,GAAhBA,QAAgB;IAAA,KAChBC,KAAmB,GAAnBA,KAAmB;EAC1B;EAEH,M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AM0E,aAAa,CAACiB,cAAc,EAAE;IACpC,OAAOJ,OAAO;EAChB;AACF;AAAC"}
@@ -57,6 +57,10 @@ export interface ComponentTemplate {
57
57
  * hide this template so that it is not listed with `bit templates`
58
58
  */
59
59
  hidden?: boolean;
60
+ /**
61
+ * env to use for the component.
62
+ */
63
+ env?: string;
60
64
  /**
61
65
  * template function for generating the file of a certain component.,
62
66
  */
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["component-template.ts"],"sourcesContent":["import { ComponentID } from '@teambit/component-id';\n\nexport interface ComponentFile {\n /**\n * relative path of the file within the component.\n */\n relativePath: string;\n\n /**\n * file content\n */\n content: string;\n\n /**\n * whether this file will be tracked as the main file\n */\n isMain?: boolean;\n}\n\nexport interface ComponentContext {\n /**\n * component-name as entered by the user, e.g. `use-date`.\n * without the scope and the namespace.\n */\n name: string;\n\n /**\n * component-name as upper camel case, e.g. `use-date` becomes `UseDate`.\n * useful when generating the file content, for example for a class name.\n */\n namePascalCase: string;\n\n /**\n * component-name as lower camel case, e.g. `use-date` becomes `useDate`.\n * useful when generating the file content, for example for a function/variable name.\n */\n nameCamelCase: string;\n\n /**\n * component id.\n * the name is the name+namespace. the scope is the scope entered by --scope flag or the defaultScope\n */\n componentId: ComponentID;\n}\n\nexport interface ConfigContext {\n /**\n * Aspect id of the aspect that register the template itself\n */\n aspectId: string;\n}\n\nexport type ComponentConfig = { [aspectName: string]: any };\n\nexport interface ComponentTemplate {\n /**\n * name of the component template. for example: `hook`, `react-component` or `module`.\n */\n name: string;\n\n /**\n * short description of the template. shown in the `bit templates` command.\n */\n description?: string;\n\n /**\n * hide this template so that it is not listed with `bit templates`\n */\n hidden?: boolean;\n\n /**\n * template function for generating the file of a certain component.,\n */\n generateFiles(context: ComponentContext): ComponentFile[];\n\n /**\n * component config. gets saved in the .bitmap file and it overrides the workspace.jsonc config.\n * for example, you can set the env that will be used for this component as follows:\n * \"teambit.envs/envs\": {\n * \"env\": \"teambit.harmony/aspect\"\n * },\n */\n config?: ComponentConfig | ((context: ConfigContext) => ComponentConfig);\n}\n"],"mappings":""}
1
+ {"version":3,"names":[],"sources":["component-template.ts"],"sourcesContent":["import { ComponentID } from '@teambit/component-id';\n\nexport interface ComponentFile {\n /**\n * relative path of the file within the component.\n */\n relativePath: string;\n\n /**\n * file content\n */\n content: string;\n\n /**\n * whether this file will be tracked as the main file\n */\n isMain?: boolean;\n}\n\nexport interface ComponentContext {\n /**\n * component-name as entered by the user, e.g. `use-date`.\n * without the scope and the namespace.\n */\n name: string;\n\n /**\n * component-name as upper camel case, e.g. `use-date` becomes `UseDate`.\n * useful when generating the file content, for example for a class name.\n */\n namePascalCase: string;\n\n /**\n * component-name as lower camel case, e.g. `use-date` becomes `useDate`.\n * useful when generating the file content, for example for a function/variable name.\n */\n nameCamelCase: string;\n\n /**\n * component id.\n * the name is the name+namespace. the scope is the scope entered by --scope flag or the defaultScope\n */\n componentId: ComponentID;\n}\n\nexport interface ConfigContext {\n /**\n * Aspect id of the aspect that register the template itself\n */\n aspectId: string;\n}\n\nexport type ComponentConfig = { [aspectName: string]: any };\n\nexport interface ComponentTemplate {\n /**\n * name of the component template. for example: `hook`, `react-component` or `module`.\n */\n name: string;\n\n /**\n * short description of the template. shown in the `bit templates` command.\n */\n description?: string;\n\n /**\n * hide this template so that it is not listed with `bit templates`\n */\n hidden?: boolean;\n\n /**\n * env to use for the component.\n */\n env?: string;\n\n /**\n * template function for generating the file of a certain component.,\n */\n generateFiles(context: ComponentContext): ComponentFile[];\n\n /**\n * component config. gets saved in the .bitmap file and it overrides the workspace.jsonc config.\n * for example, you can set the env that will be used for this component as follows:\n * \"teambit.envs/envs\": {\n * \"env\": \"teambit.harmony/aspect\"\n * },\n */\n config?: ComponentConfig | ((context: ConfigContext) => ComponentConfig);\n}\n"],"mappings":""}
@@ -0,0 +1,13 @@
1
+ import { EnvHandler } from "@teambit/envs";
2
+ import { TemplateList } from "./template-list";
3
+ import { StarterList } from "./starter-list";
4
+ export interface GeneratorEnv {
5
+ /**
6
+ * return a template list instance.
7
+ */
8
+ generators(): EnvHandler<TemplateList>;
9
+ /**
10
+ * return a starter list instance.
11
+ */
12
+ starters(): EnvHandler<StarterList>;
13
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+
3
+ //# sourceMappingURL=generator-env-type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["generator-env-type.ts"],"sourcesContent":["import { EnvHandler } from \"@teambit/envs\";\nimport { TemplateList } from \"./template-list\";\nimport { StarterList } from \"./starter-list\";\n\nexport interface GeneratorEnv {\n /**\n * return a template list instance.\n */\n generators(): EnvHandler<TemplateList>;\n /**\n * return a starter list instance.\n */\n starters(): EnvHandler<StarterList>;\n}\n"],"mappings":""}
@@ -1,9 +1,9 @@
1
1
  import { GraphqlMain } from '@teambit/graphql';
2
2
  import { CLIMain } from '@teambit/cli';
3
3
  import { Workspace } from '@teambit/workspace';
4
- import { EnvsMain } from '@teambit/envs';
4
+ import { EnvDefinition, EnvsMain } from '@teambit/envs';
5
5
  import type { CommunityMain } from '@teambit/community';
6
- import { Component } from '@teambit/component';
6
+ import type { ComponentMain, Component } from '@teambit/component';
7
7
  import { SlotRegistry } from '@teambit/harmony';
8
8
  import { AspectLoaderMain } from '@teambit/aspect-loader';
9
9
  import { NewComponentHelperMain } from '@teambit/new-component-helper';
@@ -17,10 +17,21 @@ export declare type ComponentTemplateSlot = SlotRegistry<ComponentTemplate[]>;
17
17
  export declare type WorkspaceTemplateSlot = SlotRegistry<WorkspaceTemplate[]>;
18
18
  export declare type TemplateDescriptor = {
19
19
  aspectId: string;
20
+ titlePrefix?: string;
20
21
  name: string;
21
22
  description?: string;
22
23
  hidden?: boolean;
23
24
  };
25
+ declare type TemplateWithId = {
26
+ id: string;
27
+ envName?: string;
28
+ };
29
+ declare type WorkspaceTemplateWithId = TemplateWithId & {
30
+ template: WorkspaceTemplate;
31
+ };
32
+ declare type ComponentTemplateWithId = TemplateWithId & {
33
+ template: ComponentTemplate;
34
+ };
24
35
  export declare type GenerateWorkspaceTemplateResult = {
25
36
  workspacePath: string;
26
37
  appName?: string;
@@ -35,6 +46,10 @@ export declare type GeneratorConfig = {
35
46
  * use this to hide them unless `--show-all` flag of `bit templates` was used
36
47
  */
37
48
  hideCoreTemplates: boolean;
49
+ /**
50
+ * default envs.
51
+ */
52
+ envs?: string[];
38
53
  };
39
54
  export declare class GeneratorMain {
40
55
  private componentTemplateSlot;
@@ -45,8 +60,9 @@ export declare class GeneratorMain {
45
60
  private aspectLoader;
46
61
  private newComponentHelper;
47
62
  private importer;
63
+ private componentAspect;
48
64
  private aspectLoaded;
49
- constructor(componentTemplateSlot: ComponentTemplateSlot, workspaceTemplateSlot: WorkspaceTemplateSlot, config: GeneratorConfig, workspace: Workspace, envs: EnvsMain, aspectLoader: AspectLoaderMain, newComponentHelper: NewComponentHelperMain, importer: ImporterMain);
65
+ constructor(componentTemplateSlot: ComponentTemplateSlot, workspaceTemplateSlot: WorkspaceTemplateSlot, config: GeneratorConfig, workspace: Workspace, envs: EnvsMain, aspectLoader: AspectLoaderMain, newComponentHelper: NewComponentHelperMain, importer: ImporterMain, componentAspect: ComponentMain);
50
66
  /**
51
67
  * register a new component template.
52
68
  */
@@ -59,11 +75,16 @@ export declare class GeneratorMain {
59
75
  * list all component templates registered in the workspace or workspace templates in case the
60
76
  * workspace is not available
61
77
  */
62
- listTemplates(): Promise<TemplateDescriptor[]>;
78
+ listTemplates({ aspect }?: {
79
+ aspect?: string;
80
+ }): Promise<TemplateDescriptor[]>;
81
+ private getTemplateDescriptor;
63
82
  /**
64
83
  * @deprecated use this.listTemplates()
65
84
  */
66
- listComponentTemplates(): Promise<TemplateDescriptor[]>;
85
+ listComponentTemplates(opts: {
86
+ aspect?: string;
87
+ }): Promise<TemplateDescriptor[]>;
67
88
  isRunningInsideWorkspace(): boolean;
68
89
  /**
69
90
  * get all component templates registered by a specific aspect ID.
@@ -72,10 +93,8 @@ export declare class GeneratorMain {
72
93
  /**
73
94
  * returns a specific component template.
74
95
  */
75
- getComponentTemplate(name: string, aspectId?: string): {
76
- id: string;
77
- template: ComponentTemplate;
78
- } | undefined;
96
+ getComponentTemplate(name: string, aspectId?: string): Promise<ComponentTemplateWithId | undefined>;
97
+ private findTemplateByAspectIdAndName;
79
98
  /**
80
99
  * in the case the aspect-id is given and this aspect doesn't exist locally, import it to the
81
100
  * global scope and load it from the capsule
@@ -95,13 +114,25 @@ export declare class GeneratorMain {
95
114
  searchRegisteredWorkspaceTemplate(name?: string, aspectId?: string): Promise<WorkspaceTemplate | undefined>;
96
115
  generateComponentTemplate(componentNames: string[], templateName: string, options: CreateOptions): Promise<GenerateResult[]>;
97
116
  generateWorkspaceTemplate(workspaceName: string, templateName: string, options: NewOptions): Promise<GenerateWorkspaceTemplateResult>;
117
+ private getAllComponentTemplatesDescriptorsFlattened;
98
118
  private getAllComponentTemplatesFlattened;
119
+ private getAllWorkspaceTemplatesDescriptorFlattened;
99
120
  private getAllWorkspaceTemplatesFlattened;
100
- private loadAspects;
121
+ /**
122
+ * list all starter templates registered by an env.
123
+ */
124
+ listEnvWorkspaceTemplates(envId: string): Promise<Array<WorkspaceTemplateWithId>>;
125
+ /**
126
+ * list all component templates registered by an env.
127
+ */
128
+ listEnvComponentTemplateDescriptors(ids?: string[]): Promise<TemplateDescriptor[]>;
129
+ listEnvComponentTemplates(ids?: string[]): Promise<Array<ComponentTemplateWithId>>;
130
+ loadEnvs(ids?: string[]): Promise<EnvDefinition[]>;
131
+ loadAspects(): Promise<void>;
101
132
  static slots: (((registerFn: () => string) => SlotRegistry<ComponentTemplate[]>) | ((registerFn: () => string) => SlotRegistry<WorkspaceTemplate[]>))[];
102
133
  static dependencies: import("@teambit/bit").Aspect[];
103
134
  static runtime: import("@teambit/bit").RuntimeDefinition;
104
- static provider([workspace, cli, graphql, envs, aspectLoader, newComponentHelper, community, importer]: [
135
+ static provider([workspace, cli, graphql, envs, aspectLoader, newComponentHelper, community, importer, componentAspect]: [
105
136
  Workspace,
106
137
  CLIMain,
107
138
  GraphqlMain,
@@ -109,6 +140,8 @@ export declare class GeneratorMain {
109
140
  AspectLoaderMain,
110
141
  NewComponentHelperMain,
111
142
  CommunityMain,
112
- ImporterMain
143
+ ImporterMain,
144
+ ComponentMain
113
145
  ], config: GeneratorConfig, [componentTemplateSlot, workspaceTemplateSlot]: [ComponentTemplateSlot, WorkspaceTemplateSlot]): Promise<GeneratorMain>;
114
146
  }
147
+ export {};
@@ -59,6 +59,13 @@ function _community() {
59
59
  };
60
60
  return data;
61
61
  }
62
+ function _component() {
63
+ const data = _interopRequireWildcard(require("@teambit/component"));
64
+ _component = function () {
65
+ return data;
66
+ };
67
+ return data;
68
+ }
62
69
  function _bit() {
63
70
  const data = require("@teambit/bit");
64
71
  _bit = function () {
@@ -94,6 +101,13 @@ function _newComponentHelper() {
94
101
  };
95
102
  return data;
96
103
  }
104
+ function _lodash() {
105
+ const data = require("lodash");
106
+ _lodash = function () {
107
+ return data;
108
+ };
109
+ return data;
110
+ }
97
111
  function _importer() {
98
112
  const data = _interopRequireDefault(require("@teambit/importer"));
99
113
  _importer = function () {
@@ -178,8 +192,12 @@ function _starter2() {
178
192
  };
179
193
  return data;
180
194
  }
195
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
196
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
197
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
198
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2().default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
181
199
  class GeneratorMain {
182
- constructor(componentTemplateSlot, workspaceTemplateSlot, config, workspace, envs, aspectLoader, newComponentHelper, importer) {
200
+ constructor(componentTemplateSlot, workspaceTemplateSlot, config, workspace, envs, aspectLoader, newComponentHelper, importer, componentAspect) {
183
201
  this.componentTemplateSlot = componentTemplateSlot;
184
202
  this.workspaceTemplateSlot = workspaceTemplateSlot;
185
203
  this.config = config;
@@ -188,7 +206,24 @@ class GeneratorMain {
188
206
  this.aspectLoader = aspectLoader;
189
207
  this.newComponentHelper = newComponentHelper;
190
208
  this.importer = importer;
209
+ this.componentAspect = componentAspect;
191
210
  (0, _defineProperty2().default)(this, "aspectLoaded", false);
211
+ (0, _defineProperty2().default)(this, "getTemplateDescriptor", ({
212
+ id,
213
+ template
214
+ }) => {
215
+ const shouldBeHidden = () => {
216
+ if (template.hidden) return true;
217
+ if (this.config.hideCoreTemplates && (0, _bit().isCoreAspect)(id)) return true;
218
+ return false;
219
+ };
220
+ return {
221
+ aspectId: id,
222
+ name: template.name,
223
+ description: template.description,
224
+ hidden: shouldBeHidden()
225
+ };
226
+ });
192
227
  }
193
228
 
194
229
  /**
@@ -211,31 +246,19 @@ class GeneratorMain {
211
246
  * list all component templates registered in the workspace or workspace templates in case the
212
247
  * workspace is not available
213
248
  */
214
- async listTemplates() {
215
- const getTemplateDescriptor = ({
216
- id,
217
- template
218
- }) => {
219
- const shouldBeHidden = () => {
220
- if (template.hidden) return true;
221
- if (this.config.hideCoreTemplates && (0, _bit().isCoreAspect)(id)) return true;
222
- return false;
223
- };
224
- return {
225
- aspectId: id,
226
- name: template.name,
227
- description: template.description,
228
- hidden: shouldBeHidden()
229
- };
230
- };
231
- return this.isRunningInsideWorkspace() ? this.getAllComponentTemplatesFlattened().map(getTemplateDescriptor) : this.getAllWorkspaceTemplatesFlattened().map(getTemplateDescriptor);
249
+ async listTemplates({
250
+ aspect
251
+ } = {}) {
252
+ if (this.isRunningInsideWorkspace()) {
253
+ return this.getAllComponentTemplatesDescriptorsFlattened(aspect);
254
+ }
255
+ return this.getAllWorkspaceTemplatesDescriptorFlattened(aspect);
232
256
  }
233
-
234
257
  /**
235
258
  * @deprecated use this.listTemplates()
236
259
  */
237
- async listComponentTemplates() {
238
- return this.listTemplates();
260
+ async listComponentTemplates(opts) {
261
+ return this.listTemplates(opts);
239
262
  }
240
263
  isRunningInsideWorkspace() {
241
264
  return Boolean(this.workspace);
@@ -251,8 +274,19 @@ class GeneratorMain {
251
274
  /**
252
275
  * returns a specific component template.
253
276
  */
254
- getComponentTemplate(name, aspectId) {
255
- const templates = this.getAllComponentTemplatesFlattened();
277
+ async getComponentTemplate(name, aspectId) {
278
+ const fromEnv = await this.listEnvComponentTemplates();
279
+ if (fromEnv && fromEnv.length) {
280
+ const found = this.findTemplateByAspectIdAndName(aspectId, name, fromEnv);
281
+ if (found) return found;
282
+ }
283
+ // fallback to aspect id not from env if provided
284
+ const templates = await this.getAllComponentTemplatesFlattened();
285
+ const found = this.findTemplateByAspectIdAndName(aspectId, name, templates);
286
+ return found;
287
+ }
288
+ findTemplateByAspectIdAndName(aspectId, name, templates) {
289
+ // @ts-ignore (should set T to be extends ComponentTemplateWithId or WorkspaceTemplateWithId)
256
290
  const found = templates.find(({
257
291
  id,
258
292
  template
@@ -323,14 +357,18 @@ class GeneratorMain {
323
357
  throw new (_bitError().BitError)(`template "${name}" was not found`);
324
358
  }
325
359
  async searchRegisteredWorkspaceTemplate(name, aspectId) {
326
- const templates = this.getAllWorkspaceTemplatesFlattened();
360
+ let fromEnv;
361
+ if (aspectId) {
362
+ fromEnv = await this.listEnvWorkspaceTemplates(aspectId);
363
+ }
364
+ const templates = fromEnv && fromEnv.length ? fromEnv : this.getAllWorkspaceTemplatesFlattened();
327
365
  const found = templates.find(({
328
366
  id,
329
- template
367
+ template: tpl
330
368
  }) => {
331
- if (aspectId && name) return aspectId === id && name === template.name;
369
+ if (aspectId && name) return aspectId === id && name === tpl.name;
332
370
  if (aspectId) return aspectId === id;
333
- if (name) return name === template.name;
371
+ if (name) return name === tpl.name;
334
372
  throw new Error(`searchRegisteredWorkspaceTemplate expects to get "name" or "aspectId"`);
335
373
  });
336
374
  return found === null || found === void 0 ? void 0 : found.template;
@@ -342,10 +380,10 @@ class GeneratorMain {
342
380
  namespace,
343
381
  aspect: aspectId
344
382
  } = options;
345
- const templateWithId = this.getComponentTemplate(templateName, aspectId);
383
+ const templateWithId = await this.getComponentTemplate(templateName, aspectId);
346
384
  if (!templateWithId) throw new (_bitError().BitError)(`template "${templateName}" was not found`);
347
385
  const componentIds = componentNames.map(componentName => this.newComponentHelper.getNewComponentId(componentName, namespace, options.scope));
348
- const componentGenerator = new (_componentGenerator().ComponentGenerator)(this.workspace, componentIds, options, templateWithId.template, this.envs, this.newComponentHelper, templateWithId.id);
386
+ const componentGenerator = new (_componentGenerator().ComponentGenerator)(this.workspace, componentIds, options, templateWithId.template, this.envs, this.newComponentHelper, templateWithId.id, templateWithId.envName ? _component().ComponentID.fromString(templateWithId.id) : undefined);
349
387
  return componentGenerator.generate();
350
388
  }
351
389
  async generateWorkspaceTemplate(workspaceName, templateName, options) {
@@ -376,14 +414,34 @@ class GeneratorMain {
376
414
  appName: template.appName
377
415
  };
378
416
  }
417
+ async getAllComponentTemplatesDescriptorsFlattened(aspectId) {
418
+ const envTemplates = await this.listEnvComponentTemplateDescriptors();
419
+ if (envTemplates && envTemplates.length) {
420
+ if (!aspectId) return envTemplates;
421
+ const filtered = envTemplates.filter(template => template.aspectId === aspectId);
422
+ if (filtered.length) return filtered;
423
+ }
424
+ const flattened = this.getAllComponentTemplatesFlattened();
425
+ const filtered = flattened.filter(template => template.id === aspectId);
426
+ return filtered.map(template => this.getTemplateDescriptor(template));
427
+ }
379
428
  getAllComponentTemplatesFlattened() {
380
429
  const templatesByAspects = this.componentTemplateSlot.toArray();
381
- return templatesByAspects.flatMap(([id, componentTemplates]) => {
430
+ const flattened = templatesByAspects.flatMap(([id, componentTemplates]) => {
382
431
  return componentTemplates.map(template => ({
383
432
  id,
384
433
  template
385
434
  }));
386
435
  });
436
+ return flattened;
437
+ }
438
+ async getAllWorkspaceTemplatesDescriptorFlattened(aspectId) {
439
+ let envTemplates;
440
+ if (aspectId) {
441
+ envTemplates = await this.listEnvWorkspaceTemplates(aspectId);
442
+ }
443
+ const templates = envTemplates && envTemplates.length ? envTemplates : this.getAllWorkspaceTemplatesFlattened();
444
+ return templates.map(template => this.getTemplateDescriptor(template));
387
445
  }
388
446
  getAllWorkspaceTemplatesFlattened() {
389
447
  const templatesByAspects = this.workspaceTemplateSlot.toArray();
@@ -394,13 +452,90 @@ class GeneratorMain {
394
452
  }));
395
453
  });
396
454
  }
455
+
456
+ /**
457
+ * list all starter templates registered by an env.
458
+ */
459
+ async listEnvWorkspaceTemplates(envId) {
460
+ const envs = await this.loadEnvs([envId]);
461
+ const workspaceTemplates = envs.flatMap(env => {
462
+ if (!env.env.getGeneratorStarters) return undefined;
463
+ const envStarters = env.env.getGeneratorStarters();
464
+ return envStarters.map(starter => {
465
+ const componentId = _component().ComponentID.fromString(env.id);
466
+ return {
467
+ id: componentId.toString(),
468
+ envName: env.name,
469
+ template: starter
470
+ };
471
+ });
472
+ });
473
+ return (0, _lodash().compact)(workspaceTemplates);
474
+ }
475
+
476
+ /**
477
+ * list all component templates registered by an env.
478
+ */
479
+ async listEnvComponentTemplateDescriptors(ids = []) {
480
+ const envTemplates = await this.listEnvComponentTemplates(ids);
481
+ const templates = envTemplates.map(envTemplate => {
482
+ const componentId = _component().ComponentID.fromString(envTemplate.id);
483
+ return _objectSpread({
484
+ aspectId: componentId.toStringWithoutVersion(),
485
+ titlePrefix: envTemplate.envName
486
+ }, envTemplate.template);
487
+ });
488
+ return templates;
489
+ }
490
+ async listEnvComponentTemplates(ids = []) {
491
+ const configEnvs = this.config.envs || [];
492
+ const envs = await this.loadEnvs(configEnvs === null || configEnvs === void 0 ? void 0 : configEnvs.concat(ids));
493
+ const templates = envs.flatMap(env => {
494
+ if (!env.env.getGeneratorTemplates) return [];
495
+ const tpls = env.env.getGeneratorTemplates() || [];
496
+ return tpls.map(template => {
497
+ const componentId = _component().ComponentID.fromString(env.id);
498
+ return {
499
+ id: componentId.toString(),
500
+ envName: env.name,
501
+ template
502
+ };
503
+ });
504
+ });
505
+ return templates;
506
+ }
507
+ async loadEnvs(ids = this.config.envs || []) {
508
+ // TODO: this will probably won't work for bit new with aspect id and without loadFrom
509
+ // as this getEnvDefinition will probably return nothing, as the env is not loaded yet, therefore, not register to the slot
510
+ // we need to check if that id is an aspect id and load it as an aspect
511
+ // and only after it, we can get the env definition
512
+ const envs = ids.map(id => {
513
+ const componentId = _component().ComponentID.fromString(id);
514
+ return {
515
+ id: componentId,
516
+ env: this.envs.getEnvDefinition(componentId)
517
+ };
518
+ });
519
+ const host = this.componentAspect.getHost();
520
+ if (!host) return [];
521
+ const toLoad = envs.filter(env => !env.env);
522
+ const componentIds = toLoad.map(component => component.id.toString());
523
+ await host.loadAspects(componentIds);
524
+ const allEnvs = envs.map(env => {
525
+ if (env.env) {
526
+ return env.env;
527
+ }
528
+ return this.envs.getEnvDefinition(env.id);
529
+ });
530
+ return (0, _lodash().compact)(allEnvs);
531
+ }
397
532
  async loadAspects() {
398
533
  if (this.aspectLoaded) return;
399
534
  await this.workspace.loadAspects(this.config.aspects);
400
535
  this.aspectLoaded = true;
401
536
  }
402
- static async provider([workspace, cli, graphql, envs, aspectLoader, newComponentHelper, community, importer], config, [componentTemplateSlot, workspaceTemplateSlot]) {
403
- const generator = new GeneratorMain(componentTemplateSlot, workspaceTemplateSlot, config, workspace, envs, aspectLoader, newComponentHelper, importer);
537
+ static async provider([workspace, cli, graphql, envs, aspectLoader, newComponentHelper, community, importer, componentAspect], config, [componentTemplateSlot, workspaceTemplateSlot]) {
538
+ const generator = new GeneratorMain(componentTemplateSlot, workspaceTemplateSlot, config, workspace, envs, aspectLoader, newComponentHelper, importer, componentAspect);
404
539
  const commands = [new (_create().CreateCmd)(generator, community.getDocsDomain()), new (_templates().TemplatesCmd)(generator), new (_new().NewCmd)(generator)];
405
540
  cli.register(...commands);
406
541
  graphql.register((0, _generator2().generatorSchema)(generator));
@@ -411,7 +546,7 @@ class GeneratorMain {
411
546
  }
412
547
  exports.GeneratorMain = GeneratorMain;
413
548
  (0, _defineProperty2().default)(GeneratorMain, "slots", [_harmony().Slot.withType(), _harmony().Slot.withType()]);
414
- (0, _defineProperty2().default)(GeneratorMain, "dependencies", [_workspace().default, _cli().CLIAspect, _graphql().GraphqlAspect, _envs().EnvsAspect, _aspectLoader().default, _newComponentHelper().default, _community().CommunityAspect, _importer().default]);
549
+ (0, _defineProperty2().default)(GeneratorMain, "dependencies", [_workspace().default, _cli().CLIAspect, _graphql().GraphqlAspect, _envs().EnvsAspect, _aspectLoader().default, _newComponentHelper().default, _community().CommunityAspect, _importer().default, _component().default]);
415
550
  (0, _defineProperty2().default)(GeneratorMain, "runtime", _cli().MainRuntime);
416
551
  _generator().GeneratorAspect.addRuntime(GeneratorMain);
417
552
 
@@ -1 +1 @@
1
- {"version":3,"names":["GeneratorMain","constructor","componentTemplateSlot","workspaceTemplateSlot","config","workspace","envs","aspectLoader","newComponentHelper","importer","registerComponentTemplate","templates","register","registerWorkspaceTemplate","listTemplates","getTemplateDescriptor","id","template","shouldBeHidden","hidden","hideCoreTemplates","isCoreAspect","aspectId","name","description","isRunningInsideWorkspace","getAllComponentTemplatesFlattened","map","getAllWorkspaceTemplatesFlattened","listComponentTemplates","Boolean","getComponentTemplateByAspect","get","getComponentTemplate","found","find","findTemplateInGlobalScope","globalScopeHarmony","components","loadAspectsFromGlobalScope","remoteGenerator","GeneratorAspect","aspect","fullAspectId","toString","fromGlobal","searchRegisteredWorkspaceTemplate","call","workspaceTemplate","findTemplateInOtherWorkspace","workspacePath","BitError","harmony","loadBit","WorkspaceAspect","err","Error","aspectComponentId","resolveComponentId","loadAspects","aspectFullId","generator","getWorkspaceTemplate","registeredTemplate","generateComponentTemplate","componentNames","templateName","options","ConsumerNotFound","namespace","templateWithId","componentIds","componentName","getNewComponentId","scope","componentGenerator","ComponentGenerator","generate","generateWorkspaceTemplate","workspaceName","loadFrom","aspectComponent","workspaceGenerator","WorkspaceGenerator","appName","templatesByAspects","toArray","flatMap","componentTemplates","workspaceTemplates","aspectLoaded","aspects","provider","cli","graphql","community","commands","CreateCmd","getDocsDomain","TemplatesCmd","NewCmd","generatorSchema","registerPlugins","StarterPlugin","componentGeneratorTemplate","starterTemplate","workspaceGeneratorTemplate","Slot","withType","CLIAspect","GraphqlAspect","EnvsAspect","AspectLoaderAspect","NewComponentHelperAspect","CommunityAspect","ImporterAspect","MainRuntime","addRuntime"],"sources":["generator.main.runtime.ts"],"sourcesContent":["import { GraphqlAspect, GraphqlMain } from '@teambit/graphql';\nimport { CLIAspect, CLIMain, MainRuntime } from '@teambit/cli';\nimport WorkspaceAspect, { Workspace } from '@teambit/workspace';\nimport { EnvsAspect, EnvsMain } from '@teambit/envs';\nimport { ConsumerNotFound } from '@teambit/legacy/dist/consumer/exceptions';\nimport { CommunityAspect } from '@teambit/community';\nimport type { CommunityMain } from '@teambit/community';\n\nimport { Component } from '@teambit/component';\nimport { isCoreAspect, loadBit } from '@teambit/bit';\nimport { Slot, SlotRegistry } from '@teambit/harmony';\nimport { BitError } from '@teambit/bit-error';\nimport AspectLoaderAspect, { AspectLoaderMain } from '@teambit/aspect-loader';\nimport NewComponentHelperAspect, { NewComponentHelperMain } from '@teambit/new-component-helper';\nimport ImporterAspect, { ImporterMain } from '@teambit/importer';\nimport { ComponentTemplate } from './component-template';\nimport { GeneratorAspect } from './generator.aspect';\nimport { CreateCmd, CreateOptions } from './create.cmd';\nimport { TemplatesCmd } from './templates.cmd';\nimport { generatorSchema } from './generator.graphql';\nimport { ComponentGenerator, GenerateResult } from './component-generator';\nimport { WorkspaceGenerator } from './workspace-generator';\nimport { WorkspaceTemplate } from './workspace-template';\nimport { NewCmd, NewOptions } from './new.cmd';\nimport { componentGeneratorTemplate } from './templates/component-generator';\nimport { workspaceGeneratorTemplate } from './templates/workspace-generator';\nimport { starterTemplate } from './templates/starter';\nimport { StarterPlugin } from './starter.plugin';\n\nexport type ComponentTemplateSlot = SlotRegistry<ComponentTemplate[]>;\nexport type WorkspaceTemplateSlot = SlotRegistry<WorkspaceTemplate[]>;\n\nexport type TemplateDescriptor = { aspectId: string; name: string; description?: string; hidden?: boolean };\nexport type GenerateWorkspaceTemplateResult = { workspacePath: string; appName?: string };\n\nexport type GeneratorConfig = {\n /**\n * array of aspects to include in the list of templates.\n */\n aspects: string[];\n\n /**\n * by default core templates are shown.\n * use this to hide them unless `--show-all` flag of `bit templates` was used\n */\n hideCoreTemplates: boolean;\n};\n\nexport class GeneratorMain {\n private aspectLoaded = false;\n constructor(\n private componentTemplateSlot: ComponentTemplateSlot,\n private workspaceTemplateSlot: WorkspaceTemplateSlot,\n private config: GeneratorConfig,\n private workspace: Workspace,\n private envs: EnvsMain,\n private aspectLoader: AspectLoaderMain,\n private newComponentHelper: NewComponentHelperMain,\n private importer: ImporterMain\n ) {}\n\n /**\n * register a new component template.\n */\n registerComponentTemplate(templates: ComponentTemplate[]) {\n this.componentTemplateSlot.register(templates);\n return this;\n }\n\n /**\n * register a new component template.\n */\n registerWorkspaceTemplate(templates: WorkspaceTemplate[]) {\n this.workspaceTemplateSlot.register(templates);\n return this;\n }\n\n /**\n * list all component templates registered in the workspace or workspace templates in case the\n * workspace is not available\n */\n async listTemplates(): Promise<TemplateDescriptor[]> {\n const getTemplateDescriptor = ({\n id,\n template,\n }: {\n id: string;\n template: WorkspaceTemplate | ComponentTemplate;\n }) => {\n const shouldBeHidden = () => {\n if (template.hidden) return true;\n if (this.config.hideCoreTemplates && isCoreAspect(id)) return true;\n return false;\n };\n return {\n aspectId: id,\n name: template.name,\n description: template.description,\n hidden: shouldBeHidden(),\n };\n };\n return this.isRunningInsideWorkspace()\n ? this.getAllComponentTemplatesFlattened().map(getTemplateDescriptor)\n : this.getAllWorkspaceTemplatesFlattened().map(getTemplateDescriptor);\n }\n\n /**\n * @deprecated use this.listTemplates()\n */\n async listComponentTemplates(): Promise<TemplateDescriptor[]> {\n return this.listTemplates();\n }\n\n isRunningInsideWorkspace(): boolean {\n return Boolean(this.workspace);\n }\n\n /**\n * get all component templates registered by a specific aspect ID.\n */\n getComponentTemplateByAspect(aspectId: string): ComponentTemplate[] {\n return this.componentTemplateSlot.get(aspectId) || [];\n }\n\n /**\n * returns a specific component template.\n */\n getComponentTemplate(name: string, aspectId?: string): { id: string; template: ComponentTemplate } | undefined {\n const templates = this.getAllComponentTemplatesFlattened();\n const found = templates.find(({ id, template }) => {\n if (aspectId && id !== aspectId) return false;\n return template.name === name;\n });\n return found;\n }\n\n /**\n * in the case the aspect-id is given and this aspect doesn't exist locally, import it to the\n * global scope and load it from the capsule\n */\n async findTemplateInGlobalScope(\n aspectId: string,\n name?: string\n ): Promise<{ workspaceTemplate?: WorkspaceTemplate; aspect?: Component }> {\n const { globalScopeHarmony, components } = await this.aspectLoader.loadAspectsFromGlobalScope([aspectId]);\n const remoteGenerator = globalScopeHarmony.get<GeneratorMain>(GeneratorAspect.id);\n const aspect = components[0];\n const fullAspectId = aspect.id.toString();\n const fromGlobal = await remoteGenerator.searchRegisteredWorkspaceTemplate.call(\n remoteGenerator,\n name,\n fullAspectId\n );\n return { workspaceTemplate: fromGlobal, aspect };\n }\n\n async findTemplateInOtherWorkspace(workspacePath: string, name: string, aspectId?: string) {\n if (!aspectId)\n throw new BitError(\n `to load a template from a different workspace, please provide the aspect-id using --aspect flag`\n );\n const harmony = await loadBit(workspacePath);\n let workspace: Workspace;\n try {\n workspace = harmony.get<Workspace>(WorkspaceAspect.id);\n } catch (err: any) {\n throw new Error(`fatal: \"${workspacePath}\" is not a valid Bit workspace, make sure the path is correct`);\n }\n const aspectComponentId = await workspace.resolveComponentId(aspectId);\n await workspace.loadAspects([aspectId], true);\n const aspectFullId = aspectComponentId.toString();\n const generator = harmony.get<GeneratorMain>(GeneratorAspect.id);\n return generator.searchRegisteredWorkspaceTemplate(name, aspectFullId);\n }\n\n /**\n * returns a specific workspace template.\n */\n async getWorkspaceTemplate(\n name: string,\n aspectId?: string\n ): Promise<{ workspaceTemplate: WorkspaceTemplate; aspect?: Component }> {\n const registeredTemplate = await this.searchRegisteredWorkspaceTemplate(name, aspectId);\n if (registeredTemplate) {\n return { workspaceTemplate: registeredTemplate };\n }\n if (!aspectId) {\n throw new BitError(`template \"${name}\" was not found, if this is a custom-template, please use --aspect flag`);\n }\n\n const { workspaceTemplate, aspect } = await this.findTemplateInGlobalScope(aspectId, name);\n if (workspaceTemplate) {\n return { workspaceTemplate, aspect };\n }\n throw new BitError(`template \"${name}\" was not found`);\n }\n\n async searchRegisteredWorkspaceTemplate(name?: string, aspectId?: string): Promise<WorkspaceTemplate | undefined> {\n const templates = this.getAllWorkspaceTemplatesFlattened();\n const found = templates.find(({ id, template }) => {\n if (aspectId && name) return aspectId === id && name === template.name;\n if (aspectId) return aspectId === id;\n if (name) return name === template.name;\n throw new Error(`searchRegisteredWorkspaceTemplate expects to get \"name\" or \"aspectId\"`);\n });\n return found?.template;\n }\n\n async generateComponentTemplate(\n componentNames: string[],\n templateName: string,\n options: CreateOptions\n ): Promise<GenerateResult[]> {\n if (!this.workspace) throw new ConsumerNotFound();\n await this.loadAspects();\n const { namespace, aspect: aspectId } = options;\n const templateWithId = this.getComponentTemplate(templateName, aspectId);\n if (!templateWithId) throw new BitError(`template \"${templateName}\" was not found`);\n\n const componentIds = componentNames.map((componentName) =>\n this.newComponentHelper.getNewComponentId(componentName, namespace, options.scope)\n );\n\n const componentGenerator = new ComponentGenerator(\n this.workspace,\n componentIds,\n options,\n templateWithId.template,\n this.envs,\n this.newComponentHelper,\n templateWithId.id\n );\n return componentGenerator.generate();\n }\n\n async generateWorkspaceTemplate(\n workspaceName: string,\n templateName: string,\n options: NewOptions\n ): Promise<GenerateWorkspaceTemplateResult> {\n if (this.workspace) {\n throw new BitError('Error: unable to generate a new workspace inside of an existing workspace');\n }\n const { aspect: aspectId, loadFrom } = options;\n let template: WorkspaceTemplate | undefined;\n let aspectComponent: Component | undefined;\n if (loadFrom) {\n template = await this.findTemplateInOtherWorkspace(loadFrom, templateName, aspectId);\n } else {\n const { workspaceTemplate, aspect } = await this.getWorkspaceTemplate(templateName, aspectId);\n template = workspaceTemplate;\n aspectComponent = aspect;\n }\n if (!template) throw new BitError(`template \"${templateName}\" was not found`);\n const workspaceGenerator = new WorkspaceGenerator(workspaceName, options, template, aspectComponent);\n const workspacePath = await workspaceGenerator.generate();\n\n return { workspacePath, appName: template.appName };\n }\n\n private getAllComponentTemplatesFlattened(): Array<{ id: string; template: ComponentTemplate }> {\n const templatesByAspects = this.componentTemplateSlot.toArray();\n return templatesByAspects.flatMap(([id, componentTemplates]) => {\n return componentTemplates.map((template) => ({\n id,\n template,\n }));\n });\n }\n\n private getAllWorkspaceTemplatesFlattened(): Array<{ id: string; template: WorkspaceTemplate }> {\n const templatesByAspects = this.workspaceTemplateSlot.toArray();\n return templatesByAspects.flatMap(([id, workspaceTemplates]) => {\n return workspaceTemplates.map((template) => ({\n id,\n template,\n }));\n });\n }\n\n private async loadAspects() {\n if (this.aspectLoaded) return;\n await this.workspace.loadAspects(this.config.aspects);\n this.aspectLoaded = true;\n }\n\n static slots = [Slot.withType<ComponentTemplate[]>(), Slot.withType<WorkspaceTemplate[]>()];\n\n static dependencies = [\n WorkspaceAspect,\n CLIAspect,\n GraphqlAspect,\n EnvsAspect,\n AspectLoaderAspect,\n NewComponentHelperAspect,\n CommunityAspect,\n ImporterAspect,\n ];\n\n static runtime = MainRuntime;\n\n static async provider(\n [workspace, cli, graphql, envs, aspectLoader, newComponentHelper, community, importer]: [\n Workspace,\n CLIMain,\n GraphqlMain,\n EnvsMain,\n AspectLoaderMain,\n NewComponentHelperMain,\n CommunityMain,\n ImporterMain\n ],\n config: GeneratorConfig,\n [componentTemplateSlot, workspaceTemplateSlot]: [ComponentTemplateSlot, WorkspaceTemplateSlot]\n ) {\n const generator = new GeneratorMain(\n componentTemplateSlot,\n workspaceTemplateSlot,\n config,\n workspace,\n envs,\n aspectLoader,\n newComponentHelper,\n importer\n );\n const commands = [\n new CreateCmd(generator, community.getDocsDomain()),\n new TemplatesCmd(generator),\n new NewCmd(generator),\n ];\n cli.register(...commands);\n graphql.register(generatorSchema(generator));\n aspectLoader.registerPlugins([new StarterPlugin(generator)]);\n\n generator.registerComponentTemplate([componentGeneratorTemplate, starterTemplate, workspaceGeneratorTemplate]);\n return generator;\n }\n}\n\nGeneratorAspect.addRuntime(GeneratorMain);\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAIA;EAAA;EAAA;IAAA;EAAA;E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CAAC+F,eAAe,CAAC,CAAC,KAAIC,yBAAa,EAAC1C,SAAS,CAAC,CAAC,CAAC;IAE5DA,SAAS,CAACnD,yBAAyB,CAAC,CAAC8F,iDAA0B,EAAEC,0BAAe,EAAEC,iDAA0B,CAAC,CAAC;IAC9G,OAAO7C,SAAS;EAClB;AACF;AAAC;AAAA,gCAjSY7D,aAAa,WA8OT,CAAC2G,eAAI,CAACC,QAAQ,EAAuB,EAAED,eAAI,CAACC,QAAQ,EAAuB,CAAC;AAAA,gCA9OhF5G,aAAa,kBAgPF,CACpBsD,oBAAe,EACfuD,gBAAS,EACTC,wBAAa,EACbC,kBAAU,EACVC,uBAAkB,EAClBC,6BAAwB,EACxBC,4BAAe,EACfC,mBAAc,CACf;AAAA,gCAzPUnH,aAAa,aA2PPoH,kBAAW;AAwC9B3E,4BAAe,CAAC4E,UAAU,CAACrH,aAAa,CAAC"}
1
+ {"version":3,"names":["GeneratorMain","constructor","componentTemplateSlot","workspaceTemplateSlot","config","workspace","envs","aspectLoader","newComponentHelper","importer","componentAspect","id","template","shouldBeHidden","hidden","hideCoreTemplates","isCoreAspect","aspectId","name","description","registerComponentTemplate","templates","register","registerWorkspaceTemplate","listTemplates","aspect","isRunningInsideWorkspace","getAllComponentTemplatesDescriptorsFlattened","getAllWorkspaceTemplatesDescriptorFlattened","listComponentTemplates","opts","Boolean","getComponentTemplateByAspect","get","getComponentTemplate","fromEnv","listEnvComponentTemplates","length","found","findTemplateByAspectIdAndName","getAllComponentTemplatesFlattened","find","findTemplateInGlobalScope","globalScopeHarmony","components","loadAspectsFromGlobalScope","remoteGenerator","GeneratorAspect","fullAspectId","toString","fromGlobal","searchRegisteredWorkspaceTemplate","call","workspaceTemplate","findTemplateInOtherWorkspace","workspacePath","BitError","harmony","loadBit","WorkspaceAspect","err","Error","aspectComponentId","resolveComponentId","loadAspects","aspectFullId","generator","getWorkspaceTemplate","registeredTemplate","listEnvWorkspaceTemplates","getAllWorkspaceTemplatesFlattened","tpl","generateComponentTemplate","componentNames","templateName","options","ConsumerNotFound","namespace","templateWithId","componentIds","map","componentName","getNewComponentId","scope","componentGenerator","ComponentGenerator","envName","ComponentID","fromString","undefined","generate","generateWorkspaceTemplate","workspaceName","loadFrom","aspectComponent","workspaceGenerator","WorkspaceGenerator","appName","envTemplates","listEnvComponentTemplateDescriptors","filtered","filter","flattened","getTemplateDescriptor","templatesByAspects","toArray","flatMap","componentTemplates","workspaceTemplates","envId","loadEnvs","env","getGeneratorStarters","envStarters","starter","componentId","compact","ids","envTemplate","toStringWithoutVersion","titlePrefix","configEnvs","concat","getGeneratorTemplates","tpls","getEnvDefinition","host","getHost","toLoad","component","allEnvs","aspectLoaded","aspects","provider","cli","graphql","community","commands","CreateCmd","getDocsDomain","TemplatesCmd","NewCmd","generatorSchema","registerPlugins","StarterPlugin","componentGeneratorTemplate","starterTemplate","workspaceGeneratorTemplate","Slot","withType","CLIAspect","GraphqlAspect","EnvsAspect","AspectLoaderAspect","NewComponentHelperAspect","CommunityAspect","ImporterAspect","ComponentAspect","MainRuntime","addRuntime"],"sources":["generator.main.runtime.ts"],"sourcesContent":["import { GraphqlAspect, GraphqlMain } from '@teambit/graphql';\nimport { CLIAspect, CLIMain, MainRuntime } from '@teambit/cli';\nimport WorkspaceAspect, { Workspace } from '@teambit/workspace';\nimport { EnvDefinition, EnvsAspect, EnvsMain } from '@teambit/envs';\nimport { ConsumerNotFound } from '@teambit/legacy/dist/consumer/exceptions';\nimport { CommunityAspect } from '@teambit/community';\nimport type { CommunityMain } from '@teambit/community';\n\nimport ComponentAspect, { ComponentID } from '@teambit/component';\nimport type { ComponentMain, Component } from '@teambit/component';\n\nimport { isCoreAspect, loadBit } from '@teambit/bit';\nimport { Slot, SlotRegistry } from '@teambit/harmony';\nimport { BitError } from '@teambit/bit-error';\nimport AspectLoaderAspect, { AspectLoaderMain } from '@teambit/aspect-loader';\nimport NewComponentHelperAspect, { NewComponentHelperMain } from '@teambit/new-component-helper';\nimport { compact } from 'lodash';\nimport ImporterAspect, { ImporterMain } from '@teambit/importer';\nimport { ComponentTemplate } from './component-template';\nimport { GeneratorAspect } from './generator.aspect';\nimport { CreateCmd, CreateOptions } from './create.cmd';\nimport { TemplatesCmd } from './templates.cmd';\nimport { generatorSchema } from './generator.graphql';\nimport { ComponentGenerator, GenerateResult } from './component-generator';\nimport { WorkspaceGenerator } from './workspace-generator';\nimport { WorkspaceTemplate } from './workspace-template';\nimport { NewCmd, NewOptions } from './new.cmd';\nimport { componentGeneratorTemplate } from './templates/component-generator';\nimport { workspaceGeneratorTemplate } from './templates/workspace-generator';\nimport { starterTemplate } from './templates/starter';\nimport { StarterPlugin } from './starter.plugin';\n\nexport type ComponentTemplateSlot = SlotRegistry<ComponentTemplate[]>;\nexport type WorkspaceTemplateSlot = SlotRegistry<WorkspaceTemplate[]>;\n\nexport type TemplateDescriptor = {\n aspectId: string;\n titlePrefix?: string;\n name: string;\n description?: string;\n hidden?: boolean;\n};\n\ntype TemplateWithId = { id: string; envName?: string };\ntype WorkspaceTemplateWithId = TemplateWithId & { template: WorkspaceTemplate };\ntype ComponentTemplateWithId = TemplateWithId & { template: ComponentTemplate };\ntype AnyTemplateWithId = TemplateWithId & { template: ComponentTemplate | WorkspaceTemplate };\n\nexport type GenerateWorkspaceTemplateResult = { workspacePath: string; appName?: string };\n\nexport type GeneratorConfig = {\n /**\n * array of aspects to include in the list of templates.\n */\n aspects: string[];\n\n /**\n * by default core templates are shown.\n * use this to hide them unless `--show-all` flag of `bit templates` was used\n */\n hideCoreTemplates: boolean;\n\n /**\n * default envs.\n */\n envs?: string[];\n};\n\nexport class GeneratorMain {\n private aspectLoaded = false;\n constructor(\n private componentTemplateSlot: ComponentTemplateSlot,\n private workspaceTemplateSlot: WorkspaceTemplateSlot,\n private config: GeneratorConfig,\n private workspace: Workspace,\n private envs: EnvsMain,\n private aspectLoader: AspectLoaderMain,\n private newComponentHelper: NewComponentHelperMain,\n private importer: ImporterMain,\n private componentAspect: ComponentMain\n ) {}\n\n /**\n * register a new component template.\n */\n registerComponentTemplate(templates: ComponentTemplate[]) {\n this.componentTemplateSlot.register(templates);\n return this;\n }\n\n /**\n * register a new component template.\n */\n registerWorkspaceTemplate(templates: WorkspaceTemplate[]) {\n this.workspaceTemplateSlot.register(templates);\n return this;\n }\n\n /**\n * list all component templates registered in the workspace or workspace templates in case the\n * workspace is not available\n */\n async listTemplates({ aspect }: { aspect?: string } = {}): Promise<TemplateDescriptor[]> {\n if (this.isRunningInsideWorkspace()) {\n return this.getAllComponentTemplatesDescriptorsFlattened(aspect);\n }\n return this.getAllWorkspaceTemplatesDescriptorFlattened(aspect);\n }\n\n private getTemplateDescriptor = ({ id, template }: AnyTemplateWithId): TemplateDescriptor => {\n const shouldBeHidden = () => {\n if (template.hidden) return true;\n if (this.config.hideCoreTemplates && isCoreAspect(id)) return true;\n return false;\n };\n return {\n aspectId: id,\n name: template.name,\n description: template.description,\n hidden: shouldBeHidden(),\n };\n };\n\n /**\n * @deprecated use this.listTemplates()\n */\n async listComponentTemplates(opts: { aspect?: string }): Promise<TemplateDescriptor[]> {\n return this.listTemplates(opts);\n }\n\n isRunningInsideWorkspace(): boolean {\n return Boolean(this.workspace);\n }\n\n /**\n * get all component templates registered by a specific aspect ID.\n */\n getComponentTemplateByAspect(aspectId: string): ComponentTemplate[] {\n return this.componentTemplateSlot.get(aspectId) || [];\n }\n\n /**\n * returns a specific component template.\n */\n async getComponentTemplate(name: string, aspectId?: string): Promise<ComponentTemplateWithId | undefined> {\n const fromEnv = await this.listEnvComponentTemplates();\n if (fromEnv && fromEnv.length){\n const found = this.findTemplateByAspectIdAndName<ComponentTemplateWithId>(aspectId, name, fromEnv);\n if (found) return found;\n }\n // fallback to aspect id not from env if provided\n const templates = await this.getAllComponentTemplatesFlattened();\n const found = this.findTemplateByAspectIdAndName<ComponentTemplateWithId>(aspectId, name, templates);\n return found;\n }\n\n private findTemplateByAspectIdAndName<T>(\n aspectId: string | undefined,\n name: string,\n templates: Array<T>\n ): T | undefined {\n // @ts-ignore (should set T to be extends ComponentTemplateWithId or WorkspaceTemplateWithId)\n const found = templates.find(({ id, template }) => {\n if (aspectId && id !== aspectId) return false;\n return template.name === name;\n });\n return found;\n }\n\n /**\n * in the case the aspect-id is given and this aspect doesn't exist locally, import it to the\n * global scope and load it from the capsule\n */\n async findTemplateInGlobalScope(\n aspectId: string,\n name?: string\n ): Promise<{ workspaceTemplate?: WorkspaceTemplate; aspect?: Component }> {\n const { globalScopeHarmony, components } = await this.aspectLoader.loadAspectsFromGlobalScope([aspectId]);\n const remoteGenerator = globalScopeHarmony.get<GeneratorMain>(GeneratorAspect.id);\n const aspect = components[0];\n const fullAspectId = aspect.id.toString();\n const fromGlobal = await remoteGenerator.searchRegisteredWorkspaceTemplate.call(\n remoteGenerator,\n name,\n fullAspectId\n );\n return { workspaceTemplate: fromGlobal, aspect };\n }\n\n async findTemplateInOtherWorkspace(workspacePath: string, name: string, aspectId?: string) {\n if (!aspectId)\n throw new BitError(\n `to load a template from a different workspace, please provide the aspect-id using --aspect flag`\n );\n const harmony = await loadBit(workspacePath);\n let workspace: Workspace;\n try {\n workspace = harmony.get<Workspace>(WorkspaceAspect.id);\n } catch (err: any) {\n throw new Error(`fatal: \"${workspacePath}\" is not a valid Bit workspace, make sure the path is correct`);\n }\n const aspectComponentId = await workspace.resolveComponentId(aspectId);\n await workspace.loadAspects([aspectId], true);\n const aspectFullId = aspectComponentId.toString();\n const generator = harmony.get<GeneratorMain>(GeneratorAspect.id);\n return generator.searchRegisteredWorkspaceTemplate(name, aspectFullId);\n }\n\n /**\n * returns a specific workspace template.\n */\n async getWorkspaceTemplate(\n name: string,\n aspectId?: string\n ): Promise<{ workspaceTemplate: WorkspaceTemplate; aspect?: Component }> {\n const registeredTemplate = await this.searchRegisteredWorkspaceTemplate(name, aspectId);\n if (registeredTemplate) {\n return { workspaceTemplate: registeredTemplate };\n }\n if (!aspectId) {\n throw new BitError(`template \"${name}\" was not found, if this is a custom-template, please use --aspect flag`);\n }\n\n const { workspaceTemplate, aspect } = await this.findTemplateInGlobalScope(aspectId, name);\n if (workspaceTemplate) {\n return { workspaceTemplate, aspect };\n }\n throw new BitError(`template \"${name}\" was not found`);\n }\n\n async searchRegisteredWorkspaceTemplate(name?: string, aspectId?: string): Promise<WorkspaceTemplate | undefined> {\n let fromEnv;\n if (aspectId) {\n fromEnv = await this.listEnvWorkspaceTemplates(aspectId);\n }\n const templates = (fromEnv && fromEnv.length) ? fromEnv : this.getAllWorkspaceTemplatesFlattened();\n const found = templates.find(({ id, template: tpl }) => {\n if (aspectId && name) return aspectId === id && name === tpl.name;\n if (aspectId) return aspectId === id;\n if (name) return name === tpl.name;\n throw new Error(`searchRegisteredWorkspaceTemplate expects to get \"name\" or \"aspectId\"`);\n });\n\n return found?.template;\n }\n\n async generateComponentTemplate(\n componentNames: string[],\n templateName: string,\n options: CreateOptions\n ): Promise<GenerateResult[]> {\n if (!this.workspace) throw new ConsumerNotFound();\n await this.loadAspects();\n const { namespace, aspect: aspectId } = options;\n const templateWithId = await this.getComponentTemplate(templateName, aspectId);\n if (!templateWithId) throw new BitError(`template \"${templateName}\" was not found`);\n\n const componentIds = componentNames.map((componentName) =>\n this.newComponentHelper.getNewComponentId(componentName, namespace, options.scope)\n );\n\n const componentGenerator = new ComponentGenerator(\n this.workspace,\n componentIds,\n options,\n templateWithId.template,\n this.envs,\n this.newComponentHelper,\n templateWithId.id,\n templateWithId.envName ? ComponentID.fromString(templateWithId.id) : undefined\n );\n return componentGenerator.generate();\n }\n\n async generateWorkspaceTemplate(\n workspaceName: string,\n templateName: string,\n options: NewOptions\n ): Promise<GenerateWorkspaceTemplateResult> {\n if (this.workspace) {\n throw new BitError('Error: unable to generate a new workspace inside of an existing workspace');\n }\n const { aspect: aspectId, loadFrom } = options;\n let template: WorkspaceTemplate | undefined;\n let aspectComponent: Component | undefined;\n if (loadFrom) {\n template = await this.findTemplateInOtherWorkspace(loadFrom, templateName, aspectId);\n } else {\n const { workspaceTemplate, aspect } = await this.getWorkspaceTemplate(templateName, aspectId);\n template = workspaceTemplate;\n aspectComponent = aspect;\n }\n if (!template) throw new BitError(`template \"${templateName}\" was not found`);\n const workspaceGenerator = new WorkspaceGenerator(workspaceName, options, template, aspectComponent);\n const workspacePath = await workspaceGenerator.generate();\n\n return { workspacePath, appName: template.appName };\n }\n\n private async getAllComponentTemplatesDescriptorsFlattened(aspectId?: string): Promise<Array<TemplateDescriptor>> {\n const envTemplates = await this.listEnvComponentTemplateDescriptors();\n if (envTemplates && envTemplates.length) {\n if (!aspectId) return envTemplates;\n const filtered = envTemplates.filter((template) => template.aspectId === aspectId);\n if (filtered.length) return filtered;\n }\n\n const flattened = this.getAllComponentTemplatesFlattened();\n const filtered = flattened.filter((template) => template.id === aspectId);\n return filtered.map((template) => this.getTemplateDescriptor(template));\n }\n\n private getAllComponentTemplatesFlattened(): Array<{ id: string; template: ComponentTemplate }> {\n const templatesByAspects = this.componentTemplateSlot.toArray();\n const flattened = templatesByAspects.flatMap(([id, componentTemplates]) => {\n return componentTemplates.map((template) => ({\n id,\n template,\n }));\n });\n return flattened;\n }\n\n private async getAllWorkspaceTemplatesDescriptorFlattened(aspectId?: string): Promise<Array<TemplateDescriptor>> {\n let envTemplates;\n if (aspectId) {\n envTemplates = await this.listEnvWorkspaceTemplates(aspectId);\n }\n\n const templates = envTemplates && envTemplates.length ? envTemplates : this.getAllWorkspaceTemplatesFlattened();\n return templates.map((template) => this.getTemplateDescriptor(template));\n }\n\n private getAllWorkspaceTemplatesFlattened(): Array<{ id: string; template: WorkspaceTemplate }> {\n const templatesByAspects = this.workspaceTemplateSlot.toArray();\n return templatesByAspects.flatMap(([id, workspaceTemplates]) => {\n return workspaceTemplates.map((template) => ({\n id,\n template,\n }));\n });\n }\n\n /**\n * list all starter templates registered by an env.\n */\n async listEnvWorkspaceTemplates(\n envId: string\n ): Promise<Array<WorkspaceTemplateWithId>> {\n const envs = await this.loadEnvs([envId]);\n const workspaceTemplates = envs.flatMap((env) => {\n if (!env.env.getGeneratorStarters) return undefined;\n const envStarters = env.env.getGeneratorStarters();\n return envStarters.map((starter) => {\n const componentId = ComponentID.fromString(env.id);\n return {\n id: componentId.toString(),\n envName: env.name,\n template: starter,\n };\n });\n });\n\n return compact(workspaceTemplates);\n }\n\n /**\n * list all component templates registered by an env.\n */\n async listEnvComponentTemplateDescriptors(ids: string[] = []): Promise<TemplateDescriptor[]> {\n const envTemplates = await this.listEnvComponentTemplates(ids);\n const templates: TemplateDescriptor[] = envTemplates.map((envTemplate) => {\n const componentId = ComponentID.fromString(envTemplate.id);\n return {\n aspectId: componentId.toStringWithoutVersion(),\n titlePrefix: envTemplate.envName,\n ...envTemplate.template,\n };\n });\n\n return templates;\n }\n\n async listEnvComponentTemplates(\n ids: string[] = []\n ): Promise<Array<ComponentTemplateWithId>> {\n const configEnvs = this.config.envs || [];\n const envs = await this.loadEnvs(configEnvs?.concat(ids));\n const templates = envs.flatMap((env) => {\n if (!env.env.getGeneratorTemplates) return [];\n const tpls = env.env.getGeneratorTemplates() || [];\n return tpls.map((template) => {\n const componentId = ComponentID.fromString(env.id);\n return {\n id: componentId.toString(),\n envName: env.name,\n template,\n };\n });\n });\n\n return templates;\n }\n\n async loadEnvs(ids: string[] = this.config.envs || []): Promise<EnvDefinition[]> {\n // TODO: this will probably won't work for bit new with aspect id and without loadFrom\n // as this getEnvDefinition will probably return nothing, as the env is not loaded yet, therefore, not register to the slot\n // we need to check if that id is an aspect id and load it as an aspect\n // and only after it, we can get the env definition\n const envs = ids.map((id) => {\n const componentId = ComponentID.fromString(id);\n return {\n id: componentId,\n env: this.envs.getEnvDefinition(componentId),\n };\n });\n\n const host = this.componentAspect.getHost();\n if (!host) return [];\n\n const toLoad = envs.filter((env) => !env.env);\n const componentIds = toLoad.map((component) => component.id.toString());\n await host.loadAspects(componentIds);\n const allEnvs = envs.map((env) => {\n if (env.env) {\n return env.env;\n }\n\n return this.envs.getEnvDefinition(env.id);\n });\n\n return compact(allEnvs);\n }\n\n async loadAspects() {\n if (this.aspectLoaded) return;\n await this.workspace.loadAspects(this.config.aspects);\n this.aspectLoaded = true;\n }\n\n static slots = [Slot.withType<ComponentTemplate[]>(), Slot.withType<WorkspaceTemplate[]>()];\n\n static dependencies = [\n WorkspaceAspect,\n CLIAspect,\n GraphqlAspect,\n EnvsAspect,\n AspectLoaderAspect,\n NewComponentHelperAspect,\n CommunityAspect,\n ImporterAspect,\n ComponentAspect\n ];\n\n static runtime = MainRuntime;\n\n static async provider(\n [workspace, cli, graphql, envs, aspectLoader, newComponentHelper, community, importer, componentAspect]: [\n Workspace,\n CLIMain,\n GraphqlMain,\n EnvsMain,\n AspectLoaderMain,\n NewComponentHelperMain,\n CommunityMain,\n ImporterMain,\n ComponentMain\n ],\n config: GeneratorConfig,\n [componentTemplateSlot, workspaceTemplateSlot]: [ComponentTemplateSlot, WorkspaceTemplateSlot]\n ) {\n const generator = new GeneratorMain(\n componentTemplateSlot,\n workspaceTemplateSlot,\n config,\n workspace,\n envs,\n aspectLoader,\n newComponentHelper,\n importer,\n componentAspect\n );\n const commands = [\n new CreateCmd(generator, community.getDocsDomain()),\n new TemplatesCmd(generator),\n new NewCmd(generator),\n ];\n cli.register(...commands);\n graphql.register(generatorSchema(generator));\n aspectLoader.registerPlugins([new StarterPlugin(generator)]);\n\n generator.registerComponentTemplate([componentGeneratorTemplate, starterTemplate, workspaceGeneratorTemplate]);\n return generator;\n }\n}\n\nGeneratorAspect.addRuntime(GeneratorMain);\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAGA;EAAA;EAAA;IAAA;EAAA;EAA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M,EAAC3E,SAAS,CAAC,CACtB;IACDoE,GAAG,CAAChH,QAAQ,CAAC,GAAGmH,QAAQ,CAAC;IACzBF,OAAO,CAACjH,QAAQ,CAAC,IAAAwH,6BAAe,EAAC5E,SAAS,CAAC,CAAC;IAC5C3D,YAAY,CAACwI,eAAe,CAAC,CAAC,KAAIC,yBAAa,EAAC9E,SAAS,CAAC,CAAC,CAAC;IAE5DA,SAAS,CAAC9C,yBAAyB,CAAC,CAAC6H,iDAA0B,EAAEC,0BAAe,EAAEC,iDAA0B,CAAC,CAAC;IAC9G,OAAOjF,SAAS;EAClB;AACF;AAAC;AAAA,gCA1aYlE,aAAa,WAoXT,CAACoJ,eAAI,CAACC,QAAQ,EAAuB,EAAED,eAAI,CAACC,QAAQ,EAAuB,CAAC;AAAA,gCApXhFrJ,aAAa,kBAsXF,CACpB2D,oBAAe,EACf2F,gBAAS,EACTC,wBAAa,EACbC,kBAAU,EACVC,uBAAkB,EAClBC,6BAAwB,EACxBC,4BAAe,EACfC,mBAAc,EACdC,oBAAe,CAChB;AAAA,gCAhYU7J,aAAa,aAkYP8J,kBAAW;AA0C9B/G,4BAAe,CAACgH,UAAU,CAAC/J,aAAa,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,4 +1,7 @@
1
1
  export type { GeneratorMain } from './generator.main.runtime';
2
2
  export { ComponentContext, ComponentTemplate, ComponentFile, ComponentConfig, ConfigContext, } from './component-template';
3
3
  export { WorkspaceContext, WorkspaceTemplate, WorkspaceTemplate as Starter, WorkspaceFile } from './workspace-template';
4
+ export { GeneratorEnv } from './generator-env-type';
4
5
  export { GeneratorAspect } from './generator.aspect';
6
+ export { TemplateList } from './template-list';
7
+ export { StarterList } from './starter-list';
package/dist/index.js CHANGED
@@ -39,12 +39,30 @@ Object.defineProperty(exports, "GeneratorAspect", {
39
39
  return _generator().GeneratorAspect;
40
40
  }
41
41
  });
42
+ Object.defineProperty(exports, "GeneratorEnv", {
43
+ enumerable: true,
44
+ get: function () {
45
+ return _generatorEnvType().GeneratorEnv;
46
+ }
47
+ });
42
48
  Object.defineProperty(exports, "Starter", {
43
49
  enumerable: true,
44
50
  get: function () {
45
51
  return _workspaceTemplate().WorkspaceTemplate;
46
52
  }
47
53
  });
54
+ Object.defineProperty(exports, "StarterList", {
55
+ enumerable: true,
56
+ get: function () {
57
+ return _starterList().StarterList;
58
+ }
59
+ });
60
+ Object.defineProperty(exports, "TemplateList", {
61
+ enumerable: true,
62
+ get: function () {
63
+ return _templateList().TemplateList;
64
+ }
65
+ });
48
66
  Object.defineProperty(exports, "WorkspaceContext", {
49
67
  enumerable: true,
50
68
  get: function () {
@@ -77,6 +95,13 @@ function _workspaceTemplate() {
77
95
  };
78
96
  return data;
79
97
  }
98
+ function _generatorEnvType() {
99
+ const data = require("./generator-env-type");
100
+ _generatorEnvType = function () {
101
+ return data;
102
+ };
103
+ return data;
104
+ }
80
105
  function _generator() {
81
106
  const data = require("./generator.aspect");
82
107
  _generator = function () {
@@ -84,5 +109,19 @@ function _generator() {
84
109
  };
85
110
  return data;
86
111
  }
112
+ function _templateList() {
113
+ const data = require("./template-list");
114
+ _templateList = function () {
115
+ return data;
116
+ };
117
+ return data;
118
+ }
119
+ function _starterList() {
120
+ const data = require("./starter-list");
121
+ _starterList = function () {
122
+ return data;
123
+ };
124
+ return data;
125
+ }
87
126
 
88
127
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export type { GeneratorMain } from './generator.main.runtime';\nexport {\n ComponentContext,\n ComponentTemplate,\n ComponentFile,\n ComponentConfig,\n ConfigContext,\n} from './component-template';\nexport { WorkspaceContext, WorkspaceTemplate, WorkspaceTemplate as Starter, WorkspaceFile } from './workspace-template';\nexport { GeneratorAspect } from './generator.aspect';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAOA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA"}
1
+ {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export type { GeneratorMain } from './generator.main.runtime';\nexport {\n ComponentContext,\n ComponentTemplate,\n ComponentFile,\n ComponentConfig,\n ConfigContext,\n} from './component-template';\nexport { WorkspaceContext, WorkspaceTemplate, WorkspaceTemplate as Starter, WorkspaceFile } from './workspace-template';\nexport { GeneratorEnv } from './generator-env-type';\nexport { GeneratorAspect } from './generator.aspect';\nexport { TemplateList } from './template-list';\nexport { StarterList } from './starter-list';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAOA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA"}
@@ -1,5 +1,5 @@
1
- import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.generator_generator@0.0.918/dist/generator.composition.js';
2
- import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.generator_generator@0.0.918/dist/generator.docs.mdx';
1
+ import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.generator_generator@0.0.920/dist/generator.composition.js';
2
+ import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.generator_generator@0.0.920/dist/generator.docs.mdx';
3
3
 
4
4
  export const compositions = [compositions_0];
5
5
  export const overview = [overview_0];
@@ -0,0 +1,13 @@
1
+ import { EnvContext, EnvHandler } from "@teambit/envs";
2
+ import { WorkspaceTemplate } from "./workspace-template";
3
+ export declare type StarterListOptions = {
4
+ name?: string;
5
+ };
6
+ export declare class StarterList {
7
+ readonly name: string;
8
+ private starters;
9
+ private context;
10
+ constructor(name: string, starters: EnvHandler<WorkspaceTemplate>[], context: EnvContext);
11
+ compute(): WorkspaceTemplate[];
12
+ static from(starters: EnvHandler<WorkspaceTemplate>[], options?: StarterListOptions): (context: EnvContext) => StarterList;
13
+ }
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.StarterList = void 0;
7
+ class StarterList {
8
+ constructor(name, starters, context) {
9
+ this.name = name;
10
+ this.starters = starters;
11
+ this.context = context;
12
+ }
13
+ compute() {
14
+ return this.starters.map(starter => starter(this.context));
15
+ }
16
+ static from(starters, options = {}) {
17
+ return context => {
18
+ const name = options.name || 'starter-list';
19
+ return new StarterList(name, starters, context);
20
+ };
21
+ }
22
+ }
23
+ exports.StarterList = StarterList;
24
+
25
+ //# sourceMappingURL=starter-list.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["StarterList","constructor","name","starters","context","compute","map","starter","from","options"],"sources":["starter-list.ts"],"sourcesContent":["import { EnvContext, EnvHandler } from \"@teambit/envs\";\nimport { WorkspaceTemplate } from \"./workspace-template\";\n\nexport type StarterListOptions = {\n name?: string;\n};\n\nexport class StarterList {\n constructor(\n readonly name: string,\n private starters: EnvHandler<WorkspaceTemplate>[],\n private context: EnvContext\n ) {}\n\n compute(): WorkspaceTemplate[] {\n return this.starters.map((starter) => starter(this.context))\n }\n\n static from(starters: EnvHandler<WorkspaceTemplate>[], options: StarterListOptions = {}) {\n return (context: EnvContext) => {\n const name = options.name || 'starter-list';\n return new StarterList(name, starters, context);\n };\n }\n}\n"],"mappings":";;;;;;AAOO,MAAMA,WAAW,CAAC;EACvBC,WAAW,CACAC,IAAY,EACbC,QAAyC,EACzCC,OAAmB,EAC3B;IAAA,KAHSF,IAAY,GAAZA,IAAY;IAAA,KACbC,QAAyC,GAAzCA,QAAyC;IAAA,KACzCC,OAAmB,GAAnBA,OAAmB;EAC1B;EAEHC,OAAO,GAAwB;IAC7B,OAAO,IAAI,CAACF,QAAQ,CAACG,GAAG,CAAEC,OAAO,IAAKA,OAAO,CAAC,IAAI,CAACH,OAAO,CAAC,CAAC;EAC9D;EAEA,OAAOI,IAAI,CAACL,QAAyC,EAAEM,OAA2B,GAAG,CAAC,CAAC,EAAE;IACvF,OAAQL,OAAmB,IAAK;MAC9B,MAAMF,IAAI,GAAGO,OAAO,CAACP,IAAI,IAAI,cAAc;MAC3C,OAAO,IAAIF,WAAW,CAACE,IAAI,EAAEC,QAAQ,EAAEC,OAAO,CAAC;IACjD,CAAC;EACH;AACF;AAAC"}
@@ -0,0 +1,13 @@
1
+ import { EnvContext, EnvHandler } from "@teambit/envs";
2
+ import { ComponentTemplate } from "./component-template";
3
+ export declare type TemplateListOptions = {
4
+ name?: string;
5
+ };
6
+ export declare class TemplateList {
7
+ readonly name: string;
8
+ private templates;
9
+ private context;
10
+ constructor(name: string, templates: EnvHandler<ComponentTemplate>[], context: EnvContext);
11
+ compute(): ComponentTemplate[];
12
+ static from(templates: EnvHandler<ComponentTemplate>[], options?: TemplateListOptions): (context: EnvContext) => TemplateList;
13
+ }
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.TemplateList = void 0;
7
+ class TemplateList {
8
+ constructor(name, templates, context) {
9
+ this.name = name;
10
+ this.templates = templates;
11
+ this.context = context;
12
+ }
13
+ compute() {
14
+ return this.templates.map(template => template(this.context));
15
+ }
16
+ static from(templates, options = {}) {
17
+ return context => {
18
+ const name = options.name || 'template-list';
19
+ return new TemplateList(name, templates, context);
20
+ };
21
+ }
22
+ }
23
+ exports.TemplateList = TemplateList;
24
+
25
+ //# sourceMappingURL=template-list.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["TemplateList","constructor","name","templates","context","compute","map","template","from","options"],"sources":["template-list.ts"],"sourcesContent":["import { EnvContext, EnvHandler } from \"@teambit/envs\";\nimport { ComponentTemplate } from \"./component-template\";\n\nexport type TemplateListOptions = {\n name?: string;\n};\n\nexport class TemplateList {\n constructor(\n readonly name: string,\n private templates: EnvHandler<ComponentTemplate>[],\n private context: EnvContext\n ) {}\n\n compute(): ComponentTemplate[] {\n return this.templates.map((template) => template(this.context))\n }\n\n static from(templates: EnvHandler<ComponentTemplate>[], options: TemplateListOptions = {}) {\n return (context: EnvContext) => {\n const name = options.name || 'template-list';\n return new TemplateList(name, templates, context);\n };\n }\n}\n"],"mappings":";;;;;;AAOO,MAAMA,YAAY,CAAC;EACxBC,WAAW,CACAC,IAAY,EACbC,SAA0C,EAC1CC,OAAmB,EAC3B;IAAA,KAHSF,IAAY,GAAZA,IAAY;IAAA,KACbC,SAA0C,GAA1CA,SAA0C;IAAA,KAC1CC,OAAmB,GAAnBA,OAAmB;EAC1B;EAEHC,OAAO,GAAwB;IAC7B,OAAO,IAAI,CAACF,SAAS,CAACG,GAAG,CAAEC,QAAQ,IAAKA,QAAQ,CAAC,IAAI,CAACH,OAAO,CAAC,CAAC;EACjE;EAEA,OAAOI,IAAI,CAACL,SAA0C,EAAEM,OAA4B,GAAG,CAAC,CAAC,EAAE;IACzF,OAAQL,OAAmB,IAAK;MAC9B,MAAMF,IAAI,GAAGO,OAAO,CAACP,IAAI,IAAI,eAAe;MAC5C,OAAO,IAAIF,YAAY,CAACE,IAAI,EAAEC,SAAS,EAAEC,OAAO,CAAC;IACnD,CAAC;EACH;AACF;AAAC"}
@@ -2,6 +2,7 @@ import { Command, CommandOptions } from '@teambit/cli';
2
2
  import { GeneratorMain } from './generator.main.runtime';
3
3
  export declare type TemplatesOptions = {
4
4
  showAll?: boolean;
5
+ aspect?: string;
5
6
  };
6
7
  export declare class TemplatesCmd implements Command {
7
8
  private generator;
@@ -37,12 +37,12 @@ class TemplatesCmd {
37
37
  (0, _defineProperty2().default)(this, "alias", '');
38
38
  (0, _defineProperty2().default)(this, "loader", true);
39
39
  (0, _defineProperty2().default)(this, "group", 'development');
40
- (0, _defineProperty2().default)(this, "options", [['s', 'show-all', 'show hidden templates']]);
40
+ (0, _defineProperty2().default)(this, "options", [['s', 'show-all', 'show hidden templates'], ['a', 'aspect <aspect-id>', 'show templates provided by the aspect-id']]);
41
41
  }
42
42
 
43
43
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
44
44
  async report(args, templatesOptions) {
45
- let results = await this.generator.listTemplates();
45
+ let results = await this.generator.listTemplates(templatesOptions);
46
46
 
47
47
  // Make sure that we don't list hidden templates
48
48
  if (!templatesOptions.showAll) {
@@ -57,7 +57,8 @@ class TemplatesCmd {
57
57
  };
58
58
  const output = Object.keys(grouped).map(aspectId => {
59
59
  const names = grouped[aspectId].map(templateOutput).join('\n');
60
- return `${_chalk().default.blue.bold(aspectId)}\n${names}\n`;
60
+ const groupTitle = grouped[aspectId][0].titlePrefix ? `${grouped[aspectId][0].titlePrefix} (${aspectId})` : aspectId;
61
+ return `${_chalk().default.blue.bold(groupTitle)}\n${names}\n`;
61
62
  }).join('\n');
62
63
  return title + output;
63
64
  }
@@ -1 +1 @@
1
- {"version":3,"names":["TemplatesCmd","constructor","generator","report","args","templatesOptions","results","listTemplates","showAll","filter","template","hidden","grouped","groupBy","titleStr","isRunningInsideWorkspace","title","chalk","green","templateOutput","desc","description","name","dim","output","Object","keys","map","aspectId","names","join","blue","bold"],"sources":["templates.cmd.ts"],"sourcesContent":["import { Command, CommandOptions } from '@teambit/cli';\nimport chalk from 'chalk';\nimport { groupBy } from 'lodash';\nimport { GeneratorMain, TemplateDescriptor } from './generator.main.runtime';\n\nexport type TemplatesOptions = {\n showAll?: boolean;\n};\n\nexport class TemplatesCmd implements Command {\n name = 'templates';\n description = 'list templates for \"bit create\" and \"bit new\"';\n extendedDescription =\n 'list components templates when inside bit-workspace (for bit-create), otherwise, list workspace templates (for bit-new)';\n alias = '';\n loader = true;\n group = 'development';\n options = [['s', 'show-all', 'show hidden templates']] as CommandOptions;\n\n constructor(private generator: GeneratorMain) {}\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n async report(args: [], templatesOptions: TemplatesOptions) {\n let results = await this.generator.listTemplates();\n\n // Make sure that we don't list hidden templates\n if (!templatesOptions.showAll) {\n results = results.filter((template) => !template.hidden);\n }\n\n const grouped = groupBy(results, 'aspectId');\n const titleStr = this.generator.isRunningInsideWorkspace()\n ? `The following template(s) are available with the command bit create: \\nExample - bit create <template-name> <component-name>`\n : `The following template(s) are available with the command bit new: \\nExample - bit new <template-name> <workspace-name>`;\n const title = chalk.green(`\\n${titleStr}\\n`);\n const templateOutput = (template: TemplateDescriptor) => {\n const desc = template.description ? ` (${template.description})` : '';\n return ` ${template.name}${chalk.dim(desc)}`;\n };\n const output = Object.keys(grouped)\n .map((aspectId) => {\n const names = grouped[aspectId].map(templateOutput).join('\\n');\n return `${chalk.blue.bold(aspectId)}\\n${names}\\n`;\n })\n .join('\\n');\n return title + output;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAOO,MAAMA,YAAY,CAAoB;EAU3CC,WAAW,CAASC,SAAwB,EAAE;IAAA,KAA1BA,SAAwB,GAAxBA,SAAwB;IAAA,8CATrC,WAAW;IAAA,qDACJ,+CAA+C;IAAA,6DAE3D,yHAAyH;IAAA,+CACnH,EAAE;IAAA,gDACD,IAAI;IAAA,+CACL,aAAa;IAAA,iDACX,CAAC,CAAC,GAAG,EAAE,UAAU,EAAE,uBAAuB,CAAC,CAAC;EAEP;;EAE/C;EACA,MAAMC,MAAM,CAACC,IAAQ,EAAEC,gBAAkC,EAAE;IACzD,IAAIC,OAAO,GAAG,MAAM,IAAI,CAACJ,SAAS,CAACK,aAAa,EAAE;;IAElD;IACA,IAAI,CAACF,gBAAgB,CAACG,OAAO,EAAE;MAC7BF,OAAO,GAAGA,OAAO,CAACG,MAAM,CAAEC,QAAQ,IAAK,CAACA,QAAQ,CAACC,MAAM,CAAC;IAC1D;IAEA,MAAMC,OAAO,GAAG,IAAAC,iBAAO,EAACP,OAAO,EAAE,UAAU,CAAC;IAC5C,MAAMQ,QAAQ,GAAG,IAAI,CAACZ,SAAS,CAACa,wBAAwB,EAAE,GACrD,+HAA8H,GAC9H,wHAAuH;IAC5H,MAAMC,KAAK,GAAGC,gBAAK,CAACC,KAAK,CAAE,KAAIJ,QAAS,IAAG,CAAC;IAC5C,MAAMK,cAAc,GAAIT,QAA4B,IAAK;MACvD,MAAMU,IAAI,GAAGV,QAAQ,CAACW,WAAW,GAAI,KAAIX,QAAQ,CAACW,WAAY,GAAE,GAAG,EAAE;MACrE,OAAQ,OAAMX,QAAQ,CAACY,IAAK,GAAEL,gBAAK,CAACM,GAAG,CAACH,IAAI,CAAE,EAAC;IACjD,CAAC;IACD,MAAMI,MAAM,GAAGC,MAAM,CAACC,IAAI,CAACd,OAAO,CAAC,CAChCe,GAAG,CAAEC,QAAQ,IAAK;MACjB,MAAMC,KAAK,GAAGjB,OAAO,CAACgB,QAAQ,CAAC,CAACD,GAAG,CAACR,cAAc,CAAC,CAACW,IAAI,CAAC,IAAI,CAAC;MAC9D,OAAQ,GAAEb,gBAAK,CAACc,IAAI,CAACC,IAAI,CAACJ,QAAQ,CAAE,KAAIC,KAAM,IAAG;IACnD,CAAC,CAAC,CACDC,IAAI,CAAC,IAAI,CAAC;IACb,OAAOd,KAAK,GAAGQ,MAAM;EACvB;AACF;AAAC"}
1
+ {"version":3,"names":["TemplatesCmd","constructor","generator","report","args","templatesOptions","results","listTemplates","showAll","filter","template","hidden","grouped","groupBy","titleStr","isRunningInsideWorkspace","title","chalk","green","templateOutput","desc","description","name","dim","output","Object","keys","map","aspectId","names","join","groupTitle","titlePrefix","blue","bold"],"sources":["templates.cmd.ts"],"sourcesContent":["import { Command, CommandOptions } from '@teambit/cli';\nimport chalk from 'chalk';\nimport { groupBy } from 'lodash';\nimport { GeneratorMain, TemplateDescriptor } from './generator.main.runtime';\n\nexport type TemplatesOptions = {\n showAll?: boolean;\n aspect?: string;\n};\n\nexport class TemplatesCmd implements Command {\n name = 'templates';\n description = 'list templates for \"bit create\" and \"bit new\"';\n extendedDescription =\n 'list components templates when inside bit-workspace (for bit-create), otherwise, list workspace templates (for bit-new)';\n alias = '';\n loader = true;\n group = 'development';\n options = [\n ['s', 'show-all', 'show hidden templates'],\n [\n 'a',\n 'aspect <aspect-id>',\n 'show templates provided by the aspect-id',\n ],\n ] as CommandOptions;\n\n constructor(private generator: GeneratorMain) {}\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n async report(args: [], templatesOptions: TemplatesOptions) {\n let results = await this.generator.listTemplates(templatesOptions);\n\n // Make sure that we don't list hidden templates\n if (!templatesOptions.showAll) {\n results = results.filter((template) => !template.hidden);\n }\n\n const grouped = groupBy(results, 'aspectId');\n const titleStr = this.generator.isRunningInsideWorkspace()\n ? `The following template(s) are available with the command bit create: \\nExample - bit create <template-name> <component-name>`\n : `The following template(s) are available with the command bit new: \\nExample - bit new <template-name> <workspace-name>`;\n const title = chalk.green(`\\n${titleStr}\\n`);\n const templateOutput = (template: TemplateDescriptor) => {\n const desc = template.description ? ` (${template.description})` : '';\n return ` ${template.name}${chalk.dim(desc)}`;\n };\n const output = Object.keys(grouped)\n .map((aspectId) => {\n const names = grouped[aspectId].map(templateOutput).join('\\n');\n const groupTitle = grouped[aspectId][0].titlePrefix\n ? `${grouped[aspectId][0].titlePrefix} (${aspectId})`\n : aspectId;\n return `${chalk.blue.bold(groupTitle)}\\n${names}\\n`;\n })\n .join('\\n');\n return title + output;\n }\n}\n"],"mappings":";;;;;;;;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AAM,GAAGC,MAAM,CAACC,IAAI,CAACd,OAAO,CAAC,CAChCe,GAAG,CAAEC,QAAQ,IAAK;MACjB,MAAMC,KAAK,GAAGjB,OAAO,CAACgB,QAAQ,CAAC,CAACD,GAAG,CAACR,cAAc,CAAC,CAACW,IAAI,CAAC,IAAI,CAAC;MAC9D,MAAMC,UAAU,GAAGnB,OAAO,CAACgB,QAAQ,CAAC,CAAC,CAAC,CAAC,CAACI,WAAW,GAC9C,GAAEpB,OAAO,CAACgB,QAAQ,CAAC,CAAC,CAAC,CAAC,CAACI,WAAY,KAAIJ,QAAS,GAAE,GACnDA,QAAQ;MACZ,OAAQ,GAAEX,gBAAK,CAACgB,IAAI,CAACC,IAAI,CAACH,UAAU,CAAE,KAAIF,KAAM,IAAG;IACrD,CAAC,CAAC,CACDC,IAAI,CAAC,IAAI,CAAC;IACb,OAAOd,KAAK,GAAGQ,MAAM;EACvB;AACF;AAAC"}
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@teambit/generator",
3
- "version": "0.0.918",
3
+ "version": "0.0.920",
4
4
  "homepage": "https://bit.dev/teambit/generator/generator",
5
5
  "main": "dist/index.js",
6
6
  "componentId": {
7
7
  "scope": "teambit.generator",
8
8
  "name": "generator",
9
- "version": "0.0.918"
9
+ "version": "0.0.920"
10
10
  },
11
11
  "dependencies": {
12
12
  "camelcase": "6.2.0",
@@ -22,21 +22,21 @@
22
22
  "@teambit/harmony": "0.3.3",
23
23
  "@teambit/bit-error": "0.0.402",
24
24
  "@teambit/component-id": "0.0.425",
25
- "@teambit/envs": "0.0.918",
26
- "@teambit/new-component-helper": "0.0.322",
27
- "@teambit/workspace": "0.0.918",
28
- "@teambit/cli": "0.0.614",
29
- "@teambit/graphql": "0.0.918",
30
- "@teambit/aspect-loader": "0.0.918",
31
- "@teambit/bit": "0.0.920",
32
- "@teambit/community": "0.0.162",
33
- "@teambit/component": "0.0.918",
34
- "@teambit/importer": "0.0.347",
35
- "@teambit/compiler": "0.0.918",
36
- "@teambit/forking": "0.0.322",
37
- "@teambit/install": "0.0.60",
38
- "@teambit/logger": "0.0.707",
39
- "@teambit/ui": "0.0.918"
25
+ "@teambit/envs": "0.0.920",
26
+ "@teambit/new-component-helper": "0.0.324",
27
+ "@teambit/workspace": "0.0.920",
28
+ "@teambit/cli": "0.0.616",
29
+ "@teambit/graphql": "0.0.920",
30
+ "@teambit/aspect-loader": "0.0.920",
31
+ "@teambit/bit": "0.0.922",
32
+ "@teambit/community": "0.0.164",
33
+ "@teambit/component": "0.0.920",
34
+ "@teambit/importer": "0.0.349",
35
+ "@teambit/compiler": "0.0.920",
36
+ "@teambit/forking": "0.0.324",
37
+ "@teambit/install": "0.0.62",
38
+ "@teambit/logger": "0.0.709",
39
+ "@teambit/ui": "0.0.920"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@types/fs-extra": "9.0.7",
@@ -47,10 +47,10 @@
47
47
  "@types/jest": "^26.0.0",
48
48
  "@types/react-dom": "^17.0.5",
49
49
  "@types/node": "12.20.4",
50
- "@teambit/generator.aspect-docs.generator": "0.0.152"
50
+ "@teambit/generator.aspect-docs.generator": "0.0.153"
51
51
  },
52
52
  "peerDependencies": {
53
- "@teambit/legacy": "1.0.395",
53
+ "@teambit/legacy": "1.0.397",
54
54
  "react-dom": "^16.8.0 || ^17.0.0",
55
55
  "react": "^16.8.0 || ^17.0.0"
56
56
  },