@teambit/generator 0.0.676 → 0.0.679
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.d.ts +2 -1
- package/dist/component-generator.js +13 -4
- package/dist/component-generator.js.map +1 -1
- package/dist/component-template.d.ts +7 -1
- package/dist/create.cmd.d.ts +2 -1
- package/dist/create.cmd.js +3 -2
- package/dist/create.cmd.js.map +1 -1
- package/dist/generator.composition.d.ts +2 -0
- package/dist/generator.composition.js +35 -0
- package/dist/generator.composition.js.map +1 -0
- package/dist/generator.docs.mdx +1 -1
- package/dist/generator.main.runtime.d.ts +8 -3
- package/dist/generator.main.runtime.js +17 -7
- package/dist/generator.main.runtime.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/dist/new.cmd.js.map +1 -1
- package/generator.composition.tsx +7 -0
- package/generator.docs.mdx +1 -1
- package/package-tar/teambit-generator-0.0.679.tgz +0 -0
- package/package.json +21 -20
- package/preview-1647509820722.js +2 -0
- package/package-tar/teambit-generator-0.0.676.tgz +0 -0
- package/preview-1647314610121.js +0 -1
|
@@ -17,7 +17,8 @@ export declare class ComponentGenerator {
|
|
|
17
17
|
private template;
|
|
18
18
|
private envs;
|
|
19
19
|
private newComponentHelper;
|
|
20
|
-
|
|
20
|
+
private aspectId;
|
|
21
|
+
constructor(workspace: Workspace, componentIds: ComponentID[], options: CreateOptions, template: ComponentTemplate, envs: EnvsMain, newComponentHelper: NewComponentHelperMain, aspectId: string);
|
|
21
22
|
generate(): Promise<GenerateResult[]>;
|
|
22
23
|
private deleteGeneratedComponents;
|
|
23
24
|
private generateOneComponent;
|
|
@@ -102,13 +102,14 @@ function _dataToPersist() {
|
|
|
102
102
|
}
|
|
103
103
|
|
|
104
104
|
class ComponentGenerator {
|
|
105
|
-
constructor(workspace, componentIds, options, template, envs, newComponentHelper) {
|
|
105
|
+
constructor(workspace, componentIds, options, template, envs, newComponentHelper, aspectId) {
|
|
106
106
|
this.workspace = workspace;
|
|
107
107
|
this.componentIds = componentIds;
|
|
108
108
|
this.options = options;
|
|
109
109
|
this.template = template;
|
|
110
110
|
this.envs = envs;
|
|
111
111
|
this.newComponentHelper = newComponentHelper;
|
|
112
|
+
this.aspectId = aspectId;
|
|
112
113
|
}
|
|
113
114
|
|
|
114
115
|
async generate() {
|
|
@@ -164,18 +165,26 @@ class ComponentGenerator {
|
|
|
164
165
|
componentId
|
|
165
166
|
});
|
|
166
167
|
const mainFile = files.find(file => file.isMain);
|
|
167
|
-
|
|
168
|
+
let config = this.template.config;
|
|
169
|
+
|
|
170
|
+
if (config && typeof config === 'function') {
|
|
171
|
+
config = config({
|
|
172
|
+
aspectId: this.aspectId
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const configWithEnv = this.addEnvIfProvidedByUser(config);
|
|
168
177
|
await this.writeComponentFiles(componentPath, files);
|
|
169
178
|
const addResults = await this.workspace.track({
|
|
170
179
|
rootDir: componentPath,
|
|
171
180
|
mainFile: mainFile === null || mainFile === void 0 ? void 0 : mainFile.relativePath,
|
|
172
181
|
componentName: componentId.fullName,
|
|
173
182
|
defaultScope: this.options.scope,
|
|
174
|
-
config
|
|
183
|
+
config: configWithEnv
|
|
175
184
|
});
|
|
176
185
|
const component = await this.workspace.get(componentId);
|
|
177
186
|
const env = this.envs.getEnv(component);
|
|
178
|
-
await this.removeOtherEnvs(component, env,
|
|
187
|
+
await this.removeOtherEnvs(component, env, configWithEnv);
|
|
179
188
|
return {
|
|
180
189
|
id: componentId,
|
|
181
190
|
dir: componentPath,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["component-generator.ts"],"names":["ComponentGenerator","constructor","workspace","componentIds","options","template","envs","newComponentHelper","generate","dirsToDeleteIfFailed","generateResults","componentId","componentPath","getNewComponentPath","path","fs","existsSync","join","BitError","hasName","fullName","push","generateOneComponent","err","deleteGeneratedComponents","bitMap","write","dirs","Promise","all","map","dir","absoluteDir","remove","code","name","namePascalCase","pascalCase","nameCamelCase","files","generateFiles","mainFile","find","file","isMain","config","addEnvIfProvidedByUser","writeComponentFiles","addResults","track","rootDir","relativePath","componentName","defaultScope","scope","component","get","env","getEnv","removeOtherEnvs","id","envId","userEnv","templateEnv","EnvsAspect","envFromTemplate","envsNotFromConfig","getEnvsNotFromEnvsConfig","envDef","envsToRemove","filter","forEach","bitMapRecord","getBitmapEntry","templateFiles","dataToPersist","DataToPersist","vinylFiles","templateFile","templateFileVinyl","Vinyl","base","contents","Buffer","from","content","AbstractVinyl","fromVinyl","results","v","addManyFiles","addBasePath","persistAllToFS"],"mappings":";;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAQO,MAAMA,kBAAN,CAAyB;AAC9BC,EAAAA,WAAW,CACDC,SADC,EAEDC,YAFC,EAGDC,OAHC,EAIDC,QAJC,EAKDC,IALC,EAMDC,kBANC,EAOT;AAAA,SANQL,SAMR,GANQA,SAMR;AAAA,SALQC,YAKR,GALQA,YAKR;AAAA,SAJQC,OAIR,GAJQA,OAIR;AAAA,SAHQC,QAGR,GAHQA,QAGR;AAAA,SAFQC,IAER,GAFQA,IAER;AAAA,SADQC,kBACR,GADQA,kBACR;AAAE;;AAEU,QAARC,QAAQ,GAA8B;AAC1C,UAAMC,oBAA8B,GAAG,EAAvC;AAC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ACiB,cAAd,EAAN;AACA,WAAOJ,OAAP;AACD;;AAhI6B","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, { EnvDefinition, EnvsMain } from '@teambit/envs';\nimport { Component } from '@teambit/component';\nimport camelcase from 'camelcase';\nimport { BitError } from '@teambit/bit-error';\nimport { PathOsBasedRelative } from '@teambit/legacy/dist/utils/path';\nimport { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';\nimport DataToPersist from '@teambit/legacy/dist/consumer/component/sources/data-to-persist';\nimport { NewComponentHelperMain } from '@teambit/new-component-helper';\nimport { ComponentID } from '@teambit/component-id';\nimport { ComponentTemplate, ComponentFile, ComponentConfig } from './component-template';\nimport { CreateOptions } from './create.cmd';\n\nexport type GenerateResult = { id: ComponentID; dir: string; files: string[]; envId: string };\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 ) {}\n\n async generate(): Promise<GenerateResult[]> {\n const dirsToDeleteIfFailed: string[] = [];\n const generateResults = await pMapSeries(this.componentIds, async (componentId) => {\n try {\n const componentPath = this.newComponentHelper.getNewComponentPath(componentId, this.options.path);\n if (fs.existsSync(path.join(this.workspace.path, componentPath))) {\n throw new BitError(`unable to create a component at \"${componentPath}\", this path already exist`);\n }\n if (await this.workspace.hasName(componentId.fullName)) {\n throw new BitError(\n `unable to create a component \"${componentId.fullName}\", a component with the same name already exist`\n );\n }\n dirsToDeleteIfFailed.push(componentPath);\n return await this.generateOneComponent(componentId, componentPath);\n } catch (err: any) {\n await this.deleteGeneratedComponents(dirsToDeleteIfFailed);\n throw err;\n }\n });\n\n await this.workspace.bitMap.write();\n\n return generateResults;\n }\n\n private async deleteGeneratedComponents(dirs: string[]) {\n await Promise.all(\n dirs.map(async (dir) => {\n const absoluteDir = path.join(this.workspace.path, dir);\n try {\n await fs.remove(absoluteDir);\n } catch (err: any) {\n if (err.code !== 'ENOENT') {\n // if not exist, it's fine\n throw err;\n }\n }\n })\n );\n }\n\n private async generateOneComponent(componentId: ComponentID, componentPath: string): Promise<GenerateResult> {\n const name = componentId.name;\n const namePascalCase = camelcase(name, { pascalCase: true });\n const nameCamelCase = camelcase(name);\n const files = this.template.generateFiles({ name, namePascalCase, nameCamelCase, componentId });\n const mainFile = files.find((file) => file.isMain);\n const config = this.addEnvIfProvidedByUser(this.template.config);\n await this.writeComponentFiles(componentPath, files);\n const addResults = await this.workspace.track({\n rootDir: componentPath,\n mainFile: mainFile?.relativePath,\n componentName: componentId.fullName,\n defaultScope: this.options.scope,\n config,\n });\n const component = await this.workspace.get(componentId);\n const env = this.envs.getEnv(component);\n await this.removeOtherEnvs(component, env, config);\n return {\n id: componentId,\n dir: componentPath,\n files: addResults.files,\n envId: env.id,\n };\n }\n\n private addEnvIfProvidedByUser(config?: ComponentConfig): 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 config[userEnv] = {};\n config[EnvsAspect.id] = config[EnvsAspect.id] || {};\n config[EnvsAspect.id].env = userEnv;\n return config;\n }\n\n private async removeOtherEnvs(component: Component, env: EnvDefinition, config?: ComponentConfig) {\n const envFromTemplate = config?.[EnvsAspect.id]?.env;\n if (!envFromTemplate) {\n return;\n }\n const envsNotFromConfig = this.envs.getEnvsNotFromEnvsConfig(component).map((envDef) => envDef.id);\n const envsToRemove = envsNotFromConfig.filter((envId) => envId !== envFromTemplate);\n envsToRemove.forEach((envId) => (config[envId] = '-'));\n const bitMapRecord = this.workspace.bitMap.getBitmapEntry(component.id);\n bitMapRecord.config = 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"]}
|
|
1
|
+
{"version":3,"sources":["component-generator.ts"],"names":["ComponentGenerator","constructor","workspace","componentIds","options","template","envs","newComponentHelper","aspectId","generate","dirsToDeleteIfFailed","generateResults","componentId","componentPath","getNewComponentPath","path","fs","existsSync","join","BitError","hasName","fullName","push","generateOneComponent","err","deleteGeneratedComponents","bitMap","write","dirs","Promise","all","map","dir","absoluteDir","remove","code","name","namePascalCase","pascalCase","nameCamelCase","files","generateFiles","mainFile","find","file","isMain","config","configWithEnv","addEnvIfProvidedByUser","writeComponentFiles","addResults","track","rootDir","relativePath","componentName","defaultScope","scope","component","get","env","getEnv","removeOtherEnvs","id","envId","userEnv","templateEnv","EnvsAspect","envFromTemplate","envsNotFromConfig","getEnvsNotFromEnvsConfig","envDef","envsToRemove","filter","forEach","bitMapRecord","getBitmapEntry","templateFiles","dataToPersist","DataToPersist","vinylFiles","templateFile","templateFileVinyl","Vinyl","base","contents","Buffer","from","content","AbstractVinyl","fromVinyl","results","v","addManyFiles","addBasePath","persistAllToFS"],"mappings":";;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;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AAqClB,SAAS,CAACK,EAA/C,CAArB;AACAY,IAAAA,YAAY,CAAC5B,MAAb,GAAsBA,MAAtB;AACD;AAED;AACF;AACA;;;AACmC,QAAnBG,mBAAmB,CAC/BpC,aAD+B,EAE/B+D,aAF+B,EAGC;AAChC,UAAMC,aAAa,GAAG,KAAIC,wBAAJ,GAAtB;AACA,UAAMC,UAAU,GAAGH,aAAa,CAAC7C,GAAd,CAAmBiD,YAAD,IAAkB;AACrD,YAAMC,iBAAiB,GAAG,KAAIC,gBAAJ,EAAU;AAClCC,QAAAA,IAAI,EAAEtE,aAD4B;AAElCE,QAAAA,IAAI,EAAEA,gBAAKG,IAAL,CAAUL,aAAV,EAAyBmE,YAAY,CAAC3B,YAAtC,CAF4B;AAGlC+B,QAAAA,QAAQ,EAAEC,MAAM,CAACC,IAAP,CAAYN,YAAY,CAACO,OAAzB;AAHwB,OAAV,CAA1B;AAKA,aAAOC,yBAAcC,SAAd,CAAwBR,iBAAxB,CAAP;AACD,KAPkB,CAAnB;AAQA,UAAMS,OAAO,GAAGX,UAAU,CAAChD,GAAX,CAAgB4D,CAAD,IAAOA,CAAC,CAAC5E,IAAxB,CAAhB;AACA8D,IAAAA,aAAa,CAACe,YAAd,CAA2Bb,UAA3B;AACAF,IAAAA,aAAa,CAACgB,WAAd,CAA0B,KAAK3F,SAAL,CAAea,IAAzC;AACA,UAAM8D,aAAa,CAACiB,cAAd,EAAN;AACA,WAAOJ,OAAP;AACD;;AArI6B","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, { EnvDefinition, EnvsMain } from '@teambit/envs';\nimport { Component } from '@teambit/component';\nimport camelcase from 'camelcase';\nimport { BitError } from '@teambit/bit-error';\nimport { PathOsBasedRelative } from '@teambit/legacy/dist/utils/path';\nimport { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';\nimport DataToPersist from '@teambit/legacy/dist/consumer/component/sources/data-to-persist';\nimport { NewComponentHelperMain } from '@teambit/new-component-helper';\nimport { ComponentID } from '@teambit/component-id';\nimport { ComponentTemplate, ComponentFile, ComponentConfig } from './component-template';\nimport { CreateOptions } from './create.cmd';\n\nexport type GenerateResult = { id: ComponentID; dir: string; files: string[]; envId: string };\n\nexport class ComponentGenerator {\n constructor(\n private workspace: Workspace,\n private componentIds: ComponentID[],\n private options: CreateOptions,\n private template: ComponentTemplate,\n private envs: EnvsMain,\n private newComponentHelper: NewComponentHelperMain,\n private aspectId: string\n ) {}\n\n async generate(): Promise<GenerateResult[]> {\n const dirsToDeleteIfFailed: string[] = [];\n const generateResults = await pMapSeries(this.componentIds, async (componentId) => {\n try {\n const componentPath = this.newComponentHelper.getNewComponentPath(componentId, this.options.path);\n if (fs.existsSync(path.join(this.workspace.path, componentPath))) {\n throw new BitError(`unable to create a component at \"${componentPath}\", this path already exist`);\n }\n if (await this.workspace.hasName(componentId.fullName)) {\n throw new BitError(\n `unable to create a component \"${componentId.fullName}\", a component with the same name already exist`\n );\n }\n dirsToDeleteIfFailed.push(componentPath);\n return await this.generateOneComponent(componentId, componentPath);\n } catch (err: any) {\n await this.deleteGeneratedComponents(dirsToDeleteIfFailed);\n throw err;\n }\n });\n\n await this.workspace.bitMap.write();\n\n return generateResults;\n }\n\n private async deleteGeneratedComponents(dirs: string[]) {\n await Promise.all(\n dirs.map(async (dir) => {\n const absoluteDir = path.join(this.workspace.path, dir);\n try {\n await fs.remove(absoluteDir);\n } catch (err: any) {\n if (err.code !== 'ENOENT') {\n // if not exist, it's fine\n throw err;\n }\n }\n })\n );\n }\n\n private async generateOneComponent(componentId: ComponentID, componentPath: string): Promise<GenerateResult> {\n const name = componentId.name;\n const namePascalCase = camelcase(name, { pascalCase: true });\n const nameCamelCase = camelcase(name);\n const files = this.template.generateFiles({ name, namePascalCase, nameCamelCase, componentId });\n const mainFile = files.find((file) => file.isMain);\n let config = this.template.config;\n if (config && typeof config === 'function') {\n config = config({ aspectId: this.aspectId });\n }\n const configWithEnv = this.addEnvIfProvidedByUser(config);\n await this.writeComponentFiles(componentPath, files);\n const addResults = await this.workspace.track({\n rootDir: componentPath,\n mainFile: mainFile?.relativePath,\n componentName: componentId.fullName,\n defaultScope: this.options.scope,\n config: configWithEnv,\n });\n const component = await this.workspace.get(componentId);\n const env = this.envs.getEnv(component);\n await this.removeOtherEnvs(component, env, configWithEnv);\n return {\n id: componentId,\n dir: componentPath,\n files: addResults.files,\n envId: env.id,\n };\n }\n\n private addEnvIfProvidedByUser(config?: ComponentConfig): 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 config[userEnv] = {};\n config[EnvsAspect.id] = config[EnvsAspect.id] || {};\n config[EnvsAspect.id].env = userEnv;\n return config;\n }\n\n private async removeOtherEnvs(component: Component, env: EnvDefinition, config?: ComponentConfig) {\n const envFromTemplate = config?.[EnvsAspect.id]?.env;\n if (!envFromTemplate) {\n return;\n }\n const envsNotFromConfig = this.envs.getEnvsNotFromEnvsConfig(component).map((envDef) => envDef.id);\n const envsToRemove = envsNotFromConfig.filter((envId) => envId !== envFromTemplate);\n envsToRemove.forEach((envId) => (config[envId] = '-'));\n const bitMapRecord = this.workspace.bitMap.getBitmapEntry(component.id);\n bitMapRecord.config = 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"]}
|
|
@@ -35,6 +35,12 @@ export interface ComponentContext {
|
|
|
35
35
|
*/
|
|
36
36
|
componentId: ComponentID;
|
|
37
37
|
}
|
|
38
|
+
export interface ConfigContext {
|
|
39
|
+
/**
|
|
40
|
+
* Aspect id of the aspect that register the template itself
|
|
41
|
+
*/
|
|
42
|
+
aspectId: string;
|
|
43
|
+
}
|
|
38
44
|
export declare type ComponentConfig = {
|
|
39
45
|
[aspectName: string]: any;
|
|
40
46
|
};
|
|
@@ -62,5 +68,5 @@ export interface ComponentTemplate {
|
|
|
62
68
|
* "env": "teambit.harmony/aspect"
|
|
63
69
|
* },
|
|
64
70
|
*/
|
|
65
|
-
config?: ComponentConfig;
|
|
71
|
+
config?: ComponentConfig | ((context: ConfigContext) => ComponentConfig);
|
|
66
72
|
}
|
package/dist/create.cmd.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export declare type CreateOptions = {
|
|
|
9
9
|
};
|
|
10
10
|
export declare class CreateCmd implements Command {
|
|
11
11
|
private generator;
|
|
12
|
+
private docsDomain;
|
|
12
13
|
name: string;
|
|
13
14
|
description: string;
|
|
14
15
|
shortDescription: string;
|
|
@@ -16,6 +17,6 @@ export declare class CreateCmd implements Command {
|
|
|
16
17
|
loader: boolean;
|
|
17
18
|
group: string;
|
|
18
19
|
options: CommandOptions;
|
|
19
|
-
constructor(generator: GeneratorMain);
|
|
20
|
+
constructor(generator: GeneratorMain, docsDomain: string);
|
|
20
21
|
report([templateName, componentNames]: [string, string[]], options: CreateOptions): Promise<string>;
|
|
21
22
|
}
|
package/dist/create.cmd.js
CHANGED
|
@@ -32,8 +32,9 @@ function _chalk() {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
class CreateCmd {
|
|
35
|
-
constructor(generator) {
|
|
35
|
+
constructor(generator, docsDomain) {
|
|
36
36
|
this.generator = generator;
|
|
37
|
+
this.docsDomain = docsDomain;
|
|
37
38
|
(0, _defineProperty2().default)(this, "name", 'create <templateName> <componentNames...>');
|
|
38
39
|
(0, _defineProperty2().default)(this, "description", 'create a new component from a template');
|
|
39
40
|
(0, _defineProperty2().default)(this, "shortDescription", '');
|
|
@@ -52,7 +53,7 @@ class CreateCmd {
|
|
|
52
53
|
env: ${result.envId}
|
|
53
54
|
`;
|
|
54
55
|
}).join('\n');
|
|
55
|
-
const footer = `env configuration is according to workspace variants, template config or --env flag. learn more at https
|
|
56
|
+
const footer = `env configuration is according to workspace variants, template config or --env flag. learn more at https://${this.docsDomain}/envs/using-envs`;
|
|
56
57
|
return `${_chalk().default.green(title)}\n\n${componentsData}\n\n${footer}`;
|
|
57
58
|
}
|
|
58
59
|
|
package/dist/create.cmd.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["create.cmd.ts"],"names":["CreateCmd","constructor","generator","report","templateName","componentNames","options","results","generateComponentTemplate","title","length","componentsData","map","result","chalk","bold","id","toString","dir","envId","join","footer","green"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAWO,MAAMA,SAAN,CAAmC;AAexCC,EAAAA,WAAW,CAASC,SAAT,
|
|
1
|
+
{"version":3,"sources":["create.cmd.ts"],"names":["CreateCmd","constructor","generator","docsDomain","report","templateName","componentNames","options","results","generateComponentTemplate","title","length","componentsData","map","result","chalk","bold","id","toString","dir","envId","join","footer","green"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAWO,MAAMA,SAAN,CAAmC;AAexCC,EAAAA,WAAW,CAASC,SAAT,EAA2CC,UAA3C,EAA+D;AAAA,SAAtDD,SAAsD,GAAtDA,SAAsD;AAAA,SAApBC,UAAoB,GAApBA,UAAoB;AAAA,kDAdnE,2CAcmE;AAAA,yDAb5D,wCAa4D;AAAA,8DAZvD,EAYuD;AAAA,mDAXlE,EAWkE;AAAA,oDAVjE,IAUiE;AAAA,mDATlE,aASkE;AAAA,qDARhE,CACR,CAAC,GAAD,EAAM,oBAAN,EAA6B,iEAA7B,CADQ,EAER,CAAC,GAAD,EAAM,gBAAN,EAAyB,iFAAzB,CAFQ,EAGR,CAAC,GAAD,EAAM,iBAAN,EAAyB,qFAAzB,CAHQ,EAIR,CAAC,GAAD,EAAM,eAAN,EAAuB,qFAAvB,CAJQ,EAKR,CAAC,GAAD,EAAM,cAAN,EAAsB,qFAAtB,CALQ,CAQgE;AAAE;;AAEhE,QAANC,MAAM,CAAC,CAACC,YAAD,EAAeC,cAAf,CAAD,EAAqDC,OAArD,EAA6E;AACvF,UAAMC,OAAO,GAAG,MAAM,KAAKN,SAAL,CAAeO,yBAAf,CAAyCH,cAAzC,EAAyDD,YAAzD,EAAuEE,OAAvE,CAAtB;AACA,UAAMG,KAAK,GAAI,GAAEF,OAAO,CAACG,MAAO,4BAAhC;AAEA,UAAMC,cAAc,GAAGJ,OAAO,CAC3BK,GADoB,CACfC,MAAD,IAAY;AACf,aAAQ,GAAEC,iBAAMC,IAAN,CAAWF,MAAM,CAACG,EAAP,CAAUC,QAAV,EAAX,CAAiC;AACnD,gBAAgBJ,MAAM,CAACK,GAAI;AAC3B,gBAAgBL,MAAM,CAACM,KAAM;AAC7B,CAHQ;AAID,KANoB,EAOpBC,IAPoB,CAOf,IAPe,CAAvB;AAQA,UAAMC,MAAM,GAAI,8GAA6G,KAAKnB,UAAW,kBAA7I;AAEA,WAAQ,GAAEY,iBAAMQ,KAAN,CAAYb,KAAZ,CAAmB,OAAME,cAAe,OAAMU,MAAO,EAA/D;AACD;;AAhCuC","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 <templateName> <componentNames...>';\n description = 'create a new component from a template';\n shortDescription = '';\n alias = '';\n loader = true;\n group = 'development';\n options = [\n ['n', 'namespace <string>', `sets the component's namespace and nested dirs inside the scope`],\n ['s', 'scope <string>', `sets the component's scope-name. if not entered, the default-scope will be used`],\n ['a', 'aspect <string>', 'aspect-id of the template. helpful when multiple aspects use the same template name'],\n ['p', 'path <string>', 'relative path in the workspace. by default the path is `<scope>/<namespace>/<name>`'],\n ['e', 'env <string>', \"set the component's environment. (overrides the env from variants and the template)\"],\n ] as CommandOptions;\n\n constructor(private generator: GeneratorMain, private docsDomain: string) {}\n\n async report([templateName, componentNames]: [string, string[]], options: CreateOptions) {\n const results = await this.generator.generateComponentTemplate(componentNames, templateName, options);\n const title = `${results.length} component(s) were created`;\n\n const componentsData = results\n .map((result) => {\n return `${chalk.bold(result.id.toString())}\n location: ${result.dir}\n env: ${result.envId}\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"]}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.Logo = void 0;
|
|
9
|
+
|
|
10
|
+
function _react() {
|
|
11
|
+
const data = _interopRequireDefault(require("react"));
|
|
12
|
+
|
|
13
|
+
_react = function () {
|
|
14
|
+
return data;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
return data;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const Logo = () => /*#__PURE__*/_react().default.createElement("div", {
|
|
21
|
+
style: {
|
|
22
|
+
height: '100%',
|
|
23
|
+
display: 'flex',
|
|
24
|
+
justifyContent: 'center'
|
|
25
|
+
}
|
|
26
|
+
}, /*#__PURE__*/_react().default.createElement("img", {
|
|
27
|
+
style: {
|
|
28
|
+
width: 70
|
|
29
|
+
},
|
|
30
|
+
src: "https://static.bit.dev/extensions-icons/generator.svg"
|
|
31
|
+
}));
|
|
32
|
+
|
|
33
|
+
exports.Logo = Logo;
|
|
34
|
+
|
|
35
|
+
//# sourceMappingURL=generator.composition.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["generator.composition.tsx"],"names":["Logo","height","display","justifyContent","width"],"mappings":";;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEO,MAAMA,IAAI,GAAG,mBAClB;AAAK,EAAA,KAAK,EAAE;AAAEC,IAAAA,MAAM,EAAE,MAAV;AAAkBC,IAAAA,OAAO,EAAE,MAA3B;AAAmCC,IAAAA,cAAc,EAAE;AAAnD;AAAZ,gBACE;AAAK,EAAA,KAAK,EAAE;AAAEC,IAAAA,KAAK,EAAE;AAAT,GAAZ;AAA2B,EAAA,GAAG,EAAC;AAA/B,EADF,CADK","sourcesContent":["import React from 'react';\n\nexport const Logo = () => (\n <div style={{ height: '100%', display: 'flex', justifyContent: 'center' }}>\n <img style={{ width: 70 }} src=\"https://static.bit.dev/extensions-icons/generator.svg\" />\n </div>\n);\n"]}
|
package/dist/generator.docs.mdx
CHANGED
|
@@ -2,6 +2,7 @@ import { GraphqlMain } from '@teambit/graphql';
|
|
|
2
2
|
import { CLIMain } from '@teambit/cli';
|
|
3
3
|
import { Workspace } from '@teambit/workspace';
|
|
4
4
|
import { EnvsMain } from '@teambit/envs';
|
|
5
|
+
import type { CommunityMain } from '@teambit/community';
|
|
5
6
|
import { Component } from '@teambit/component';
|
|
6
7
|
import { SlotRegistry } from '@teambit/harmony';
|
|
7
8
|
import { AspectLoaderMain } from '@teambit/aspect-loader';
|
|
@@ -65,7 +66,10 @@ export declare class GeneratorMain {
|
|
|
65
66
|
/**
|
|
66
67
|
* returns a specific component template.
|
|
67
68
|
*/
|
|
68
|
-
getComponentTemplate(name: string, aspectId?: string):
|
|
69
|
+
getComponentTemplate(name: string, aspectId?: string): {
|
|
70
|
+
id: string;
|
|
71
|
+
template: ComponentTemplate;
|
|
72
|
+
} | undefined;
|
|
69
73
|
/**
|
|
70
74
|
* in the case the aspect-id is given and this aspect doesn't exist locally, import it to the
|
|
71
75
|
* global scope and load it from the capsule
|
|
@@ -88,12 +92,13 @@ export declare class GeneratorMain {
|
|
|
88
92
|
static slots: (((registerFn: () => string) => SlotRegistry<ComponentTemplate[]>) | ((registerFn: () => string) => SlotRegistry<WorkspaceTemplate[]>))[];
|
|
89
93
|
static dependencies: import("@teambit/bit").Aspect[];
|
|
90
94
|
static runtime: import("@teambit/bit").RuntimeDefinition;
|
|
91
|
-
static provider([workspace, cli, graphql, envs, aspectLoader, newComponentHelper]: [
|
|
95
|
+
static provider([workspace, cli, graphql, envs, aspectLoader, newComponentHelper, community]: [
|
|
92
96
|
Workspace,
|
|
93
97
|
CLIMain,
|
|
94
98
|
GraphqlMain,
|
|
95
99
|
EnvsMain,
|
|
96
100
|
AspectLoaderMain,
|
|
97
|
-
NewComponentHelperMain
|
|
101
|
+
NewComponentHelperMain,
|
|
102
|
+
CommunityMain
|
|
98
103
|
], config: GeneratorConfig, [componentTemplateSlot, workspaceTemplateSlot]: [ComponentTemplateSlot, WorkspaceTemplateSlot]): Promise<GeneratorMain>;
|
|
99
104
|
}
|
|
@@ -77,6 +77,16 @@ function _exceptions() {
|
|
|
77
77
|
return data;
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
+
function _community() {
|
|
81
|
+
const data = require("@teambit/community");
|
|
82
|
+
|
|
83
|
+
_community = function () {
|
|
84
|
+
return data;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
return data;
|
|
88
|
+
}
|
|
89
|
+
|
|
80
90
|
function _bit() {
|
|
81
91
|
const data = require("@teambit/bit");
|
|
82
92
|
|
|
@@ -307,7 +317,7 @@ class GeneratorMain {
|
|
|
307
317
|
if (aspectId && id !== aspectId) return false;
|
|
308
318
|
return template.name === name;
|
|
309
319
|
});
|
|
310
|
-
return found
|
|
320
|
+
return found;
|
|
311
321
|
}
|
|
312
322
|
/**
|
|
313
323
|
* in the case the aspect-id is given and this aspect doesn't exist locally, import it to the
|
|
@@ -392,10 +402,10 @@ class GeneratorMain {
|
|
|
392
402
|
namespace,
|
|
393
403
|
aspect: aspectId
|
|
394
404
|
} = options;
|
|
395
|
-
const
|
|
396
|
-
if (!
|
|
405
|
+
const templateWithId = this.getComponentTemplate(templateName, aspectId);
|
|
406
|
+
if (!templateWithId) throw new (_bitError().BitError)(`template "${templateName}" was not found`);
|
|
397
407
|
const componentIds = componentNames.map(componentName => this.newComponentHelper.getNewComponentId(componentName, namespace, options.scope));
|
|
398
|
-
const componentGenerator = new (_componentGenerator().ComponentGenerator)(this.workspace, componentIds, options, template, this.envs, this.newComponentHelper);
|
|
408
|
+
const componentGenerator = new (_componentGenerator().ComponentGenerator)(this.workspace, componentIds, options, templateWithId.template, this.envs, this.newComponentHelper, templateWithId.id);
|
|
399
409
|
return componentGenerator.generate();
|
|
400
410
|
}
|
|
401
411
|
|
|
@@ -454,9 +464,9 @@ class GeneratorMain {
|
|
|
454
464
|
this.aspectLoaded = true;
|
|
455
465
|
}
|
|
456
466
|
|
|
457
|
-
static async provider([workspace, cli, graphql, envs, aspectLoader, newComponentHelper], config, [componentTemplateSlot, workspaceTemplateSlot]) {
|
|
467
|
+
static async provider([workspace, cli, graphql, envs, aspectLoader, newComponentHelper, community], config, [componentTemplateSlot, workspaceTemplateSlot]) {
|
|
458
468
|
const generator = new GeneratorMain(componentTemplateSlot, workspaceTemplateSlot, config, workspace, envs, aspectLoader, newComponentHelper);
|
|
459
|
-
const commands = [new (_create().CreateCmd)(generator), new (_templates().TemplatesCmd)(generator), new (_new().NewCmd)(generator)];
|
|
469
|
+
const commands = [new (_create().CreateCmd)(generator, community.getDocsDomain()), new (_templates().TemplatesCmd)(generator), new (_new().NewCmd)(generator)];
|
|
460
470
|
cli.register(...commands);
|
|
461
471
|
graphql.register((0, _generator2().generatorSchema)(generator));
|
|
462
472
|
generator.registerComponentTemplate([_componentGenerator2().componentGeneratorTemplate, _workspaceGenerator2().workspaceGeneratorTemplate]);
|
|
@@ -467,7 +477,7 @@ class GeneratorMain {
|
|
|
467
477
|
|
|
468
478
|
exports.GeneratorMain = GeneratorMain;
|
|
469
479
|
(0, _defineProperty2().default)(GeneratorMain, "slots", [_harmony().Slot.withType(), _harmony().Slot.withType()]);
|
|
470
|
-
(0, _defineProperty2().default)(GeneratorMain, "dependencies", [_workspace().default, _cli().CLIAspect, _graphql().GraphqlAspect, _envs().EnvsAspect, _aspectLoader().default, _newComponentHelper().default]);
|
|
480
|
+
(0, _defineProperty2().default)(GeneratorMain, "dependencies", [_workspace().default, _cli().CLIAspect, _graphql().GraphqlAspect, _envs().EnvsAspect, _aspectLoader().default, _newComponentHelper().default, _community().CommunityAspect]);
|
|
471
481
|
(0, _defineProperty2().default)(GeneratorMain, "runtime", _cli().MainRuntime);
|
|
472
482
|
|
|
473
483
|
_generator().GeneratorAspect.addRuntime(GeneratorMain);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["generator.main.runtime.ts"],"names":["GeneratorMain","constructor","componentTemplateSlot","workspaceTemplateSlot","config","workspace","envs","aspectLoader","newComponentHelper","registerComponentTemplate","templates","register","registerWorkspaceTemplate","listTemplates","getTemplateDescriptor","id","template","shouldBeHidden","hidden","hideCoreTemplates","aspectId","name","description","isRunningInsideWorkspace","getAllComponentTemplatesFlattened","map","getAllWorkspaceTemplatesFlattened","listComponentTemplates","Boolean","getComponentTemplateByAspect","get","getComponentTemplate","found","find","findTemplateInGlobalScope","aspects","loadAspectsFromGlobalScope","fullAspectId","toString","searchRegisteredWorkspaceTemplate","findTemplateInOtherWorkspace","workspacePath","BitError","harmony","WorkspaceAspect","err","Error","aspectComponentId","resolveComponentId","loadAspects","aspectFullId","generator","GeneratorAspect","getWorkspaceTemplate","registeredTemplate","workspaceTemplate","aspect","fromGlobal","generateComponentTemplate","componentNames","templateName","options","ConsumerNotFound","namespace","componentIds","componentName","getNewComponentId","scope","componentGenerator","ComponentGenerator","generate","generateWorkspaceTemplate","workspaceName","loadFrom","aspectComponent","workspaceGenerator","WorkspaceGenerator","templatesByAspects","toArray","flatMap","componentTemplates","workspaceTemplates","aspectLoaded","provider","cli","graphql","commands","CreateCmd","TemplatesCmd","NewCmd","componentGeneratorTemplate","workspaceGeneratorTemplate","Slot","withType","CLIAspect","GraphqlAspect","EnvsAspect","AspectLoaderAspect","NewComponentHelperAspect","MainRuntime","addRuntime"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AA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,GAAZ,EAAiBC,OAAjB,EAA0B/E,IAA1B,EAAgCC,YAAhC,EAA8CC,kBAA9C,CADmB,EASnBJ,MATmB,EAUnB,CAACF,qBAAD,EAAwBC,qBAAxB,CAVmB,EAWnB;AACA,UAAMgD,SAAS,GAAG,IAAInD,aAAJ,CAChBE,qBADgB,EAEhBC,qBAFgB,EAGhBC,MAHgB,EAIhBC,SAJgB,EAKhBC,IALgB,EAMhBC,YANgB,EAOhBC,kBAPgB,CAAlB;AASA,UAAM8E,QAAQ,GAAG,CAAC,KAAIC,mBAAJ,EAAcpC,SAAd,CAAD,EAA2B,KAAIqC,yBAAJ,EAAiBrC,SAAjB,CAA3B,EAAwD,KAAIsC,aAAJ,EAAWtC,SAAX,CAAxD,CAAjB;AACAiC,IAAAA,GAAG,CAACzE,QAAJ,CAAa,GAAG2E,QAAhB;AACAD,IAAAA,OAAO,CAAC1E,QAAR,CAAiB,mCAAgBwC,SAAhB,CAAjB;AACAA,IAAAA,SAAS,CAAC1C,yBAAV,CAAoC,CAACiF,iDAAD,EAA6BC,iDAA7B,CAApC;AACA,WAAOxC,SAAP;AACD;;AAvQwB;;;gCAAdnD,a,WAgOI,CAAC4F,gBAAKC,QAAL,EAAD,EAAuCD,gBAAKC,QAAL,EAAvC,C;gCAhOJ7F,a,kBAkOW,CACpB4C,oBADoB,EAEpBkD,gBAFoB,EAGpBC,wBAHoB,EAIpBC,kBAJoB,EAKpBC,uBALoB,EAMpBC,6BANoB,C;gCAlOXlG,a,aA2OMmG,kB;;AA+BnB/C,6BAAgBgD,UAAhB,CAA2BpG,aAA3B","sourcesContent":["import { GraphqlAspect, GraphqlMain } from '@teambit/graphql';\nimport { CLIAspect, CLIMain, MainRuntime } from '@teambit/cli';\nimport WorkspaceAspect, { Workspace } from '@teambit/workspace';\nimport { EnvsAspect, EnvsMain } from '@teambit/envs';\nimport { ConsumerNotFound } from '@teambit/legacy/dist/consumer/exceptions';\nimport { Component } from '@teambit/component';\nimport { isCoreAspect, loadBit } from '@teambit/bit';\nimport { Slot, SlotRegistry } from '@teambit/harmony';\nimport { BitError } from '@teambit/bit-error';\nimport AspectLoaderAspect, { AspectLoaderMain } from '@teambit/aspect-loader';\nimport NewComponentHelperAspect, { NewComponentHelperMain } from '@teambit/new-component-helper';\nimport { ComponentTemplate } from './component-template';\nimport { GeneratorAspect } from './generator.aspect';\nimport { CreateCmd, CreateOptions } from './create.cmd';\nimport { TemplatesCmd } from './templates.cmd';\nimport { generatorSchema } from './generator.graphql';\nimport { ComponentGenerator, GenerateResult } from './component-generator';\nimport { WorkspaceGenerator } from './workspace-generator';\nimport { WorkspaceTemplate } from './workspace-template';\nimport { NewCmd, NewOptions } from './new.cmd';\nimport { componentGeneratorTemplate } from './templates/component-generator';\nimport { workspaceGeneratorTemplate } from './templates/workspace-generator';\n\nexport type ComponentTemplateSlot = SlotRegistry<ComponentTemplate[]>;\nexport type WorkspaceTemplateSlot = SlotRegistry<WorkspaceTemplate[]>;\n\nexport type TemplateDescriptor = { aspectId: string; name: string; description?: string; hidden?: boolean };\n\nexport type GeneratorConfig = {\n /**\n * array of aspects to include in the list of templates.\n */\n aspects: string[];\n\n /**\n * by default core templates are shown.\n * use this to hide them unless `--show-all` flag of `bit templates` was used\n */\n hideCoreTemplates: boolean;\n};\n\nexport class GeneratorMain {\n private aspectLoaded = false;\n constructor(\n private componentTemplateSlot: ComponentTemplateSlot,\n private workspaceTemplateSlot: WorkspaceTemplateSlot,\n private config: GeneratorConfig,\n private workspace: Workspace,\n private envs: EnvsMain,\n private aspectLoader: AspectLoaderMain,\n private newComponentHelper: NewComponentHelperMain\n ) {}\n\n /**\n * register a new component template.\n */\n registerComponentTemplate(templates: ComponentTemplate[]) {\n this.componentTemplateSlot.register(templates);\n return this;\n }\n\n /**\n * register a new component template.\n */\n registerWorkspaceTemplate(templates: WorkspaceTemplate[]) {\n this.workspaceTemplateSlot.register(templates);\n return this;\n }\n\n /**\n * list all component templates registered in the workspace or workspace templates in case the\n * workspace is not available\n */\n async listTemplates(): Promise<TemplateDescriptor[]> {\n const getTemplateDescriptor = ({\n id,\n template,\n }: {\n id: string;\n template: WorkspaceTemplate | ComponentTemplate;\n }) => {\n const shouldBeHidden = () => {\n if (template.hidden) return true;\n if (this.config.hideCoreTemplates && isCoreAspect(id)) return true;\n return false;\n };\n return {\n aspectId: id,\n name: template.name,\n description: template.description,\n hidden: shouldBeHidden(),\n };\n };\n return this.isRunningInsideWorkspace()\n ? this.getAllComponentTemplatesFlattened().map(getTemplateDescriptor)\n : this.getAllWorkspaceTemplatesFlattened().map(getTemplateDescriptor);\n }\n\n /**\n * @deprecated use this.listTemplates()\n */\n async listComponentTemplates(): Promise<TemplateDescriptor[]> {\n return this.listTemplates();\n }\n\n isRunningInsideWorkspace(): boolean {\n return Boolean(this.workspace);\n }\n\n /**\n * get all component templates registered by a specific aspect ID.\n */\n getComponentTemplateByAspect(aspectId: string): ComponentTemplate[] {\n return this.componentTemplateSlot.get(aspectId) || [];\n }\n\n /**\n * returns a specific component template.\n */\n getComponentTemplate(name: string, aspectId?: string): ComponentTemplate | undefined {\n const templates = this.getAllComponentTemplatesFlattened();\n const found = templates.find(({ id, template }) => {\n if (aspectId && id !== aspectId) return false;\n return template.name === name;\n });\n return found?.template;\n }\n\n /**\n * in the case the aspect-id is given and this aspect doesn't exist locally, import it to the\n * global scope and load it from the capsule\n */\n async findTemplateInGlobalScope(aspectId: string, name?: string): Promise<WorkspaceTemplate | undefined> {\n const aspects = await this.aspectLoader.loadAspectsFromGlobalScope([aspectId]);\n const fullAspectId = aspects[0].id.toString();\n return this.searchRegisteredWorkspaceTemplate(name, fullAspectId);\n }\n\n async findTemplateInOtherWorkspace(workspacePath: string, name: string, aspectId?: string) {\n if (!aspectId)\n throw new BitError(\n `to load a template from a different workspace, please provide the aspect-id using --aspect flag`\n );\n const harmony = await loadBit(workspacePath);\n let workspace: Workspace;\n try {\n workspace = harmony.get<Workspace>(WorkspaceAspect.id);\n } catch (err: any) {\n throw new Error(`fatal: \"${workspacePath}\" is not a valid Bit workspace, make sure the path is correct`);\n }\n const aspectComponentId = await workspace.resolveComponentId(aspectId);\n await workspace.loadAspects([aspectId], true);\n const aspectFullId = aspectComponentId.toString();\n const generator = harmony.get<GeneratorMain>(GeneratorAspect.id);\n return generator.searchRegisteredWorkspaceTemplate(name, aspectFullId);\n }\n\n /**\n * returns a specific workspace template.\n */\n async getWorkspaceTemplate(\n name: string,\n aspectId?: string\n ): Promise<{ workspaceTemplate: WorkspaceTemplate; aspect?: Component }> {\n const registeredTemplate = await this.searchRegisteredWorkspaceTemplate(name, aspectId);\n if (registeredTemplate) {\n return { workspaceTemplate: registeredTemplate };\n }\n if (!aspectId) {\n throw new BitError(`template \"${name}\" was not found, if this is a custom-template, please use --aspect flag`);\n }\n const aspects = await this.aspectLoader.loadAspectsFromGlobalScope([aspectId]);\n const aspect = aspects[0];\n const fullAspectId = aspect.id.toString();\n const fromGlobal = await this.searchRegisteredWorkspaceTemplate(name, fullAspectId);\n if (fromGlobal) {\n return { workspaceTemplate: fromGlobal, aspect };\n }\n throw new BitError(`template \"${name}\" was not found`);\n }\n\n async searchRegisteredWorkspaceTemplate(name?: string, aspectId?: string): Promise<WorkspaceTemplate | undefined> {\n const templates = this.getAllWorkspaceTemplatesFlattened();\n const found = templates.find(({ id, template }) => {\n if (aspectId && name) return aspectId === id && name === template.name;\n if (aspectId) return aspectId === id;\n if (name) return name === template.name;\n throw new Error(`searchRegisteredWorkspaceTemplate expects to get \"name\" or \"aspectId\"`);\n });\n return found?.template;\n }\n\n async generateComponentTemplate(\n componentNames: string[],\n templateName: string,\n options: CreateOptions\n ): Promise<GenerateResult[]> {\n if (!this.workspace) throw new ConsumerNotFound();\n await this.loadAspects();\n const { namespace, aspect: aspectId } = options;\n const template = this.getComponentTemplate(templateName, aspectId);\n if (!template) throw new BitError(`template \"${templateName}\" was not found`);\n\n const componentIds = componentNames.map((componentName) =>\n this.newComponentHelper.getNewComponentId(componentName, namespace, options.scope)\n );\n\n const componentGenerator = new ComponentGenerator(\n this.workspace,\n componentIds,\n options,\n template,\n this.envs,\n this.newComponentHelper\n );\n return componentGenerator.generate();\n }\n\n async generateWorkspaceTemplate(workspaceName: string, templateName: string, options: NewOptions) {\n if (this.workspace) {\n throw new BitError('Error: unable to generate a new workspace inside of an existing workspace');\n }\n const { aspect: aspectId, loadFrom } = options;\n let template: WorkspaceTemplate | undefined;\n let aspectComponent: Component | undefined;\n if (loadFrom) {\n template = await this.findTemplateInOtherWorkspace(loadFrom, templateName, aspectId);\n } else {\n const { workspaceTemplate, aspect } = await this.getWorkspaceTemplate(templateName, aspectId);\n template = workspaceTemplate;\n aspectComponent = aspect;\n }\n if (!template) throw new BitError(`template \"${templateName}\" was not found`);\n const workspaceGenerator = new WorkspaceGenerator(workspaceName, options, template, aspectComponent);\n const workspacePath = await workspaceGenerator.generate();\n\n return workspacePath;\n }\n\n private getAllComponentTemplatesFlattened(): Array<{ id: string; template: ComponentTemplate }> {\n const templatesByAspects = this.componentTemplateSlot.toArray();\n return templatesByAspects.flatMap(([id, componentTemplates]) => {\n return componentTemplates.map((template) => ({\n id,\n template,\n }));\n });\n }\n\n private getAllWorkspaceTemplatesFlattened(): Array<{ id: string; template: WorkspaceTemplate }> {\n const templatesByAspects = this.workspaceTemplateSlot.toArray();\n return templatesByAspects.flatMap(([id, workspaceTemplates]) => {\n return workspaceTemplates.map((template) => ({\n id,\n template,\n }));\n });\n }\n\n private async loadAspects() {\n if (this.aspectLoaded) return;\n await this.workspace.loadAspects(this.config.aspects);\n this.aspectLoaded = true;\n }\n\n static slots = [Slot.withType<ComponentTemplate[]>(), Slot.withType<WorkspaceTemplate[]>()];\n\n static dependencies = [\n WorkspaceAspect,\n CLIAspect,\n GraphqlAspect,\n EnvsAspect,\n AspectLoaderAspect,\n NewComponentHelperAspect,\n ];\n\n static runtime = MainRuntime;\n\n static async provider(\n [workspace, cli, graphql, envs, aspectLoader, newComponentHelper]: [\n Workspace,\n CLIMain,\n GraphqlMain,\n EnvsMain,\n AspectLoaderMain,\n NewComponentHelperMain\n ],\n config: GeneratorConfig,\n [componentTemplateSlot, workspaceTemplateSlot]: [ComponentTemplateSlot, WorkspaceTemplateSlot]\n ) {\n const generator = new GeneratorMain(\n componentTemplateSlot,\n workspaceTemplateSlot,\n config,\n workspace,\n envs,\n aspectLoader,\n newComponentHelper\n );\n const commands = [new CreateCmd(generator), new TemplatesCmd(generator), new NewCmd(generator)];\n cli.register(...commands);\n graphql.register(generatorSchema(generator));\n generator.registerComponentTemplate([componentGeneratorTemplate, workspaceGeneratorTemplate]);\n return generator;\n }\n}\n\nGeneratorAspect.addRuntime(GeneratorMain);\n"]}
|
|
1
|
+
{"version":3,"sources":["generator.main.runtime.ts"],"names":["GeneratorMain","constructor","componentTemplateSlot","workspaceTemplateSlot","config","workspace","envs","aspectLoader","newComponentHelper","registerComponentTemplate","templates","register","registerWorkspaceTemplate","listTemplates","getTemplateDescriptor","id","template","shouldBeHidden","hidden","hideCoreTemplates","aspectId","name","description","isRunningInsideWorkspace","getAllComponentTemplatesFlattened","map","getAllWorkspaceTemplatesFlattened","listComponentTemplates","Boolean","getComponentTemplateByAspect","get","getComponentTemplate","found","find","findTemplateInGlobalScope","aspects","loadAspectsFromGlobalScope","fullAspectId","toString","searchRegisteredWorkspaceTemplate","findTemplateInOtherWorkspace","workspacePath","BitError","harmony","WorkspaceAspect","err","Error","aspectComponentId","resolveComponentId","loadAspects","aspectFullId","generator","GeneratorAspect","getWorkspaceTemplate","registeredTemplate","workspaceTemplate","aspect","fromGlobal","generateComponentTemplate","componentNames","templateName","options","ConsumerNotFound","namespace","templateWithId","componentIds","componentName","getNewComponentId","scope","componentGenerator","ComponentGenerator","generate","generateWorkspaceTemplate","workspaceName","loadFrom","aspectComponent","workspaceGenerator","WorkspaceGenerator","templatesByAspects","toArray","flatMap","componentTemplates","workspaceTemplates","aspectLoaded","provider","cli","graphql","community","commands","CreateCmd","getDocsDomain","TemplatesCmd","NewCmd","componentGeneratorTemplate","workspaceGeneratorTemplate","Slot","withType","CLIAspect","GraphqlAspect","EnvsAspect","AspectLoaderAspect","NewComponentHelperAspect","CommunityAspect","MainRuntime","addRuntime"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAIA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAoBO,MAAMA,aAAN,CAAoB;AAEzBC,EAAAA,WAAW,CACDC,qBADC,EAEDC,qBAFC,EAGDC,MAHC,EAIDC,SAJC,EAKDC,IALC,EAMDC,YANC,EAODC,kBAPC,EAQT;AAAA,SAPQN,qBAOR,GAPQA,qBAOR;AA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B,CAAlB;AASA,UAAMgF,QAAQ,GAAG,CACf,KAAIC,mBAAJ,EAActC,SAAd,EAAyBoC,SAAS,CAACG,aAAV,EAAzB,CADe,EAEf,KAAIC,yBAAJ,EAAiBxC,SAAjB,CAFe,EAGf,KAAIyC,aAAJ,EAAWzC,SAAX,CAHe,CAAjB;AAKAkC,IAAAA,GAAG,CAAC1E,QAAJ,CAAa,GAAG6E,QAAhB;AACAF,IAAAA,OAAO,CAAC3E,QAAR,CAAiB,mCAAgBwC,SAAhB,CAAjB;AACAA,IAAAA,SAAS,CAAC1C,yBAAV,CAAoC,CAACoF,iDAAD,EAA6BC,iDAA7B,CAApC;AACA,WAAO3C,SAAP;AACD;;AA9QwB;;;gCAAdnD,a,WAiOI,CAAC+F,gBAAKC,QAAL,EAAD,EAAuCD,gBAAKC,QAAL,EAAvC,C;gCAjOJhG,a,kBAmOW,CACpB4C,oBADoB,EAEpBqD,gBAFoB,EAGpBC,wBAHoB,EAIpBC,kBAJoB,EAKpBC,uBALoB,EAMpBC,6BANoB,EAOpBC,4BAPoB,C;gCAnOXtG,a,aA6OMuG,kB;;AAoCnBnD,6BAAgBoD,UAAhB,CAA2BxG,aAA3B","sourcesContent":["import { GraphqlAspect, GraphqlMain } from '@teambit/graphql';\nimport { CLIAspect, CLIMain, MainRuntime } from '@teambit/cli';\nimport WorkspaceAspect, { Workspace } from '@teambit/workspace';\nimport { EnvsAspect, EnvsMain } from '@teambit/envs';\nimport { ConsumerNotFound } from '@teambit/legacy/dist/consumer/exceptions';\nimport { CommunityAspect } from '@teambit/community';\nimport type { CommunityMain } from '@teambit/community';\n\nimport { Component } from '@teambit/component';\nimport { isCoreAspect, loadBit } from '@teambit/bit';\nimport { Slot, SlotRegistry } from '@teambit/harmony';\nimport { BitError } from '@teambit/bit-error';\nimport AspectLoaderAspect, { AspectLoaderMain } from '@teambit/aspect-loader';\nimport NewComponentHelperAspect, { NewComponentHelperMain } from '@teambit/new-component-helper';\nimport { ComponentTemplate } from './component-template';\nimport { GeneratorAspect } from './generator.aspect';\nimport { CreateCmd, CreateOptions } from './create.cmd';\nimport { TemplatesCmd } from './templates.cmd';\nimport { generatorSchema } from './generator.graphql';\nimport { ComponentGenerator, GenerateResult } from './component-generator';\nimport { WorkspaceGenerator } from './workspace-generator';\nimport { WorkspaceTemplate } from './workspace-template';\nimport { NewCmd, NewOptions } from './new.cmd';\nimport { componentGeneratorTemplate } from './templates/component-generator';\nimport { workspaceGeneratorTemplate } from './templates/workspace-generator';\n\nexport type ComponentTemplateSlot = SlotRegistry<ComponentTemplate[]>;\nexport type WorkspaceTemplateSlot = SlotRegistry<WorkspaceTemplate[]>;\n\nexport type TemplateDescriptor = { aspectId: string; name: string; description?: string; hidden?: boolean };\n\nexport type GeneratorConfig = {\n /**\n * array of aspects to include in the list of templates.\n */\n aspects: string[];\n\n /**\n * by default core templates are shown.\n * use this to hide them unless `--show-all` flag of `bit templates` was used\n */\n hideCoreTemplates: boolean;\n};\n\nexport class GeneratorMain {\n private aspectLoaded = false;\n constructor(\n private componentTemplateSlot: ComponentTemplateSlot,\n private workspaceTemplateSlot: WorkspaceTemplateSlot,\n private config: GeneratorConfig,\n private workspace: Workspace,\n private envs: EnvsMain,\n private aspectLoader: AspectLoaderMain,\n private newComponentHelper: NewComponentHelperMain\n ) {}\n\n /**\n * register a new component template.\n */\n registerComponentTemplate(templates: ComponentTemplate[]) {\n this.componentTemplateSlot.register(templates);\n return this;\n }\n\n /**\n * register a new component template.\n */\n registerWorkspaceTemplate(templates: WorkspaceTemplate[]) {\n this.workspaceTemplateSlot.register(templates);\n return this;\n }\n\n /**\n * list all component templates registered in the workspace or workspace templates in case the\n * workspace is not available\n */\n async listTemplates(): Promise<TemplateDescriptor[]> {\n const getTemplateDescriptor = ({\n id,\n template,\n }: {\n id: string;\n template: WorkspaceTemplate | ComponentTemplate;\n }) => {\n const shouldBeHidden = () => {\n if (template.hidden) return true;\n if (this.config.hideCoreTemplates && isCoreAspect(id)) return true;\n return false;\n };\n return {\n aspectId: id,\n name: template.name,\n description: template.description,\n hidden: shouldBeHidden(),\n };\n };\n return this.isRunningInsideWorkspace()\n ? this.getAllComponentTemplatesFlattened().map(getTemplateDescriptor)\n : this.getAllWorkspaceTemplatesFlattened().map(getTemplateDescriptor);\n }\n\n /**\n * @deprecated use this.listTemplates()\n */\n async listComponentTemplates(): Promise<TemplateDescriptor[]> {\n return this.listTemplates();\n }\n\n isRunningInsideWorkspace(): boolean {\n return Boolean(this.workspace);\n }\n\n /**\n * get all component templates registered by a specific aspect ID.\n */\n getComponentTemplateByAspect(aspectId: string): ComponentTemplate[] {\n return this.componentTemplateSlot.get(aspectId) || [];\n }\n\n /**\n * returns a specific component template.\n */\n getComponentTemplate(name: string, aspectId?: string): { id: string; template: ComponentTemplate } | undefined {\n const templates = this.getAllComponentTemplatesFlattened();\n const found = templates.find(({ id, template }) => {\n if (aspectId && id !== aspectId) return false;\n return template.name === name;\n });\n return found;\n }\n\n /**\n * in the case the aspect-id is given and this aspect doesn't exist locally, import it to the\n * global scope and load it from the capsule\n */\n async findTemplateInGlobalScope(aspectId: string, name?: string): Promise<WorkspaceTemplate | undefined> {\n const aspects = await this.aspectLoader.loadAspectsFromGlobalScope([aspectId]);\n const fullAspectId = aspects[0].id.toString();\n return this.searchRegisteredWorkspaceTemplate(name, fullAspectId);\n }\n\n async findTemplateInOtherWorkspace(workspacePath: string, name: string, aspectId?: string) {\n if (!aspectId)\n throw new BitError(\n `to load a template from a different workspace, please provide the aspect-id using --aspect flag`\n );\n const harmony = await loadBit(workspacePath);\n let workspace: Workspace;\n try {\n workspace = harmony.get<Workspace>(WorkspaceAspect.id);\n } catch (err: any) {\n throw new Error(`fatal: \"${workspacePath}\" is not a valid Bit workspace, make sure the path is correct`);\n }\n const aspectComponentId = await workspace.resolveComponentId(aspectId);\n await workspace.loadAspects([aspectId], true);\n const aspectFullId = aspectComponentId.toString();\n const generator = harmony.get<GeneratorMain>(GeneratorAspect.id);\n return generator.searchRegisteredWorkspaceTemplate(name, aspectFullId);\n }\n\n /**\n * returns a specific workspace template.\n */\n async getWorkspaceTemplate(\n name: string,\n aspectId?: string\n ): Promise<{ workspaceTemplate: WorkspaceTemplate; aspect?: Component }> {\n const registeredTemplate = await this.searchRegisteredWorkspaceTemplate(name, aspectId);\n if (registeredTemplate) {\n return { workspaceTemplate: registeredTemplate };\n }\n if (!aspectId) {\n throw new BitError(`template \"${name}\" was not found, if this is a custom-template, please use --aspect flag`);\n }\n const aspects = await this.aspectLoader.loadAspectsFromGlobalScope([aspectId]);\n const aspect = aspects[0];\n const fullAspectId = aspect.id.toString();\n const fromGlobal = await this.searchRegisteredWorkspaceTemplate(name, fullAspectId);\n if (fromGlobal) {\n return { workspaceTemplate: fromGlobal, aspect };\n }\n throw new BitError(`template \"${name}\" was not found`);\n }\n\n async searchRegisteredWorkspaceTemplate(name?: string, aspectId?: string): Promise<WorkspaceTemplate | undefined> {\n const templates = this.getAllWorkspaceTemplatesFlattened();\n const found = templates.find(({ id, template }) => {\n if (aspectId && name) return aspectId === id && name === template.name;\n if (aspectId) return aspectId === id;\n if (name) return name === template.name;\n throw new Error(`searchRegisteredWorkspaceTemplate expects to get \"name\" or \"aspectId\"`);\n });\n return found?.template;\n }\n\n async generateComponentTemplate(\n componentNames: string[],\n templateName: string,\n options: CreateOptions\n ): Promise<GenerateResult[]> {\n if (!this.workspace) throw new ConsumerNotFound();\n await this.loadAspects();\n const { namespace, aspect: aspectId } = options;\n const templateWithId = this.getComponentTemplate(templateName, aspectId);\n if (!templateWithId) throw new BitError(`template \"${templateName}\" was not found`);\n\n const componentIds = componentNames.map((componentName) =>\n this.newComponentHelper.getNewComponentId(componentName, namespace, options.scope)\n );\n\n const componentGenerator = new ComponentGenerator(\n this.workspace,\n componentIds,\n options,\n templateWithId.template,\n this.envs,\n this.newComponentHelper,\n templateWithId.id\n );\n return componentGenerator.generate();\n }\n\n async generateWorkspaceTemplate(workspaceName: string, templateName: string, options: NewOptions) {\n if (this.workspace) {\n throw new BitError('Error: unable to generate a new workspace inside of an existing workspace');\n }\n const { aspect: aspectId, loadFrom } = options;\n let template: WorkspaceTemplate | undefined;\n let aspectComponent: Component | undefined;\n if (loadFrom) {\n template = await this.findTemplateInOtherWorkspace(loadFrom, templateName, aspectId);\n } else {\n const { workspaceTemplate, aspect } = await this.getWorkspaceTemplate(templateName, aspectId);\n template = workspaceTemplate;\n aspectComponent = aspect;\n }\n if (!template) throw new BitError(`template \"${templateName}\" was not found`);\n const workspaceGenerator = new WorkspaceGenerator(workspaceName, options, template, aspectComponent);\n const workspacePath = await workspaceGenerator.generate();\n\n return workspacePath;\n }\n\n private getAllComponentTemplatesFlattened(): Array<{ id: string; template: ComponentTemplate }> {\n const templatesByAspects = this.componentTemplateSlot.toArray();\n return templatesByAspects.flatMap(([id, componentTemplates]) => {\n return componentTemplates.map((template) => ({\n id,\n template,\n }));\n });\n }\n\n private getAllWorkspaceTemplatesFlattened(): Array<{ id: string; template: WorkspaceTemplate }> {\n const templatesByAspects = this.workspaceTemplateSlot.toArray();\n return templatesByAspects.flatMap(([id, workspaceTemplates]) => {\n return workspaceTemplates.map((template) => ({\n id,\n template,\n }));\n });\n }\n\n private async loadAspects() {\n if (this.aspectLoaded) return;\n await this.workspace.loadAspects(this.config.aspects);\n this.aspectLoaded = true;\n }\n\n static slots = [Slot.withType<ComponentTemplate[]>(), Slot.withType<WorkspaceTemplate[]>()];\n\n static dependencies = [\n WorkspaceAspect,\n CLIAspect,\n GraphqlAspect,\n EnvsAspect,\n AspectLoaderAspect,\n NewComponentHelperAspect,\n CommunityAspect,\n ];\n\n static runtime = MainRuntime;\n\n static async provider(\n [workspace, cli, graphql, envs, aspectLoader, newComponentHelper, community]: [\n Workspace,\n CLIMain,\n GraphqlMain,\n EnvsMain,\n AspectLoaderMain,\n NewComponentHelperMain,\n CommunityMain\n ],\n config: GeneratorConfig,\n [componentTemplateSlot, workspaceTemplateSlot]: [ComponentTemplateSlot, WorkspaceTemplateSlot]\n ) {\n const generator = new GeneratorMain(\n componentTemplateSlot,\n workspaceTemplateSlot,\n config,\n workspace,\n envs,\n aspectLoader,\n newComponentHelper\n );\n const commands = [\n new CreateCmd(generator, community.getDocsDomain()),\n new TemplatesCmd(generator),\n new NewCmd(generator),\n ];\n cli.register(...commands);\n graphql.register(generatorSchema(generator));\n generator.registerComponentTemplate([componentGeneratorTemplate, workspaceGeneratorTemplate]);\n return generator;\n }\n}\n\nGeneratorAspect.addRuntime(GeneratorMain);\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export type { GeneratorMain } from './generator.main.runtime';
|
|
2
|
-
export { ComponentContext, ComponentTemplate, ComponentFile, ComponentConfig } from './component-template';
|
|
2
|
+
export { ComponentContext, ComponentTemplate, ComponentFile, ComponentConfig, ConfigContext, } from './component-template';
|
|
3
3
|
export { WorkspaceContext, WorkspaceTemplate, WorkspaceFile } from './workspace-template';
|
|
4
4
|
export { GeneratorAspect } from './generator.aspect';
|
package/dist/index.js
CHANGED
|
@@ -27,6 +27,12 @@ Object.defineProperty(exports, "ComponentTemplate", {
|
|
|
27
27
|
return _componentTemplate().ComponentTemplate;
|
|
28
28
|
}
|
|
29
29
|
});
|
|
30
|
+
Object.defineProperty(exports, "ConfigContext", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () {
|
|
33
|
+
return _componentTemplate().ConfigContext;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
30
36
|
Object.defineProperty(exports, "GeneratorAspect", {
|
|
31
37
|
enumerable: true,
|
|
32
38
|
get: function () {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAOA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA","sourcesContent":["export type { GeneratorMain } from './generator.main.runtime';\nexport {\n ComponentContext,\n ComponentTemplate,\n ComponentFile,\n ComponentConfig,\n ConfigContext,\n} from './component-template';\nexport { WorkspaceContext, WorkspaceTemplate, WorkspaceFile } from './workspace-template';\nexport { GeneratorAspect } from './generator.aspect';\n"]}
|
package/dist/new.cmd.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["new.cmd.ts"],"names":["NewCmd","constructor","generator","report","templateName","workspaceName","options","skipGit","standalone","results","generateWorkspaceTemplate","chalk","white","green","yellow","bold"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAWO,MAAMA,MAAN,CAAgC;AAwBrCC,EAAAA,WAAW,CAASC,SAAT,EAAmC;AAAA,SAA1BA,SAA0B,GAA1BA,SAA0B;AAAA,kDAvBvC,oCAuBuC;AAAA,yDAtBhC,wCAsBgC;AAAA,8DArB3B,EAqB2B;AAAA,mDApBtC,EAoBsC;AAAA,oDAnBrC,IAmBqC;AAAA,mDAlBtC,OAkBsC;AAAA,qDAjBpC,CACR,CACE,GADF,EAEE,iBAFF,EAGE,iHAHF,CADQ,EAMR,CAAC,GAAD,EAAM,wBAAN,EAAiC,6CAAjC,CANQ,EAOR,CAAC,EAAD,EAAK,YAAL,EAAmB,oCAAnB,CAPQ,EAQR,CAAC,GAAD,EAAM,UAAN,EAAkB,mCAAlB,CARQ,EASR,CAAC,GAAD,EAAM,OAAN,EAAe,4FAAf,CATQ,EAUR,CACE,EADF,EAEE,oBAFF,EAGE,qGAHF,CAVQ,CAiBoC;AAAE;;AAEpC,QAANC,MAAM,CAAC,CAACC,YAAD,EAAeC,aAAf,CAAD,EAAkDC,OAAlD,EAAiG;AAAA;;AAC3GA,IAAAA,OAAO,CAACC,OAAR,uBAAkBD,OAAO,CAACC,OAA1B,+DAAqCD,OAAO,CAACE,UAA7C;AACA,UAAMC,OAAO,GAAG,MAAM,KAAKP,SAAL,CAAeQ,yBAAf,
|
|
1
|
+
{"version":3,"sources":["new.cmd.ts"],"names":["NewCmd","constructor","generator","report","templateName","workspaceName","options","skipGit","standalone","results","generateWorkspaceTemplate","chalk","white","green","yellow","bold"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAWO,MAAMA,MAAN,CAAgC;AAwBrCC,EAAAA,WAAW,CAASC,SAAT,EAAmC;AAAA,SAA1BA,SAA0B,GAA1BA,SAA0B;AAAA,kDAvBvC,oCAuBuC;AAAA,yDAtBhC,wCAsBgC;AAAA,8DArB3B,EAqB2B;AAAA,mDApBtC,EAoBsC;AAAA,oDAnBrC,IAmBqC;AAAA,mDAlBtC,OAkBsC;AAAA,qDAjBpC,CACR,CACE,GADF,EAEE,iBAFF,EAGE,iHAHF,CADQ,EAMR,CAAC,GAAD,EAAM,wBAAN,EAAiC,6CAAjC,CANQ,EAOR,CAAC,EAAD,EAAK,YAAL,EAAmB,oCAAnB,CAPQ,EAQR,CAAC,GAAD,EAAM,UAAN,EAAkB,mCAAlB,CARQ,EASR,CAAC,GAAD,EAAM,OAAN,EAAe,4FAAf,CATQ,EAUR,CACE,EADF,EAEE,oBAFF,EAGE,qGAHF,CAVQ,CAiBoC;AAAE;;AAEpC,QAANC,MAAM,CAAC,CAACC,YAAD,EAAeC,aAAf,CAAD,EAAkDC,OAAlD,EAAiG;AAAA;;AAC3GA,IAAAA,OAAO,CAACC,OAAR,uBAAkBD,OAAO,CAACC,OAA1B,+DAAqCD,OAAO,CAACE,UAA7C;AACA,UAAMC,OAAO,GAAG,MAAM,KAAKP,SAAL,CAAeQ,yBAAf,CACpBL,aADoB,EAEpBD,YAFoB,EAGpBE,OAHoB,CAAtB;AAKA,WAAOK,iBAAMC,KAAN,CACJ,GAAED,iBAAME,KAAN,CAAa;AACtB;AACA,8DAA8DJ,OAAQ,GAF7D,CAEiE;AAC1E;AACA,wBAAwBJ,aAAc;AACtC;AACA,QAAQM,iBAAMG,MAAN,CAAa,WAAb,CAA0B;AAClC;AACA;AACA,QAAQH,iBAAMG,MAAN,CAAa,aAAb,CAA4B;AACpC;AACA;AACA,QAAQH,iBAAMG,MAAN,CAAa,YAAb,CAA2B;AACnC;AACA;AACA,QAAQH,iBAAMG,MAAN,CAAa,aAAb,CAA4B;AACpC;AACA;AACA,QAAQH,iBAAMG,MAAN,CAAa,UAAb,CAAyB;AACjC;AACA;AACA,QAAQH,iBAAMG,MAAN,CAAa,eAAb,CAA8B;AACtC;AACA;AACA,QAAQH,iBAAMG,MAAN,CAAa,UAAb,CAAyB;AACjC;AACA;AACA;AACA,EAAEH,iBAAME,KAAN,CAAYE,IAAZ,CAAiB,oBAAjB,CAAuC;AACzC;AACA,QAAQJ,iBAAMG,MAAN,CAAc,MAAKT,aAAc,EAAjC,CAAoC;AAC5C,QAAQM,iBAAMG,MAAN,CAAc,WAAd,CAA0B;AAClC;AACA,OAlCW,CAAP;AAoCD;;AArEoC","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 <templateName> <workspaceName>';\n description = 'Create a new workspace from a template';\n shortDescription = '';\n alias = '';\n loader = true;\n group = 'start';\n options = [\n [\n 'a',\n 'aspect <string>',\n 'aspect-id of the template. mandatory for non-core aspects. helpful for core aspects in case of a name collision',\n ],\n ['d', 'default-scope <string>', `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 <string>',\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([templateName, workspaceName]: [string, string], options: NewOptions & { standalone: boolean }) {\n options.skipGit = options.skipGit ?? options.standalone;\n const results = 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 '${results}'`)}\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 ${chalk.yellow(`cd ${workspaceName}`)}\n ${chalk.yellow(`bit start`)}\n\n `\n );\n }\n}\n"]}
|
package/generator.docs.mdx
CHANGED
|
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.679",
|
|
4
4
|
"homepage": "https://bit.dev/teambit/generator/generator",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"componentId": {
|
|
7
7
|
"scope": "teambit.generator",
|
|
8
8
|
"name": "generator",
|
|
9
|
-
"version": "0.0.
|
|
9
|
+
"version": "0.0.679"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"camelcase": "6.2.0",
|
|
@@ -22,35 +22,36 @@
|
|
|
22
22
|
"@babel/runtime": "7.12.18",
|
|
23
23
|
"core-js": "^3.0.0",
|
|
24
24
|
"@teambit/bit-error": "0.0.394",
|
|
25
|
-
"@teambit/component-id": "0.0.
|
|
26
|
-
"@teambit/component": "0.0.
|
|
27
|
-
"@teambit/envs": "0.0.
|
|
28
|
-
"@teambit/new-component-helper": "0.0.
|
|
29
|
-
"@teambit/workspace": "0.0.
|
|
30
|
-
"@teambit/cli": "0.0.
|
|
31
|
-
"@teambit/graphql": "0.0.
|
|
32
|
-
"@teambit/aspect-loader": "0.0.
|
|
33
|
-
"@teambit/bit": "0.0.
|
|
34
|
-
"@teambit/
|
|
35
|
-
"@teambit/
|
|
36
|
-
"@teambit/
|
|
37
|
-
"@teambit/
|
|
38
|
-
"@teambit/
|
|
39
|
-
"@teambit/
|
|
25
|
+
"@teambit/component-id": "0.0.402",
|
|
26
|
+
"@teambit/component": "0.0.679",
|
|
27
|
+
"@teambit/envs": "0.0.679",
|
|
28
|
+
"@teambit/new-component-helper": "0.0.83",
|
|
29
|
+
"@teambit/workspace": "0.0.679",
|
|
30
|
+
"@teambit/cli": "0.0.454",
|
|
31
|
+
"@teambit/graphql": "0.0.679",
|
|
32
|
+
"@teambit/aspect-loader": "0.0.679",
|
|
33
|
+
"@teambit/bit": "0.0.681",
|
|
34
|
+
"@teambit/community": "0.0.2",
|
|
35
|
+
"@teambit/compiler": "0.0.679",
|
|
36
|
+
"@teambit/dependency-resolver": "0.0.679",
|
|
37
|
+
"@teambit/legacy-bit-id": "0.0.399",
|
|
38
|
+
"@teambit/logger": "0.0.546",
|
|
39
|
+
"@teambit/pkg": "0.0.679",
|
|
40
|
+
"@teambit/ui": "0.0.679"
|
|
40
41
|
},
|
|
41
42
|
"devDependencies": {
|
|
42
43
|
"@types/fs-extra": "9.0.7",
|
|
44
|
+
"@types/react": "^17.0.8",
|
|
43
45
|
"@types/lodash": "4.14.165",
|
|
44
46
|
"@types/mocha": "9.1.0",
|
|
45
47
|
"@types/testing-library__jest-dom": "5.9.5",
|
|
46
48
|
"@types/jest": "^26.0.0",
|
|
47
49
|
"@types/react-dom": "^17.0.5",
|
|
48
|
-
"@types/react": "^17.0.8",
|
|
49
50
|
"@types/node": "12.20.4",
|
|
50
51
|
"@teambit/generator.aspect-docs.generator": "0.0.138"
|
|
51
52
|
},
|
|
52
53
|
"peerDependencies": {
|
|
53
|
-
"@teambit/legacy": "1.0.
|
|
54
|
+
"@teambit/legacy": "1.0.233",
|
|
54
55
|
"react-dom": "^16.8.0 || ^17.0.0",
|
|
55
56
|
"react": "^16.8.0 || ^17.0.0"
|
|
56
57
|
},
|
|
@@ -78,7 +79,7 @@
|
|
|
78
79
|
"react": "-"
|
|
79
80
|
},
|
|
80
81
|
"peerDependencies": {
|
|
81
|
-
"@teambit/legacy": "1.0.
|
|
82
|
+
"@teambit/legacy": "1.0.233",
|
|
82
83
|
"react-dom": "^16.8.0 || ^17.0.0",
|
|
83
84
|
"react": "^16.8.0 || ^17.0.0"
|
|
84
85
|
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export const compositions = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.generator_generator@0.0.679/dist/generator.composition.js')]
|
|
2
|
+
export const overview = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.generator_generator@0.0.679/dist/generator.docs.mdx')]
|
|
Binary file
|
package/preview-1647314610121.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const overview = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.generator_generator@0.0.676/dist/generator.docs.mdx')]
|