ngx-devkit-builders 2.0.0 β 2.0.1
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/copy-environment/index.js +2 -14
- package/package.json +1 -1
- package/sort-imports/index.js +57 -81
|
@@ -3,16 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const architect_1 = require("@angular-devkit/architect");
|
|
4
4
|
const core_1 = require("@angular-devkit/core");
|
|
5
5
|
const fs_extra_1 = require("fs-extra");
|
|
6
|
-
async function copyFiles({ sourceFile, targetFile, overwrite }) {
|
|
7
|
-
return new Promise((resolve, reject) => {
|
|
8
|
-
(0, fs_extra_1.copy)(sourceFile, targetFile, { overwrite }, () => {
|
|
9
|
-
reject();
|
|
10
|
-
});
|
|
11
|
-
resolve();
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
6
|
exports.default = (0, architect_1.createBuilder)(async ({ verbose, source, target, overwrite }, ctx) => {
|
|
15
|
-
ctx.logger.info('π§
|
|
7
|
+
ctx.logger.info('π§ Copying environmentβ¦');
|
|
16
8
|
const projectMetadata = await ctx.getProjectMetadata(ctx.target.project);
|
|
17
9
|
if (projectMetadata.projectType !== 'application') {
|
|
18
10
|
ctx.logger.error('β Project must be type of application');
|
|
@@ -30,11 +22,7 @@ exports.default = (0, architect_1.createBuilder)(async ({ verbose, source, targe
|
|
|
30
22
|
const sourceFile = `${environmentsFolder}/${source}`;
|
|
31
23
|
const targetFile = `${environmentsFolder}/${target}`;
|
|
32
24
|
try {
|
|
33
|
-
await
|
|
34
|
-
sourceFile,
|
|
35
|
-
targetFile,
|
|
36
|
-
overwrite,
|
|
37
|
-
});
|
|
25
|
+
await (0, fs_extra_1.copy)(sourceFile, targetFile, { overwrite });
|
|
38
26
|
if (overwrite) {
|
|
39
27
|
ctx.logger.info(`βοΈ Environment replaced in "${targetFile}"`);
|
|
40
28
|
}
|
package/package.json
CHANGED
package/sort-imports/index.js
CHANGED
|
@@ -5,20 +5,6 @@ const ast_utils_1 = require("@schematics/angular/utility/ast-utils");
|
|
|
5
5
|
const fs_1 = require("fs");
|
|
6
6
|
const path_1 = require("path");
|
|
7
7
|
const ts = require("typescript");
|
|
8
|
-
// ANSI color codes for terminal output
|
|
9
|
-
const colors = {
|
|
10
|
-
reset: '\x1b[0m',
|
|
11
|
-
bright: '\x1b[1m',
|
|
12
|
-
dim: '\x1b[2m',
|
|
13
|
-
red: '\x1b[31m',
|
|
14
|
-
green: '\x1b[32m',
|
|
15
|
-
yellow: '\x1b[33m',
|
|
16
|
-
blue: '\x1b[34m',
|
|
17
|
-
magenta: '\x1b[35m',
|
|
18
|
-
cyan: '\x1b[36m',
|
|
19
|
-
white: '\x1b[37m',
|
|
20
|
-
gray: '\x1b[90m',
|
|
21
|
-
};
|
|
22
8
|
const walkDirectory = (dir, files = []) => {
|
|
23
9
|
const items = (0, fs_1.readdirSync)(dir, { withFileTypes: true });
|
|
24
10
|
for (const item of items) {
|
|
@@ -144,96 +130,86 @@ const updateComponentImports = (content, sortedImports) => {
|
|
|
144
130
|
visitNode(sourceFile);
|
|
145
131
|
return updatedContent;
|
|
146
132
|
};
|
|
147
|
-
const outputResults = (analyses, options) => {
|
|
133
|
+
const outputResults = (analyses, options, context) => {
|
|
148
134
|
const changedFiles = analyses.filter((a) => a.hasChanges);
|
|
149
135
|
const unchangedFiles = analyses.filter((a) => !a.hasChanges);
|
|
150
|
-
|
|
151
|
-
|
|
136
|
+
context.logger.info('\nπ COMPONENT IMPORTS SORTING ANALYSIS');
|
|
137
|
+
context.logger.info('β'.repeat(80));
|
|
152
138
|
if (options.dryRun) {
|
|
153
|
-
|
|
154
|
-
console.log('');
|
|
139
|
+
context.logger.info('π DRY RUN MODE - No files were modified');
|
|
155
140
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
141
|
+
context.logger.info(`π Summary: ${analyses.length} files analyzed`);
|
|
142
|
+
context.logger.info(`β
${unchangedFiles.length} files already have sorted imports`);
|
|
143
|
+
context.logger.info(`π ${changedFiles.length} files ${options.dryRun ? 'would be' : 'were'} updated`);
|
|
159
144
|
if (options.verbose && changedFiles.length > 0) {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
console.log('β'.repeat(80));
|
|
145
|
+
context.logger.info(`π Files ${options.dryRun ? 'that would be' : 'that were'} updated:`);
|
|
146
|
+
context.logger.info('β'.repeat(80));
|
|
147
|
+
context.logger.info('Component Name'.padEnd(35) + 'Sorted Imports');
|
|
148
|
+
context.logger.info('β'.repeat(80));
|
|
165
149
|
changedFiles.forEach((analysis) => {
|
|
166
150
|
const componentName = analysis.componentName.length > 32 ? analysis.componentName.substring(0, 29) + '...' : analysis.componentName;
|
|
167
151
|
const sortedImports = `[${analysis.sortedImports.join(', ')}]`;
|
|
168
|
-
|
|
169
|
-
console.log(componentName.padEnd(35) + colors.cyan + sortedImports + colors.reset);
|
|
152
|
+
context.logger.info(componentName.padEnd(35) + sortedImports);
|
|
170
153
|
});
|
|
171
|
-
|
|
154
|
+
context.logger.info('β'.repeat(80));
|
|
172
155
|
}
|
|
173
156
|
if (options.verbose && unchangedFiles.length > 0) {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
console.log('β'.repeat(80));
|
|
157
|
+
context.logger.info('β¨ Files with already sorted imports:');
|
|
158
|
+
context.logger.info('β'.repeat(80));
|
|
159
|
+
context.logger.info('Component Name'.padEnd(35) + 'Current Imports');
|
|
160
|
+
context.logger.info('β'.repeat(80));
|
|
179
161
|
unchangedFiles.forEach((analysis) => {
|
|
180
162
|
const componentName = analysis.componentName.length > 32 ? analysis.componentName.substring(0, 29) + '...' : analysis.componentName;
|
|
181
163
|
if (analysis.importsArray.length > 0) {
|
|
182
164
|
const imports = `[${analysis.importsArray.join(', ')}]`;
|
|
183
|
-
|
|
184
|
-
console.log(componentName.padEnd(35) + colors.cyan + imports + colors.reset);
|
|
165
|
+
context.logger.info(componentName.padEnd(35) + imports);
|
|
185
166
|
}
|
|
186
167
|
else {
|
|
187
|
-
// Use gray/dim color for components without imports
|
|
188
168
|
const noImportsText = 'No imports array found';
|
|
189
|
-
|
|
169
|
+
context.logger.info(componentName.padEnd(35) + noImportsText);
|
|
190
170
|
}
|
|
191
171
|
});
|
|
192
|
-
|
|
172
|
+
context.logger.info('β'.repeat(80));
|
|
193
173
|
}
|
|
194
|
-
|
|
174
|
+
context.logger.info('β'.repeat(80));
|
|
195
175
|
};
|
|
196
|
-
exports.default = (0, architect_1.createBuilder)((options, context) => {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
176
|
+
exports.default = (0, architect_1.createBuilder)(async (options, context) => {
|
|
177
|
+
try {
|
|
178
|
+
const projectRoot = context.target?.project
|
|
179
|
+
? (0, path_1.join)(context.workspaceRoot, 'projects', context.target.project)
|
|
180
|
+
: context.workspaceRoot;
|
|
181
|
+
const srcDir = (0, path_1.join)(projectRoot, 'src');
|
|
182
|
+
if (!(0, fs_1.statSync)(srcDir).isDirectory()) {
|
|
183
|
+
context.logger.error(`Source directory not found: ${srcDir}`);
|
|
184
|
+
return { success: false };
|
|
185
|
+
}
|
|
186
|
+
// Find all TypeScript files recursively
|
|
187
|
+
const allTsFiles = walkDirectory(srcDir);
|
|
188
|
+
// Filter to only component and directive files
|
|
189
|
+
const targetFiles = allTsFiles.filter((file) => isAngularComponentOrDirective(file, options.includeDirectives));
|
|
190
|
+
if (targetFiles.length === 0) {
|
|
191
|
+
context.logger.info('No Angular components or directives found.');
|
|
192
|
+
return { success: true };
|
|
193
|
+
}
|
|
194
|
+
// Process each file
|
|
195
|
+
const analyses = [];
|
|
196
|
+
for (const filePath of targetFiles) {
|
|
197
|
+
try {
|
|
198
|
+
const analysis = processFile(filePath, options);
|
|
199
|
+
analyses.push(analysis);
|
|
216
200
|
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
try {
|
|
221
|
-
const analysis = processFile(filePath, options);
|
|
222
|
-
analyses.push(analysis);
|
|
223
|
-
}
|
|
224
|
-
catch (error) {
|
|
225
|
-
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
226
|
-
context.logger.warn(`Failed to process ${filePath}: ${errorMessage}`);
|
|
227
|
-
}
|
|
201
|
+
catch (error) {
|
|
202
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
203
|
+
context.logger.warn(`Failed to process ${filePath}: ${errorMessage}`);
|
|
228
204
|
}
|
|
229
|
-
// Output results
|
|
230
|
-
outputResults(analyses, options);
|
|
231
|
-
resolve({ success: true });
|
|
232
|
-
}
|
|
233
|
-
catch (err) {
|
|
234
|
-
const errorMessage = err instanceof Error ? err.message : 'Unknown error';
|
|
235
|
-
context.logger.error('Error sorting imports: ' + errorMessage);
|
|
236
|
-
resolve({ success: false });
|
|
237
205
|
}
|
|
238
|
-
|
|
206
|
+
// Output results
|
|
207
|
+
outputResults(analyses, options, context);
|
|
208
|
+
return { success: true };
|
|
209
|
+
}
|
|
210
|
+
catch (err) {
|
|
211
|
+
const errorMessage = err instanceof Error ? err.message : 'Unknown error';
|
|
212
|
+
context.logger.error('Error sorting imports: ' + errorMessage);
|
|
213
|
+
return { success: false };
|
|
214
|
+
}
|
|
239
215
|
});
|