@teambit/generator 0.0.1083 → 0.0.1084
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.
- package/dist/component-generator.js +1 -1
- package/dist/component-generator.js.map +1 -1
- package/dist/component-template.d.ts +2 -2
- package/dist/component-template.js.map +1 -1
- package/dist/create.cmd.d.ts +3 -1
- package/dist/create.cmd.js +3 -1
- package/dist/create.cmd.js.map +1 -1
- package/dist/new.cmd.d.ts +1 -0
- package/dist/new.cmd.js +3 -3
- package/dist/new.cmd.js.map +1 -1
- package/dist/{preview-1687231140262.js → preview-1687362266169.js} +2 -2
- package/dist/workspace-generator.d.ts +1 -0
- package/dist/workspace-generator.js +13 -8
- package/dist/workspace-generator.js.map +1 -1
- package/dist/workspace-template.d.ts +3 -3
- package/dist/workspace-template.js.map +1 -1
- package/package-tar/teambit-generator-0.0.1084.tgz +0 -0
- package/package.json +20 -20
- package/package-tar/teambit-generator-0.0.1083.tgz +0 -0
@@ -152,7 +152,7 @@ class ComponentGenerator {
|
|
152
152
|
});
|
153
153
|
const nameCamelCase = (0, _camelcase().default)(name);
|
154
154
|
const aspectId = _componentId().ComponentID.fromString(this.aspectId);
|
155
|
-
const files = this.template.generateFiles({
|
155
|
+
const files = await this.template.generateFiles({
|
156
156
|
name,
|
157
157
|
namePascalCase,
|
158
158
|
nameCamelCase,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["ComponentGenerator","constructor","workspace","componentIds","options","template","envs","newComponentHelper","tracker","logger","aspectId","envId","generate","dirsToDeleteIfFailed","generateResults","pMapSeries","componentId","componentPath","getNewComponentPath","path","fs","existsSync","join","BitError","hasName","fullName","push","generateOneComponent","err","deleteGeneratedComponents","bitMap","write","ids","map","r","id","linkToNodeModulesByIds","_legacy","consoleFailure","message","dirs","Promise","all","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","isInWorkspace","exists","toStringWithoutVersion","toString","env","templateEnv","EnvsAspect","Object","keys","length","undefined","configWithEnv","addEnvIfProvidedByFlag","setEntireConfig","getEnvData","envFromFlag","envFromTemplate","setBy","packageName","componentIdToPackageName","state","_consumer","envSetBy","userEnv","addEnvToConfig","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 { Logger } from '@teambit/logger';\nimport { TrackerMain } from '@teambit/tracker';\nimport { linkToNodeModulesByIds } from '@teambit/workspace.modules.node-modules-linker';\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 logger: Logger,\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 const ids = generateResults.map((r) => r.id);\n try {\n await linkToNodeModulesByIds(\n this.workspace,\n ids.map((id) => id._legacy)\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 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 const isInWorkspace = this.workspace.exists(this.envId);\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 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 await this.tracker.addEnvToConfig(userEnv, config);\n\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;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;AAaO,MAAMA,kBAAkB,CAAC;EAC9BC,WAAW,CACDC,SAAoB,EACpBC,YAA2B,EAC3BC,OAAsB,EACtBC,QAA2B,EAC3BC,IAAc,EACdC,kBAA0C,EAC1CC,OAAoB,EACpBC,MAAc,EACdC,QAAgB,EAChBC,KAAmB,EAC3B;IAAA,KAVQT,SAAo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A;AACF;AACA;EACE,MAAcd,mBAAmB,CAC/B3C,aAAqB,EACrBqF,aAA8B,EACE;IAChC,MAAMC,aAAa,GAAG,KAAIC,wBAAa,GAAE;IACzC,MAAMC,UAAU,GAAGH,aAAa,CAACrE,GAAG,CAAEyE,YAAY,IAAK;MACrD,MAAMC,iBAAiB,GAAG,KAAIC,gBAAK,EAAC;QAClCC,IAAI,EAAE5F,aAAa;QACnBE,IAAI,EAAEA,eAAI,CAACG,IAAI,CAACL,aAAa,EAAEyF,YAAY,CAAC1C,YAAY,CAAC;QACzD8C,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,CAACxE,GAAG,CAAEoF,CAAC,IAAKA,CAAC,CAAClG,IAAI,CAAC;IAC7CoF,aAAa,CAACe,YAAY,CAACb,UAAU,CAAC;IACtCF,aAAa,CAACgB,WAAW,CAAC,IAAI,CAACrH,SAAS,CAACiB,IAAI,CAAC;IAC9C,MAAMoF,aAAa,CAACiB,cAAc,EAAE;IACpC,OAAOJ,OAAO;EAChB;AACF;AAAC"}
|
1
|
+
{"version":3,"names":["ComponentGenerator","constructor","workspace","componentIds","options","template","envs","newComponentHelper","tracker","logger","aspectId","envId","generate","dirsToDeleteIfFailed","generateResults","pMapSeries","componentId","componentPath","getNewComponentPath","path","fs","existsSync","join","BitError","hasName","fullName","push","generateOneComponent","err","deleteGeneratedComponents","bitMap","write","ids","map","r","id","linkToNodeModulesByIds","_legacy","consoleFailure","message","dirs","Promise","all","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","isInWorkspace","exists","toStringWithoutVersion","toString","env","templateEnv","EnvsAspect","Object","keys","length","undefined","configWithEnv","addEnvIfProvidedByFlag","setEntireConfig","getEnvData","envFromFlag","envFromTemplate","setBy","packageName","componentIdToPackageName","state","_consumer","envSetBy","userEnv","addEnvToConfig","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 { Logger } from '@teambit/logger';\nimport { TrackerMain } from '@teambit/tracker';\nimport { linkToNodeModulesByIds } from '@teambit/workspace.modules.node-modules-linker';\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 logger: Logger,\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 const ids = generateResults.map((r) => r.id);\n try {\n await linkToNodeModulesByIds(\n this.workspace,\n ids.map((id) => id._legacy)\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 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 = await 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 const isInWorkspace = this.workspace.exists(this.envId);\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 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 await this.tracker.addEnvToConfig(userEnv, config);\n\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;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;AAaO,MAAMA,kBAAkB,CAAC;EAC9BC,WAAW,CACDC,SAAoB,EACpBC,YAA2B,EAC3BC,OAAsB,EACtBC,QAA2B,EAC3BC,IAAc,EACdC,kBAA0C,EAC1CC,OAAoB,EACpBC,MAAc,EACdC,QAAgB,EAChBC,KAAmB,EAC3B;IAAA,KAVQT,SAAoB,GAApBA,SAAoB;IAAA,KACpBC,YAA2B,GAA3BA,YAA2B;IAAA,KAC3BC,OAAsB,GAAtBA,O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AAMC,aAAa,GAAG,KAAIC,wBAAa,GAAE;IACzC,MAAMC,UAAU,GAAGH,aAAa,CAACrE,GAAG,CAAEyE,YAAY,IAAK;MACrD,MAAMC,iBAAiB,GAAG,KAAIC,gBAAK,EAAC;QAClCC,IAAI,EAAE5F,aAAa;QACnBE,IAAI,EAAEA,eAAI,CAACG,IAAI,CAACL,aAAa,EAAEyF,YAAY,CAAC1C,YAAY,CAAC;QACzD8C,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,CAACxE,GAAG,CAAEoF,CAAC,IAAKA,CAAC,CAAClG,IAAI,CAAC;IAC7CoF,aAAa,CAACe,YAAY,CAACb,UAAU,CAAC;IACtCF,aAAa,CAACgB,WAAW,CAAC,IAAI,CAACrH,SAAS,CAACiB,IAAI,CAAC;IAC9C,MAAMoF,aAAa,CAACiB,cAAc,EAAE;IACpC,OAAOJ,OAAO;EAChB;AACF;AAAC"}
|
@@ -41,7 +41,7 @@ export interface ComponentContext {
|
|
41
41
|
/**
|
42
42
|
* env id of the env that register the template itself
|
43
43
|
* This will be usually identical to the aspectId
|
44
|
-
* but aspectId will
|
44
|
+
* but aspectId will always exist, while envId will be undefined if the template is not registered by an env
|
45
45
|
* so in case you want to use the envId, you should check if it exists first
|
46
46
|
* You can use this in case you want to only do something if the template was registered by an env
|
47
47
|
*/
|
@@ -76,7 +76,7 @@ export interface ComponentTemplate {
|
|
76
76
|
/**
|
77
77
|
* template function for generating the file of a certain component.,
|
78
78
|
*/
|
79
|
-
generateFiles(context: ComponentContext): ComponentFile[];
|
79
|
+
generateFiles(context: ComponentContext): Promise<ComponentFile[]> | ComponentFile[];
|
80
80
|
/**
|
81
81
|
* component config. gets saved in the .bitmap file and it overrides the workspace.jsonc config.
|
82
82
|
* for example, you can set the env that will be used for this component as follows:
|
@@ -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
|
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 always exist, 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): 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"],"mappings":""}
|
package/dist/create.cmd.d.ts
CHANGED
@@ -26,5 +26,7 @@ export declare class CreateCmd implements Command {
|
|
26
26
|
group: string;
|
27
27
|
options: CommandOptions;
|
28
28
|
constructor(generator: GeneratorMain, docsDomain: string);
|
29
|
-
report([templateName, componentNames]: [string, string[]], options: CreateOptions
|
29
|
+
report([templateName, componentNames]: [string, string[]], options: CreateOptions & {
|
30
|
+
template?: string;
|
31
|
+
}): Promise<string>;
|
30
32
|
}
|
package/dist/create.cmd.js
CHANGED
@@ -51,9 +51,11 @@ class CreateCmd {
|
|
51
51
|
description: "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')."
|
52
52
|
}]);
|
53
53
|
(0, _defineProperty2().default)(this, "group", 'development');
|
54
|
-
(0, _defineProperty2().default)(this, "options", [['n', 'namespace <string>', `sets the component's namespace and nested dirs inside the scope`], ['s', 'scope <string>', `sets the component's scope-name. if not entered, the default-scope will be used`], ['a', 'aspect <string>', 'aspect-id of the template. helpful when multiple aspects use the same template name'], ['p', 'path <string>', 'relative path in the workspace. by default the path is `<scope>/<namespace>/<name>`'], ['e', 'env <string>', "set the component's environment. (overrides the env from variants and the template)"]]);
|
54
|
+
(0, _defineProperty2().default)(this, "options", [['n', 'namespace <string>', `sets the component's namespace and nested dirs inside the scope`], ['s', 'scope <string>', `sets the component's scope-name. if not entered, the default-scope will be used`], ['a', 'aspect <string>', 'aspect-id of the template. helpful when multiple aspects use the same template name'], ['t', 'template <string>', 'env-id of the template. alias for --aspect.'], ['p', 'path <string>', 'relative path in the workspace. by default the path is `<scope>/<namespace>/<name>`'], ['e', 'env <string>', "set the component's environment. (overrides the env from variants and the template)"]]);
|
55
55
|
}
|
56
56
|
async report([templateName, componentNames], options) {
|
57
|
+
var _options$aspect;
|
58
|
+
options.aspect = (_options$aspect = options.aspect) !== null && _options$aspect !== void 0 ? _options$aspect : options.template;
|
57
59
|
const results = await this.generator.generateComponentTemplate(componentNames, templateName, options);
|
58
60
|
const title = `${results.length} component(s) were created`;
|
59
61
|
const componentsData = results.map(result => {
|
package/dist/create.cmd.js.map
CHANGED
@@ -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","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[]]
|
1
|
+
{"version":3,"names":["CreateCmd","constructor","generator","docsDomain","name","description","cmd","report","templateName","componentNames","options","aspect","template","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 ['t', 'template <string>', 'env-id of the template. alias for --aspect.'],\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(\n [templateName, componentNames]: [string, string[]],\n options: CreateOptions & {\n template?: string;\n }\n ) {\n options.aspect = options.aspect ?? options.template;\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;EA+CxCC,WAAW,CAASC,SAAwB,EAAUC,UAAkB,EAAE;IAAA,KAAtDD,SAAwB,GAAxBA,SAAwB;IAAA,KAAUC,UAAkB,GAAlBA,UAAkB;IAAA,8CA9CjE,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,mBAAmB,EAAE,6CAA6C,CAAC,EACzE,CAAC,GAAG,EAAE,eAAe,EAAE,qFAAqF,CAAC,EAC7G,CAAC,GAAG,EAAE,cAAc,EAAE,qFAAqF,CAAC,CAC7G;EAE0E;EAE3E,MAAME,MAAM,CACV,CAACC,YAAY,EAAEC,cAAc,CAAqB,EAClDC,OAEC,EACD;IAAA;IACAA,OAAO,CAACC,MAAM,sBAAGD,OAAO,CAACC,MAAM,6DAAID,OAAO,CAACE,QAAQ;IACnD,MAAMC,OAAO,GAAG,MAAM,IAAI,CAACX,SAAS,CAACY,yBAAyB,CAACL,cAAc,EAAED,YAAY,EAAEE,OAAO,CAAC;IACrG,MAAMK,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,CAAC1B,UAAW,kBAAiB;IAE9J,OAAQ,GAAEiB,gBAAK,CAACU,KAAK,CAACf,KAAK,CAAE,OAAME,cAAe,OAAMY,MAAO,EAAC;EAClE;AACF;AAAC"}
|
package/dist/new.cmd.d.ts
CHANGED
package/dist/new.cmd.js
CHANGED
@@ -36,12 +36,12 @@ class NewCmd {
|
|
36
36
|
(0, _defineProperty2().default)(this, "alias", '');
|
37
37
|
(0, _defineProperty2().default)(this, "loader", true);
|
38
38
|
(0, _defineProperty2().default)(this, "group", 'start');
|
39
|
-
(0, _defineProperty2().default)(this, "options", [['a', 'aspect <aspect-id>', 'aspect-id of the template. mandatory for non-core aspects. helpful for core aspects in case of a name collision'], ['', 'env <env-id>', 'env-id of the template'], ['d', 'default-scope <scope-name>', `set defaultScope in the new workspace.jsonc`], ['', 'standalone', 'DEPRECATED. use --skip-git instead'], ['s', 'skip-git', 'skip generation of Git repository'], ['e', 'empty', 'empty workspace with no components (relevant for templates that add components by default)'], ['', 'load-from <path-to-template>', 'path to the workspace containing the template. helpful during a development of a workspace-template']]);
|
39
|
+
(0, _defineProperty2().default)(this, "options", [['a', 'aspect <aspect-id>', 'aspect-id of the template. mandatory for non-core aspects. helpful for core aspects in case of a name collision'], ['t', 'template <env-id>', 'env-id of the template. alias for --env.'], ['', 'env <env-id>', 'env-id of the template'], ['d', 'default-scope <scope-name>', `set defaultScope in the new workspace.jsonc`], ['', 'standalone', 'DEPRECATED. use --skip-git instead'], ['s', 'skip-git', 'skip generation of Git repository'], ['e', 'empty', 'empty workspace with no components (relevant for templates that add components by default)'], ['', 'load-from <path-to-template>', 'path to the workspace containing the template. helpful during a development of a workspace-template']]);
|
40
40
|
}
|
41
41
|
async report([templateName, workspaceName], options) {
|
42
|
-
var _options$skipGit, _options$aspect;
|
42
|
+
var _options$skipGit, _ref, _options$aspect;
|
43
43
|
options.skipGit = (_options$skipGit = options.skipGit) !== null && _options$skipGit !== void 0 ? _options$skipGit : options.standalone;
|
44
|
-
options.aspect = (_options$aspect = options.aspect) !== null && _options$aspect !== void 0 ? _options$aspect : options.env;
|
44
|
+
options.aspect = (_ref = (_options$aspect = options.aspect) !== null && _options$aspect !== void 0 ? _options$aspect : options.env) !== null && _ref !== void 0 ? _ref : options.template;
|
45
45
|
const {
|
46
46
|
workspacePath,
|
47
47
|
appName
|
package/dist/new.cmd.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["NewCmd","constructor","generator","name","description","report","templateName","workspaceName","options","skipGit","standalone","aspect","env","workspacePath","appName","generateWorkspaceTemplate","chalk","white","green","yellow","bold","getBottomSection","cdLine","parts","push","join"],"sources":["new.cmd.ts"],"sourcesContent":["import { Command, CommandOptions } from '@teambit/cli';\nimport chalk from 'chalk';\nimport { GeneratorMain } from './generator.main.runtime';\n\nexport type NewOptions = {\n aspect?: string;\n defaultScope?: string;\n skipGit?: boolean;\n loadFrom?: string;\n empty?: boolean;\n};\n\nexport class NewCmd implements Command {\n name = 'new <template-name> <workspace-name>';\n description = 'create a new workspace from a template';\n arguments = [\n {\n name: 'template-name',\n description:\n \"the name of the workspace template (run 'bit templates', outside of a workspace, to get a list of available templates)\",\n },\n { name: 'workspace-name', description: 'the name for the new workspace and workspace directory' },\n ];\n alias = '';\n loader = true;\n group = 'start';\n options = [\n [\n 'a',\n 'aspect <aspect-id>',\n 'aspect-id of the template. mandatory for non-core aspects. helpful for core aspects in case of a name collision',\n ],\n ['', 'env <env-id>', 'env-id of the template'],\n ['d', 'default-scope <scope-name>', `set defaultScope in the new workspace.jsonc`],\n ['', 'standalone', 'DEPRECATED. use --skip-git instead'],\n ['s', 'skip-git', 'skip generation of Git repository'],\n ['e', 'empty', 'empty workspace with no components (relevant for templates that add components by default)'],\n [\n '',\n 'load-from <path-to-template>',\n 'path to the workspace containing the template. helpful during a development of a workspace-template',\n ],\n ] as CommandOptions;\n\n constructor(private generator: GeneratorMain) {}\n\n async report(\n [templateName, workspaceName]: [string, string],\n options: NewOptions & {\n standalone: boolean;\n env?: string;\n }\n ) {\n options.skipGit = options.skipGit ?? options.standalone;\n options.aspect = options.aspect ?? options.env;\n const { workspacePath, appName } = await this.generator.generateWorkspaceTemplate(\n workspaceName,\n templateName,\n options\n );\n return chalk.white(\n `${chalk.green(`\n\nCongrats! A new workspace has been created successfully at '${workspacePath}'`)}\n\nInside the directory '${workspaceName}' you can run various commands including:\n\n ${chalk.yellow('bit start')}\n Starts the workspace in development mode\n\n ${chalk.yellow('bit install')}\n Installs any missing dependencies\n\n ${chalk.yellow('bit status')}\n Shows the status of the components\n\n ${chalk.yellow('bit compile')}\n Compiles the components\n\n ${chalk.yellow('bit test')}\n Runs the tests on all your components\n\n ${chalk.yellow('bit templates')}\n Shows all available component templates\n\n ${chalk.yellow('bit help')}\n Shows all available commands\n\n\n${chalk.green.bold(\"Let's get started!\")}\n\n ${getBottomSection(workspaceName, appName)}\n `\n );\n }\n}\n\nfunction getBottomSection(workspaceName: string, appName: string | undefined) {\n const cdLine = chalk.yellow(`cd ${workspaceName}`);\n const parts = [cdLine];\n if (appName) {\n parts.push(chalk.yellow(` bit run ${appName}`));\n }\n parts.push(chalk.yellow(` bit start`));\n return parts.join('\\n');\n}\n"],"mappings":";;;;;;;;;;;;;;;;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAWO,MAAMA,MAAM,CAAoB;
|
1
|
+
{"version":3,"names":["NewCmd","constructor","generator","name","description","report","templateName","workspaceName","options","skipGit","standalone","aspect","env","template","workspacePath","appName","generateWorkspaceTemplate","chalk","white","green","yellow","bold","getBottomSection","cdLine","parts","push","join"],"sources":["new.cmd.ts"],"sourcesContent":["import { Command, CommandOptions } from '@teambit/cli';\nimport chalk from 'chalk';\nimport { GeneratorMain } from './generator.main.runtime';\n\nexport type NewOptions = {\n aspect?: string;\n defaultScope?: string;\n skipGit?: boolean;\n loadFrom?: string;\n empty?: boolean;\n};\n\nexport class NewCmd implements Command {\n name = 'new <template-name> <workspace-name>';\n description = 'create a new workspace from a template';\n arguments = [\n {\n name: 'template-name',\n description:\n \"the name of the workspace template (run 'bit templates', outside of a workspace, to get a list of available templates)\",\n },\n { name: 'workspace-name', description: 'the name for the new workspace and workspace directory' },\n ];\n alias = '';\n loader = true;\n group = 'start';\n options = [\n [\n 'a',\n 'aspect <aspect-id>',\n 'aspect-id of the template. mandatory for non-core aspects. helpful for core aspects in case of a name collision',\n ],\n ['t', 'template <env-id>', 'env-id of the template. alias for --env.'],\n ['', 'env <env-id>', 'env-id of the template'],\n ['d', 'default-scope <scope-name>', `set defaultScope in the new workspace.jsonc`],\n ['', 'standalone', 'DEPRECATED. use --skip-git instead'],\n ['s', 'skip-git', 'skip generation of Git repository'],\n ['e', 'empty', 'empty workspace with no components (relevant for templates that add components by default)'],\n [\n '',\n 'load-from <path-to-template>',\n 'path to the workspace containing the template. helpful during a development of a workspace-template',\n ],\n ] as CommandOptions;\n\n constructor(private generator: GeneratorMain) {}\n\n async report(\n [templateName, workspaceName]: [string, string],\n options: NewOptions & {\n standalone: boolean;\n env?: string;\n template?: string;\n }\n ) {\n options.skipGit = options.skipGit ?? options.standalone;\n options.aspect = options.aspect ?? options.env ?? options.template;\n const { workspacePath, appName } = await this.generator.generateWorkspaceTemplate(\n workspaceName,\n templateName,\n options\n );\n return chalk.white(\n `${chalk.green(`\n\nCongrats! A new workspace has been created successfully at '${workspacePath}'`)}\n\nInside the directory '${workspaceName}' you can run various commands including:\n\n ${chalk.yellow('bit start')}\n Starts the workspace in development mode\n\n ${chalk.yellow('bit install')}\n Installs any missing dependencies\n\n ${chalk.yellow('bit status')}\n Shows the status of the components\n\n ${chalk.yellow('bit compile')}\n Compiles the components\n\n ${chalk.yellow('bit test')}\n Runs the tests on all your components\n\n ${chalk.yellow('bit templates')}\n Shows all available component templates\n\n ${chalk.yellow('bit help')}\n Shows all available commands\n\n\n${chalk.green.bold(\"Let's get started!\")}\n\n ${getBottomSection(workspaceName, appName)}\n `\n );\n }\n}\n\nfunction getBottomSection(workspaceName: string, appName: string | undefined) {\n const cdLine = chalk.yellow(`cd ${workspaceName}`);\n const parts = [cdLine];\n if (appName) {\n parts.push(chalk.yellow(` bit run ${appName}`));\n }\n parts.push(chalk.yellow(` bit start`));\n return parts.join('\\n');\n}\n"],"mappings":";;;;;;;;;;;;;;;;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAWO,MAAMA,MAAM,CAAoB;EAiCrCC,WAAW,CAASC,SAAwB,EAAE;IAAA,KAA1BA,SAAwB,GAAxBA,SAAwB;IAAA,8CAhCrC,sCAAsC;IAAA,qDAC/B,wCAAwC;IAAA,mDAC1C,CACV;MACEC,IAAI,EAAE,eAAe;MACrBC,WAAW,EACT;IACJ,CAAC,EACD;MAAED,IAAI,EAAE,gBAAgB;MAAEC,WAAW,EAAE;IAAyD,CAAC,CAClG;IAAA,+CACO,EAAE;IAAA,gDACD,IAAI;IAAA,+CACL,OAAO;IAAA,iDACL,CACR,CACE,GAAG,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E;AACjC;AACA;AACA,QAAQH,gBAAK,CAACG,MAAM,CAAC,eAAe,CAAE;AACtC;AACA;AACA,QAAQH,gBAAK,CAACG,MAAM,CAAC,UAAU,CAAE;AACjC;AACA;AACA;AACA,EAAEH,gBAAK,CAACE,KAAK,CAACE,IAAI,CAAC,oBAAoB,CAAE;AACzC;AACA,QAAQC,gBAAgB,CAACf,aAAa,EAAEQ,OAAO,CAAE;AACjD,OAAO,CACF;EACH;AACF;AAAC;AAED,SAASO,gBAAgB,CAACf,aAAqB,EAAEQ,OAA2B,EAAE;EAC5E,MAAMQ,MAAM,GAAGN,gBAAK,CAACG,MAAM,CAAE,MAAKb,aAAc,EAAC,CAAC;EAClD,MAAMiB,KAAK,GAAG,CAACD,MAAM,CAAC;EACtB,IAAIR,OAAO,EAAE;IACXS,KAAK,CAACC,IAAI,CAACR,gBAAK,CAACG,MAAM,CAAE,iBAAgBL,OAAQ,EAAC,CAAC,CAAC;EACtD;EACAS,KAAK,CAACC,IAAI,CAACR,gBAAK,CAACG,MAAM,CAAE,iBAAgB,CAAC,CAAC;EAC3C,OAAOI,KAAK,CAACE,IAAI,CAAC,IAAI,CAAC;AACzB"}
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.generator_generator@0.0.
|
2
|
-
import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.generator_generator@0.0.
|
1
|
+
import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.generator_generator@0.0.1084/dist/generator.composition.js';
|
2
|
+
import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.generator_generator@0.0.1084/dist/generator.docs.mdx';
|
3
3
|
|
4
4
|
export const compositions = [compositions_0];
|
5
5
|
export const overview = [overview_0];
|
@@ -186,18 +186,21 @@ class WorkspaceGenerator {
|
|
186
186
|
const uiMain = this.harmony.get(_ui().default.id);
|
187
187
|
await uiMain.createRuntime({});
|
188
188
|
}
|
189
|
-
|
190
|
-
|
191
|
-
* writes the generated template files to the default directory set in the workspace config
|
192
|
-
*/
|
193
|
-
async writeWorkspaceFiles() {
|
194
|
-
const workspaceContext = {
|
189
|
+
getWorkspaceContext() {
|
190
|
+
return {
|
195
191
|
name: this.workspaceName,
|
196
192
|
defaultScope: this.options.defaultScope,
|
197
193
|
empty: this.options.empty,
|
198
194
|
aspectComponent: this.aspectComponent,
|
199
195
|
template: this.template
|
200
196
|
};
|
197
|
+
}
|
198
|
+
|
199
|
+
/**
|
200
|
+
* writes the generated template files to the default directory set in the workspace config
|
201
|
+
*/
|
202
|
+
async writeWorkspaceFiles() {
|
203
|
+
const workspaceContext = this.getWorkspaceContext();
|
201
204
|
const templateFiles = await this.template.generateFiles(workspaceContext);
|
202
205
|
await Promise.all(templateFiles.map(async templateFile => {
|
203
206
|
await _fsExtra().default.outputFile((0, _path().join)(this.workspacePath, templateFile.relativePath), templateFile.content);
|
@@ -215,7 +218,8 @@ class WorkspaceGenerator {
|
|
215
218
|
async forkComponentsFromRemote() {
|
216
219
|
var _this$template, _this$template$import, _this$template2, _this$template2$fork;
|
217
220
|
if (this.options.empty) return;
|
218
|
-
const
|
221
|
+
const workspaceContext = this.getWorkspaceContext();
|
222
|
+
const componentsToFork = ((_this$template = this.template) === null || _this$template === void 0 ? void 0 : (_this$template$import = _this$template.importComponents) === null || _this$template$import === void 0 ? void 0 : _this$template$import.call(_this$template, workspaceContext)) || ((_this$template2 = this.template) === null || _this$template2 === void 0 ? void 0 : (_this$template2$fork = _this$template2.fork) === null || _this$template2$fork === void 0 ? void 0 : _this$template2$fork.call(_this$template2, workspaceContext)) || [];
|
219
223
|
if (!componentsToFork.length) return;
|
220
224
|
const componentsToForkRestructured = componentsToFork.map(({
|
221
225
|
id,
|
@@ -237,7 +241,8 @@ class WorkspaceGenerator {
|
|
237
241
|
async importComponentsFromRemote() {
|
238
242
|
var _this$template3, _this$template3$impor;
|
239
243
|
if (this.options.empty) return;
|
240
|
-
const
|
244
|
+
const workspaceContext = this.getWorkspaceContext();
|
245
|
+
const componentsToImport = ((_this$template3 = this.template) === null || _this$template3 === void 0 ? void 0 : (_this$template3$impor = _this$template3.import) === null || _this$template3$impor === void 0 ? void 0 : _this$template3$impor.call(_this$template3, workspaceContext)) || [];
|
241
246
|
if (!componentsToImport.length) return;
|
242
247
|
await (0, _pMapSeries().default)(componentsToImport, async componentToImport => {
|
243
248
|
await this.importer.import({
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["WorkspaceGenerator","constructor","workspaceName","options","template","aspectComponent","workspacePath","resolve","generate","fs","existsSync","Error","ensureDir","process","chdir","initGit","init","skipGit","writeWorkspaceFiles","reloadBitInWorkspaceDir","forkComponentsFromRemote","importComponentsFromRemote","install","undefined","dedupe","import","copyPeerToRuntimeOnRoot","copyPeerToRuntimeOnComponents","updateExisting","err","logger","error","remove","gitExecutablePath","getGitExecutablePath","params","execa","exitCodeName","GitNotFound","buildUI","uiMain","harmony","get","UIAspect","id","createRuntime","workspaceContext","name","defaultScope","empty","templateFiles","generateFiles","Promise","all","map","templateFile","outputFile","join","relativePath","content","loadBit","workspace","WorkspaceAspect","InstallAspect","loggerMain","LoggerAspect","createLogger","GeneratorAspect","importer","ImporterAspect","forking","ForkingAspect","componentsToFork","importComponents","fork","length","componentsToForkRestructured","targetName","path","sourceId","targetId","forkMultipleFromRemote","scope","refactor","clearCache","compileComponents","componentsToImport","pMapSeries","componentToImport","ids","installNpmPackages","writeToPath","bitMap","write","compiler","CompilerAspect","compileOnWorkspace"],"sources":["workspace-generator.ts"],"sourcesContent":["import fs from 'fs-extra';\nimport { loadBit } from '@teambit/bit';\nimport { Harmony } from '@teambit/harmony';\nimport { Component } from '@teambit/component';\nimport execa from 'execa';\nimport pMapSeries from 'p-map-series';\nimport UIAspect, { UiMain } from '@teambit/ui';\nimport { Logger, LoggerAspect, LoggerMain } from '@teambit/logger';\nimport { WorkspaceAspect, Workspace } from '@teambit/workspace';\nimport ForkingAspect, { ForkingMain } from '@teambit/forking';\nimport { init } from '@teambit/legacy/dist/api/consumer';\nimport ImporterAspect, { ImporterMain } from '@teambit/importer';\nimport { CompilerAspect, CompilerMain } from '@teambit/compiler';\nimport getGitExecutablePath from '@teambit/legacy/dist/utils/git/git-executable';\nimport GitNotFound from '@teambit/legacy/dist/utils/git/exceptions/git-not-found';\nimport { resolve, join } from 'path';\nimport { ComponentID } from '@teambit/component-id';\nimport { InstallAspect, InstallMain } from '@teambit/install';\nimport { WorkspaceTemplate, WorkspaceContext } from './workspace-template';\nimport { NewOptions } from './new.cmd';\nimport { GeneratorAspect } from './generator.aspect';\n\nexport type GenerateResult = { id: ComponentID; dir: string; files: string[]; envId: string };\n\nexport class WorkspaceGenerator {\n private workspacePath: string;\n private harmony: Harmony;\n private workspace: Workspace;\n private install: InstallMain;\n private importer: ImporterMain;\n private logger: Logger;\n private forking: ForkingMain;\n constructor(\n private workspaceName: string,\n private options: NewOptions,\n private template: WorkspaceTemplate,\n private aspectComponent?: Component\n ) {\n this.workspacePath = resolve(this.workspaceName);\n }\n\n async generate(): Promise<string> {\n if (fs.existsSync(this.workspacePath)) {\n throw new Error(`unable to create a workspace at \"${this.workspaceName}\", this path already exist`);\n }\n await fs.ensureDir(this.workspacePath);\n try {\n process.chdir(this.workspacePath);\n await this.initGit();\n await init(this.workspacePath, this.options.skipGit, false, false, false, false, false, false, {});\n await this.writeWorkspaceFiles();\n await this.reloadBitInWorkspaceDir();\n await this.forkComponentsFromRemote();\n await this.importComponentsFromRemote();\n await this.install.install(undefined, {\n dedupe: true,\n import: false,\n copyPeerToRuntimeOnRoot: true,\n copyPeerToRuntimeOnComponents: false,\n updateExisting: false,\n });\n // await this.buildUI(); // disabled for now. it takes too long\n } catch (err: any) {\n this.logger.error(`failed generating a new workspace, will delete the dir ${this.workspacePath}`, err);\n await fs.remove(this.workspacePath);\n throw err;\n }\n\n return this.workspacePath;\n }\n\n private async initGit() {\n if (this.options.skipGit) return;\n const gitExecutablePath = getGitExecutablePath();\n const params = ['init'];\n try {\n await execa(gitExecutablePath, params);\n } catch (err: any) {\n if (err.exitCodeName === 'ENOENT') {\n throw new GitNotFound(gitExecutablePath, err);\n }\n throw err;\n }\n }\n\n private async buildUI() {\n const uiMain = this.harmony.get<UiMain>(UIAspect.id);\n await uiMain.createRuntime({});\n }\n\n /**\n * writes the generated template files to the default directory set in the workspace config\n */\n private async writeWorkspaceFiles(): Promise<void> {\n const workspaceContext: WorkspaceContext = {\n name: this.workspaceName,\n defaultScope: this.options.defaultScope,\n empty: this.options.empty,\n aspectComponent: this.aspectComponent,\n template: this.template,\n };\n const templateFiles = await this.template.generateFiles(workspaceContext);\n await Promise.all(\n templateFiles.map(async (templateFile) => {\n await fs.outputFile(join(this.workspacePath, templateFile.relativePath), templateFile.content);\n })\n );\n }\n\n private async reloadBitInWorkspaceDir() {\n this.harmony = await loadBit(this.workspacePath);\n this.workspace = this.harmony.get<Workspace>(WorkspaceAspect.id);\n this.install = this.harmony.get<InstallMain>(InstallAspect.id);\n const loggerMain = this.harmony.get<LoggerMain>(LoggerAspect.id);\n this.logger = loggerMain.createLogger(GeneratorAspect.id);\n this.importer = this.harmony.get<ImporterMain>(ImporterAspect.id);\n this.forking = this.harmony.get<ForkingMain>(ForkingAspect.id);\n }\n\n private async forkComponentsFromRemote() {\n if (this.options.empty) return;\n const componentsToFork = this.template?.importComponents?.() || this.template?.fork?.() || [];\n if (!componentsToFork.length) return;\n const componentsToForkRestructured = componentsToFork.map(({ id, targetName, path }) => ({\n sourceId: id,\n targetId: targetName,\n path,\n }));\n await this.forking.forkMultipleFromRemote(componentsToForkRestructured, {\n scope: this.workspace.defaultScope,\n refactor: true,\n install: false,\n });\n this.workspace.clearCache();\n await this.compileComponents();\n }\n\n private async importComponentsFromRemote() {\n if (this.options.empty) return;\n const componentsToImport = this.template?.import?.() || [];\n\n if (!componentsToImport.length) return;\n\n await pMapSeries(componentsToImport, async (componentToImport) => {\n await this.importer.import(\n {\n ids: [componentToImport.id],\n installNpmPackages: false,\n writeToPath: componentToImport.path,\n },\n []\n );\n });\n\n await this.workspace.bitMap.write();\n this.workspace.clearCache();\n await this.compileComponents();\n }\n\n private async compileComponents() {\n const compiler = this.harmony.get<CompilerMain>(CompilerAspect.id);\n await compiler.compileOnWorkspace();\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;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;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAGA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAIO,MAAMA,kBAAkB,CAAC;EAQ9BC,WAAW,CACDC,aAAqB,EACrBC,OAAmB,EACnBC,QAA2B,EAC3BC,eAA2B,EACnC;IAAA,KAJQH,aAAqB,GAArBA,aAAqB;IAAA,KACrBC,OAAmB,GAAnBA,OAAmB;IAAA,KACnBC,QAA2B,GAA3BA,QAA2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MACZoC,QAAQ,EAAEH,UAAU;MACpBC;IACF,CAAC,CAAC,CAAC;IACH,MAAM,IAAI,CAACR,OAAO,CAACW,sBAAsB,CAACL,4BAA4B,EAAE;MACtEM,KAAK,EAAE,IAAI,CAACrB,SAAS,CAACb,YAAY;MAClCmC,QAAQ,EAAE,IAAI;MACd7D,OAAO,EAAE;IACX,CAAC,CAAC;IACF,IAAI,CAACuC,SAAS,CAACuB,UAAU,EAAE;IAC3B,MAAM,IAAI,CAACC,iBAAiB,EAAE;EAChC;EAEA,MAAchE,0BAA0B,GAAG;IAAA;IACzC,IAAI,IAAI,CAAClB,OAAO,CAAC8C,KAAK,EAAE;IACxB,MAAMqC,kBAAkB,GAAG,wBAAI,CAAClF,QAAQ,6EAAb,gBAAeqB,MAAM,0DAArB,2CAAyB,KAAI,EAAE;IAE1D,IAAI,CAAC6D,kBAAkB,CAACX,MAAM,EAAE;IAEhC,MAAM,IAAAY,qBAAU,EAACD,kBAAkB,EAAE,MAAOE,iBAAiB,IAAK;MAChE,MAAM,IAAI,CAACpB,QAAQ,CAAC3C,MAAM,CACxB;QACEgE,GAAG,EAAE,CAACD,iBAAiB,CAAC5C,EAAE,CAAC;QAC3B8C,kBAAkB,EAAE,KAAK;QACzBC,WAAW,EAAEH,iBAAiB,CAACV;MACjC,CAAC,EACD,EAAE,CACH;IACH,CAAC,CAAC;IAEF,MAAM,IAAI,CAACjB,SAAS,CAAC+B,MAAM,CAACC,KAAK,EAAE;IACnC,IAAI,CAAChC,SAAS,CAACuB,UAAU,EAAE;IAC3B,MAAM,IAAI,CAACC,iBAAiB,EAAE;EAChC;EAEA,MAAcA,iBAAiB,GAAG;IAChC,MAAMS,QAAQ,GAAG,IAAI,CAACrD,OAAO,CAACC,GAAG,CAAeqD,0BAAc,CAACnD,EAAE,CAAC;IAClE,MAAMkD,QAAQ,CAACE,kBAAkB,EAAE;EACrC;AACF;AAAC"}
|
1
|
+
{"version":3,"names":["WorkspaceGenerator","constructor","workspaceName","options","template","aspectComponent","workspacePath","resolve","generate","fs","existsSync","Error","ensureDir","process","chdir","initGit","init","skipGit","writeWorkspaceFiles","reloadBitInWorkspaceDir","forkComponentsFromRemote","importComponentsFromRemote","install","undefined","dedupe","import","copyPeerToRuntimeOnRoot","copyPeerToRuntimeOnComponents","updateExisting","err","logger","error","remove","gitExecutablePath","getGitExecutablePath","params","execa","exitCodeName","GitNotFound","buildUI","uiMain","harmony","get","UIAspect","id","createRuntime","getWorkspaceContext","name","defaultScope","empty","workspaceContext","templateFiles","generateFiles","Promise","all","map","templateFile","outputFile","join","relativePath","content","loadBit","workspace","WorkspaceAspect","InstallAspect","loggerMain","LoggerAspect","createLogger","GeneratorAspect","importer","ImporterAspect","forking","ForkingAspect","componentsToFork","importComponents","fork","length","componentsToForkRestructured","targetName","path","sourceId","targetId","forkMultipleFromRemote","scope","refactor","clearCache","compileComponents","componentsToImport","pMapSeries","componentToImport","ids","installNpmPackages","writeToPath","bitMap","write","compiler","CompilerAspect","compileOnWorkspace"],"sources":["workspace-generator.ts"],"sourcesContent":["import fs from 'fs-extra';\nimport { loadBit } from '@teambit/bit';\nimport { Harmony } from '@teambit/harmony';\nimport { Component } from '@teambit/component';\nimport execa from 'execa';\nimport pMapSeries from 'p-map-series';\nimport UIAspect, { UiMain } from '@teambit/ui';\nimport { Logger, LoggerAspect, LoggerMain } from '@teambit/logger';\nimport { WorkspaceAspect, Workspace } from '@teambit/workspace';\nimport ForkingAspect, { ForkingMain } from '@teambit/forking';\nimport { init } from '@teambit/legacy/dist/api/consumer';\nimport ImporterAspect, { ImporterMain } from '@teambit/importer';\nimport { CompilerAspect, CompilerMain } from '@teambit/compiler';\nimport getGitExecutablePath from '@teambit/legacy/dist/utils/git/git-executable';\nimport GitNotFound from '@teambit/legacy/dist/utils/git/exceptions/git-not-found';\nimport { resolve, join } from 'path';\nimport { ComponentID } from '@teambit/component-id';\nimport { InstallAspect, InstallMain } from '@teambit/install';\nimport { WorkspaceTemplate, WorkspaceContext } from './workspace-template';\nimport { NewOptions } from './new.cmd';\nimport { GeneratorAspect } from './generator.aspect';\n\nexport type GenerateResult = { id: ComponentID; dir: string; files: string[]; envId: string };\n\nexport class WorkspaceGenerator {\n private workspacePath: string;\n private harmony: Harmony;\n private workspace: Workspace;\n private install: InstallMain;\n private importer: ImporterMain;\n private logger: Logger;\n private forking: ForkingMain;\n constructor(\n private workspaceName: string,\n private options: NewOptions,\n private template: WorkspaceTemplate,\n private aspectComponent?: Component\n ) {\n this.workspacePath = resolve(this.workspaceName);\n }\n\n async generate(): Promise<string> {\n if (fs.existsSync(this.workspacePath)) {\n throw new Error(`unable to create a workspace at \"${this.workspaceName}\", this path already exist`);\n }\n await fs.ensureDir(this.workspacePath);\n try {\n process.chdir(this.workspacePath);\n await this.initGit();\n await init(this.workspacePath, this.options.skipGit, false, false, false, false, false, false, {});\n await this.writeWorkspaceFiles();\n await this.reloadBitInWorkspaceDir();\n await this.forkComponentsFromRemote();\n await this.importComponentsFromRemote();\n await this.install.install(undefined, {\n dedupe: true,\n import: false,\n copyPeerToRuntimeOnRoot: true,\n copyPeerToRuntimeOnComponents: false,\n updateExisting: false,\n });\n // await this.buildUI(); // disabled for now. it takes too long\n } catch (err: any) {\n this.logger.error(`failed generating a new workspace, will delete the dir ${this.workspacePath}`, err);\n await fs.remove(this.workspacePath);\n throw err;\n }\n\n return this.workspacePath;\n }\n\n private async initGit() {\n if (this.options.skipGit) return;\n const gitExecutablePath = getGitExecutablePath();\n const params = ['init'];\n try {\n await execa(gitExecutablePath, params);\n } catch (err: any) {\n if (err.exitCodeName === 'ENOENT') {\n throw new GitNotFound(gitExecutablePath, err);\n }\n throw err;\n }\n }\n\n private async buildUI() {\n const uiMain = this.harmony.get<UiMain>(UIAspect.id);\n await uiMain.createRuntime({});\n }\n\n private getWorkspaceContext(): WorkspaceContext {\n return {\n name: this.workspaceName,\n defaultScope: this.options.defaultScope,\n empty: this.options.empty,\n aspectComponent: this.aspectComponent,\n template: this.template,\n };\n }\n\n /**\n * writes the generated template files to the default directory set in the workspace config\n */\n private async writeWorkspaceFiles(): Promise<void> {\n const workspaceContext = this.getWorkspaceContext();\n const templateFiles = await this.template.generateFiles(workspaceContext);\n await Promise.all(\n templateFiles.map(async (templateFile) => {\n await fs.outputFile(join(this.workspacePath, templateFile.relativePath), templateFile.content);\n })\n );\n }\n\n private async reloadBitInWorkspaceDir() {\n this.harmony = await loadBit(this.workspacePath);\n this.workspace = this.harmony.get<Workspace>(WorkspaceAspect.id);\n this.install = this.harmony.get<InstallMain>(InstallAspect.id);\n const loggerMain = this.harmony.get<LoggerMain>(LoggerAspect.id);\n this.logger = loggerMain.createLogger(GeneratorAspect.id);\n this.importer = this.harmony.get<ImporterMain>(ImporterAspect.id);\n this.forking = this.harmony.get<ForkingMain>(ForkingAspect.id);\n }\n\n private async forkComponentsFromRemote() {\n if (this.options.empty) return;\n const workspaceContext = this.getWorkspaceContext();\n const componentsToFork =\n this.template?.importComponents?.(workspaceContext) || this.template?.fork?.(workspaceContext) || [];\n if (!componentsToFork.length) return;\n const componentsToForkRestructured = componentsToFork.map(({ id, targetName, path }) => ({\n sourceId: id,\n targetId: targetName,\n path,\n }));\n await this.forking.forkMultipleFromRemote(componentsToForkRestructured, {\n scope: this.workspace.defaultScope,\n refactor: true,\n install: false,\n });\n this.workspace.clearCache();\n await this.compileComponents();\n }\n\n private async importComponentsFromRemote() {\n if (this.options.empty) return;\n const workspaceContext = this.getWorkspaceContext();\n const componentsToImport = this.template?.import?.(workspaceContext) || [];\n\n if (!componentsToImport.length) return;\n\n await pMapSeries(componentsToImport, async (componentToImport) => {\n await this.importer.import(\n {\n ids: [componentToImport.id],\n installNpmPackages: false,\n writeToPath: componentToImport.path,\n },\n []\n );\n });\n\n await this.workspace.bitMap.write();\n this.workspace.clearCache();\n await this.compileComponents();\n }\n\n private async compileComponents() {\n const compiler = this.harmony.get<CompilerMain>(CompilerAspect.id);\n await compiler.compileOnWorkspace();\n }\n}\n"],"mappings":";;;;;;;;;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;MACd9D,OAAO,EAAE;IACX,CAAC,CAAC;IACF,IAAI,CAACwC,SAAS,CAACuB,UAAU,EAAE;IAC3B,MAAM,IAAI,CAACC,iBAAiB,EAAE;EAChC;EAEA,MAAcjE,0BAA0B,GAAG;IAAA;IACzC,IAAI,IAAI,CAAClB,OAAO,CAAC8C,KAAK,EAAE;IACxB,MAAMC,gBAAgB,GAAG,IAAI,CAACJ,mBAAmB,EAAE;IACnD,MAAMyC,kBAAkB,GAAG,wBAAI,CAACnF,QAAQ,6EAAb,gBAAeqB,MAAM,0DAArB,4CAAwByB,gBAAgB,CAAC,KAAI,EAAE;IAE1E,IAAI,CAACqC,kBAAkB,CAACX,MAAM,EAAE;IAEhC,MAAM,IAAAY,qBAAU,EAACD,kBAAkB,EAAE,MAAOE,iBAAiB,IAAK;MAChE,MAAM,IAAI,CAACpB,QAAQ,CAAC5C,MAAM,CACxB;QACEiE,GAAG,EAAE,CAACD,iBAAiB,CAAC7C,EAAE,CAAC;QAC3B+C,kBAAkB,EAAE,KAAK;QACzBC,WAAW,EAAEH,iBAAiB,CAACV;MACjC,CAAC,EACD,EAAE,CACH;IACH,CAAC,CAAC;IAEF,MAAM,IAAI,CAACjB,SAAS,CAAC+B,MAAM,CAACC,KAAK,EAAE;IACnC,IAAI,CAAChC,SAAS,CAACuB,UAAU,EAAE;IAC3B,MAAM,IAAI,CAACC,iBAAiB,EAAE;EAChC;EAEA,MAAcA,iBAAiB,GAAG;IAChC,MAAMS,QAAQ,GAAG,IAAI,CAACtD,OAAO,CAACC,GAAG,CAAesD,0BAAc,CAACpD,EAAE,CAAC;IAClE,MAAMmD,QAAQ,CAACE,kBAAkB,EAAE;EACrC;AACF;AAAC"}
|
@@ -88,14 +88,14 @@ export interface WorkspaceTemplate {
|
|
88
88
|
* @deprecated use `fork()` or `import()` instead
|
89
89
|
* this is working similarly to `fork()`
|
90
90
|
*/
|
91
|
-
importComponents?: () => ForkComponentInfo[];
|
91
|
+
importComponents?: (context: WorkspaceContext) => ForkComponentInfo[];
|
92
92
|
/**
|
93
93
|
* import components into the new workspace, don't change their source code.
|
94
94
|
*/
|
95
|
-
import?: () => ImportComponentInfo[];
|
95
|
+
import?: (context: WorkspaceContext) => ImportComponentInfo[];
|
96
96
|
/**
|
97
97
|
* populate existing components into the new workspace and add them as new components.
|
98
98
|
* change their source code and update the dependency names according to the new component names.
|
99
99
|
*/
|
100
|
-
fork?: () => ForkComponentInfo[];
|
100
|
+
fork?: (context: WorkspaceContext) => ForkComponentInfo[];
|
101
101
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":[],"sources":["workspace-template.ts"],"sourcesContent":["import type { Component } from '@teambit/component';\n\nexport interface WorkspaceFile {\n /**\n * relative path of the file within the workspace.\n */\n relativePath: string;\n\n /**\n * file content\n */\n content: string;\n}\n\nexport interface WorkspaceContext {\n /**\n * workspace-name as entered by the user, e.g. `react-app`.\n * it is used as the directory name for the workspace.\n */\n name: string;\n\n /**\n * default scope as entered by the user.\n * it will be set in the workspace.jsonc and be used for components\n */\n defaultScope?: string;\n\n /**\n * whether user entered `--empty` flag in `bit new` to avoid creating components.\n */\n empty?: boolean;\n\n /**\n * in case the \"--aspect\" flag used to import a remote aspect, this is populated with that aspect.\n * useful to get the aspect-id and other info.\n */\n aspectComponent?: Component;\n\n /**\n * the template the user selected to create the workspace.\n */\n template: WorkspaceTemplate;\n}\n\nexport interface ForkComponentInfo {\n /**\n * full component id\n */\n id: string;\n\n /**\n * path where to write the component\n */\n path?: string;\n\n /**\n * a new component name. if not specified, use the original id (without the scope)\n */\n targetName?: string;\n}\n\n/**\n * @deprecated use ForkComponentInfo instead.\n */\nexport type ComponentToImport = ForkComponentInfo;\n\nexport interface ImportComponentInfo {\n /**\n * full component id\n */\n id: string;\n\n /**\n * path where to write the component\n */\n path: string;\n}\n\nexport interface WorkspaceTemplate {\n /**\n * name of the workspace template. for example: `react-workspace`.\n */\n name: string;\n\n /**\n * name of an app created in the workspace. for example: `my-app`.\n * This will be used to instruct the user to run `bit run <appName>` in the new workspace.\n */\n appName?: string;\n\n /**\n * short description of the template. shown in the `bit templates` command when outside of bit-workspace.\n */\n description?: string;\n\n /**\n * hide this template so that it is not listed with `bit templates`\n */\n hidden?: boolean;\n\n /**\n * template function for generating the template files,\n */\n generateFiles(context: WorkspaceContext): Promise<WorkspaceFile[]>;\n\n /**\n * @deprecated use `fork()` or `import()` instead\n * this is working similarly to `fork()`\n */\n importComponents?: () => ForkComponentInfo[];\n\n /**\n * import components into the new workspace, don't change their source code.\n */\n import?: () => ImportComponentInfo[];\n\n /**\n * populate existing components into the new workspace and add them as new components.\n * change their source code and update the dependency names according to the new component names.\n */\n fork?: () => ForkComponentInfo[];\n}\n"],"mappings":""}
|
1
|
+
{"version":3,"names":[],"sources":["workspace-template.ts"],"sourcesContent":["import type { Component } from '@teambit/component';\n\nexport interface WorkspaceFile {\n /**\n * relative path of the file within the workspace.\n */\n relativePath: string;\n\n /**\n * file content\n */\n content: string;\n}\n\nexport interface WorkspaceContext {\n /**\n * workspace-name as entered by the user, e.g. `react-app`.\n * it is used as the directory name for the workspace.\n */\n name: string;\n\n /**\n * default scope as entered by the user.\n * it will be set in the workspace.jsonc and be used for components\n */\n defaultScope?: string;\n\n /**\n * whether user entered `--empty` flag in `bit new` to avoid creating components.\n */\n empty?: boolean;\n\n /**\n * in case the \"--aspect\" flag used to import a remote aspect, this is populated with that aspect.\n * useful to get the aspect-id and other info.\n */\n aspectComponent?: Component;\n\n /**\n * the template the user selected to create the workspace.\n */\n template: WorkspaceTemplate;\n}\n\nexport interface ForkComponentInfo {\n /**\n * full component id\n */\n id: string;\n\n /**\n * path where to write the component\n */\n path?: string;\n\n /**\n * a new component name. if not specified, use the original id (without the scope)\n */\n targetName?: string;\n}\n\n/**\n * @deprecated use ForkComponentInfo instead.\n */\nexport type ComponentToImport = ForkComponentInfo;\n\nexport interface ImportComponentInfo {\n /**\n * full component id\n */\n id: string;\n\n /**\n * path where to write the component\n */\n path: string;\n}\n\nexport interface WorkspaceTemplate {\n /**\n * name of the workspace template. for example: `react-workspace`.\n */\n name: string;\n\n /**\n * name of an app created in the workspace. for example: `my-app`.\n * This will be used to instruct the user to run `bit run <appName>` in the new workspace.\n */\n appName?: string;\n\n /**\n * short description of the template. shown in the `bit templates` command when outside of bit-workspace.\n */\n description?: string;\n\n /**\n * hide this template so that it is not listed with `bit templates`\n */\n hidden?: boolean;\n\n /**\n * template function for generating the template files,\n */\n generateFiles(context: WorkspaceContext): Promise<WorkspaceFile[]>;\n\n /**\n * @deprecated use `fork()` or `import()` instead\n * this is working similarly to `fork()`\n */\n importComponents?: (context: WorkspaceContext) => ForkComponentInfo[];\n\n /**\n * import components into the new workspace, don't change their source code.\n */\n import?: (context: WorkspaceContext) => ImportComponentInfo[];\n\n /**\n * populate existing components into the new workspace and add them as new components.\n * change their source code and update the dependency names according to the new component names.\n */\n fork?: (context: WorkspaceContext) => ForkComponentInfo[];\n}\n"],"mappings":""}
|
Binary file
|
package/package.json
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
{
|
2
2
|
"name": "@teambit/generator",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.1084",
|
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": "0.0.
|
9
|
+
"version": "0.0.1084"
|
10
10
|
},
|
11
11
|
"dependencies": {
|
12
12
|
"camelcase": "6.2.0",
|
@@ -22,23 +22,23 @@
|
|
22
22
|
"@teambit/component-id": "0.0.427",
|
23
23
|
"@teambit/harmony": "0.4.6",
|
24
24
|
"@teambit/bit-error": "0.0.402",
|
25
|
-
"@teambit/envs": "0.0.
|
26
|
-
"@teambit/logger": "0.0.
|
27
|
-
"@teambit/new-component-helper": "0.0.
|
28
|
-
"@teambit/tracker": "0.0.
|
29
|
-
"@teambit/workspace.modules.node-modules-linker": "0.0.
|
30
|
-
"@teambit/workspace": "0.0.
|
31
|
-
"@teambit/cli": "0.0.
|
32
|
-
"@teambit/graphql": "0.0.
|
33
|
-
"@teambit/aspect-loader": "0.0.
|
34
|
-
"@teambit/bit": "0.1.
|
35
|
-
"@teambit/community": "0.0.
|
36
|
-
"@teambit/component": "0.0.
|
37
|
-
"@teambit/compiler": "0.0.
|
38
|
-
"@teambit/forking": "0.0.
|
39
|
-
"@teambit/importer": "0.0.
|
40
|
-
"@teambit/install": "0.0.
|
41
|
-
"@teambit/ui": "0.0.
|
25
|
+
"@teambit/envs": "0.0.1084",
|
26
|
+
"@teambit/logger": "0.0.821",
|
27
|
+
"@teambit/new-component-helper": "0.0.488",
|
28
|
+
"@teambit/tracker": "0.0.115",
|
29
|
+
"@teambit/workspace.modules.node-modules-linker": "0.0.72",
|
30
|
+
"@teambit/workspace": "0.0.1084",
|
31
|
+
"@teambit/cli": "0.0.728",
|
32
|
+
"@teambit/graphql": "0.0.1084",
|
33
|
+
"@teambit/aspect-loader": "0.0.1084",
|
34
|
+
"@teambit/bit": "0.1.71",
|
35
|
+
"@teambit/community": "0.0.276",
|
36
|
+
"@teambit/component": "0.0.1084",
|
37
|
+
"@teambit/compiler": "0.0.1084",
|
38
|
+
"@teambit/forking": "0.0.488",
|
39
|
+
"@teambit/importer": "0.0.513",
|
40
|
+
"@teambit/install": "0.0.186",
|
41
|
+
"@teambit/ui": "0.0.1084"
|
42
42
|
},
|
43
43
|
"devDependencies": {
|
44
44
|
"@types/fs-extra": "9.0.7",
|
@@ -52,7 +52,7 @@
|
|
52
52
|
"@teambit/generator.aspect-docs.generator": "0.0.157"
|
53
53
|
},
|
54
54
|
"peerDependencies": {
|
55
|
-
"@teambit/legacy": "1.0.
|
55
|
+
"@teambit/legacy": "1.0.509",
|
56
56
|
"react": "^16.8.0 || ^17.0.0",
|
57
57
|
"react-dom": "^16.8.0 || ^17.0.0"
|
58
58
|
},
|
Binary file
|