@teambit/generator 1.0.107 → 1.0.109
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/component-generator.ts +284 -0
- package/component-template.ts +152 -0
- package/create.cmd.ts +88 -0
- package/dist/component-generator.d.ts +3 -3
- package/dist/component-generator.js +5 -9
- package/dist/component-generator.js.map +1 -1
- package/dist/component-template.d.ts +2 -2
- package/dist/create.cmd.d.ts +1 -1
- package/dist/generator.composition.d.ts +2 -2
- package/dist/generator.graphql.d.ts +1 -1
- package/dist/generator.main.runtime.d.ts +11 -10
- package/dist/generator.main.runtime.js +2 -2
- package/dist/generator.main.runtime.js.map +1 -1
- package/dist/generator.service.d.ts +1 -1
- package/dist/generator.service.js +1 -1
- package/dist/generator.service.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js.map +1 -1
- package/dist/new.cmd.d.ts +2 -1
- package/dist/new.cmd.js +1 -1
- package/dist/new.cmd.js.map +1 -1
- package/dist/{preview-1703505948637.js → preview-1703647408454.js} +2 -2
- package/dist/starter-list.d.ts +1 -1
- package/dist/template-list.d.ts +1 -1
- package/dist/templates.cmd.d.ts +1 -1
- package/dist/workspace-generator.d.ts +6 -2
- package/dist/workspace-generator.js +24 -20
- package/dist/workspace-generator.js.map +1 -1
- package/dist/workspace-template.d.ts +36 -2
- package/dist/workspace-template.js.map +1 -1
- package/generator-env-type.ts +14 -0
- package/generator.aspect.ts +5 -0
- package/generator.graphql.ts +62 -0
- package/generator.main.runtime.ts +600 -0
- package/index.ts +23 -0
- package/new.cmd.ts +120 -0
- package/package.json +30 -37
- package/starter-list.ts +21 -0
- package/starter.plugin.ts +16 -0
- package/template-list.ts +21 -0
- package/templates.cmd.ts +57 -0
- package/tsconfig.json +16 -21
- package/types/asset.d.ts +15 -3
- package/types.ts +3 -0
- package/workspace-generator.ts +220 -0
- package/workspace-template.ts +183 -0
@@ -1,5 +1,5 @@
|
|
1
|
-
import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.generator_generator@1.0.
|
2
|
-
import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.generator_generator@1.0.
|
1
|
+
import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.generator_generator@1.0.109/dist/generator.composition.js';
|
2
|
+
import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.generator_generator@1.0.109/dist/generator.docs.mdx';
|
3
3
|
|
4
4
|
export const compositions = [compositions_0];
|
5
5
|
export const overview = [overview_0];
|
package/dist/starter-list.d.ts
CHANGED
package/dist/template-list.d.ts
CHANGED
package/dist/templates.cmd.d.ts
CHANGED
@@ -2,7 +2,7 @@ import { Component } from '@teambit/component';
|
|
2
2
|
import { ComponentID } from '@teambit/component-id';
|
3
3
|
import { WorkspaceTemplate } from './workspace-template';
|
4
4
|
import { NewOptions } from './new.cmd';
|
5
|
-
export
|
5
|
+
export type GenerateResult = {
|
6
6
|
id: ComponentID;
|
7
7
|
dir: string;
|
8
8
|
files: string[];
|
@@ -22,7 +22,10 @@ export declare class WorkspaceGenerator {
|
|
22
22
|
private forking;
|
23
23
|
private git;
|
24
24
|
private wsConfigFiles;
|
25
|
-
|
25
|
+
private generator;
|
26
|
+
constructor(workspaceName: string, options: NewOptions & {
|
27
|
+
currentDir?: boolean;
|
28
|
+
}, template: WorkspaceTemplate, aspectComponent?: Component);
|
26
29
|
generate(): Promise<string>;
|
27
30
|
private initGit;
|
28
31
|
private setupGitBitmapMergeDriver;
|
@@ -33,6 +36,7 @@ export declare class WorkspaceGenerator {
|
|
33
36
|
*/
|
34
37
|
private writeWorkspaceFiles;
|
35
38
|
private reloadBitInWorkspaceDir;
|
39
|
+
private createComponentsFromRemote;
|
36
40
|
private forkComponentsFromRemote;
|
37
41
|
private importComponentsFromRemote;
|
38
42
|
private compileComponents;
|
@@ -151,10 +151,11 @@ class WorkspaceGenerator {
|
|
151
151
|
_defineProperty(this, "forking", void 0);
|
152
152
|
_defineProperty(this, "git", void 0);
|
153
153
|
_defineProperty(this, "wsConfigFiles", void 0);
|
154
|
-
this
|
154
|
+
_defineProperty(this, "generator", void 0);
|
155
|
+
this.workspacePath = options.currentDir ? process.cwd() : (0, _path().resolve)(this.workspaceName);
|
155
156
|
}
|
156
157
|
async generate() {
|
157
|
-
if (_fsExtra().default.existsSync(this.workspacePath)) {
|
158
|
+
if (!this.options.currentDir && _fsExtra().default.existsSync(this.workspacePath)) {
|
158
159
|
throw new Error(`unable to create a workspace at "${this.workspaceName}", this path already exist`);
|
159
160
|
}
|
160
161
|
await _fsExtra().default.ensureDir(this.workspacePath);
|
@@ -168,6 +169,7 @@ class WorkspaceGenerator {
|
|
168
169
|
// the workspace will be in install context until the end of the generation install process
|
169
170
|
this.workspace.inInstallContext = true;
|
170
171
|
await this.setupGitBitmapMergeDriver();
|
172
|
+
await this.createComponentsFromRemote();
|
171
173
|
await this.forkComponentsFromRemote();
|
172
174
|
await this.importComponentsFromRemote();
|
173
175
|
await this.workspace.clearCache();
|
@@ -183,8 +185,7 @@ class WorkspaceGenerator {
|
|
183
185
|
await this.compileComponents(true);
|
184
186
|
await this.wsConfigFiles.writeConfigFiles({});
|
185
187
|
} catch (err) {
|
186
|
-
|
187
|
-
(_this$logger = this.logger) === null || _this$logger === void 0 || _this$logger.error(`failed generating a new workspace, will delete the dir ${this.workspacePath}`, err);
|
188
|
+
this.logger?.error(`failed generating a new workspace, will delete the dir ${this.workspacePath}`, err);
|
188
189
|
await _fsExtra().default.remove(this.workspacePath);
|
189
190
|
throw err;
|
190
191
|
}
|
@@ -244,33 +245,37 @@ class WorkspaceGenerator {
|
|
244
245
|
this.forking = this.harmony.get(_forking().default.id);
|
245
246
|
this.git = this.harmony.get(_git().default.id);
|
246
247
|
this.wsConfigFiles = this.harmony.get(_workspaceConfigFiles().default.id);
|
248
|
+
this.generator = this.harmony.get(_generator().GeneratorAspect.id);
|
249
|
+
}
|
250
|
+
async createComponentsFromRemote() {
|
251
|
+
if (this.options.empty || !this.template.create) return;
|
252
|
+
const workspaceContext = this.getWorkspaceContext();
|
253
|
+
const componentsToCreate = this.template.create(workspaceContext);
|
254
|
+
await (0, _pMapSeries().default)(componentsToCreate, async componentToCreate => {
|
255
|
+
return this.generator.generateComponentTemplate([componentToCreate.componentName], componentToCreate.templateName, {
|
256
|
+
aspect: componentToCreate.aspect,
|
257
|
+
env: componentToCreate.env,
|
258
|
+
path: componentToCreate.path,
|
259
|
+
scope: componentToCreate.scope
|
260
|
+
});
|
261
|
+
});
|
247
262
|
}
|
248
|
-
|
249
|
-
// WIP
|
250
|
-
// private async createComponentsFromRemote() {
|
251
|
-
// if (this.options.empty || !this.template.create) return
|
252
|
-
// const workspaceContext = this.getWorkspaceContext();
|
253
|
-
// const componentsToCreate = this.template.create(workspaceContext)
|
254
|
-
// await pMapSeries(componentsToCreate, async (componentToCreate) => {
|
255
|
-
// await ComponentGenerator.generate(componentToCreate);
|
256
|
-
// });
|
257
|
-
// }
|
258
|
-
|
259
263
|
async forkComponentsFromRemote() {
|
260
|
-
var _this$template, _this$template$import, _this$template2, _this$template2$fork;
|
261
264
|
if (this.options.empty) return;
|
262
265
|
const workspaceContext = this.getWorkspaceContext();
|
263
|
-
const componentsToFork =
|
266
|
+
const componentsToFork = this.template?.importComponents?.(workspaceContext) || this.template?.fork?.(workspaceContext) || [];
|
264
267
|
if (!componentsToFork.length) return;
|
265
268
|
const componentsToForkRestructured = componentsToFork.map(({
|
266
269
|
id,
|
267
270
|
targetName,
|
268
271
|
path,
|
269
272
|
env,
|
270
|
-
config
|
273
|
+
config,
|
274
|
+
targetScope
|
271
275
|
}) => ({
|
272
276
|
sourceId: id,
|
273
277
|
targetId: targetName,
|
278
|
+
targetScope,
|
274
279
|
path,
|
275
280
|
env,
|
276
281
|
config
|
@@ -282,10 +287,9 @@ class WorkspaceGenerator {
|
|
282
287
|
});
|
283
288
|
}
|
284
289
|
async importComponentsFromRemote() {
|
285
|
-
var _this$template3, _this$template3$impor;
|
286
290
|
if (this.options.empty) return;
|
287
291
|
const workspaceContext = this.getWorkspaceContext();
|
288
|
-
const componentsToImport =
|
292
|
+
const componentsToImport = this.template?.import?.(workspaceContext) || [];
|
289
293
|
if (!componentsToImport.length) return;
|
290
294
|
await (0, _pMapSeries().default)(componentsToImport, async componentToImport => {
|
291
295
|
await this.importer.import({
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_fsExtra","data","_interopRequireDefault","require","_bit","_execa","_pMapSeries","_ui","_logger","_workspace","_forking","_consumer","_importer","_compiler","_gitExecutable","_gitNotFound","_path","_git","_install","_workspaceConfigFiles","_generator","obj","__esModule","default","_defineProperty","key","value","_toPropertyKey","Object","defineProperty","enumerable","configurable","writable","t","i","_toPrimitive","String","r","e","Symbol","toPrimitive","call","TypeError","Number","WorkspaceGenerator","constructor","workspaceName","options","template","aspectComponent","workspacePath","resolve","generate","fs","existsSync","Error","ensureDir","process","chdir","initGit","init","skipGit","writeWorkspaceFiles","reloadBitInWorkspaceDir","workspace","inInstallContext","setupGitBitmapMergeDriver","forkComponentsFromRemote","importComponentsFromRemote","clearCache","install","undefined","dedupe","import","copyPeerToRuntimeOnRoot","copyPeerToRuntimeOnComponents","updateExisting","compileComponents","wsConfigFiles","writeConfigFiles","err","_this$logger","logger","error","remove","gitExecutablePath","getGitExecutablePath","params","execa","exitCodeName","GitNotFound","git","setGitMergeDriver","global","buildUI","uiMain","harmony","get","UIAspect","id","createRuntime","getWorkspaceContext","name","defaultScope","empty","workspaceContext","templateFiles","generateFiles","Promise","all","map","templateFile","outputFile","join","relativePath","content","loadBit","WorkspaceAspect","InstallAspect","loggerMain","LoggerAspect","createLogger","GeneratorAspect","importer","ImporterAspect","forking","ForkingAspect","GitAspect","WorkspaceConfigFilesAspect","_this$template","_this$template$import","_this$template2","_this$template2$fork","componentsToFork","importComponents","fork","length","componentsToForkRestructured","targetName","path","env","config","sourceId","targetId","forkMultipleFromRemote","scope","refactor","_this$template3","_this$template3$impor","componentsToImport","pMapSeries","componentToImport","ids","installNpmPackages","writeToPath","bitMap","write","compiler","CompilerAspect","compileOnWorkspace","exports"],"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 GitAspect, { GitMain } from '@teambit/git';\nimport { InstallAspect, InstallMain } from '@teambit/install';\nimport WorkspaceConfigFilesAspect, { WorkspaceConfigFilesMain } from '@teambit/workspace-config-files';\n// import { ComponentGenerator } from './component-generator';\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 private git: GitMain;\n private wsConfigFiles: WorkspaceConfigFilesMain;\n // private componentGenerator?: ComponentGenerator;\n\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 // Setting the workspace to be in install context to prevent errors during the workspace generation\n // the workspace will be in install context until the end of the generation install process\n this.workspace.inInstallContext = true;\n await this.setupGitBitmapMergeDriver();\n await this.forkComponentsFromRemote();\n await this.importComponentsFromRemote();\n await this.workspace.clearCache();\n await this.install.install(undefined, {\n dedupe: true,\n import: false,\n copyPeerToRuntimeOnRoot: true,\n copyPeerToRuntimeOnComponents: false,\n updateExisting: false,\n });\n\n // compile the components again now that we have the dependencies installed\n await this.compileComponents(true);\n await this.wsConfigFiles.writeConfigFiles({});\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 setupGitBitmapMergeDriver() {\n if (this.options.skipGit) return;\n await this.git.setGitMergeDriver({ global: false });\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 skipGit: this.options.skipGit,\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 this.git = this.harmony.get<GitMain>(GitAspect.id);\n this.wsConfigFiles = this.harmony.get<WorkspaceConfigFilesMain>(WorkspaceConfigFilesAspect.id);\n }\n\n // WIP\n // private async createComponentsFromRemote() {\n // if (this.options.empty || !this.template.create) return\n // const workspaceContext = this.getWorkspaceContext();\n // const componentsToCreate = this.template.create(workspaceContext)\n // await pMapSeries(componentsToCreate, async (componentToCreate) => {\n // await ComponentGenerator.generate(componentToCreate);\n // });\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, env, config }) => ({\n sourceId: id,\n targetId: targetName,\n path,\n env,\n config,\n }));\n await this.forking.forkMultipleFromRemote(componentsToForkRestructured, {\n scope: this.workspace.defaultScope,\n refactor: true,\n install: false,\n });\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 writeConfigFiles: false,\n writeToPath: componentToImport.path,\n },\n []\n );\n });\n\n await this.workspace.bitMap.write('new');\n }\n\n private async compileComponents(clearCache = true) {\n if (clearCache) {\n await this.workspace.clearCache();\n }\n const compiler = this.harmony.get<CompilerMain>(CompilerAspect.id);\n await compiler.compileOnWorkspace();\n }\n}\n"],"mappings":";;;;;;AAAA,SAAAA,SAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,QAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,KAAA;EAAA,MAAAH,IAAA,GAAAE,OAAA;EAAAC,IAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAGA,SAAAI,OAAA;EAAA,MAAAJ,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAE,MAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAK,YAAA;EAAA,MAAAL,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAG,WAAA,YAAAA,CAAA;IAAA,OAAAL,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAM,IAAA;EAAA,MAAAN,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAI,GAAA,YAAAA,CAAA;IAAA,OAAAN,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAO,QAAA;EAAA,MAAAP,IAAA,GAAAE,OAAA;EAAAK,OAAA,YAAAA,CAAA;IAAA,OAAAP,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAQ,WAAA;EAAA,MAAAR,IAAA,GAAAE,OAAA;EAAAM,UAAA,YAA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CAACD,iBAAiB,CAACpD,EAAE,CAAC;QAC3BsD,kBAAkB,EAAE,KAAK;QACzB1E,gBAAgB,EAAE,KAAK;QACvB2E,WAAW,EAAEH,iBAAiB,CAACZ;MACjC,CAAC,EACD,EACF,CAAC;IACH,CAAC,CAAC;IAEF,MAAM,IAAI,CAAC3E,SAAS,CAAC2F,MAAM,CAACC,KAAK,CAAC,KAAK,CAAC;EAC1C;EAEA,MAAc/E,iBAAiBA,CAACR,UAAU,GAAG,IAAI,EAAE;IACjD,IAAIA,UAAU,EAAE;MACd,MAAM,IAAI,CAACL,SAAS,CAACK,UAAU,CAAC,CAAC;IACnC;IACA,MAAMwF,QAAQ,GAAG,IAAI,CAAC7D,OAAO,CAACC,GAAG,CAAe6D,0BAAc,CAAC3D,EAAE,CAAC;IAClE,MAAM0D,QAAQ,CAACE,kBAAkB,CAAC,CAAC;EACrC;AACF;AAACC,OAAA,CAAApH,kBAAA,GAAAA,kBAAA"}
|
1
|
+
{"version":3,"names":["_fsExtra","data","_interopRequireDefault","require","_bit","_execa","_pMapSeries","_ui","_logger","_workspace","_forking","_consumer","_importer","_compiler","_gitExecutable","_gitNotFound","_path","_git","_install","_workspaceConfigFiles","_generator","obj","__esModule","default","_defineProperty","key","value","_toPropertyKey","Object","defineProperty","enumerable","configurable","writable","t","i","_toPrimitive","String","r","e","Symbol","toPrimitive","call","TypeError","Number","WorkspaceGenerator","constructor","workspaceName","options","template","aspectComponent","workspacePath","currentDir","process","cwd","resolve","generate","fs","existsSync","Error","ensureDir","chdir","initGit","init","skipGit","writeWorkspaceFiles","reloadBitInWorkspaceDir","workspace","inInstallContext","setupGitBitmapMergeDriver","createComponentsFromRemote","forkComponentsFromRemote","importComponentsFromRemote","clearCache","install","undefined","dedupe","import","copyPeerToRuntimeOnRoot","copyPeerToRuntimeOnComponents","updateExisting","compileComponents","wsConfigFiles","writeConfigFiles","err","logger","error","remove","gitExecutablePath","getGitExecutablePath","params","execa","exitCodeName","GitNotFound","git","setGitMergeDriver","global","buildUI","uiMain","harmony","get","UIAspect","id","createRuntime","getWorkspaceContext","name","defaultScope","empty","workspaceContext","templateFiles","generateFiles","Promise","all","map","templateFile","outputFile","join","relativePath","content","loadBit","WorkspaceAspect","InstallAspect","loggerMain","LoggerAspect","createLogger","GeneratorAspect","importer","ImporterAspect","forking","ForkingAspect","GitAspect","WorkspaceConfigFilesAspect","generator","create","componentsToCreate","pMapSeries","componentToCreate","generateComponentTemplate","componentName","templateName","aspect","env","path","scope","componentsToFork","importComponents","fork","length","componentsToForkRestructured","targetName","config","targetScope","sourceId","targetId","forkMultipleFromRemote","refactor","componentsToImport","componentToImport","ids","installNpmPackages","writeToPath","bitMap","write","compiler","CompilerAspect","compileOnWorkspace","exports"],"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 GitAspect, { GitMain } from '@teambit/git';\nimport { InstallAspect, InstallMain } from '@teambit/install';\nimport WorkspaceConfigFilesAspect, { WorkspaceConfigFilesMain } from '@teambit/workspace-config-files';\n// import { ComponentGenerator } from './component-generator';\nimport { WorkspaceTemplate, WorkspaceContext } from './workspace-template';\nimport { NewOptions } from './new.cmd';\nimport { GeneratorAspect } from './generator.aspect';\nimport { GeneratorMain } from './generator.main.runtime';\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 private git: GitMain;\n private wsConfigFiles: WorkspaceConfigFilesMain;\n private generator: GeneratorMain;\n\n // private componentGenerator?: ComponentGenerator;\n\n constructor(\n private workspaceName: string,\n private options: NewOptions & { currentDir?: boolean },\n private template: WorkspaceTemplate,\n private aspectComponent?: Component\n ) {\n this.workspacePath = options.currentDir ? process.cwd() : resolve(this.workspaceName);\n }\n\n async generate(): Promise<string> {\n if (!this.options.currentDir && 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 // Setting the workspace to be in install context to prevent errors during the workspace generation\n // the workspace will be in install context until the end of the generation install process\n this.workspace.inInstallContext = true;\n await this.setupGitBitmapMergeDriver();\n await this.createComponentsFromRemote();\n await this.forkComponentsFromRemote();\n await this.importComponentsFromRemote();\n await this.workspace.clearCache();\n await this.install.install(undefined, {\n dedupe: true,\n import: false,\n copyPeerToRuntimeOnRoot: true,\n copyPeerToRuntimeOnComponents: false,\n updateExisting: false,\n });\n\n // compile the components again now that we have the dependencies installed\n await this.compileComponents(true);\n await this.wsConfigFiles.writeConfigFiles({});\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 setupGitBitmapMergeDriver() {\n if (this.options.skipGit) return;\n await this.git.setGitMergeDriver({ global: false });\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 skipGit: this.options.skipGit,\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 this.git = this.harmony.get<GitMain>(GitAspect.id);\n this.wsConfigFiles = this.harmony.get<WorkspaceConfigFilesMain>(WorkspaceConfigFilesAspect.id);\n this.generator = this.harmony.get<GeneratorMain>(GeneratorAspect.id);\n }\n\n private async createComponentsFromRemote() {\n if (this.options.empty || !this.template.create) return;\n const workspaceContext = this.getWorkspaceContext();\n const componentsToCreate = this.template.create(workspaceContext);\n await pMapSeries(componentsToCreate, async (componentToCreate) => {\n return this.generator.generateComponentTemplate(\n [componentToCreate.componentName],\n componentToCreate.templateName,\n {\n aspect: componentToCreate.aspect,\n env: componentToCreate.env,\n path: componentToCreate.path,\n scope: componentToCreate.scope,\n }\n );\n });\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, env, config, targetScope }) => ({\n sourceId: id,\n targetId: targetName,\n targetScope,\n path,\n env,\n config,\n }));\n await this.forking.forkMultipleFromRemote(componentsToForkRestructured, {\n scope: this.workspace.defaultScope,\n refactor: true,\n install: false,\n });\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 writeConfigFiles: false,\n writeToPath: componentToImport.path,\n },\n []\n );\n });\n\n await this.workspace.bitMap.write('new');\n }\n\n private async compileComponents(clearCache = true) {\n if (clearCache) {\n await this.workspace.clearCache();\n }\n const compiler = this.harmony.get<CompilerMain>(CompilerAspect.id);\n await compiler.compileOnWorkspace();\n }\n}\n"],"mappings":";;;;;;AAAA,SAAAA,SAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,QAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,KAAA;EAAA,MAAAH,IAAA,GAAAE,OAAA;EAAAC,IAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAGA,SAAAI,OAAA;EAAA,MAAAJ,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAE,MAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAAA;EAA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AE;IACjD,IAAIA,UAAU,EAAE;MACd,MAAM,IAAI,CAACN,SAAS,CAACM,UAAU,CAAC,CAAC;IACnC;IACA,MAAM0F,QAAQ,GAAG,IAAI,CAAChE,OAAO,CAACC,GAAG,CAAegE,0BAAc,CAAC9D,EAAE,CAAC;IAClE,MAAM6D,QAAQ,CAACE,kBAAkB,CAAC,CAAC;EACrC;AACF;AAACC,OAAA,CAAAzH,kBAAA,GAAAA,kBAAA"}
|
@@ -40,7 +40,7 @@ export interface BaseWorkspaceOptions {
|
|
40
40
|
/**
|
41
41
|
* WorkspaceContext represents foundational properties for a workspace context.
|
42
42
|
*/
|
43
|
-
export
|
43
|
+
export type WorkspaceContext = BaseWorkspaceOptions;
|
44
44
|
export interface WorkspaceFile {
|
45
45
|
/**
|
46
46
|
* relative path of the file within the workspace.
|
@@ -51,11 +51,41 @@ export interface WorkspaceFile {
|
|
51
51
|
*/
|
52
52
|
content: string;
|
53
53
|
}
|
54
|
+
export interface CreateComponentInfo {
|
55
|
+
/**
|
56
|
+
* the template for generating the component
|
57
|
+
*/
|
58
|
+
templateName: string;
|
59
|
+
/**
|
60
|
+
* component name to generate
|
61
|
+
*/
|
62
|
+
componentName: string;
|
63
|
+
/**
|
64
|
+
* sets the component's scope-name. if not entered, the default-scope will be used
|
65
|
+
*/
|
66
|
+
scope?: string;
|
67
|
+
/**
|
68
|
+
* relative path in the workspace. by default the path is `<scope>/<namespace>/<name>`
|
69
|
+
*/
|
70
|
+
path?: string;
|
71
|
+
/**
|
72
|
+
* set the component's environment. (overrides the env from variants and the template)
|
73
|
+
*/
|
74
|
+
env?: string;
|
75
|
+
/**
|
76
|
+
* aspect-id of the template.
|
77
|
+
*/
|
78
|
+
aspect?: string;
|
79
|
+
}
|
54
80
|
export interface ForkComponentInfo extends ImportComponentInfo {
|
55
81
|
/**
|
56
82
|
* a new component name. if not specified, use the original id (without the scope)
|
57
83
|
*/
|
58
84
|
targetName?: string;
|
85
|
+
/**
|
86
|
+
* a new scope for the component. if not specified, use the original scope
|
87
|
+
*/
|
88
|
+
targetScope?: string;
|
59
89
|
/**
|
60
90
|
* env to use for the component.
|
61
91
|
*/
|
@@ -72,7 +102,7 @@ export interface ForkComponentInfo extends ImportComponentInfo {
|
|
72
102
|
/**
|
73
103
|
* @deprecated use ForkComponentInfo instead.
|
74
104
|
*/
|
75
|
-
export
|
105
|
+
export type ComponentToImport = ForkComponentInfo;
|
76
106
|
export interface ImportComponentInfo {
|
77
107
|
/**
|
78
108
|
* full component id
|
@@ -119,4 +149,8 @@ export interface WorkspaceTemplate {
|
|
119
149
|
* change their source code and update the dependency names according to the new component names.
|
120
150
|
*/
|
121
151
|
fork?: (context: WorkspaceContext) => ForkComponentInfo[];
|
152
|
+
/**
|
153
|
+
* populate new components into the new workspace and add them as new components.
|
154
|
+
*/
|
155
|
+
create?: (context: WorkspaceContext) => CreateComponentInfo[];
|
122
156
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":[],"sources":["workspace-template.ts"],"sourcesContent":["import type { Component } from '@teambit/component';\nimport { ComponentConfig } from './component-template';\n\n/**\n * BaseWorkspaceOptions describes the foundational properties for workspaces.\n */\nexport interface BaseWorkspaceOptions {\n /**\n * The name of the workspace as provided by the user (e.g., `react-app`).\n * This is also used as the directory name for the workspace.\n */\n name: string;\n\n /**\n * The default scope provided by the user.\n * This is set in the workspace.jsonc and is utilized for components within the workspace.\n */\n defaultScope?: string;\n\n /**\n * Indicates whether the user has opted to avoid creating components (typically with a `--empty` flag).\n */\n empty?: boolean;\n\n /**\n * Represents the aspect in the context where a remote aspect is imported (often via the `--aspect` flag).\n * This is useful for obtaining the aspect-id and other related information.\n */\n aspectComponent?: Component;\n\n /**\n * Represents the selected template to initialize or create the workspace.\n */\n template: WorkspaceTemplate;\n\n /**\n * Flag to check if Git repository generation should be skipped.\n */\n skipGit?: boolean;\n\n /**\n * Local path to the workspace template.\n * Useful during the development of a workspace-template.\n */\n loadFrom?: string;\n}\n\n/**\n * WorkspaceContext represents foundational properties for a workspace context.\n */\nexport type WorkspaceContext = BaseWorkspaceOptions;\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 ForkComponentInfo extends ImportComponentInfo {\n /**\n * a new component name. if not specified, use the original id (without the scope)\n */\n targetName?: string;\n /**\n * env to use for the component.\n */\n env?: string;\n\n /**\n * component config. gets saved in the .bitmap file and 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;\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 starter. 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 starter. shown in the `bit starter` command when outside of bit-workspace.\n */\n description?: string;\n\n /**\n * hide this starter so that it is not listed with `bit starter`\n */\n hidden?: boolean;\n\n /**\n * starter 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":""}
|
1
|
+
{"version":3,"names":[],"sources":["workspace-template.ts"],"sourcesContent":["import type { Component } from '@teambit/component';\nimport { ComponentConfig } from './component-template';\n\n/**\n * BaseWorkspaceOptions describes the foundational properties for workspaces.\n */\nexport interface BaseWorkspaceOptions {\n /**\n * The name of the workspace as provided by the user (e.g., `react-app`).\n * This is also used as the directory name for the workspace.\n */\n name: string;\n\n /**\n * The default scope provided by the user.\n * This is set in the workspace.jsonc and is utilized for components within the workspace.\n */\n defaultScope?: string;\n\n /**\n * Indicates whether the user has opted to avoid creating components (typically with a `--empty` flag).\n */\n empty?: boolean;\n\n /**\n * Represents the aspect in the context where a remote aspect is imported (often via the `--aspect` flag).\n * This is useful for obtaining the aspect-id and other related information.\n */\n aspectComponent?: Component;\n\n /**\n * Represents the selected template to initialize or create the workspace.\n */\n template: WorkspaceTemplate;\n\n /**\n * Flag to check if Git repository generation should be skipped.\n */\n skipGit?: boolean;\n\n /**\n * Local path to the workspace template.\n * Useful during the development of a workspace-template.\n */\n loadFrom?: string;\n}\n\n/**\n * WorkspaceContext represents foundational properties for a workspace context.\n */\nexport type WorkspaceContext = BaseWorkspaceOptions;\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 CreateComponentInfo {\n /**\n * the template for generating the component\n */\n templateName: string;\n /**\n * component name to generate\n */\n componentName: string;\n /**\n * sets the component's scope-name. if not entered, the default-scope will be used\n */\n scope?: string;\n /**\n * relative path in the workspace. by default the path is `<scope>/<namespace>/<name>`\n */\n path?: string;\n /**\n * set the component's environment. (overrides the env from variants and the template)\n */\n env?: string;\n /**\n * aspect-id of the template.\n */\n aspect?: string;\n}\n\nexport interface ForkComponentInfo extends ImportComponentInfo {\n /**\n * a new component name. if not specified, use the original id (without the scope)\n */\n targetName?: string;\n\n /**\n * a new scope for the component. if not specified, use the original scope\n */\n targetScope?: string;\n\n /**\n * env to use for the component.\n */\n env?: string;\n\n /**\n * component config. gets saved in the .bitmap file and 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;\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 starter. 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 starter. shown in the `bit starter` command when outside of bit-workspace.\n */\n description?: string;\n\n /**\n * hide this starter so that it is not listed with `bit starter`\n */\n hidden?: boolean;\n\n /**\n * starter 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 /**\n * populate new components into the new workspace and add them as new components.\n */\n create?: (context: WorkspaceContext) => CreateComponentInfo[];\n}\n"],"mappings":""}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import { EnvHandler } from '@teambit/envs';
|
2
|
+
import { TemplateList } from './template-list';
|
3
|
+
import { StarterList } from './starter-list';
|
4
|
+
|
5
|
+
export interface GeneratorEnv {
|
6
|
+
/**
|
7
|
+
* return a template list instance.
|
8
|
+
*/
|
9
|
+
generators(): EnvHandler<TemplateList>;
|
10
|
+
/**
|
11
|
+
* return a starter list instance.
|
12
|
+
*/
|
13
|
+
starters(): EnvHandler<StarterList>;
|
14
|
+
}
|
@@ -0,0 +1,62 @@
|
|
1
|
+
import { Schema } from '@teambit/graphql';
|
2
|
+
import gql from 'graphql-tag';
|
3
|
+
import { GeneratorMain } from './generator.main.runtime';
|
4
|
+
import { CreateOptions } from './create.cmd';
|
5
|
+
|
6
|
+
export type CreateQueryOptions = CreateOptions & { templateName: string };
|
7
|
+
|
8
|
+
export function generatorSchema(generator: GeneratorMain): Schema {
|
9
|
+
return {
|
10
|
+
typeDefs: gql`
|
11
|
+
type GenerateResult {
|
12
|
+
id: String
|
13
|
+
dir: String
|
14
|
+
files: [String]
|
15
|
+
}
|
16
|
+
|
17
|
+
type Mutation {
|
18
|
+
# create Component by template
|
19
|
+
createComponent(
|
20
|
+
name: String!
|
21
|
+
templateName: String!
|
22
|
+
scope: String
|
23
|
+
namespace: String
|
24
|
+
aspect: String
|
25
|
+
): [GenerateResult]
|
26
|
+
}
|
27
|
+
|
28
|
+
type TemplateDescriptor {
|
29
|
+
aspectId: String!
|
30
|
+
name: String!
|
31
|
+
}
|
32
|
+
|
33
|
+
type Generator {
|
34
|
+
templates: [TemplateDescriptor]
|
35
|
+
}
|
36
|
+
|
37
|
+
type Query {
|
38
|
+
generator: Generator
|
39
|
+
}
|
40
|
+
`,
|
41
|
+
resolvers: {
|
42
|
+
Mutation: {
|
43
|
+
createComponent: async (req: any, { name, templateName, ...options }: CreateQueryOptions) => {
|
44
|
+
const res = await generator.generateComponentTemplate([name], templateName, { name, ...options });
|
45
|
+
return res.map((component) => ({
|
46
|
+
id: component.id.toString(),
|
47
|
+
dir: component.dir,
|
48
|
+
files: component.files,
|
49
|
+
}));
|
50
|
+
},
|
51
|
+
},
|
52
|
+
Generator: {
|
53
|
+
templates: async () => {
|
54
|
+
return generator.listTemplates();
|
55
|
+
},
|
56
|
+
},
|
57
|
+
Query: {
|
58
|
+
generator: () => generator,
|
59
|
+
},
|
60
|
+
},
|
61
|
+
};
|
62
|
+
}
|