@teambit/generator 0.0.988 → 0.0.990

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.
@@ -154,7 +154,6 @@ class ComponentGenerator {
154
154
  componentName: componentId.fullName,
155
155
  defaultScope: this.options.scope
156
156
  });
157
- await this.workspace.triggerOnMultipleComponentsAdd();
158
157
  const component = await this.workspace.get(componentId);
159
158
  const hasEnvConfiguredOriginally = this.envs.hasEnvConfigured(component);
160
159
  const envBeforeConfigChanges = this.envs.getEnv(component);
@@ -1 +1 @@
1
- {"version":3,"names":["ComponentGenerator","constructor","workspace","componentIds","options","template","envs","newComponentHelper","tracker","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","ComponentID","fromString","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","packageName","componentIdToPackageName","state","_consumer","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 { TrackerMain } from '@teambit/tracker';\nimport { PathOsBasedRelative } from '@teambit/legacy/dist/utils/path';\nimport { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';\nimport componentIdToPackageName from '@teambit/legacy/dist/utils/bit/component-id-to-package-name';\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 = {\n id: ComponentID;\n dir: string;\n files: string[];\n envId: string;\n envSetBy: string;\n packageName: string;\n};\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 tracker: TrackerMain,\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 aspectId = ComponentID.fromString(this.aspectId);\n\n const files = this.template.generateFiles({\n name,\n namePascalCase,\n nameCamelCase,\n componentId,\n aspectId,\n envId: this.envId,\n });\n const mainFile = files.find((file) => file.isMain);\n await this.writeComponentFiles(componentPath, files);\n const addResults = await this.tracker.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 packageName: componentIdToPackageName(component.state._consumer),\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;EA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AkB,CAACF,OAAO,CAAC;IAClE,MAAMG,6BAA6B,GAAG,MAAM,IAAI,CAAC7F,SAAS,CAAC8F,yCAAyC,CAACH,SAAS,CAAC;IAC/G1B,MAAM,CAAC4B,6BAA6B,CAAC,GAAG,CAAC,CAAC;IAC1C5B,MAAM,CAACO,eAAU,CAACC,EAAE,CAAC,GAAGR,MAAM,CAACO,eAAU,CAACC,EAAE,CAAC,IAAI,CAAC,CAAC;IACnDR,MAAM,CAACO,eAAU,CAACC,EAAE,CAAC,CAACJ,GAAG,GAAGsB,SAAS,CAACrB,sBAAsB,EAAE;IAC9D,OAAOL,MAAM;EACf;;EAEA;AACF;AACA;EACE,MAAcf,mBAAmB,CAC/BpC,aAAqB,EACrBiF,aAA8B,EACE;IAChC,MAAMC,aAAa,GAAG,KAAIC,wBAAa,GAAE;IACzC,MAAMC,UAAU,GAAGH,aAAa,CAAC/D,GAAG,CAAEmE,YAAY,IAAK;MACrD,MAAMC,iBAAiB,GAAG,KAAIC,gBAAK,EAAC;QAClCC,IAAI,EAAExF,aAAa;QACnBE,IAAI,EAAEA,eAAI,CAACG,IAAI,CAACL,aAAa,EAAEqF,YAAY,CAAC7C,YAAY,CAAC;QACzDiD,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,CAAClE,GAAG,CAAE8E,CAAC,IAAKA,CAAC,CAAC9F,IAAI,CAAC;IAC7CgF,aAAa,CAACe,YAAY,CAACb,UAAU,CAAC;IACtCF,aAAa,CAACgB,WAAW,CAAC,IAAI,CAAChH,SAAS,CAACgB,IAAI,CAAC;IAC9C,MAAMgF,aAAa,CAACiB,cAAc,EAAE;IACpC,OAAOJ,OAAO;EAChB;AACF;AAAC"}
1
+ {"version":3,"names":["ComponentGenerator","constructor","workspace","componentIds","options","template","envs","newComponentHelper","tracker","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","ComponentID","fromString","files","generateFiles","mainFile","find","file","isMain","writeComponentFiles","addResults","track","rootDir","relativePath","componentName","defaultScope","scope","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","packageName","componentIdToPackageName","state","_consumer","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 { TrackerMain } from '@teambit/tracker';\nimport { PathOsBasedRelative } from '@teambit/legacy/dist/utils/path';\nimport { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';\nimport componentIdToPackageName from '@teambit/legacy/dist/utils/bit/component-id-to-package-name';\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 = {\n id: ComponentID;\n dir: string;\n files: string[];\n envId: string;\n envSetBy: string;\n packageName: string;\n};\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 tracker: TrackerMain,\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 aspectId = ComponentID.fromString(this.aspectId);\n\n const files = this.template.generateFiles({\n name,\n namePascalCase,\n nameCamelCase,\n componentId,\n aspectId,\n envId: this.envId,\n });\n const mainFile = files.find((file) => file.isMain);\n await this.writeComponentFiles(componentPath, files);\n const addResults = await this.tracker.track({\n rootDir: componentPath,\n mainFile: mainFile?.relativePath,\n componentName: componentId.fullName,\n defaultScope: this.options.scope,\n });\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 packageName: componentIdToPackageName(component.state._consumer),\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;AAGA;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;AAaO,MAAMA,kBAAkB,CAAC;EAC9BC,WAAW,CACDC,SAAoB,EACpBC,YAA2B,EAC3BC,OAAsB,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wBAAa,GAAE;IACzC,MAAMC,UAAU,GAAGH,aAAa,CAAC9D,GAAG,CAAEkE,YAAY,IAAK;MACrD,MAAMC,iBAAiB,GAAG,KAAIC,gBAAK,EAAC;QAClCC,IAAI,EAAEvF,aAAa;QACnBE,IAAI,EAAEA,eAAI,CAACG,IAAI,CAACL,aAAa,EAAEoF,YAAY,CAAC5C,YAAY,CAAC;QACzDgD,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,CAACjE,GAAG,CAAE6E,CAAC,IAAKA,CAAC,CAAC7F,IAAI,CAAC;IAC7C+E,aAAa,CAACe,YAAY,CAACb,UAAU,CAAC;IACtCF,aAAa,CAACgB,WAAW,CAAC,IAAI,CAAC/G,SAAS,CAACgB,IAAI,CAAC;IAC9C,MAAM+E,aAAa,CAACiB,cAAc,EAAE;IACpC,OAAOJ,OAAO;EAChB;AACF;AAAC"}
@@ -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 /**\n * aspect id of the aspect that register the template itself\n */\n aspectId: ComponentID,\n\n /**\n * env id of the env that register the template itself\n * This will be usually identical to the aspectId\n * but aspectId will be exist always, while envId will be undefined if the template is not registered by an env\n * so in case you want to use the envId, you should check if it exists first\n * You can use this in case you want to only do something if the template was registered by an env\n */\n envId?: 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":""}
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 /**\n * aspect id of the aspect that register the template itself\n */\n aspectId: ComponentID;\n\n /**\n * env id of the env that register the template itself\n * This will be usually identical to the aspectId\n * but aspectId will be exist always, while envId will be undefined if the template is not registered by an env\n * so in case you want to use the envId, you should check if it exists first\n * You can use this in case you want to only do something if the template was registered by an env\n */\n envId?: 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":""}
@@ -1,6 +1,6 @@
1
- import { EnvHandler } from "@teambit/envs";
2
- import { TemplateList } from "./template-list";
3
- import { StarterList } from "./starter-list";
1
+ import { EnvHandler } from '@teambit/envs';
2
+ import { TemplateList } from './template-list';
3
+ import { StarterList } from './starter-list';
4
4
  export interface GeneratorEnv {
5
5
  /**
6
6
  * return a template list instance.
@@ -1 +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
+ {"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 +1 @@
1
- {"version":3,"names":["GeneratorService","transform","env","context","generators","undefined","getGeneratorTemplates","generatorList","compute","getGeneratorStarters","starters","starterList"],"sources":["generator.service.tsx"],"sourcesContent":["import { EnvService, Env, EnvContext, ServiceTransformationMap } from '@teambit/envs';\nimport { ComponentTemplate } from './component-template';\nimport { WorkspaceTemplate } from './workspace-template';\n\ntype GeneratorTransformationMap = ServiceTransformationMap & {\n getGeneratorTemplates: () => ComponentTemplate;\n getGeneratorStarters: () => WorkspaceTemplate;\n}\nexport class GeneratorService implements EnvService<any> {\n name = 'generator';\n\n transform(env: Env, context: EnvContext): GeneratorTransformationMap | undefined {\n // Old env\n if (!env?.generators) return undefined;\n return {\n getGeneratorTemplates: () => {\n if (!env.generators) return undefined;\n const generatorList = env.generators()(context);\n return generatorList.compute();\n },\n getGeneratorStarters: () => {\n if (!env.starters) return undefined;\n const starterList = env.starters()(context);\n return starterList.compute();\n },\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAQO,MAAMA,gBAAgB,CAA4B;EAAA;IAAA,8CAChD,WAAW;EAAA;EAElBC,SAAS,CAACC,GAAQ,EAAEC,OAAmB,EAA0C;IAC/E;IACA,IAAI,EAACD,GAAG,aAAHA,GAAG,eAAHA,GAAG,CAAEE,UAAU,GAAE,OAAOC,SAAS;IACtC,OAAO;MACLC,qBAAqB,EAAE,MAAM;QAC3B,IAAI,CAACJ,GAAG,CAACE,UAAU,EAAE,OAAOC,SAAS;QACrC,MAAME,aAAa,GAAGL,GAAG,CAACE,UAAU,EAAE,CAACD,OAAO,CAAC;QAC/C,OAAOI,aAAa,CAACC,OAAO,EAAE;MAChC,CAAC;MACDC,oBAAoB,EAAE,MAAM;QAC1B,IAAI,CAACP,GAAG,CAACQ,QAAQ,EAAE,OAAOL,SAAS;QACnC,MAAMM,WAAW,GAAGT,GAAG,CAACQ,QAAQ,EAAE,CAACP,OAAO,CAAC;QAC3C,OAAOQ,WAAW,CAACH,OAAO,EAAE;MAC9B;IACF,CAAC;EACH;AACF;AAAC"}
1
+ {"version":3,"names":["GeneratorService","transform","env","context","generators","undefined","getGeneratorTemplates","generatorList","compute","getGeneratorStarters","starters","starterList"],"sources":["generator.service.tsx"],"sourcesContent":["import { EnvService, Env, EnvContext, ServiceTransformationMap } from '@teambit/envs';\nimport { ComponentTemplate } from './component-template';\nimport { WorkspaceTemplate } from './workspace-template';\n\ntype GeneratorTransformationMap = ServiceTransformationMap & {\n getGeneratorTemplates: () => ComponentTemplate;\n getGeneratorStarters: () => WorkspaceTemplate;\n};\nexport class GeneratorService implements EnvService<any> {\n name = 'generator';\n\n transform(env: Env, context: EnvContext): GeneratorTransformationMap | undefined {\n // Old env\n if (!env?.generators) return undefined;\n return {\n getGeneratorTemplates: () => {\n if (!env.generators) return undefined;\n const generatorList = env.generators()(context);\n return generatorList.compute();\n },\n getGeneratorStarters: () => {\n if (!env.starters) return undefined;\n const starterList = env.starters()(context);\n return starterList.compute();\n },\n };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAQO,MAAMA,gBAAgB,CAA4B;EAAA;IAAA,8CAChD,WAAW;EAAA;EAElBC,SAAS,CAACC,GAAQ,EAAEC,OAAmB,EAA0C;IAC/E;IACA,IAAI,EAACD,GAAG,aAAHA,GAAG,eAAHA,GAAG,CAAEE,UAAU,GAAE,OAAOC,SAAS;IACtC,OAAO;MACLC,qBAAqB,EAAE,MAAM;QAC3B,IAAI,CAACJ,GAAG,CAACE,UAAU,EAAE,OAAOC,SAAS;QACrC,MAAME,aAAa,GAAGL,GAAG,CAACE,UAAU,EAAE,CAACD,OAAO,CAAC;QAC/C,OAAOI,aAAa,CAACC,OAAO,EAAE;MAChC,CAAC;MACDC,oBAAoB,EAAE,MAAM;QAC1B,IAAI,CAACP,GAAG,CAACQ,QAAQ,EAAE,OAAOL,SAAS;QACnC,MAAMM,WAAW,GAAGT,GAAG,CAACQ,QAAQ,EAAE,CAACP,OAAO,CAAC;QAC3C,OAAOQ,WAAW,CAACH,OAAO,EAAE;MAC9B;IACF,CAAC;EACH;AACF;AAAC"}
@@ -1,5 +1,5 @@
1
- import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.generator_generator@0.0.988/dist/generator.composition.js';
2
- import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.generator_generator@0.0.988/dist/generator.docs.mdx';
1
+ import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.generator_generator@0.0.990/dist/generator.composition.js';
2
+ import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.generator_generator@0.0.990/dist/generator.docs.mdx';
3
3
 
4
4
  export const compositions = [compositions_0];
5
5
  export const overview = [overview_0];
@@ -1,5 +1,5 @@
1
- import { EnvContext, EnvHandler } from "@teambit/envs";
2
- import { WorkspaceTemplate } from "./workspace-template";
1
+ import { EnvContext, EnvHandler } from '@teambit/envs';
2
+ import { WorkspaceTemplate } from './workspace-template';
3
3
  export declare type StarterListOptions = {
4
4
  name?: string;
5
5
  };
@@ -1 +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"}
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(readonly name: string, private starters: EnvHandler<WorkspaceTemplate>[], private context: EnvContext) {}\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,CAAUC,IAAY,EAAUC,QAAyC,EAAUC,OAAmB,EAAE;IAAA,KAA9FF,IAAY,GAAZA,IAAY;IAAA,KAAUC,QAAyC,GAAzCA,QAAyC;IAAA,KAAUC,OAAmB,GAAnBA,OAAmB;EAAG;EAEpHC,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"}
@@ -1,5 +1,5 @@
1
- import { EnvContext, EnvHandler } from "@teambit/envs";
2
- import { ComponentTemplate } from "./component-template";
1
+ import { EnvContext, EnvHandler } from '@teambit/envs';
2
+ import { ComponentTemplate } from './component-template';
3
3
  export declare type TemplateListOptions = {
4
4
  name?: string;
5
5
  };
@@ -1 +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"}
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(readonly name: string, private templates: EnvHandler<ComponentTemplate>[], private context: EnvContext) {}\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,CAAUC,IAAY,EAAUC,SAA0C,EAAUC,OAAmB,EAAE;IAAA,KAA/FF,IAAY,GAAZA,IAAY;IAAA,KAAUC,SAA0C,GAA1CA,SAA0C;IAAA,KAAUC,OAAmB,GAAnBA,OAAmB;EAAG;EAErHC,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"}
@@ -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","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":";;;;;;;;;;;;;;;;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAQO,MAAMA,YAAY,CAAoB;EAiB3CC,WAAW,CAASC,SAAwB,EAAE;IAAA,KAA1BA,SAAwB,GAAxBA,SAAwB;IAAA,8CAhBrC,WAAW;IAAA,qDACJ,+CAA+C;IAAA,6DAE3D,yHAAyH;IAAA,+CACnH,EAAE;IAAA,gDACD,IAAI;IAAA,+CACL,aAAa;IAAA,iDACX,CACR,CAAC,GAAG,EAAE,UAAU,EAAE,uBAAuB,CAAC,EAC1C,CACE,GAAG,EACH,oBAAoB,EACpB,0CAA0C,CAC3C,CACF;EAE8C;;EAE/C;EACA,MAAMC,MAAM,CAACC,IAAQ,EAAEC,gBAAkC,EAAE;IACzD,IAAIC,OAAO,GAAG,MAAM,IAAI,CAACJ,SAAS,CAACK,aAAa,CAACF,gBAAgB,CAAC;;IAElE;IACA,IAAI,CAACA,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,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"}
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 ['a', 'aspect <aspect-id>', 'show templates provided by the aspect-id'],\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":";;;;;;;;;;;;;;;;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAA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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"}
@@ -2,10 +2,10 @@ import { EnvService, Env, EnvContext, ServiceTransformationMap } from '@teambit/
2
2
  import { ComponentTemplate } from './component-template';
3
3
  import { WorkspaceTemplate } from './workspace-template';
4
4
 
5
- type GeneratorTransformationMap = ServiceTransformationMap & {
5
+ type GeneratorTransformationMap = ServiceTransformationMap & {
6
6
  getGeneratorTemplates: () => ComponentTemplate;
7
7
  getGeneratorStarters: () => WorkspaceTemplate;
8
- }
8
+ };
9
9
  export class GeneratorService implements EnvService<any> {
10
10
  name = 'generator';
11
11
 
@@ -23,6 +23,6 @@ export class GeneratorService implements EnvService<any> {
23
23
  const starterList = env.starters()(context);
24
24
  return starterList.compute();
25
25
  },
26
- }
26
+ };
27
27
  }
28
28
  }
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@teambit/generator",
3
- "version": "0.0.988",
3
+ "version": "0.0.990",
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.988"
9
+ "version": "0.0.990"
10
10
  },
11
11
  "dependencies": {
12
12
  "camelcase": "6.2.0",
@@ -21,23 +21,23 @@
21
21
  "@babel/runtime": "7.20.0",
22
22
  "@teambit/harmony": "0.4.6",
23
23
  "@teambit/bit-error": "0.0.402",
24
- "@teambit/component-id": "0.0.426",
25
- "@teambit/envs": "0.0.988",
26
- "@teambit/new-component-helper": "0.0.392",
27
- "@teambit/tracker": "0.0.19",
28
- "@teambit/workspace": "0.0.988",
29
- "@teambit/cli": "0.0.663",
30
- "@teambit/graphql": "0.0.988",
31
- "@teambit/aspect-loader": "0.0.988",
32
- "@teambit/bit": "0.0.990",
33
- "@teambit/community": "0.0.211",
34
- "@teambit/component": "0.0.988",
35
- "@teambit/compiler": "0.0.988",
36
- "@teambit/forking": "0.0.392",
37
- "@teambit/importer": "0.0.417",
38
- "@teambit/install": "0.0.111",
39
- "@teambit/logger": "0.0.756",
40
- "@teambit/ui": "0.0.988"
24
+ "@teambit/component-id": "0.0.427",
25
+ "@teambit/envs": "0.0.990",
26
+ "@teambit/new-component-helper": "0.0.394",
27
+ "@teambit/tracker": "0.0.21",
28
+ "@teambit/workspace": "0.0.990",
29
+ "@teambit/cli": "0.0.664",
30
+ "@teambit/graphql": "0.0.990",
31
+ "@teambit/aspect-loader": "0.0.990",
32
+ "@teambit/bit": "0.0.992",
33
+ "@teambit/community": "0.0.212",
34
+ "@teambit/component": "0.0.990",
35
+ "@teambit/compiler": "0.0.990",
36
+ "@teambit/forking": "0.0.394",
37
+ "@teambit/importer": "0.0.419",
38
+ "@teambit/install": "0.0.113",
39
+ "@teambit/logger": "0.0.757",
40
+ "@teambit/ui": "0.0.990"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@types/fs-extra": "9.0.7",
@@ -51,7 +51,7 @@
51
51
  "@teambit/generator.aspect-docs.generator": "0.0.155"
52
52
  },
53
53
  "peerDependencies": {
54
- "@teambit/legacy": "1.0.444",
54
+ "@teambit/legacy": "1.0.445",
55
55
  "react": "^16.8.0 || ^17.0.0",
56
56
  "react-dom": "^16.8.0 || ^17.0.0"
57
57
  },