@teambit/generator 1.0.649 → 1.0.651

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"names":["_fsExtra","data","_interopRequireDefault","require","_enquirer","_pMapSeries","_path","_envs","_camelcase","_bitError","_workspaceModules","_pkgModules","_componentId","e","__esModule","default","ComponentGenerator","constructor","workspace","componentIds","options","template","envs","newComponentHelper","tracker","wsConfigFiles","logger","onComponentCreateSlot","aspectId","envId","installOptions","promptResults","generate","force","dirsToDeleteIfFailed","generateResults","pMapSeries","componentId","componentPath","getNewComponentPath","pathFromUser","path","componentsToCreate","length","fs","existsSync","join","BitError","push","generateOneComponent","err","deleteGeneratedComponents","bitMap","write","ids","map","r","id","tryLinkToNodeModules","runOnComponentCreateHook","tryWriteConfigFiles","linkToNodeModulesByIds","consoleFailure","message","fns","values","Promise","all","fn","shouldWrite","isWorkspaceConfigWriteEnabled","clearComponentCache","writeConfigFiles","clean","silent","dedupe","throw","dirs","dir","absoluteDir","remove","code","getOptionResultFromArgs","option","args","process","argv","slice","argIndex","indexOf","name","type","argValue","Error","choices","includes","getPromptOptionResult","prompt","getPromptResults","promptOptions","undefined","fromArg","skip","optionResult","namePascalCase","camelcase","pascalCase","nameCamelCase","ComponentID","fromString","files","generateFiles","mainFile","find","file","isMain","writeComponentFiles","f","relativePath","content","addResults","track","rootDir","componentName","fullName","defaultScope","scope","component","get","hasEnvConfiguredOriginally","hasEnvConfigured","envBeforeConfigChanges","getEnv","config","boundConfig","bind","userEnv","env","isInWorkspace","hasId","ignoreVersion","toStringWithoutVersion","toString","templateEnv","EnvsAspect","Object","keys","configWithEnv","addEnvIfProvidedByFlag","setEntireConfig","getEnvData","envFromFlag","envFromTemplate","setBy","isSameAsThisEnvId","packageName","componentIdToPackageName","state","_consumer","envSetBy","isApp","isEnv","dependencies","installMissingDependencies","addEnvToConfig","exports"],"sources":["component-generator.ts"],"sourcesContent":["import fs from 'fs-extra';\nimport { prompt } from 'enquirer';\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 { Logger } from '@teambit/logger';\nimport { TrackerMain } from '@teambit/tracker';\nimport { linkToNodeModulesByIds } from '@teambit/workspace.modules.node-modules-linker';\nimport { componentIdToPackageName } from '@teambit/pkg.modules.component-package-name';\nimport { NewComponentHelperMain } from '@teambit/new-component-helper';\nimport { ComponentID } from '@teambit/component-id';\nimport { WorkspaceConfigFilesMain } from '@teambit/workspace-config-files';\n\nimport { ComponentTemplate, ComponentConfig, PromptOption, PromptResults } from './component-template';\nimport { CreateOptions } from './create.cmd';\nimport { OnComponentCreateSlot } from './generator.main.runtime';\n\nexport type GenerateResult = {\n id: ComponentID;\n dir: string;\n files: string[];\n envId: string;\n envSetBy: string;\n packageName: string;\n isApp?: boolean;\n isEnv?: boolean;\n dependencies?: string[];\n installMissingDependencies?: boolean;\n};\n\nexport type InstallOptions = { optimizeReportForNonTerminal?: boolean };\n\nexport type OnComponentCreateFn = (generateResults: GenerateResult[], installOptions?: InstallOptions) => Promise<void>;\n\nexport class ComponentGenerator {\n constructor(\n private workspace: Workspace,\n private componentIds: ComponentID[],\n private options: Partial<CreateOptions>,\n private template: ComponentTemplate,\n private envs: EnvsMain,\n private newComponentHelper: NewComponentHelperMain,\n private tracker: TrackerMain,\n private wsConfigFiles: WorkspaceConfigFilesMain,\n private logger: Logger,\n private onComponentCreateSlot: OnComponentCreateSlot,\n private aspectId: string,\n private envId?: ComponentID,\n private installOptions: InstallOptions = {},\n private promptResults?: PromptResults,\n ) {}\n\n async generate(force = false): Promise<GenerateResult[]> {\n const dirsToDeleteIfFailed: string[] = [];\n const generateResults = await pMapSeries(this.componentIds, async (componentId) => {\n try {\n const componentPath = this.newComponentHelper.getNewComponentPath(componentId, {\n pathFromUser: this.options.path,\n componentsToCreate: this.componentIds.length,\n });\n if (!force && fs.existsSync(path.join(this.workspace.path, componentPath))) {\n throw new BitError(\n `unable to create a component at \"${componentPath}\", this path already exists, please use \"--path\" to create the component in a different path`\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(`create (${this.componentIds.length} components)`);\n\n const ids = generateResults.map((r) => r.id);\n await this.tryLinkToNodeModules(ids);\n await this.runOnComponentCreateHook(generateResults);\n // We are running this after the runOnComponentCreateHook as it require\n // the env to be installed to work properly, and the hook might install\n // the env.\n await this.tryWriteConfigFiles(ids);\n\n return generateResults;\n }\n\n private async tryLinkToNodeModules(ids: ComponentID[]) {\n try {\n await linkToNodeModulesByIds(\n this.workspace,\n ids.map((id) => id)\n );\n } catch (err: any) {\n this.logger.consoleFailure(\n `failed linking the new components to node_modules, please run \"bit link\" manually. error: ${err.message}`\n );\n }\n }\n\n private async runOnComponentCreateHook(generateResults: GenerateResult[]) {\n const fns = this.onComponentCreateSlot.values();\n if (!fns.length) return;\n await Promise.all(fns.map((fn) => fn(generateResults, this.installOptions)));\n }\n\n /**\n * The function `tryWriteConfigFiles` attempts to write workspace config files, and if it fails, it logs an error\n * message.\n * @returns If the condition `!shouldWrite` is true, then nothing is being returned. Otherwise, if the `writeConfigFiles`\n * function is successfully executed, nothing is being returned. If an error occurs during the execution of\n * `writeConfigFiles`, an error message is being returned.\n */\n private async tryWriteConfigFiles(ids: ComponentID[]) {\n const shouldWrite = this.wsConfigFiles.isWorkspaceConfigWriteEnabled();\n if (!shouldWrite) return;\n ids.map((id) => this.workspace.clearComponentCache(id));\n const { err } = await this.wsConfigFiles.writeConfigFiles({\n clean: true,\n silent: true,\n dedupe: true,\n throw: false,\n });\n if (err) {\n this.logger.consoleFailure(\n `failed generating workspace config files, please run \"bit ws-config write\" manually. error: ${err.message}`\n );\n }\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 getOptionResultFromArgs(option: PromptOption): string | boolean | undefined {\n const args = process.argv.slice(2);\n const argIndex = args.indexOf(`--${option.name}`);\n if (argIndex === -1) {\n return;\n }\n if (option.type === 'confirm') {\n return true;\n }\n const argValue = args[argIndex + 1];\n if (!argValue) {\n throw new Error(`Missing value for ${option.name}`);\n }\n if (option.type === 'select' && !option.choices?.includes(argValue)) {\n throw new Error(`Invalid value for ${option.name}. Please use one of the following values: ${option.choices?.join(', ')}`);\n }\n return argValue;\n }\n\n private async getPromptOptionResult(option: PromptOption): Promise<Record<string, string | boolean>> {\n switch (option.type) {\n case 'input':\n return prompt({\n type: 'input',\n name: option.name,\n message: option.message\n });\n case 'confirm':\n return prompt({\n type: 'confirm',\n name: option.name,\n message: option.message,\n });\n case 'select':\n return prompt({\n type: 'select',\n name: option.name,\n message: option.message,\n choices: option.choices,\n });\n default:\n throw new Error(`unexpected prompt type ${option.type}`);\n }\n }\n\n private async getPromptResults(): Promise<PromptResults | undefined> {\n if (this.promptResults) {\n return this.promptResults;\n }\n const promptOptions = this.template.promptOptions?.();\n if (!promptOptions) {\n return undefined\n }\n const promptResults: PromptResults = {};\n for await (const option of promptOptions) {\n const fromArg = this.getOptionResultFromArgs(option);\n if (fromArg) {\n promptResults[option.name] = fromArg;\n continue;\n }\n if (option.skip && option.skip(promptResults)) {\n continue;\n }\n try {\n const optionResult = await this.getPromptOptionResult(option);\n promptResults[option.name] = optionResult[option.name];\n } catch (err: any) {\n if (!err) { // for some reason, when the user clicks Ctrl+C, the error is an empty string\n throw new Error(`The prompt has been canceled`);\n }\n throw err;\n }\n }\n return promptResults;\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 const promptResults = await this.getPromptResults();\n\n const files = await this.template.generateFiles({\n name,\n namePascalCase,\n nameCamelCase,\n componentId,\n aspectId,\n envId: this.envId,\n promptResults,\n });\n const mainFile = files.find((file) => file.isMain);\n await this.newComponentHelper.writeComponentFiles(\n componentPath,\n files.map((f) => ({ path: f.relativePath, content: f.content }))\n );\n const addResults = await this.tracker.track({\n rootDir: componentPath,\n mainFile: mainFile?.relativePath,\n componentName: componentId.fullName,\n defaultScope: this.options.scope || componentId.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 const userEnv = this.options.env;\n\n if (!config && this.envId && !userEnv) {\n const isInWorkspace = this.workspace.hasId(this.envId, { ignoreVersion: true });\n config = {\n [isInWorkspace ? this.envId.toStringWithoutVersion() : 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 // eslint-disable-next-line prefer-const\n let { envId, setBy } = getEnvData();\n if (envId) {\n const isInWorkspace = this.workspace.hasId(envId, { ignoreVersion: true });\n const isSameAsThisEnvId = envId === this.envId?.toString() || envId === this.envId?.toStringWithoutVersion();\n if (isSameAsThisEnvId && this.envId) {\n envId = isInWorkspace ? this.envId.toStringWithoutVersion() : this.envId.toString();\n }\n }\n return {\n id: componentId,\n dir: componentPath,\n files: addResults.files,\n packageName: componentIdToPackageName(component.state._consumer),\n envId,\n envSetBy: setBy,\n isApp: this.template.isApp,\n isEnv: this.template.isEnv,\n dependencies: this.template.dependencies,\n installMissingDependencies: this.template.installMissingDependencies,\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 await this.tracker.addEnvToConfig(userEnv, config);\n\n return config;\n }\n}\n"],"mappings":";;;;;;AAAA,SAAAA,SAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,QAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,UAAA;EAAA,MAAAH,IAAA,GAAAE,OAAA;EAAAC,SAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAI,YAAA;EAAA,MAAAJ,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAE,WAAA,YAAAA,CAAA;IAAA,OAAA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":[]}
1
+ {"version":3,"names":["_fsExtra","data","_interopRequireDefault","require","_enquirer","_pMapSeries","_path","_envs","_camelcase","_bitError","_workspaceModules","_pkgModules","_componentId","e","__esModule","default","ComponentGenerator","constructor","workspace","componentIds","options","template","envs","newComponentHelper","tracker","wsConfigFiles","logger","onComponentCreateSlot","aspectId","envId","installOptions","promptResults","generate","force","dirsToDeleteIfFailed","generateResults","pMapSeries","componentId","componentPath","getNewComponentPath","pathFromUser","path","componentsToCreate","length","fs","existsSync","join","BitError","push","generateOneComponent","err","deleteGeneratedComponents","bitMap","write","ids","map","r","id","tryLinkToNodeModules","runOnComponentCreateHook","tryWriteConfigFiles","linkToNodeModulesByIds","consoleFailure","message","fns","values","Promise","all","fn","shouldWrite","isWorkspaceConfigWriteEnabled","clearComponentCache","writeConfigFiles","clean","silent","dedupe","throw","dirs","dir","absoluteDir","remove","code","getOptionResultFromArgs","option","args","process","argv","slice","argIndex","indexOf","name","type","argValue","Error","choices","includes","getPromptOptionResult","prompt","getPromptResults","promptOptions","undefined","fromArg","skip","optionResult","namePascalCase","camelcase","pascalCase","nameCamelCase","ComponentID","fromString","files","generateFiles","mainFile","find","file","isMain","writeComponentFiles","f","relativePath","content","addResults","track","rootDir","componentName","fullName","defaultScope","scope","component","get","hasEnvConfiguredOriginally","hasEnvConfigured","envBeforeConfigChanges","getEnv","config","boundConfig","bind","userEnv","env","isInWorkspace","hasId","ignoreVersion","toStringWithoutVersion","toString","templateEnv","EnvsAspect","Object","keys","configWithEnv","addEnvIfProvidedByFlag","setEntireConfig","getEnvData","envFromFlag","envFromTemplate","setBy","isSameAsThisEnvId","packageName","componentIdToPackageName","state","_consumer","envSetBy","isApp","isEnv","dependencies","installMissingDependencies","addEnvToConfig","exports"],"sources":["component-generator.ts"],"sourcesContent":["import fs from 'fs-extra';\nimport { prompt } from 'enquirer';\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 { Logger } from '@teambit/logger';\nimport { TrackerMain } from '@teambit/tracker';\nimport { linkToNodeModulesByIds } from '@teambit/workspace.modules.node-modules-linker';\nimport { componentIdToPackageName } from '@teambit/pkg.modules.component-package-name';\nimport { NewComponentHelperMain } from '@teambit/new-component-helper';\nimport { ComponentID } from '@teambit/component-id';\nimport { WorkspaceConfigFilesMain } from '@teambit/workspace-config-files';\n\nimport { ComponentTemplate, ComponentConfig, PromptOption, PromptResults } from './component-template';\nimport { CreateOptions } from './create.cmd';\nimport { OnComponentCreateSlot } from './generator.main.runtime';\n\nexport type GenerateResult = {\n id: ComponentID;\n dir: string;\n files: string[];\n envId: string;\n envSetBy: string;\n packageName: string;\n isApp?: boolean;\n isEnv?: boolean;\n dependencies?: string[];\n installMissingDependencies?: boolean;\n};\n\nexport type InstallOptions = { optimizeReportForNonTerminal?: boolean };\n\nexport type OnComponentCreateFn = (generateResults: GenerateResult[], installOptions?: InstallOptions) => Promise<void>;\n\nexport class ComponentGenerator {\n constructor(\n private workspace: Workspace,\n private componentIds: ComponentID[],\n private options: Partial<CreateOptions>,\n private template: ComponentTemplate,\n private envs: EnvsMain,\n private newComponentHelper: NewComponentHelperMain,\n private tracker: TrackerMain,\n private wsConfigFiles: WorkspaceConfigFilesMain,\n private logger: Logger,\n private onComponentCreateSlot: OnComponentCreateSlot,\n private aspectId: string,\n private envId?: ComponentID,\n private installOptions: InstallOptions = {},\n private promptResults?: PromptResults\n ) {}\n\n async generate(force = false): Promise<GenerateResult[]> {\n const dirsToDeleteIfFailed: string[] = [];\n const generateResults = await pMapSeries(this.componentIds, async (componentId) => {\n try {\n const componentPath = this.newComponentHelper.getNewComponentPath(componentId, {\n pathFromUser: this.options.path,\n componentsToCreate: this.componentIds.length,\n });\n if (!force && fs.existsSync(path.join(this.workspace.path, componentPath))) {\n throw new BitError(\n `unable to create a component at \"${componentPath}\", this path already exists, please use \"--path\" to create the component in a different path`\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(`create (${this.componentIds.length} components)`);\n\n const ids = generateResults.map((r) => r.id);\n await this.tryLinkToNodeModules(ids);\n await this.runOnComponentCreateHook(generateResults);\n // We are running this after the runOnComponentCreateHook as it require\n // the env to be installed to work properly, and the hook might install\n // the env.\n await this.tryWriteConfigFiles(ids);\n\n return generateResults;\n }\n\n private async tryLinkToNodeModules(ids: ComponentID[]) {\n try {\n await linkToNodeModulesByIds(\n this.workspace,\n ids.map((id) => id)\n );\n } catch (err: any) {\n this.logger.consoleFailure(\n `failed linking the new components to node_modules, please run \"bit link\" manually. error: ${err.message}`\n );\n }\n }\n\n private async runOnComponentCreateHook(generateResults: GenerateResult[]) {\n const fns = this.onComponentCreateSlot.values();\n if (!fns.length) return;\n await Promise.all(fns.map((fn) => fn(generateResults, this.installOptions)));\n }\n\n /**\n * The function `tryWriteConfigFiles` attempts to write workspace config files, and if it fails, it logs an error\n * message.\n * @returns If the condition `!shouldWrite` is true, then nothing is being returned. Otherwise, if the `writeConfigFiles`\n * function is successfully executed, nothing is being returned. If an error occurs during the execution of\n * `writeConfigFiles`, an error message is being returned.\n */\n private async tryWriteConfigFiles(ids: ComponentID[]) {\n const shouldWrite = this.wsConfigFiles.isWorkspaceConfigWriteEnabled();\n if (!shouldWrite) return;\n ids.map((id) => this.workspace.clearComponentCache(id));\n const { err } = await this.wsConfigFiles.writeConfigFiles({\n clean: true,\n silent: true,\n dedupe: true,\n throw: false,\n });\n if (err) {\n this.logger.consoleFailure(\n `failed generating workspace config files, please run \"bit ws-config write\" manually. error: ${err.message}`\n );\n }\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 getOptionResultFromArgs(option: PromptOption): string | boolean | undefined {\n const args = process.argv.slice(2);\n const argIndex = args.indexOf(`--${option.name}`);\n if (argIndex === -1) {\n return;\n }\n if (option.type === 'confirm') {\n return true;\n }\n const argValue = args[argIndex + 1];\n if (!argValue) {\n throw new Error(`Missing value for ${option.name}`);\n }\n if (option.type === 'select' && !option.choices?.includes(argValue)) {\n throw new Error(\n `Invalid value for ${option.name}. Please use one of the following values: ${option.choices?.join(', ')}`\n );\n }\n return argValue;\n }\n\n private async getPromptOptionResult(option: PromptOption): Promise<Record<string, string | boolean>> {\n switch (option.type) {\n case 'input':\n return prompt({\n type: 'input',\n name: option.name,\n message: option.message,\n });\n case 'confirm':\n return prompt({\n type: 'confirm',\n name: option.name,\n message: option.message,\n });\n case 'select':\n return prompt({\n type: 'select',\n name: option.name,\n message: option.message,\n choices: option.choices,\n });\n default:\n throw new Error(`unexpected prompt type ${option.type}`);\n }\n }\n\n private async getPromptResults(): Promise<PromptResults | undefined> {\n if (this.promptResults) {\n return this.promptResults;\n }\n const promptOptions = this.template.promptOptions?.();\n if (!promptOptions) {\n return undefined;\n }\n const promptResults: PromptResults = {};\n for await (const option of promptOptions) {\n const fromArg = this.getOptionResultFromArgs(option);\n if (fromArg) {\n promptResults[option.name] = fromArg;\n continue;\n }\n if (option.skip && option.skip(promptResults)) {\n continue;\n }\n try {\n const optionResult = await this.getPromptOptionResult(option);\n promptResults[option.name] = optionResult[option.name];\n } catch (err: any) {\n if (!err) {\n // for some reason, when the user clicks Ctrl+C, the error is an empty string\n throw new Error(`The prompt has been canceled`);\n }\n throw err;\n }\n }\n return promptResults;\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 const promptResults = await this.getPromptResults();\n\n const files = await this.template.generateFiles({\n name,\n namePascalCase,\n nameCamelCase,\n componentId,\n aspectId,\n envId: this.envId,\n promptResults,\n });\n const mainFile = files.find((file) => file.isMain);\n await this.newComponentHelper.writeComponentFiles(\n componentPath,\n files.map((f) => ({ path: f.relativePath, content: f.content }))\n );\n const addResults = await this.tracker.track({\n rootDir: componentPath,\n mainFile: mainFile?.relativePath,\n componentName: componentId.fullName,\n defaultScope: this.options.scope || componentId.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 const userEnv = this.options.env;\n\n if (!config && this.envId && !userEnv) {\n const isInWorkspace = this.workspace.hasId(this.envId, { ignoreVersion: true });\n config = {\n [isInWorkspace ? this.envId.toStringWithoutVersion() : 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 // eslint-disable-next-line prefer-const\n let { envId, setBy } = getEnvData();\n if (envId) {\n const isInWorkspace = this.workspace.hasId(envId, { ignoreVersion: true });\n const isSameAsThisEnvId = envId === this.envId?.toString() || envId === this.envId?.toStringWithoutVersion();\n if (isSameAsThisEnvId && this.envId) {\n envId = isInWorkspace ? this.envId.toStringWithoutVersion() : this.envId.toString();\n }\n }\n return {\n id: componentId,\n dir: componentPath,\n files: addResults.files,\n packageName: componentIdToPackageName(component.state._consumer),\n envId,\n envSetBy: setBy,\n isApp: this.template.isApp,\n isEnv: this.template.isEnv,\n dependencies: this.template.dependencies,\n installMissingDependencies: this.template.installMissingDependencies,\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 await this.tracker.addEnvToConfig(userEnv, config);\n\n return config;\n }\n}\n"],"mappings":";;;;;;AAAA,SAAAA,SAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,QAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,UAAA;EAAA,MAAAH,IAAA,GAAAE,OAAA;EAAAC,SAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAI,YAAA;EAAA,MAAAJ,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAE,WAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAK,MAAA;EAAA,MAAAL,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EA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CAAC7G,KAAK,CAACgH,sBAAsB,CAAC,CAAC,GAAG,IAAI,CAAChH,KAAK,CAACiH,QAAQ,CAAC,CAAC;MACrF;IACF;IACA,OAAO;MACLrF,EAAE,EAAEpB,WAAW;MACfyC,GAAG,EAAExC,aAAa;MAClBwE,KAAK,EAAEU,UAAU,CAACV,KAAK;MACvB6C,WAAW,EAAE,IAAAC,sCAAwB,EAAC7B,SAAS,CAAC8B,KAAK,CAACC,SAAS,CAAC;MAChEjI,KAAK;MACLkI,QAAQ,EAAEN,KAAK;MACfO,KAAK,EAAE,IAAI,CAAC3I,QAAQ,CAAC2I,KAAK;MAC1BC,KAAK,EAAE,IAAI,CAAC5I,QAAQ,CAAC4I,KAAK;MAC1BC,YAAY,EAAE,IAAI,CAAC7I,QAAQ,CAAC6I,YAAY;MACxCC,0BAA0B,EAAE,IAAI,CAAC9I,QAAQ,CAAC8I;IAC5C,CAAC;EACH;EAEA,MAAcf,sBAAsBA,CAACf,MAAwB,EAAwC;IACnG,MAAMG,OAAO,GAAG,IAAI,CAACpH,OAAO,CAACqH,GAAG,CAAC,CAAC;IAClC,MAAMM,WAAW,GAAGV,MAAM,GAAGW,kBAAU,CAACvF,EAAE,CAAC,EAAEgF,GAAG;IAChD,IAAI,CAACD,OAAO,IAAIA,OAAO,KAAKO,WAAW,EAAE;MACvC,OAAOV,MAAM;IACf;IACAA,MAAM,GAAGA,MAAM,IAAI,CAAC,CAAC;IACrB,IAAIU,WAAW,EAAE;MACf;MACA,OAAOV,MAAM,CAACU,WAAW,CAAC;IAC5B;IACA,MAAM,IAAI,CAACvH,OAAO,CAAC4I,cAAc,CAAC5B,OAAO,EAAEH,MAAM,CAAC;IAElD,OAAOA,MAAM;EACf;AACF;AAACgC,OAAA,CAAArJ,kBAAA,GAAAA,kBAAA","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["component-template.ts"],"sourcesContent":["import { ComponentID } from '@teambit/component';\n\n/**\n * BaseComponentTemplateOptions describes the foundational properties for components.\n */\nexport interface BaseComponentTemplateOptions {\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 | string;\n\n /**\n * env id of the env that register the template itself.\n * This will be usually identical to the aspectId but aspectId will always exist,\n * while envId will be undefined if the template is not registered by an env.\n */\n envId?: ComponentID;\n\n /**\n * path of the component.\n */\n path?: string;\n /**\n * scope of the component.\n */\n scope?: string;\n /**\n * namespace of the component.\n */\n namespace?: string;\n /**\n * when a template implements the promptOptions function, this object will be populated with the user responses.\n */\n promptResults?: PromptResults;\n}\n\n/**\n * ComponentContext represents foundational properties for a component context.\n */\nexport type ComponentContext = BaseComponentTemplateOptions;\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 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 ComponentTemplateOptions {\n /**\n * name of the component template. for example: `hook`, `react-component` or `module`.\n */\n name?: string;\n\n /**\n * display name of the template.\n */\n displayName?: string;\n\n /**\n * example name for the component template.\n */\n exampleComponentName?: 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 generated component.\n */\n env?: string;\n\n /**\n * adds a metadata that the component that this template creates is of type env.\n * This will be used later to do further configuration for example:\n * - ensure to create the .bit_root for it\n */\n isEnv?: boolean;\n\n /**\n * adds a metadata that the component that this template creates is of type app.\n * This will be used later to do further configuration for example:\n * - add it to the workspace.jsonc as app\n * - ensure to create the .bit_root for it\n */\n isApp?: boolean;\n\n /**\n * list of dependencies to install when the component is created.\n */\n dependencies?: string[];\n\n /**\n * Perform installation of missing dependencies after component generation.\n * This is the same as of running `bit install --add-missing-deps` after component generation.\n */\n installMissingDependencies?: boolean;\n}\n\n/**\n * PromptOption is shown to the user before calling the generateFiles function.\n * The prompt is using enquirer under the hood. see https://www.npmjs.com/package/enquirer.\n * Examples:\n * - input: {name: 'name', message: 'enter your name', type: 'input'}\n * - confirm: {name: 'isHappy', message: 'are you happy?', type: 'confirm'}\n * - select: {name: 'color', message: 'pick a color', type: 'select', choices: ['red', 'blue', 'green']}\n */\nexport type PromptOption = {\n name: string;\n message: string;\n type: 'input' | 'confirm' | 'select';\n choices?: string[]; // for select type\n skip?: (previousResults: PromptResults) => boolean; // skip this prompt if this function returns true\n}\n\n/**\n * PromptResults is the result of the user input received from the promptOptions.\n * The key is the name of the prompt option and the value is the user input.\n * in case the prompt-option is of type 'confirm', the value will be a boolean.\n */\nexport type PromptResults = Record<string, string | boolean>;\n\nexport interface ComponentTemplate extends ComponentTemplateOptions {\n name: string;\n\n /**\n * in case the template requires user input, this function will be called to prompt the user.\n * the results will be passed to the generateFiles function.\n */\n promptOptions?: () => PromptOption[];\n\n /**\n * template function for generating the file of a certain component.,\n */\n generateFiles(context: ComponentContext): Promise<ComponentFile[]> | 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\nexport type GetComponentTemplates = () => ComponentTemplate[];"],"mappings":"","ignoreList":[]}
1
+ {"version":3,"names":[],"sources":["component-template.ts"],"sourcesContent":["import { ComponentID } from '@teambit/component';\n\n/**\n * BaseComponentTemplateOptions describes the foundational properties for components.\n */\nexport interface BaseComponentTemplateOptions {\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 | string;\n\n /**\n * env id of the env that register the template itself.\n * This will be usually identical to the aspectId but aspectId will always exist,\n * while envId will be undefined if the template is not registered by an env.\n */\n envId?: ComponentID;\n\n /**\n * path of the component.\n */\n path?: string;\n /**\n * scope of the component.\n */\n scope?: string;\n /**\n * namespace of the component.\n */\n namespace?: string;\n /**\n * when a template implements the promptOptions function, this object will be populated with the user responses.\n */\n promptResults?: PromptResults;\n}\n\n/**\n * ComponentContext represents foundational properties for a component context.\n */\nexport type ComponentContext = BaseComponentTemplateOptions;\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 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 ComponentTemplateOptions {\n /**\n * name of the component template. for example: `hook`, `react-component` or `module`.\n */\n name?: string;\n\n /**\n * display name of the template.\n */\n displayName?: string;\n\n /**\n * example name for the component template.\n */\n exampleComponentName?: 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 generated component.\n */\n env?: string;\n\n /**\n * adds a metadata that the component that this template creates is of type env.\n * This will be used later to do further configuration for example:\n * - ensure to create the .bit_root for it\n */\n isEnv?: boolean;\n\n /**\n * adds a metadata that the component that this template creates is of type app.\n * This will be used later to do further configuration for example:\n * - add it to the workspace.jsonc as app\n * - ensure to create the .bit_root for it\n */\n isApp?: boolean;\n\n /**\n * list of dependencies to install when the component is created.\n */\n dependencies?: string[];\n\n /**\n * Perform installation of missing dependencies after component generation.\n * This is the same as of running `bit install --add-missing-deps` after component generation.\n */\n installMissingDependencies?: boolean;\n}\n\n/**\n * PromptOption is shown to the user before calling the generateFiles function.\n * The prompt is using enquirer under the hood. see https://www.npmjs.com/package/enquirer.\n * Examples:\n * - input: {name: 'name', message: 'enter your name', type: 'input'}\n * - confirm: {name: 'isHappy', message: 'are you happy?', type: 'confirm'}\n * - select: {name: 'color', message: 'pick a color', type: 'select', choices: ['red', 'blue', 'green']}\n */\nexport type PromptOption = {\n name: string;\n message: string;\n type: 'input' | 'confirm' | 'select';\n choices?: string[]; // for select type\n skip?: (previousResults: PromptResults) => boolean; // skip this prompt if this function returns true\n};\n\n/**\n * PromptResults is the result of the user input received from the promptOptions.\n * The key is the name of the prompt option and the value is the user input.\n * in case the prompt-option is of type 'confirm', the value will be a boolean.\n */\nexport type PromptResults = Record<string, string | boolean>;\n\nexport interface ComponentTemplate extends ComponentTemplateOptions {\n name: string;\n\n /**\n * in case the template requires user input, this function will be called to prompt the user.\n * the results will be passed to the generateFiles function.\n */\n promptOptions?: () => PromptOption[];\n\n /**\n * template function for generating the file of a certain component.,\n */\n generateFiles(context: ComponentContext): Promise<ComponentFile[]> | 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\nexport type GetComponentTemplates = () => ComponentTemplate[];\n"],"mappings":"","ignoreList":[]}
@@ -0,0 +1,7 @@
1
+ import * as compositions_0 from '/Users/davidfirst/Library/Caches/Bit/capsules/4ff44c81b/teambit.generator_generator@1.0.651/dist/generator.composition.js';
2
+ import * as overview_0 from '/Users/davidfirst/Library/Caches/Bit/capsules/4ff44c81b/teambit.generator_generator@1.0.651/dist/generator.docs.mdx';
3
+
4
+ export const compositions = [compositions_0];
5
+ export const overview = [overview_0];
6
+
7
+ export const compositions_metadata = {"compositions":[{"displayName":"Logo","identifier":"Logo"}]};
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@teambit/generator",
3
- "version": "1.0.649",
3
+ "version": "1.0.651",
4
4
  "homepage": "https://bit.cloud/teambit/generator/generator",
5
5
  "main": "dist/index.js",
6
6
  "componentId": {
7
7
  "scope": "teambit.generator",
8
8
  "name": "generator",
9
- "version": "1.0.649"
9
+ "version": "1.0.651"
10
10
  },
11
11
  "dependencies": {
12
12
  "camelcase": "6.2.0",
@@ -21,32 +21,32 @@
21
21
  "@teambit/component-id": "1.2.4",
22
22
  "@teambit/harmony": "0.4.7",
23
23
  "@teambit/git.modules.git-ignore": "1.0.2",
24
- "@teambit/envs": "1.0.648",
25
- "@teambit/logger": "0.0.1318",
26
- "@teambit/new-component-helper": "1.0.648",
27
- "@teambit/pkg.modules.component-package-name": "0.0.61",
28
- "@teambit/tracker": "1.0.648",
29
- "@teambit/workspace-config-files": "1.0.648",
30
- "@teambit/workspace.modules.node-modules-linker": "0.0.282",
31
- "@teambit/workspace": "1.0.648",
32
- "@teambit/component": "1.0.648",
33
- "@teambit/cli": "0.0.1225",
34
- "@teambit/graphql": "1.0.648",
35
- "@teambit/aspect-loader": "1.0.648",
36
- "@teambit/deprecation": "1.0.648",
37
- "@teambit/git": "1.0.648",
24
+ "@teambit/envs": "1.0.650",
25
+ "@teambit/logger": "0.0.1320",
26
+ "@teambit/new-component-helper": "1.0.650",
27
+ "@teambit/pkg.modules.component-package-name": "0.0.62",
28
+ "@teambit/tracker": "1.0.650",
29
+ "@teambit/workspace-config-files": "1.0.650",
30
+ "@teambit/workspace.modules.node-modules-linker": "0.0.283",
31
+ "@teambit/workspace": "1.0.650",
32
+ "@teambit/component": "1.0.650",
33
+ "@teambit/cli": "0.0.1227",
34
+ "@teambit/graphql": "1.0.650",
35
+ "@teambit/aspect-loader": "1.0.650",
36
+ "@teambit/deprecation": "1.0.650",
37
+ "@teambit/git": "1.0.650",
38
38
  "@teambit/legacy.constants": "0.0.12",
39
- "@teambit/legacy.consumer-config": "0.0.54",
40
- "@teambit/legacy.scope": "0.0.54",
41
- "@teambit/scope": "1.0.648",
42
- "@teambit/compiler": "1.0.648",
43
- "@teambit/forking": "1.0.648",
39
+ "@teambit/legacy.consumer-config": "0.0.55",
40
+ "@teambit/legacy.scope": "0.0.55",
41
+ "@teambit/scope": "1.0.650",
42
+ "@teambit/compiler": "1.0.650",
43
+ "@teambit/forking": "1.0.650",
44
44
  "@teambit/git.modules.git-executable": "0.0.13",
45
- "@teambit/host-initializer": "0.0.361",
46
- "@teambit/importer": "1.0.648",
47
- "@teambit/install": "1.0.648",
48
- "@teambit/ui": "1.0.648",
49
- "@teambit/config": "0.0.1399"
45
+ "@teambit/host-initializer": "0.0.363",
46
+ "@teambit/importer": "1.0.650",
47
+ "@teambit/install": "1.0.650",
48
+ "@teambit/ui": "1.0.650",
49
+ "@teambit/config": "0.0.1401"
50
50
  },
51
51
  "devDependencies": {
52
52
  "@types/fs-extra": "9.0.7",
@@ -1,7 +0,0 @@
1
- import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad/teambit.generator_generator@1.0.649/dist/generator.composition.js';
2
- import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad/teambit.generator_generator@1.0.649/dist/generator.docs.mdx';
3
-
4
- export const compositions = [compositions_0];
5
- export const overview = [overview_0];
6
-
7
- export const compositions_metadata = {"compositions":[{"displayName":"Logo","identifier":"Logo"}]};