@teambit/generator 0.0.946 → 0.0.947

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.
@@ -10,6 +10,7 @@ export declare type GenerateResult = {
10
10
  files: string[];
11
11
  envId: string;
12
12
  envSetBy: string;
13
+ packageName: string;
13
14
  };
14
15
  export declare class ComponentGenerator {
15
16
  private workspace;
@@ -63,6 +63,13 @@ function _sources() {
63
63
  };
64
64
  return data;
65
65
  }
66
+ function _componentIdToPackageName() {
67
+ const data = _interopRequireDefault(require("@teambit/legacy/dist/utils/bit/component-id-to-package-name"));
68
+ _componentIdToPackageName = function () {
69
+ return data;
70
+ };
71
+ return data;
72
+ }
66
73
  function _dataToPersist() {
67
74
  const data = _interopRequireDefault(require("@teambit/legacy/dist/consumer/component/sources/data-to-persist"));
68
75
  _dataToPersist = function () {
@@ -195,6 +202,7 @@ class ComponentGenerator {
195
202
  id: componentId,
196
203
  dir: componentPath,
197
204
  files: addResults.files,
205
+ packageName: (0, _componentIdToPackageName().default)(component.state._consumer),
198
206
  envId,
199
207
  envSetBy: setBy
200
208
  };
@@ -1 +1 @@
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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AAI,CAAC,CAAC;IACnDR,MAAM,CAACO,eAAU,CAACC,EAAE,CAAC,CAACJ,GAAG,GAAGkB,SAAS,CAACjB,sBAAsB,EAAE;IAC9D,OAAOL,MAAM;EACf;;EAEA;AACF;AACA;EACE,MAAcf,mBAAmB,CAC/BlC,aAAqB,EACrB2E,aAA8B,EACE;IAChC,MAAMC,aAAa,GAAG,KAAIC,wBAAa,GAAE;IACzC,MAAMC,UAAU,GAAGH,aAAa,CAACzD,GAAG,CAAE6D,YAAY,IAAK;MACrD,MAAMC,iBAAiB,GAAG,KAAIC,gBAAK,EAAC;QAClCC,IAAI,EAAElF,aAAa;QACnBE,IAAI,EAAEA,eAAI,CAACG,IAAI,CAACL,aAAa,EAAE+E,YAAY,CAACzC,YAAY,CAAC;QACzD6C,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,CAAC5D,GAAG,CAAEwE,CAAC,IAAKA,CAAC,CAACxF,IAAI,CAAC;IAC7C0E,aAAa,CAACe,YAAY,CAACb,UAAU,CAAC;IACtCF,aAAa,CAACgB,WAAW,CAAC,IAAI,CAACzG,SAAS,CAACe,IAAI,CAAC;IAC9C,MAAM0E,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","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 { 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 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 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;AAEA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAeO,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;EAE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ACb,UAAU,CAAC;IACtCF,aAAa,CAACgB,WAAW,CAAC,IAAI,CAAC7G,SAAS,CAACe,IAAI,CAAC;IAC9C,MAAM8E,aAAa,CAACiB,cAAc,EAAE;IACpC,OAAOJ,OAAO;EAChB;AACF;AAAC"}
@@ -60,6 +60,7 @@ class CreateCmd {
60
60
  return `${_chalk().default.bold(result.id.toString())}
61
61
  location: ${result.dir}
62
62
  env: ${result.envId} (set by ${result.envSetBy})
63
+ package: ${result.packageName}
63
64
  `;
64
65
  }).join('\n');
65
66
  const footer = `env configuration is according to workspace variants, template config or --env flag. learn more at https://${this.docsDomain}/envs/using-envs`;
@@ -1 +1 @@
1
- {"version":3,"names":["CreateCmd","constructor","generator","docsDomain","name","description","cmd","report","templateName","componentNames","options","results","generateComponentTemplate","title","length","componentsData","map","result","chalk","bold","id","toString","dir","envId","envSetBy","join","footer","green"],"sources":["create.cmd.ts"],"sourcesContent":["import { Command, CommandOptions } from '@teambit/cli';\nimport chalk from 'chalk';\nimport { GeneratorMain } from './generator.main.runtime';\n\nexport type CreateOptions = {\n namespace?: string;\n aspect?: string;\n scope?: string;\n path?: string;\n env?: string;\n};\n\nexport class CreateCmd implements Command {\n name = 'create <template-name> <component-names...>';\n description = 'create a new component (source files and config) using a template.';\n alias = '';\n loader = true;\n helpUrl = 'reference/starters/create-starter';\n arguments = [\n {\n name: 'template-name',\n description:\n \"the template for generating the component \\n(run 'bit templates' for a list of available templates)\",\n },\n {\n name: 'component-names...',\n description: 'a list of component names to generate',\n },\n ];\n examples = [\n {\n cmd: 'bit create react ui/button',\n description: \"creates a component named 'ui/button' using the 'react' template\",\n },\n {\n cmd: 'bit create react ui/button pages/register',\n description: \"creates two components, 'ui/button' and 'pages/register', using the 'react' template\",\n },\n {\n cmd: 'bit create react ui/button --scope my-org.my-scope',\n description:\n \"creates a component named 'ui/button' and sets it scope to 'my-org.my-scope'. \\nby default, the scope is the `defaultScope` value, configured in your `workspace.jsonc`.\",\n },\n {\n cmd: 'bit create react ui/button --env teambit.community/envs/community-react@1.95.13',\n description:\n \"creates a component named 'ui/button' and sets it to use the 'community-react' env. \\n(the template's default env is 'teambit.react/react').\",\n },\n ];\n group = 'development';\n options = [\n ['n', 'namespace <string>', `sets the component's namespace and nested dirs inside the scope`],\n ['s', 'scope <string>', `sets the component's scope-name. if not entered, the default-scope will be used`],\n ['a', 'aspect <string>', 'aspect-id of the template. helpful when multiple aspects use the same template name'],\n ['p', 'path <string>', 'relative path in the workspace. by default the path is `<scope>/<namespace>/<name>`'],\n ['e', 'env <string>', \"set the component's environment. (overrides the env from variants and the template)\"],\n ] as CommandOptions;\n\n constructor(private generator: GeneratorMain, private docsDomain: string) {}\n\n async report([templateName, componentNames]: [string, string[]], options: CreateOptions) {\n const results = await this.generator.generateComponentTemplate(componentNames, templateName, options);\n const title = `${results.length} component(s) were created`;\n\n const componentsData = results\n .map((result) => {\n return `${chalk.bold(result.id.toString())}\n location: ${result.dir}\n env: ${result.envId} (set by ${result.envSetBy})\n`;\n })\n .join('\\n');\n const footer = `env configuration is according to workspace variants, template config or --env flag. learn more at https://${this.docsDomain}/envs/using-envs`;\n\n return `${chalk.green(title)}\\n\\n${componentsData}\\n\\n${footer}`;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAWO,MAAMA,SAAS,CAAoB;EA8CxCC,WAAW,CAASC,SAAwB,EAAUC,UAAkB,EAAE;IAAA,KAAtDD,SAAwB,GAAxBA,SAAwB;IAAA,KAAUC,UAAkB,GAAlBA,UAAkB;IAAA,8CA7CjE,6CAA6C;IAAA,qDACtC,oEAAoE;IAAA,+CAC1E,EAAE;IAAA,gDACD,IAAI;IAAA,iDACH,mCAAmC;IAAA,mDACjC,CACV;MACEC,IAAI,EAAE,eAAe;MACrBC,WAAW,EACT;IACJ,CAAC,EACD;MACED,IAAI,EAAE,oBAAoB;MAC1BC,WAAW,EAAE;IACf,CAAC,CACF;IAAA,kDACU,CACT;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,cAAe,OAAMW,MAAO,EAAC;EAClE;AACF;AAAC"}
1
+ {"version":3,"names":["CreateCmd","constructor","generator","docsDomain","name","description","cmd","report","templateName","componentNames","options","results","generateComponentTemplate","title","length","componentsData","map","result","chalk","bold","id","toString","dir","envId","envSetBy","packageName","join","footer","green"],"sources":["create.cmd.ts"],"sourcesContent":["import { Command, CommandOptions } from '@teambit/cli';\nimport chalk from 'chalk';\nimport { GeneratorMain } from './generator.main.runtime';\n\nexport type CreateOptions = {\n namespace?: string;\n aspect?: string;\n scope?: string;\n path?: string;\n env?: string;\n};\n\nexport class CreateCmd implements Command {\n name = 'create <template-name> <component-names...>';\n description = 'create a new component (source files and config) using a template.';\n alias = '';\n loader = true;\n helpUrl = 'reference/starters/create-starter';\n arguments = [\n {\n name: 'template-name',\n description:\n \"the template for generating the component \\n(run 'bit templates' for a list of available templates)\",\n },\n {\n name: 'component-names...',\n description: 'a list of component names to generate',\n },\n ];\n examples = [\n {\n cmd: 'bit create react ui/button',\n description: \"creates a component named 'ui/button' using the 'react' template\",\n },\n {\n cmd: 'bit create react ui/button pages/register',\n description: \"creates two components, 'ui/button' and 'pages/register', using the 'react' template\",\n },\n {\n cmd: 'bit create react ui/button --scope my-org.my-scope',\n description:\n \"creates a component named 'ui/button' and sets it scope to 'my-org.my-scope'. \\nby default, the scope is the `defaultScope` value, configured in your `workspace.jsonc`.\",\n },\n {\n cmd: 'bit create react ui/button --env teambit.community/envs/community-react@1.95.13',\n description:\n \"creates a component named 'ui/button' and sets it to use the 'community-react' env. \\n(the template's default env is 'teambit.react/react').\",\n },\n ];\n group = 'development';\n options = [\n ['n', 'namespace <string>', `sets the component's namespace and nested dirs inside the scope`],\n ['s', 'scope <string>', `sets the component's scope-name. if not entered, the default-scope will be used`],\n ['a', 'aspect <string>', 'aspect-id of the template. helpful when multiple aspects use the same template name'],\n ['p', 'path <string>', 'relative path in the workspace. by default the path is `<scope>/<namespace>/<name>`'],\n ['e', 'env <string>', \"set the component's environment. (overrides the env from variants and the template)\"],\n ] as CommandOptions;\n\n constructor(private generator: GeneratorMain, private docsDomain: string) {}\n\n async report([templateName, componentNames]: [string, string[]], options: CreateOptions) {\n const results = await this.generator.generateComponentTemplate(componentNames, templateName, options);\n const title = `${results.length} component(s) were created`;\n\n const componentsData = results\n .map((result) => {\n return `${chalk.bold(result.id.toString())}\n location: ${result.dir}\n env: ${result.envId} (set by ${result.envSetBy})\n package: ${result.packageName}\n`;\n })\n .join('\\n');\n const footer = `env configuration is according to workspace variants, template config or --env flag. learn more at https://${this.docsDomain}/envs/using-envs`;\n\n return `${chalk.green(title)}\\n\\n${componentsData}\\n\\n${footer}`;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAWO,MAAMA,SAAS,CAAoB;EA8CxCC,WAAW,CAASC,SAAwB,EAAUC,UAAkB,EAAE;IAAA,KAAtDD,SAAwB,GAAxBA,SAAwB;IAAA,KAAUC,UAAkB,GAAlBA,UAAkB;IAAA,8CA7CjE,6CAA6C;IAAA,qDACtC,oEAAoE;IAAA,+CAC1E,EAAE;IAAA,gDACD,IAAI;IAAA,iDACH,mCAAmC;IAAA,mDACjC,CACV;MACEC,IAAI,EAAE,eAAe;MACrBC,WAAW,EACT;IACJ,CAAC,EACD;MACED,IAAI,EAAE,oBAAoB;MAC1BC,WAAW,EAAE;IACf,CAAC,CACF;IAAA,kDACU,CACT;MACEC,GAAG,EAAE,4BAA4B;MACjCD,WAAW,EAAE;IACf,CAAC,EACD;MACEC,GAAG,EAAE,2CAA2C;MAChDD,WAAW,EAAE;IACf,CAAC,EACD;MACEC,GAAG,EAAE,oDAAoD;MACzDD,WAAW,EACT;IACJ,CAAC,EACD;MACEC,GAAG,EAAE,iFAAiF;MACtFD,WAAW,EACT;IACJ,CAAC,CACF;IAAA,+CACO,aAAa;IAAA,iDACX,CACR,CAAC,GAAG,EAAE,oBAAoB,EAAG,iEAAgE,CAAC,EAC9F,CAAC,GAAG,EAAE,gBAAgB,EAAG,iFAAgF,CAAC,EAC1G,CAAC,GAAG,EAAE,iBAAiB,EAAE,qFAAqF,CAAC,EAC/G,CAAC,GAAG,EAAE,eAAe,EAAE,qFAAqF,CAAC,EAC7G,CAAC,GAAG,EAAE,cAAc,EAAE,qFAAqF,CAAC,CAC7G;EAE0E;EAE3E,MAAME,MAAM,CAAC,CAACC,YAAY,EAAEC,cAAc,CAAqB,EAAEC,OAAsB,EAAE;IACvF,MAAMC,OAAO,GAAG,MAAM,IAAI,CAACT,SAAS,CAACU,yBAAyB,CAACH,cAAc,EAAED,YAAY,EAAEE,OAAO,CAAC;IACrG,MAAMG,KAAK,GAAI,GAAEF,OAAO,CAACG,MAAO,4BAA2B;IAE3D,MAAMC,cAAc,GAAGJ,OAAO,CAC3BK,GAAG,CAAEC,MAAM,IAAK;MACf,OAAQ,GAAEC,gBAAK,CAACC,IAAI,CAACF,MAAM,CAACG,EAAE,CAACC,QAAQ,EAAE,CAAE;AACnD,gBAAgBJ,MAAM,CAACK,GAAI;AAC3B,gBAAgBL,MAAM,CAACM,KAAM,YAAWN,MAAM,CAACO,QAAS;AACxD,gBAAgBP,MAAM,CAACQ,WAAY;AACnC,CAAC;IACK,CAAC,CAAC,CACDC,IAAI,CAAC,IAAI,CAAC;IACb,MAAMC,MAAM,GAAI,8GAA6G,IAAI,CAACxB,UAAW,kBAAiB;IAE9J,OAAQ,GAAEe,gBAAK,CAACU,KAAK,CAACf,KAAK,CAAE,OAAME,cAAe,OAAMY,MAAO,EAAC;EAClE;AACF;AAAC"}
@@ -1,5 +1,5 @@
1
- import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.generator_generator@0.0.946/dist/generator.composition.js';
2
- import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.generator_generator@0.0.946/dist/generator.docs.mdx';
1
+ import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.generator_generator@0.0.947/dist/generator.composition.js';
2
+ import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.generator_generator@0.0.947/dist/generator.docs.mdx';
3
3
 
4
4
  export const compositions = [compositions_0];
5
5
  export const overview = [overview_0];
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@teambit/generator",
3
- "version": "0.0.946",
3
+ "version": "0.0.947",
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.946"
9
+ "version": "0.0.947"
10
10
  },
11
11
  "dependencies": {
12
12
  "camelcase": "6.2.0",
@@ -22,21 +22,21 @@
22
22
  "@teambit/harmony": "0.4.6",
23
23
  "@teambit/bit-error": "0.0.402",
24
24
  "@teambit/component-id": "0.0.425",
25
- "@teambit/envs": "0.0.946",
26
- "@teambit/new-component-helper": "0.0.350",
27
- "@teambit/workspace": "0.0.946",
28
- "@teambit/cli": "0.0.633",
29
- "@teambit/graphql": "0.0.946",
30
- "@teambit/aspect-loader": "0.0.946",
31
- "@teambit/bit": "0.0.948",
32
- "@teambit/community": "0.0.181",
33
- "@teambit/component": "0.0.946",
34
- "@teambit/importer": "0.0.375",
35
- "@teambit/compiler": "0.0.946",
36
- "@teambit/forking": "0.0.350",
37
- "@teambit/install": "0.0.81",
38
- "@teambit/logger": "0.0.726",
39
- "@teambit/ui": "0.0.946"
25
+ "@teambit/envs": "0.0.947",
26
+ "@teambit/new-component-helper": "0.0.351",
27
+ "@teambit/workspace": "0.0.947",
28
+ "@teambit/cli": "0.0.634",
29
+ "@teambit/graphql": "0.0.947",
30
+ "@teambit/aspect-loader": "0.0.947",
31
+ "@teambit/bit": "0.0.949",
32
+ "@teambit/community": "0.0.182",
33
+ "@teambit/component": "0.0.947",
34
+ "@teambit/importer": "0.0.376",
35
+ "@teambit/compiler": "0.0.947",
36
+ "@teambit/forking": "0.0.351",
37
+ "@teambit/install": "0.0.82",
38
+ "@teambit/logger": "0.0.727",
39
+ "@teambit/ui": "0.0.947"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@types/fs-extra": "9.0.7",
@@ -50,7 +50,7 @@
50
50
  "@teambit/generator.aspect-docs.generator": "0.0.154"
51
51
  },
52
52
  "peerDependencies": {
53
- "@teambit/legacy": "1.0.414",
53
+ "@teambit/legacy": "1.0.415",
54
54
  "react": "^16.8.0 || ^17.0.0",
55
55
  "react-dom": "^16.8.0 || ^17.0.0"
56
56
  },