@pega/custom-dx-components 26.1.12-alpha.0.5 → 26.1.12-alpha.0.6

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pega/custom-dx-components",
3
- "version": "26.1.12-alpha.0.5",
3
+ "version": "26.1.12-alpha.0.6",
4
4
  "description": "Utility for building custom UI components",
5
5
  "bin": {
6
6
  "custom-dx-components": "./bin/index.js"
@@ -4,6 +4,9 @@ import fs from 'fs';
4
4
 
5
5
  import inquirer from 'inquirer';
6
6
  import chalk from 'chalk';
7
+ import { execa } from 'execa';
8
+
9
+ import { SHARED_DIRECTORY } from '../../constants.js';
7
10
 
8
11
  import {
9
12
  convertIntoPascalCase,
@@ -147,6 +150,25 @@ const compileMustacheTemplates = async (
147
150
  });
148
151
  };
149
152
 
153
+ // Formats the generated files with the project's own Prettier so they pass the project's `prettier -c .` check.
154
+ // Skipped when the project has no local Prettier. A formatting failure is reported but does not fail the create.
155
+ const formatGeneratedFiles = async (componentDirectory) => {
156
+ const projectDirectory = process.cwd();
157
+ if (!fs.existsSync(path.join(projectDirectory, 'node_modules', 'prettier'))) return;
158
+
159
+ // The shared folder only exists in library-based mode and holds files generated by this task.
160
+ const directories = [componentDirectory, path.join(path.dirname(componentDirectory), SHARED_DIRECTORY)].filter((directory) =>
161
+ fs.existsSync(directory),
162
+ );
163
+ const result = await execa('npx', ['--no-install', 'prettier', '--write', '--log-level', 'warn', ...directories], {
164
+ cwd: projectDirectory,
165
+ reject: false,
166
+ });
167
+ if (result.exitCode !== 0) {
168
+ console.log(chalk.yellow(`Generated files could not be formatted with Prettier: ${result.stderr || result.stdout}`));
169
+ }
170
+ };
171
+
150
172
  const validateCompile = async ({ componentName, componentLabel, library, version, framework, type, subtype, description, organization }, options) => {
151
173
  const isLibraryBased = getLibraryBased();
152
174
  let sSubType = subtype;
@@ -231,6 +253,7 @@ const validateCompile = async ({ componentName, componentLabel, library, version
231
253
  description,
232
254
  organization,
233
255
  });
256
+ await formatGeneratedFiles(targetDirectory);
234
257
 
235
258
  console.log(chalk.green(`${componentKey} component is created in ${targetDirectory}`));
236
259
  };
@@ -40,8 +40,8 @@ export const updateConfig = async ({ oldComponentKey, newComponentKey, library,
40
40
  configData.library = library;
41
41
  configData.version = version;
42
42
 
43
- // stringify "4", makes the json string look like JSON in the file, formatted instead of a single line
44
- fs.writeFileSync(join(targetDirectory, '/config.json'), JSON.stringify(configData, null, 4), {
43
+ // stringify "2", makes the json string look like JSON in the file, formatted instead of a single line
44
+ fs.writeFileSync(join(targetDirectory, '/config.json'), JSON.stringify(configData, null, 2), {
45
45
  encoding: 'utf8',
46
46
  flag: 'w',
47
47
  });
@@ -42,8 +42,8 @@ export const setTasksConfig = async (libraryName, version, devBuild, currDir) =>
42
42
  compConfig.version = version;
43
43
 
44
44
  // update file
45
- // stringify "4", makes the json string look like JSON in the file, formatted instead of a single line
46
- fs.writeFileSync(pegaConfigJsonPath, JSON.stringify(configData, null, 4), { encoding: 'utf8', flag: 'w' });
45
+ // stringify "2", makes the json string look like JSON in the file, formatted instead of a single line
46
+ fs.writeFileSync(pegaConfigJsonPath, JSON.stringify(configData, null, 2), { encoding: 'utf8', flag: 'w' });
47
47
  };
48
48
 
49
49
  export const setPackageOrg = async (organization, currDir) => {
@@ -55,8 +55,8 @@ export const setPackageOrg = async (organization, currDir) => {
55
55
  packageData.organization = organization;
56
56
 
57
57
  // update file
58
- // stringify "4", makes the json string look like JSON in the file, formatted instead of a single line
59
- fs.writeFileSync(packageJsonPath, JSON.stringify(packageData, null, 4), { encoding: 'utf8', flag: 'w' });
58
+ // stringify "2", makes the json string look like JSON in the file, formatted instead of a single line
59
+ fs.writeFileSync(packageJsonPath, `${JSON.stringify(packageData, null, 2)}\n`, { encoding: 'utf8', flag: 'w' });
60
60
  };
61
61
 
62
62
  export const updateConfig = async ({ oldComponentKey, newComponentKey, organization, library, version, currentDirectory }) => {
@@ -71,8 +71,8 @@ export const updateConfig = async ({ oldComponentKey, newComponentKey, organizat
71
71
  configData.library = library;
72
72
  configData.version = version;
73
73
 
74
- // stringify "4", makes the json string look like JSON in the file, formatted instead of a single line
75
- fs.writeFileSync(join(currentDirectory, '/config.json'), JSON.stringify(configData, null, 4), {
74
+ // stringify "2", makes the json string look like JSON in the file, formatted instead of a single line
75
+ fs.writeFileSync(join(currentDirectory, '/config.json'), `${JSON.stringify(configData, null, 2)}\n`, {
76
76
  encoding: 'utf8',
77
77
  flag: 'w',
78
78
  });
@@ -62,8 +62,8 @@ export const updateConfig = async ({ oldComponentKey, newComponentKey, library,
62
62
  configData.library = library;
63
63
  configData.version = version;
64
64
 
65
- // stringify "4", makes the json string look like JSON in the file, formatted instead of a single line
66
- fs.writeFileSync(join(targetDirectory, '/config.json'), JSON.stringify(configData, null, 4), {
65
+ // stringify "2", makes the json string look like JSON in the file, formatted instead of a single line
66
+ fs.writeFileSync(join(targetDirectory, '/config.json'), `${JSON.stringify(configData, null, 2)}\n`, {
67
67
  encoding: 'utf8',
68
68
  flag: 'w',
69
69
  });
@@ -48,8 +48,8 @@ export const updateConfig = async ({ oldComponentKey, newComponentKey, library,
48
48
  configData.description = newLabel;
49
49
  }
50
50
 
51
- // stringify "4", makes the json string look like JSON in the file, formatted instead of a single line
52
- fs.writeFileSync(join(targetDirectory, '/config.json'), JSON.stringify(configData, null, 4), { encoding: 'utf8' });
51
+ // stringify "2", makes the json string look like JSON in the file, formatted instead of a single line
52
+ fs.writeFileSync(join(targetDirectory, '/config.json'), `${JSON.stringify(configData, null, 2)}\n`, { encoding: 'utf8' });
53
53
  };
54
54
 
55
55
  export const updateFile = async (fileName, oldComponentKeyPC, newComponentKeyPC, targetDirectory) => {
@@ -0,0 +1,17 @@
1
+ # Docs and templates that are not formatted with Prettier
2
+ **/*.md
3
+ **/*.mustache
4
+ **/*.txt
5
+ **/*.npmrc
6
+ **/*.gitignore
7
+ **/LICENSE
8
+
9
+ # CLI-managed state, rewritten by the CLI with its own formatting
10
+ /store/
11
+ /tasks.config.json
12
+
13
+ # Library build output (one folder per org_library, e.g. PegaQa_DxTestLib/)
14
+ /*_*/
15
+ /build/
16
+ /dist/
17
+ /coverage/