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.
@@ -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('🚧 Creating robots file…');
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 copyFiles({
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ngx-devkit-builders",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "author": {
5
5
  "name": "Dominik HladΓ­k",
6
6
  "email": "dominik.hladik@seznam.cz",
@@ -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
- console.log('\nπŸ“‹ COMPONENT IMPORTS SORTING ANALYSIS');
151
- console.log('━'.repeat(80));
136
+ context.logger.info('\nπŸ“‹ COMPONENT IMPORTS SORTING ANALYSIS');
137
+ context.logger.info('━'.repeat(80));
152
138
  if (options.dryRun) {
153
- console.log('πŸ” DRY RUN MODE - No files were modified');
154
- console.log('');
139
+ context.logger.info('πŸ” DRY RUN MODE - No files were modified');
155
140
  }
156
- console.log(`πŸ“Š Summary: ${analyses.length} files analyzed`);
157
- console.log(`βœ… ${unchangedFiles.length} files already have sorted imports`);
158
- console.log(`πŸ”„ ${changedFiles.length} files ${options.dryRun ? 'would be' : 'were'} updated`);
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
- console.log('');
161
- console.log(`πŸ“ Files ${options.dryRun ? 'that would be' : 'that were'} updated:`);
162
- console.log('─'.repeat(80));
163
- console.log('Component Name'.padEnd(35) + 'Sorted Imports');
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
- // Use cyan color for sorted imports to match the existing imports color
169
- console.log(componentName.padEnd(35) + colors.cyan + sortedImports + colors.reset);
152
+ context.logger.info(componentName.padEnd(35) + sortedImports);
170
153
  });
171
- console.log('─'.repeat(80));
154
+ context.logger.info('─'.repeat(80));
172
155
  }
173
156
  if (options.verbose && unchangedFiles.length > 0) {
174
- console.log('');
175
- console.log('✨ Files with already sorted imports:');
176
- console.log('─'.repeat(80));
177
- console.log('Component Name'.padEnd(35) + 'Current Imports');
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
- // Use cyan color for components with existing sorted imports
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
- console.log(componentName.padEnd(35) + colors.gray + colors.dim + noImportsText + colors.reset);
169
+ context.logger.info(componentName.padEnd(35) + noImportsText);
190
170
  }
191
171
  });
192
- console.log('─'.repeat(80));
172
+ context.logger.info('─'.repeat(80));
193
173
  }
194
- console.log('━'.repeat(80));
174
+ context.logger.info('━'.repeat(80));
195
175
  };
196
- exports.default = (0, architect_1.createBuilder)((options, context) => {
197
- return new Promise((resolve) => {
198
- try {
199
- const projectRoot = context.target?.project
200
- ? (0, path_1.join)(context.workspaceRoot, 'projects', context.target.project)
201
- : context.workspaceRoot;
202
- const srcDir = (0, path_1.join)(projectRoot, 'src');
203
- if (!(0, fs_1.statSync)(srcDir).isDirectory()) {
204
- context.logger.error(`Source directory not found: ${srcDir}`);
205
- resolve({ success: false });
206
- return;
207
- }
208
- // Find all TypeScript files recursively
209
- const allTsFiles = walkDirectory(srcDir);
210
- // Filter to only component and directive files
211
- const targetFiles = allTsFiles.filter((file) => isAngularComponentOrDirective(file, options.includeDirectives));
212
- if (targetFiles.length === 0) {
213
- console.log('No Angular components or directives found.');
214
- resolve({ success: true });
215
- return;
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
- // Process each file
218
- const analyses = [];
219
- for (const filePath of targetFiles) {
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
  });