@teambit/workspace-config-files 1.0.108 → 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/ws-config.cmd.ts DELETED
@@ -1,186 +0,0 @@
1
- /* eslint-disable max-classes-per-file */
2
-
3
- import { Command, CommandOptions } from '@teambit/cli';
4
- import chalk from 'chalk';
5
- import { WorkspaceConfigFilesMain, WriteConfigFilesResult } from './workspace-config-files.main.runtime';
6
- import { formatCleanOutput, formatListOutput, formatWriteOutput, verboseFormatWriteOutput } from './outputs';
7
-
8
- export type CleanConfigCmdFlags = {
9
- dryRun?: boolean;
10
- silent?: boolean;
11
- };
12
-
13
- export type WriteConfigCmdFlags = {
14
- dryRun?: boolean;
15
- writers?: string;
16
- noDedupe?: boolean;
17
- dryRunWithContent?: boolean;
18
- clean?: boolean;
19
- silent?: boolean;
20
- verbose?: boolean;
21
- };
22
-
23
- const COMMAND_NAME = 'ws-config';
24
-
25
- export class WsConfigCmd implements Command {
26
- name = `${COMMAND_NAME} <sub-command>`;
27
- alias = 'workspace-config';
28
- description = 'manage workspace config files';
29
- options = [];
30
- group = 'development';
31
- commands: Command[] = [];
32
- // helpUrl = '';
33
-
34
- async report([unrecognizedSubcommand]: [string]) {
35
- return chalk.red(
36
- `"${unrecognizedSubcommand}" is not a subcommand of "ws-config", please run "bit ws-config --help" to list the subcommands`
37
- );
38
- }
39
- }
40
-
41
- export class WsConfigWriteCmd implements Command {
42
- name = 'write';
43
- description = 'write config files in the workspace. useful for IDEs';
44
- alias = '';
45
- group = 'development';
46
- options = [
47
- [
48
- 'c',
49
- 'clean',
50
- 'delete existing config files from the workspace. highly recommended to run it with "--dry-run" first',
51
- ],
52
- [
53
- 'w',
54
- 'writers <writers>',
55
- `only write config files for the given writers. use comma to separate multiple writers. use ${COMMAND_NAME} list to see all writers`,
56
- ],
57
- ['s', 'silent', 'do not prompt for confirmation'],
58
- ['', 'no-dedupe', "write configs inside each one of the component's dir, avoid deduping"],
59
- ['', 'dry-run', 'show the paths that configs will be written per env'],
60
- [
61
- '',
62
- 'dry-run-with-content',
63
- 'use with --json flag. show the config content and the paths that will be written per env',
64
- ],
65
- ['v', 'verbose', 'showing verbose output for writing'],
66
- ['j', 'json', 'json format'],
67
- ] as CommandOptions;
68
-
69
- constructor(private workspaceConfigFilesMain: WorkspaceConfigFilesMain) {}
70
-
71
- async report(_args, flags: WriteConfigCmdFlags) {
72
- const results = (await this.json(_args, flags)) as WriteConfigFilesResult;
73
- if (flags.dryRunWithContent) {
74
- throw new Error(`use --json flag along with --dry-run-with-content`);
75
- }
76
- const envsNotImplementing = this.workspaceConfigFilesMain.getEnvsNotImplementing();
77
- const warning = getWarningForNonImplementingEnvs(envsNotImplementing);
78
- const output = flags.verbose ? verboseFormatWriteOutput(results, flags) : formatWriteOutput(results, flags);
79
- return warning + output;
80
- }
81
-
82
- async json(_args, flags: WriteConfigCmdFlags) {
83
- const { clean, silent, noDedupe, dryRunWithContent, writers } = flags;
84
- const dryRun = dryRunWithContent ? true : !!flags.dryRun;
85
- const { cleanResults, writeResults, wsDir } = await this.workspaceConfigFilesMain.writeConfigFiles({
86
- clean,
87
- dedupe: !noDedupe,
88
- dryRun,
89
- silent,
90
- writers: writers?.split(','),
91
- });
92
-
93
- if (dryRun) {
94
- const updatedWriteResults = writeResults;
95
- if (!dryRunWithContent) {
96
- updatedWriteResults.writersResult = updatedWriteResults.writersResult.map((oneWriterResult) => {
97
- oneWriterResult.realConfigFiles.forEach((realConfigFile) => {
98
- realConfigFile.writtenRealConfigFile.content = '';
99
- });
100
- oneWriterResult.extendingConfigFiles.forEach((extendingConfigFile) => {
101
- extendingConfigFile.extendingConfigFile.content = '';
102
- });
103
- return oneWriterResult;
104
- });
105
- }
106
-
107
- return {
108
- wsDir,
109
- cleanResults,
110
- writeResults: updatedWriteResults,
111
- };
112
- }
113
- return { wsDir, cleanResults, writeResults };
114
- }
115
- }
116
-
117
- export class WsConfigCleanCmd implements Command {
118
- name = 'clean';
119
- description = 'clean (delete) written config files in the workspace. useful for IDEs';
120
- alias = '';
121
- group = 'development';
122
- options = [
123
- ['s', 'silent', 'do not prompt for confirmation'],
124
- [
125
- 'w',
126
- 'writers <writers>',
127
- `only clean config files for the given writers. use comma to separate multiple writers. use ${COMMAND_NAME} list to see all writers`,
128
- ],
129
- ['', 'dry-run', 'show the paths of configs that will be cleaned'],
130
- ['j', 'json', 'json format'],
131
- ] as CommandOptions;
132
-
133
- constructor(private workspaceConfigFilesMain: WorkspaceConfigFilesMain) {}
134
-
135
- async report(_args, flags: CleanConfigCmdFlags) {
136
- const results = await this.json(_args, flags);
137
- const envsNotImplementing = this.workspaceConfigFilesMain.getEnvsNotImplementing();
138
- const warning = getWarningForNonImplementingEnvs(envsNotImplementing);
139
- const output = formatCleanOutput(results, flags);
140
- return warning + output;
141
- }
142
-
143
- async json(_args, flags: WriteConfigCmdFlags) {
144
- const { silent, dryRun } = flags;
145
- const cleanResults = await this.workspaceConfigFilesMain.cleanConfigFiles({
146
- dryRun,
147
- silent,
148
- writers: flags.writers?.split(','),
149
- });
150
- return cleanResults;
151
- }
152
- }
153
-
154
- export class WsConfigListCmd implements Command {
155
- name = 'list';
156
- description = 'list config writers';
157
- alias = '';
158
- group = 'development';
159
- options = [['j', 'json', 'json format']] as CommandOptions;
160
-
161
- constructor(private workspaceConfigFilesMain: WorkspaceConfigFilesMain) {}
162
-
163
- async report() {
164
- const results = await this.json();
165
- const envsNotImplementing = this.workspaceConfigFilesMain.getEnvsNotImplementing();
166
- const warning = getWarningForNonImplementingEnvs(envsNotImplementing);
167
- const output = formatListOutput(results);
168
- return warning + output;
169
- }
170
-
171
- async json() {
172
- const cleanResults = await this.workspaceConfigFilesMain.listConfigWriters();
173
- return cleanResults;
174
- }
175
- }
176
-
177
- function getWarningForNonImplementingEnvs(envsNotImplementing: string[]) {
178
- if (!envsNotImplementing.length) return '';
179
- const message =
180
- chalk.yellow(`Bit cannot determine the correct contents for the config files to write. this may result in incorrect content.
181
- The following environments need to add support for config files: ${chalk.cyan(envsNotImplementing.join(', '))}.
182
- Read here how to correct and improve dev-ex - LINK
183
-
184
- `);
185
- return message;
186
- }