@teambit/generator 0.0.555 → 0.0.556
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/package.json +26 -20
- package/component-generator.ts +0 -119
- package/component-template.ts +0 -66
- package/create.cmd.ts +0 -44
- package/generator.aspect.ts +0 -5
- package/generator.docs.mdx +0 -8
- package/generator.graphql.ts +0 -66
- package/generator.main.runtime.ts +0 -279
- package/index.ts +0 -4
- package/new.cmd.ts +0 -79
- package/package-tar/teambit-generator-0.0.555.tgz +0 -0
- package/templates/component-generator/files/aspect-file.ts +0 -10
- package/templates/component-generator/files/docs-file.ts +0 -54
- package/templates/component-generator/files/index.ts +0 -10
- package/templates/component-generator/files/main-runtime.ts +0 -125
- package/templates/component-generator/index.ts +0 -32
- package/templates/workspace-generator/files/aspect-file.ts +0 -10
- package/templates/workspace-generator/files/docs-file.ts +0 -37
- package/templates/workspace-generator/files/git-ignore-tpl.ts +0 -113
- package/templates/workspace-generator/files/index-tpl.ts +0 -29
- package/templates/workspace-generator/files/index.ts +0 -10
- package/templates/workspace-generator/files/main-runtime.ts +0 -24
- package/templates/workspace-generator/files/readme-tpl.ts +0 -39
- package/templates/workspace-generator/files/workspace-config-tpl.ts +0 -18
- package/templates/workspace-generator/index.ts +0 -52
- package/templates.cmd.ts +0 -48
- package/tsconfig.json +0 -34
- package/types/asset.d.ts +0 -29
- package/types/style.d.ts +0 -42
- package/types.ts +0 -3
- package/workspace-generator.ts +0 -246
- package/workspace-template.ts +0 -82
package/templates.cmd.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { Command, CommandOptions } from '@teambit/cli';
|
|
2
|
-
import chalk from 'chalk';
|
|
3
|
-
import { groupBy } from 'lodash';
|
|
4
|
-
import { GeneratorMain, TemplateDescriptor } from './generator.main.runtime';
|
|
5
|
-
|
|
6
|
-
export type TemplatesOptions = {
|
|
7
|
-
showAll?: boolean;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export class TemplatesCmd implements Command {
|
|
11
|
-
name = 'templates';
|
|
12
|
-
description =
|
|
13
|
-
'list components templates when inside bit-workspace (for bit-create), otherwise, list workspace templates (for bit-new)';
|
|
14
|
-
shortDescription = 'list templates for "bit create" and "bit new"';
|
|
15
|
-
alias = '';
|
|
16
|
-
loader = true;
|
|
17
|
-
group = 'development';
|
|
18
|
-
options = [['s', 'show-all', 'show hidden templates']] as CommandOptions;
|
|
19
|
-
|
|
20
|
-
constructor(private generator: GeneratorMain) {}
|
|
21
|
-
|
|
22
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
23
|
-
async report(args: [], templatesOptions: TemplatesOptions) {
|
|
24
|
-
let results = await this.generator.listTemplates();
|
|
25
|
-
|
|
26
|
-
// Make sure that we don't list hidden templates
|
|
27
|
-
if (!templatesOptions.showAll) {
|
|
28
|
-
results = results.filter((template) => !template.hidden);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const grouped = groupBy(results, 'aspectId');
|
|
32
|
-
const titleStr = this.generator.isRunningInsideWorkspace()
|
|
33
|
-
? `The following template(s) are available with the command bit create: \nExample - bit create <template-name> <component-name>`
|
|
34
|
-
: `The following template(s) are available with the command bit new: \nExample - bit new <template-name> <workspace-name>`;
|
|
35
|
-
const title = chalk.green(`\n${titleStr}\n`);
|
|
36
|
-
const templateOutput = (template: TemplateDescriptor) => {
|
|
37
|
-
const desc = template.description ? ` (${template.description})` : '';
|
|
38
|
-
return ` ${template.name}${chalk.dim(desc)}`;
|
|
39
|
-
};
|
|
40
|
-
const output = Object.keys(grouped)
|
|
41
|
-
.map((aspectId) => {
|
|
42
|
-
const names = grouped[aspectId].map(templateOutput).join('\n');
|
|
43
|
-
return `${chalk.blue.bold(aspectId)}\n${names}\n`;
|
|
44
|
-
})
|
|
45
|
-
.join('\n');
|
|
46
|
-
return title + output;
|
|
47
|
-
}
|
|
48
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"lib": [
|
|
4
|
-
"es2019",
|
|
5
|
-
"DOM",
|
|
6
|
-
"ES6",
|
|
7
|
-
"DOM.Iterable",
|
|
8
|
-
"ScriptHost"
|
|
9
|
-
],
|
|
10
|
-
"target": "es2015",
|
|
11
|
-
"module": "commonjs",
|
|
12
|
-
"jsx": "react",
|
|
13
|
-
"declaration": true,
|
|
14
|
-
"sourceMap": true,
|
|
15
|
-
"skipLibCheck": true,
|
|
16
|
-
"moduleResolution": "node",
|
|
17
|
-
"esModuleInterop": true,
|
|
18
|
-
"outDir": "dist",
|
|
19
|
-
"composite": true,
|
|
20
|
-
"emitDeclarationOnly": true,
|
|
21
|
-
"experimentalDecorators": true,
|
|
22
|
-
"emitDecoratorMetadata": true,
|
|
23
|
-
"allowSyntheticDefaultImports": true,
|
|
24
|
-
"strictPropertyInitialization": false,
|
|
25
|
-
"strict": true,
|
|
26
|
-
"noImplicitAny": false,
|
|
27
|
-
"rootDir": ".",
|
|
28
|
-
"preserveConstEnums": true,
|
|
29
|
-
"resolveJsonModule": true
|
|
30
|
-
},
|
|
31
|
-
"exclude": [
|
|
32
|
-
"dist"
|
|
33
|
-
]
|
|
34
|
-
}
|
package/types/asset.d.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
declare module '*.png' {
|
|
2
|
-
const value: any;
|
|
3
|
-
export = value;
|
|
4
|
-
}
|
|
5
|
-
declare module '*.svg' {
|
|
6
|
-
import type { FunctionComponent, SVGProps } from 'react';
|
|
7
|
-
|
|
8
|
-
export const ReactComponent: FunctionComponent<SVGProps<SVGSVGElement> & { title?: string }>;
|
|
9
|
-
const src: string;
|
|
10
|
-
export default src;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
// @TODO Gilad
|
|
14
|
-
declare module '*.jpg' {
|
|
15
|
-
const value: any;
|
|
16
|
-
export = value;
|
|
17
|
-
}
|
|
18
|
-
declare module '*.jpeg' {
|
|
19
|
-
const value: any;
|
|
20
|
-
export = value;
|
|
21
|
-
}
|
|
22
|
-
declare module '*.gif' {
|
|
23
|
-
const value: any;
|
|
24
|
-
export = value;
|
|
25
|
-
}
|
|
26
|
-
declare module '*.bmp' {
|
|
27
|
-
const value: any;
|
|
28
|
-
export = value;
|
|
29
|
-
}
|
package/types/style.d.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
declare module '*.module.css' {
|
|
2
|
-
const classes: { readonly [key: string]: string };
|
|
3
|
-
export default classes;
|
|
4
|
-
}
|
|
5
|
-
declare module '*.module.scss' {
|
|
6
|
-
const classes: { readonly [key: string]: string };
|
|
7
|
-
export default classes;
|
|
8
|
-
}
|
|
9
|
-
declare module '*.module.sass' {
|
|
10
|
-
const classes: { readonly [key: string]: string };
|
|
11
|
-
export default classes;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
declare module '*.module.less' {
|
|
15
|
-
const classes: { readonly [key: string]: string };
|
|
16
|
-
export default classes;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
declare module '*.less' {
|
|
20
|
-
const classes: { readonly [key: string]: string };
|
|
21
|
-
export default classes;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
declare module '*.css' {
|
|
25
|
-
const classes: { readonly [key: string]: string };
|
|
26
|
-
export default classes;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
declare module '*.sass' {
|
|
30
|
-
const classes: { readonly [key: string]: string };
|
|
31
|
-
export default classes;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
declare module '*.scss' {
|
|
35
|
-
const classes: { readonly [key: string]: string };
|
|
36
|
-
export default classes;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
declare module '*.mdx' {
|
|
40
|
-
const component: any;
|
|
41
|
-
export default component;
|
|
42
|
-
}
|
package/types.ts
DELETED
package/workspace-generator.ts
DELETED
|
@@ -1,246 +0,0 @@
|
|
|
1
|
-
import fs from 'fs-extra';
|
|
2
|
-
import { isBinaryFile } from 'isbinaryfile';
|
|
3
|
-
import { loadBit } from '@teambit/bit';
|
|
4
|
-
import { Harmony } from '@teambit/harmony';
|
|
5
|
-
import { Component } from '@teambit/component';
|
|
6
|
-
import execa from 'execa';
|
|
7
|
-
import { BitId } from '@teambit/legacy-bit-id';
|
|
8
|
-
import pMapSeries from 'p-map-series';
|
|
9
|
-
import UIAspect, { UiMain } from '@teambit/ui';
|
|
10
|
-
import { Logger, LoggerAspect, LoggerMain } from '@teambit/logger';
|
|
11
|
-
import { WorkspaceAspect, Workspace } from '@teambit/workspace';
|
|
12
|
-
import { PkgAspect, PkgMain } from '@teambit/pkg';
|
|
13
|
-
import { init } from '@teambit/legacy/dist/api/consumer';
|
|
14
|
-
import { CompilerAspect, CompilerMain } from '@teambit/compiler';
|
|
15
|
-
import getGitExecutablePath from '@teambit/legacy/dist/utils/git/git-executable';
|
|
16
|
-
import GitNotFound from '@teambit/legacy/dist/utils/git/exceptions/git-not-found';
|
|
17
|
-
import path from 'path';
|
|
18
|
-
import { DependencyResolverMain, DependencyResolverAspect } from '@teambit/dependency-resolver';
|
|
19
|
-
import { ComponentID } from '@teambit/component-id';
|
|
20
|
-
import { WorkspaceTemplate } from './workspace-template';
|
|
21
|
-
import { NewOptions } from './new.cmd';
|
|
22
|
-
import { GeneratorAspect } from './generator.aspect';
|
|
23
|
-
|
|
24
|
-
export type GenerateResult = { id: ComponentID; dir: string; files: string[]; envId: string };
|
|
25
|
-
|
|
26
|
-
type CompToImportResolved = {
|
|
27
|
-
id: ComponentID;
|
|
28
|
-
path: string;
|
|
29
|
-
targetName?: string;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export class WorkspaceGenerator {
|
|
33
|
-
private workspacePath: string;
|
|
34
|
-
private harmony: Harmony;
|
|
35
|
-
private workspace: Workspace;
|
|
36
|
-
private logger: Logger;
|
|
37
|
-
constructor(
|
|
38
|
-
private workspaceName: string,
|
|
39
|
-
private options: NewOptions,
|
|
40
|
-
private template: WorkspaceTemplate,
|
|
41
|
-
private aspectComponent?: Component
|
|
42
|
-
) {
|
|
43
|
-
this.workspacePath = path.resolve(this.workspaceName);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
async generate(): Promise<string> {
|
|
47
|
-
if (fs.existsSync(this.workspacePath)) {
|
|
48
|
-
throw new Error(`unable to create a workspace at "${this.workspaceName}", this path already exist`);
|
|
49
|
-
}
|
|
50
|
-
await fs.ensureDir(this.workspacePath);
|
|
51
|
-
try {
|
|
52
|
-
process.chdir(this.workspacePath);
|
|
53
|
-
await this.initGit();
|
|
54
|
-
await init(this.workspacePath, this.options.skipGit, false, false, false, false, {});
|
|
55
|
-
await this.writeWorkspaceFiles();
|
|
56
|
-
await this.reloadBitInWorkspaceDir();
|
|
57
|
-
await this.addComponentsFromRemote();
|
|
58
|
-
await this.workspace.install(undefined, {
|
|
59
|
-
dedupe: true,
|
|
60
|
-
import: false,
|
|
61
|
-
copyPeerToRuntimeOnRoot: true,
|
|
62
|
-
copyPeerToRuntimeOnComponents: false,
|
|
63
|
-
updateExisting: false,
|
|
64
|
-
});
|
|
65
|
-
// await this.buildUI(); // disabled for now. it takes too long
|
|
66
|
-
} catch (err: any) {
|
|
67
|
-
await fs.remove(this.workspacePath);
|
|
68
|
-
throw err;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
return this.workspacePath;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
private async initGit() {
|
|
75
|
-
if (this.options.skipGit) return;
|
|
76
|
-
const gitExecutablePath = getGitExecutablePath();
|
|
77
|
-
const params = ['init'];
|
|
78
|
-
try {
|
|
79
|
-
await execa(gitExecutablePath, params);
|
|
80
|
-
} catch (err: any) {
|
|
81
|
-
if (err.exitCodeName === 'ENOENT') {
|
|
82
|
-
throw new GitNotFound(gitExecutablePath, err);
|
|
83
|
-
}
|
|
84
|
-
throw err;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
private async buildUI() {
|
|
89
|
-
const uiMain = this.harmony.get<UiMain>(UIAspect.id);
|
|
90
|
-
await uiMain.createRuntime({});
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* writes the generated template files to the default directory set in the workspace config
|
|
95
|
-
*/
|
|
96
|
-
private async writeWorkspaceFiles(): Promise<void> {
|
|
97
|
-
const workspaceContext = {
|
|
98
|
-
name: this.workspaceName,
|
|
99
|
-
defaultScope: this.options.defaultScope,
|
|
100
|
-
empty: this.options.empty,
|
|
101
|
-
aspectComponent: this.aspectComponent,
|
|
102
|
-
};
|
|
103
|
-
const templateFiles = await this.template.generateFiles(workspaceContext);
|
|
104
|
-
await Promise.all(
|
|
105
|
-
templateFiles.map(async (templateFile) => {
|
|
106
|
-
await fs.outputFile(path.join(this.workspacePath, templateFile.relativePath), templateFile.content);
|
|
107
|
-
})
|
|
108
|
-
);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
private async reloadBitInWorkspaceDir() {
|
|
112
|
-
this.harmony = await loadBit(this.workspacePath);
|
|
113
|
-
this.workspace = this.harmony.get<Workspace>(WorkspaceAspect.id);
|
|
114
|
-
const loggerMain = this.harmony.get<LoggerMain>(LoggerAspect.id);
|
|
115
|
-
this.logger = loggerMain.createLogger(GeneratorAspect.id);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
private async addComponentsFromRemote() {
|
|
119
|
-
if (this.options.empty) return;
|
|
120
|
-
const componentsToImport = this.template?.importComponents?.();
|
|
121
|
-
if (!componentsToImport || !componentsToImport.length) return;
|
|
122
|
-
const dependencyResolver = this.harmony.get<DependencyResolverMain>(DependencyResolverAspect.id);
|
|
123
|
-
|
|
124
|
-
const componentsToImportResolved = await Promise.all(
|
|
125
|
-
componentsToImport.map(async (c) => ({
|
|
126
|
-
id: ComponentID.fromLegacy(BitId.parse(c.id, true)),
|
|
127
|
-
path: c.path,
|
|
128
|
-
targetName: c.targetName,
|
|
129
|
-
}))
|
|
130
|
-
);
|
|
131
|
-
const componentIds = componentsToImportResolved.map((c) => c.id);
|
|
132
|
-
// @todo: improve performance by changing `getRemoteComponent` api to accept multiple ids
|
|
133
|
-
const components = await Promise.all(componentIds.map((id) => this.workspace.scope.getRemoteComponent(id)));
|
|
134
|
-
const oldAndNewPackageNames = this.getNewPackageNames(components, componentsToImportResolved);
|
|
135
|
-
const oldAndNewComponentIds = this.getNewComponentIds(components, componentsToImportResolved);
|
|
136
|
-
await Promise.all(
|
|
137
|
-
components.map((comp) =>
|
|
138
|
-
this.replaceOriginalPackageNameWithNew(comp, oldAndNewPackageNames, oldAndNewComponentIds)
|
|
139
|
-
)
|
|
140
|
-
);
|
|
141
|
-
await pMapSeries(components, async (comp) => {
|
|
142
|
-
const compData = componentsToImportResolved.find((c) => c.id._legacy.isEqualWithoutVersion(comp.id._legacy));
|
|
143
|
-
if (!compData) throw new Error(`workspace-generator, unable to find ${comp.id.toString()} in the given ids`);
|
|
144
|
-
await this.workspace.write(compData.path, comp);
|
|
145
|
-
await this.workspace.track({
|
|
146
|
-
rootDir: compData.path,
|
|
147
|
-
componentName: compData.targetName || compData.id.fullName,
|
|
148
|
-
mainFile: comp.state._consumer.mainFile,
|
|
149
|
-
});
|
|
150
|
-
const deps = await dependencyResolver.getDependencies(comp);
|
|
151
|
-
|
|
152
|
-
const currentPackages = Object.keys(oldAndNewPackageNames);
|
|
153
|
-
// only bring auto-resolved dependencies, others should be set in the workspace.jsonc template
|
|
154
|
-
const workspacePolicyEntries = deps
|
|
155
|
-
.filter((dep) => dep.source === 'auto')
|
|
156
|
-
.map((dep) => ({
|
|
157
|
-
dependencyId: dep.getPackageName?.() || dep.id,
|
|
158
|
-
lifecycleType: dep.lifecycle === 'dev' ? 'runtime' : dep.lifecycle,
|
|
159
|
-
value: {
|
|
160
|
-
version: dep.version,
|
|
161
|
-
},
|
|
162
|
-
}))
|
|
163
|
-
.filter((entry) => !currentPackages.includes(entry.dependencyId)); // remove components that are now imported
|
|
164
|
-
dependencyResolver.addToRootPolicy(workspacePolicyEntries, { updateExisting: true });
|
|
165
|
-
});
|
|
166
|
-
await this.workspace.writeBitMap();
|
|
167
|
-
await dependencyResolver.persistConfig(this.workspace.path);
|
|
168
|
-
this.workspace.clearCache();
|
|
169
|
-
await this.compileComponents();
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
private async compileComponents() {
|
|
173
|
-
const compiler = this.harmony.get<CompilerMain>(CompilerAspect.id);
|
|
174
|
-
await compiler.compileOnWorkspace();
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
private getNewPackageNames(
|
|
178
|
-
components: Component[],
|
|
179
|
-
compsData: CompToImportResolved[]
|
|
180
|
-
): { [oldPackageName: string]: string } {
|
|
181
|
-
const pkg = this.harmony.get<PkgMain>(PkgAspect.id);
|
|
182
|
-
const packageToReplace = {};
|
|
183
|
-
const scopeToReplace = this.workspace.defaultScope.replace('.', '/');
|
|
184
|
-
components.forEach((comp) => {
|
|
185
|
-
const newId = this.resolveNewCompId(comp, compsData);
|
|
186
|
-
const currentPackageName = pkg.getPackageName(comp);
|
|
187
|
-
const newName = newId.fullName.replace(/\//g, '.');
|
|
188
|
-
const newPackageName = `@${scopeToReplace}.${newName}`;
|
|
189
|
-
packageToReplace[currentPackageName] = newPackageName;
|
|
190
|
-
});
|
|
191
|
-
return packageToReplace;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
private getNewComponentIds(
|
|
195
|
-
components: Component[],
|
|
196
|
-
compsData: CompToImportResolved[]
|
|
197
|
-
): { [oldComponentId: string]: string } {
|
|
198
|
-
const componentToReplace = {};
|
|
199
|
-
components.forEach((comp) => {
|
|
200
|
-
const newId = this.resolveNewCompId(comp, compsData);
|
|
201
|
-
componentToReplace[comp.id.toStringWithoutVersion()] = newId.toStringWithoutVersion();
|
|
202
|
-
});
|
|
203
|
-
return componentToReplace;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
private resolveNewCompId(comp: Component, compsData: CompToImportResolved[]): ComponentID {
|
|
207
|
-
const scopeToReplace = this.workspace.defaultScope;
|
|
208
|
-
const compData = compsData.find((c) => c.id._legacy.isEqualWithoutScopeAndVersion(comp.id._legacy));
|
|
209
|
-
if (!compData) {
|
|
210
|
-
throw new Error(`workspace-generator: unable to find data for "${comp.id._legacy.toString()}"`);
|
|
211
|
-
}
|
|
212
|
-
return compData.targetName
|
|
213
|
-
? ComponentID.fromLegacy(BitId.parse(compData.targetName, false).changeScope(scopeToReplace))
|
|
214
|
-
: comp.id.changeScope(scopeToReplace);
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
private async replaceOriginalPackageNameWithNew(
|
|
218
|
-
comp: Component,
|
|
219
|
-
packageToReplace: Record<string, string>,
|
|
220
|
-
oldAndNewComponentIds: Record<string, string>
|
|
221
|
-
) {
|
|
222
|
-
await Promise.all(
|
|
223
|
-
comp.filesystem.files.map(async (file) => {
|
|
224
|
-
const isBinary = await isBinaryFile(file.contents);
|
|
225
|
-
if (isBinary) return;
|
|
226
|
-
const strContent = file.contents.toString();
|
|
227
|
-
let newContent = strContent;
|
|
228
|
-
Object.keys(packageToReplace).forEach((currentPackage) => {
|
|
229
|
-
if (strContent.includes(currentPackage)) {
|
|
230
|
-
const currentPkgRegex = new RegExp(currentPackage, 'g');
|
|
231
|
-
newContent = newContent.replace(currentPkgRegex, packageToReplace[currentPackage]);
|
|
232
|
-
}
|
|
233
|
-
});
|
|
234
|
-
Object.keys(oldAndNewComponentIds).forEach((currentId) => {
|
|
235
|
-
if (strContent.includes(currentId)) {
|
|
236
|
-
const currentIdRegex = new RegExp(currentId, 'g');
|
|
237
|
-
newContent = newContent.replace(currentIdRegex, oldAndNewComponentIds[currentId]);
|
|
238
|
-
}
|
|
239
|
-
});
|
|
240
|
-
if (strContent !== newContent) {
|
|
241
|
-
file.contents = Buffer.from(newContent);
|
|
242
|
-
}
|
|
243
|
-
})
|
|
244
|
-
);
|
|
245
|
-
}
|
|
246
|
-
}
|
package/workspace-template.ts
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import type { Component } from '@teambit/component';
|
|
2
|
-
|
|
3
|
-
export interface WorkspaceFile {
|
|
4
|
-
/**
|
|
5
|
-
* relative path of the file within the workspace.
|
|
6
|
-
*/
|
|
7
|
-
relativePath: string;
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* file content
|
|
11
|
-
*/
|
|
12
|
-
content: string;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export interface WorkspaceContext {
|
|
16
|
-
/**
|
|
17
|
-
* workspace-name as entered by the user, e.g. `react-app`.
|
|
18
|
-
* it is used as the directory name for the workspace.
|
|
19
|
-
*/
|
|
20
|
-
name: string;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* default scope as entered by the user.
|
|
24
|
-
* it will be set in the workspace.jsonc and be used for components
|
|
25
|
-
*/
|
|
26
|
-
defaultScope?: string;
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* whether user entered `--empty` flag in `bit new` to avoid creating components.
|
|
30
|
-
*/
|
|
31
|
-
empty?: boolean;
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* in case the "--aspect" flag used to import a remote aspect, this is populated with that aspect.
|
|
35
|
-
* useful to get the aspect-id and other info.
|
|
36
|
-
*/
|
|
37
|
-
aspectComponent?: Component;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export interface ComponentToImport {
|
|
41
|
-
/**
|
|
42
|
-
* full component id
|
|
43
|
-
*/
|
|
44
|
-
id: string;
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* path where to write the component
|
|
48
|
-
*/
|
|
49
|
-
path: string;
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* a new component name. if not specified, use the original id (without the scope)
|
|
53
|
-
*/
|
|
54
|
-
targetName?: string;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export interface WorkspaceTemplate {
|
|
58
|
-
/**
|
|
59
|
-
* name of the workspace template. for example: `react-workspace`.
|
|
60
|
-
*/
|
|
61
|
-
name: string;
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* short description of the template. shown in the `bit templates` command when outside of bit-workspace.
|
|
65
|
-
*/
|
|
66
|
-
description?: string;
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* hide this template so that it is not listed with `bit templates`
|
|
70
|
-
*/
|
|
71
|
-
hidden?: boolean;
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* template function for generating the template files,
|
|
75
|
-
*/
|
|
76
|
-
generateFiles(context: WorkspaceContext): Promise<WorkspaceFile[]>;
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* populate existing components into the new workspace and add them as new components
|
|
80
|
-
*/
|
|
81
|
-
importComponents?: () => ComponentToImport[];
|
|
82
|
-
}
|