@pega/custom-dx-components 8.8.16 → 8.8.17

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": "8.8.16",
3
+ "version": "8.8.17",
4
4
  "description": "Utility for building custom UI components",
5
5
  "bin": "./bin/index.js",
6
6
  "scripts": {
package/src/cli.js CHANGED
@@ -14,6 +14,8 @@ import {
14
14
  publishComponent,
15
15
  publishAllComponents,
16
16
  renameComponent,
17
+ revertWebPack,
18
+ promoteWebPack,
17
19
  updateComponent,
18
20
  validate,
19
21
  upgrade
@@ -25,6 +27,8 @@ const TASKS = {
25
27
  CREATE_ALL: 'createAll',
26
28
  BUILD: 'buildComponent',
27
29
  BUILD_ALL: 'buildAllComponents',
30
+ PROMOTE_WEBPACK: 'promoteWebPack',
31
+ REVERT_WEBPACK: 'revertWebPack',
28
32
  PUBLISH: 'publish',
29
33
  PUBLISH_All: 'publishAll',
30
34
  RENAME: 'rename',
@@ -72,6 +76,14 @@ export default async (args = []) => {
72
76
  createAllComponents(options);
73
77
  break;
74
78
  }
79
+ case TASKS.PROMOTE_WEBPACK: {
80
+ promoteWebPack(options);
81
+ break;
82
+ }
83
+ case TASKS.REVERT_WEBPACK: {
84
+ revertWebPack(options);
85
+ break;
86
+ }
75
87
  case TASKS.PUBLISH: {
76
88
  publishComponent(options);
77
89
  break;
package/src/constants.js CHANGED
@@ -1,6 +1,7 @@
1
1
  // cSpell:ignore words timeofday caseview casepreview objectview
2
2
  export const TASKS_CONFIG_JSON_FILENAME = 'tasks.config.json';
3
3
  export const BUILD_CONFIG_JSON_FILENAME = 'build.config.json';
4
+ export const WEBPACK_CONFIG_JS_FILENAME = "webpack.config.js";
4
5
  export const COMPONENTS_DIRECTORY_PATH = 'components-directory-path';
5
6
  export const COMPONENTS_PATH = 'component';
6
7
  export const TOKEN_PATH = 'node_modules/@pega/custom-dx-components/.access_token';
@@ -28,6 +29,8 @@ export const COMPONENT_PREFIX_FIELD_PATH = 'field/';
28
29
  export const COMPONENT_PREFIX_TEMPLATE_PATH = 'template/';
29
30
  export const COMPONENT_PREFIX_WIDGET_PATH = 'widget/';
30
31
 
32
+ export const BUILDER_INDEX_FILE_PATH = '../bundle/builder/index.js';
33
+
31
34
  export const CATEGORY_CONSTELLATION = 'constellation';
32
35
 
33
36
  export const AUTHENTICATE_DEFAULTS = {
@@ -4,7 +4,12 @@ import webpack from 'webpack';
4
4
  import FileSizeReporter from 'react-dev-utils/FileSizeReporter.js';
5
5
  import printBuildError from 'react-dev-utils/printBuildError.js';
6
6
 
7
+
8
+ // used by promote and revert webPack commands, do not change
7
9
  import configFactory from './webpack.config.js';
10
+ //import configFactory from '../../../../../../../webpack.config.js';
11
+ // do not change
12
+
8
13
  import paths from './paths.js';
9
14
 
10
15
  // Do this as the first thing so that any code reading it knows the right env.
@@ -3,9 +3,11 @@ export { default as createAllComponents } from './create-all/index.js';
3
3
  export { default as deleteComponent } from './delete/index.js';
4
4
  export { default as deleteAllComponents } from './delete-all/index.js';
5
5
  export { default as initProject } from './init/index.js';
6
+ export { default as promoteWebPack } from './promote-webpack/index.js';
6
7
  export { default as publishComponent } from './publish/index.js';
7
8
  export { default as publishAllComponents } from './publish-all/index.js';
8
9
  export { default as renameComponent } from './rename/index.js';
10
+ export { default as revertWebPack } from './revert-webpack/index.js';
9
11
  export { default as listComponents } from './list/index.js';
10
12
  export { default as updateComponent } from './update/index.js';
11
13
  export { default as validate } from './validator/index.js';
@@ -58,7 +58,7 @@
58
58
  },
59
59
  "devDependencies": {
60
60
  "@pega/configs": "^0.5.3",
61
- "@pega/custom-dx-components": "^8.8.16",
61
+ "@pega/custom-dx-components": "^8.8.17",
62
62
  "@pega/eslint-config": "^0.3.2",
63
63
  "@storybook/addon-actions": "^6.5.12",
64
64
  "@storybook/addon-essentials": "^6.5.12",
@@ -0,0 +1,94 @@
1
+
2
+ import fs from 'fs';
3
+ import path from 'path';
4
+ import { join } from 'path';
5
+ import { URL, fileURLToPath } from 'url';
6
+ import chalk from 'chalk';
7
+ import inquirer from 'inquirer';
8
+
9
+ import {
10
+ convertIntoPascalCase,
11
+ showVersion
12
+ } from '../../util.js';
13
+
14
+ import {
15
+ WEBPACK_CONFIG_JS_FILENAME,
16
+ BUILDER_INDEX_FILE_PATH
17
+ } from '../../constants.js';
18
+
19
+
20
+
21
+ let redirectFile = "";
22
+
23
+ export const copyWebPack = async () => {
24
+
25
+ // first check to see if already have the file
26
+ const newWebPackDir = path.resolve(WEBPACK_CONFIG_JS_FILENAME);
27
+ let override = true;
28
+ if (fs.existsSync(newWebPackDir)) {
29
+
30
+ console.log("Promoted file " + chalk.bold.yellow(`${newWebPackDir}`) + " already exists.");
31
+ const questions = [
32
+ {
33
+ name: 'override',
34
+ type: 'confirm',
35
+ message: `Overwrite`,
36
+ default: false
37
+ }
38
+ ];
39
+
40
+ await inquirer.prompt(questions).then(async answers => {
41
+ override = answers.override;
42
+ });
43
+
44
+ }
45
+
46
+
47
+ if (override) {
48
+ // call this function from top level
49
+ //fs.copyFileSync("./webpack.config.js", "webpack.config.js")
50
+ const promoteWebPackDir = fileURLToPath(new URL(WEBPACK_CONFIG_JS_FILENAME, import.meta.url));
51
+
52
+ fs.copyFileSync(promoteWebPackDir, newWebPackDir);
53
+
54
+ }
55
+
56
+ redirectFile = newWebPackDir;
57
+
58
+
59
+
60
+ }
61
+
62
+ export const updateBuilder = async () => {
63
+
64
+ const builderIndexDir = fileURLToPath(new URL(BUILDER_INDEX_FILE_PATH, import.meta.url));
65
+
66
+ let indexFileJS = fs.readFileSync(builderIndexDir, { encoding: 'utf8' });
67
+
68
+ if (indexFileJS.length > 0) {
69
+ // comment out original webpack reference
70
+
71
+ // if not commented out, comment out
72
+ if (indexFileJS.indexOf("//import configFactory from './webpack.config.js';") < 0) {
73
+ indexFileJS = indexFileJS.replaceAll("import configFactory from './webpack.config.js';", "//import configFactory from './webpack.config.js';");
74
+ }
75
+
76
+ // uncomment out promoted webpack reference
77
+ indexFileJS = indexFileJS.replaceAll("//import configFactory from '../../../../../../../webpack.config.js';", "import configFactory from '../../../../../../../webpack.config.js';");
78
+
79
+ fs.writeFileSync(builderIndexDir, indexFileJS, { encoding: 'utf8' });
80
+
81
+ console.log(chalk.bold.green(`Bundler now using ${redirectFile}.`));
82
+ console.log(chalk.bold.green(`Utilize this file for webpack mofifications.`));
83
+ }
84
+
85
+
86
+ }
87
+
88
+ export default async options => {
89
+ showVersion();
90
+
91
+ await copyWebPack();
92
+ await updateBuilder();
93
+
94
+ };
@@ -0,0 +1,376 @@
1
+ const path = require('path');
2
+ const fs = require('fs');
3
+
4
+ const webpack = require('webpack');
5
+ const TerserPlugin = require('terser-webpack-plugin');
6
+ const MiniCssExtractPlugin = require('mini-css-extract-plugin');
7
+ const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
8
+ const getCSSModuleLocalIdent = require('react-dev-utils/getCSSModuleLocalIdent.js');
9
+ const ModuleNotFoundPlugin = require('react-dev-utils/ModuleNotFoundPlugin.js');
10
+ const CompressionPlugin = require('compression-webpack-plugin');
11
+
12
+ // Source maps are resource heavy and can cause out of memory issue for large source files.
13
+
14
+ const compressionBRConfObj = {
15
+ filename: '[path][base].br',
16
+ algorithm: 'brotliCompress',
17
+ test: /\.(js|css|html|svg|png|jpg|woff|woff2)$/,
18
+ compressionOptions: { level: 11 }
19
+ };
20
+
21
+ /* For gzip use below */
22
+ const compressionGZConfObj = {
23
+ filename: '[path][base].gz',
24
+ algorithm: 'gzip',
25
+ test: /\.(js|css|html|svg|png|jpg|woff|woff2)$/,
26
+ compressionOptions: { level: 9 }
27
+ };
28
+
29
+ let shouldUseSourceMap = process.env.SOURCE_MAP;
30
+
31
+ const imageInlineSizeLimit = Number.parseInt(process.env.IMAGE_INLINE_SIZE_LIMIT || '10000', 10);
32
+
33
+ // style files regex
34
+ const cssRegex = /\.css$/;
35
+ const cssModuleRegex = /\.module\.css$/;
36
+ const sassRegex = /\.(scss|sass)$/;
37
+ const sassModuleRegex = /\.module\.(scss|sass)$/;
38
+
39
+ // Make sure any symlinks in the project folder are resolved:
40
+ // https://github.com/facebook/create-react-app/issues/637
41
+ const appDirectory = fs.realpathSync(process.cwd());
42
+ const resolveApp = relativePath => path.resolve(appDirectory, relativePath);
43
+
44
+ buildPath = 'dist/components';
45
+
46
+ const moduleFileExtensions = [
47
+ 'web.mjs',
48
+ 'mjs',
49
+ 'web.js',
50
+ 'js',
51
+ 'web.ts',
52
+ 'ts',
53
+ 'web.tsx',
54
+ 'tsx',
55
+ 'json',
56
+ 'web.jsx',
57
+ 'jsx'
58
+ ];
59
+
60
+ // Resolve file paths in the same order as webpack
61
+ const resolveModule = (resolveFn, filePath) => {
62
+ const extension = moduleFileExtensions.find(ext =>
63
+ fs.existsSync(resolveFn(`${filePath}.${ext}`))
64
+ );
65
+
66
+ if (extension) {
67
+ return resolveFn(`${filePath}.${extension}`);
68
+ }
69
+
70
+ return resolveFn(`${filePath}.js`);
71
+ };
72
+
73
+ // config after eject: we're in ./config/
74
+
75
+ const appPath = resolveApp('.');
76
+ const appBuild = resolveApp(buildPath);
77
+ const appSrc = resolveApp('src');
78
+
79
+
80
+ // This is the production and development configuration.
81
+ // It is focused on developer experience, fast rebuilds, and a minimal bundle.
82
+ //export default (
83
+ module.exports = (
84
+ webpackEnv,
85
+ // eslint-disable-next-line no-unused-vars
86
+ { inputFile, outputFile, componentKey, externals, globals, sourceMap, devBuild }
87
+ ) => {
88
+ const isEnvDevelopment = webpackEnv === 'development' || devBuild;
89
+ const isEnvProduction = webpackEnv === 'production';
90
+ sourceMap = sourceMap === 'true';
91
+ shouldUseSourceMap = shouldUseSourceMap || sourceMap;
92
+
93
+ // common function to get style loaders
94
+ const getStyleLoaders = (cssOptions, preProcessor) => {
95
+ const loaders = [
96
+ isEnvProduction && {
97
+ loader: MiniCssExtractPlugin.loader
98
+ },
99
+ {
100
+ loader: require.resolve('css-loader'),
101
+ options: cssOptions
102
+ },
103
+ {
104
+ // Options for PostCSS as we reference these options twice
105
+ // Adds vendor prefixing based on your specified browser support in
106
+ // package.json
107
+ loader: require.resolve('postcss-loader'),
108
+ options: {
109
+ postcssOptions: {
110
+ plugins: [
111
+ [
112
+ 'postcss-preset-env',
113
+ {
114
+ // Options
115
+ }
116
+ ]
117
+ ]
118
+ },
119
+ sourceMap: isEnvProduction ? shouldUseSourceMap : isEnvDevelopment
120
+ }
121
+ }
122
+ ].filter(Boolean);
123
+ if (preProcessor) {
124
+ loaders.push(
125
+ {
126
+ loader: require.resolve('resolve-url-loader'),
127
+ options: {
128
+ sourceMap: isEnvProduction ? shouldUseSourceMap : isEnvDevelopment,
129
+ root: appSrc
130
+ }
131
+ },
132
+ {
133
+ loader: require.resolve(preProcessor),
134
+ options: {
135
+ sourceMap: true
136
+ }
137
+ }
138
+ );
139
+ }
140
+ return loaders;
141
+ };
142
+ return {
143
+ mode: devBuild ? 'development' : 'production',
144
+ // Stop compilation early in production
145
+ bail: isEnvProduction,
146
+ // These are the "entry points" to our application.
147
+ // This means they will be the "root" imports that are included in JS bundle.
148
+ entry: inputFile,
149
+ devtool: devBuild ? 'eval-cheap-module-source-map' : false,
150
+ output: {
151
+ // The build folder.
152
+ //path: paths.appBuild,
153
+ //path: resolveApp('dist/components'),
154
+ path: appBuild,
155
+ // There will be one main bundle, and one file per asynchronous chunk.
156
+ // In development, it does not produce real files.
157
+ filename: isEnvProduction
158
+ ? `${componentKey}/${componentKey}.js`
159
+ : isEnvDevelopment && `${componentKey}/${componentKey}.js`,
160
+ chunkFilename: isEnvProduction
161
+ ? `${componentKey}/js/[name].[contenthash:8].chunk.js`
162
+ : isEnvDevelopment && `${componentKey}/js/[name].chunk.js`,
163
+ library: {
164
+ name: componentKey,
165
+ type: 'umd',
166
+ export: 'default'
167
+ },
168
+ publicPath: ''
169
+ },
170
+ optimization: {
171
+ minimize: isEnvProduction,
172
+ minimizer: [new TerserPlugin(), new CssMinimizerPlugin()]
173
+ },
174
+ resolve: {
175
+ plugins: [],
176
+ extensions: ['.tsx', '.ts', '.js']
177
+ },
178
+ resolveLoader: {
179
+ plugins: []
180
+ },
181
+ module: {
182
+ strictExportPresence: true,
183
+ rules: [
184
+ {
185
+ // "oneOf" will traverse all following loaders until one will
186
+ // match the requirements. When no loader matches it will fall
187
+ // back to the "file" loader at the end of the loader list.
188
+ oneOf: [
189
+ // TODO: Merge this config once `image/avif` is in the mime-db
190
+ // https://github.com/jshttp/mime-db
191
+ {
192
+ test: [/\.avif$/],
193
+ loader: require.resolve('url-loader'),
194
+ options: {
195
+ limit: imageInlineSizeLimit,
196
+ mimetype: 'image/avif',
197
+ name: `${componentKey}/media/[name].[hash:8].[ext]`
198
+ }
199
+ },
200
+ // "url" loader works like "file" loader except that it embeds assets
201
+ // smaller than specified limit in bytes as data URLs to avoid requests.
202
+ // A missing `test` is equivalent to a match.
203
+ {
204
+ test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/, /\.svg$/],
205
+ loader: require.resolve('url-loader'),
206
+ options: {
207
+ limit: imageInlineSizeLimit,
208
+ name: `${componentKey}/media/[name].[hash:8].[ext]`
209
+ }
210
+ },
211
+ // Process application JS with TS-Loader.
212
+ // The preset includes JSX, Flow, TypeScript, and some ESnext features.
213
+ {
214
+ test: /\.(js|mjs|jsx)$/,
215
+ include: appSrc,
216
+ loader: 'ts-loader',
217
+ options: {
218
+ configFile: 'tsconfig.build.json'
219
+ },
220
+ exclude: /node_modules/
221
+ },
222
+
223
+ {
224
+ test: /\.(ts|tsx)$/,
225
+ loader: 'ts-loader',
226
+ options: {
227
+ configFile: 'tsconfig.build.json'
228
+ },
229
+ exclude: /node_modules/
230
+ },
231
+ // "postcss" loader applies autoprefixer to our CSS.
232
+ // "css" loader resolves paths in CSS and adds assets as dependencies.
233
+ // "style" loader turns CSS into JS modules that inject <style> tags.
234
+ // In production, we use MiniCSSExtractPlugin to extract that CSS
235
+ // to a file, but in development "style" loader enables hot editing
236
+ // of CSS.
237
+ // By default we support CSS Modules with the extension .module.css
238
+ {
239
+ test: cssRegex,
240
+ exclude: cssModuleRegex,
241
+ use: getStyleLoaders({
242
+ importLoaders: 1,
243
+ sourceMap: isEnvProduction ? shouldUseSourceMap : isEnvDevelopment
244
+ }),
245
+ // Don't consider CSS imports dead code even if the
246
+ // containing package claims to have no side effects.
247
+ // Remove this when webpack adds a warning or an error for this.
248
+ // See https://github.com/webpack/webpack/issues/6571
249
+ sideEffects: true
250
+ },
251
+ // Adds support for CSS Modules (https://github.com/css-modules/css-modules)
252
+ // using the extension .module.css
253
+ {
254
+ test: cssModuleRegex,
255
+ use: getStyleLoaders({
256
+ importLoaders: 1,
257
+ sourceMap: isEnvProduction ? shouldUseSourceMap : isEnvDevelopment,
258
+ modules: {
259
+ getLocalIdent: getCSSModuleLocalIdent
260
+ }
261
+ })
262
+ },
263
+ // Opt-in support for SASS (using .scss or .sass extensions).
264
+ // By default we support SASS Modules with the
265
+ // extensions .module.scss or .module.sass
266
+ {
267
+ test: sassRegex,
268
+ exclude: sassModuleRegex,
269
+ use: getStyleLoaders(
270
+ {
271
+ importLoaders: 3,
272
+ sourceMap: isEnvProduction ? shouldUseSourceMap : isEnvDevelopment
273
+ },
274
+ 'sass-loader'
275
+ ),
276
+ // Don't consider CSS imports dead code even if the
277
+ // containing package claims to have no side effects.
278
+ // Remove this when webpack adds a warning or an error for this.
279
+ // See https://github.com/webpack/webpack/issues/6571
280
+ sideEffects: true
281
+ },
282
+ // Adds support for CSS Modules, but using SASS
283
+ // using the extension .module.scss or .module.sass
284
+ {
285
+ test: sassModuleRegex,
286
+ use: getStyleLoaders(
287
+ {
288
+ importLoaders: 3,
289
+ sourceMap: isEnvProduction ? shouldUseSourceMap : isEnvDevelopment,
290
+ modules: {
291
+ getLocalIdent: getCSSModuleLocalIdent
292
+ }
293
+ },
294
+ 'sass-loader'
295
+ )
296
+ },
297
+ // "file" loader makes sure those assets get served by WebpackDevServer.
298
+ // When you `import` an asset, you get its (virtual) filename.
299
+ // In production, they would get copied to the `build` folder.
300
+ // This loader doesn't use a "test" so it will catch all modules
301
+ // that fall through the other loaders.
302
+ {
303
+ loader: require.resolve('file-loader'),
304
+ // Exclude `js` files to keep "css" loader working as it injects
305
+ // its runtime that would otherwise be processed through "file" loader.
306
+ // Also exclude `html` and `json` extensions so they get processed
307
+ // by webpack's internal loaders.
308
+ exclude: [/\.(js|mjs|jsx|ts|tsx)$/, /\.html$/, /\.json$/],
309
+ options: {
310
+ name: `${componentKey}/media/[name].[hash:8].[ext]`
311
+ }
312
+ }
313
+ // ** STOP ** Are you adding a new loader?
314
+ // Make sure to add the new loader(s) before the "file" loader.
315
+ ]
316
+ }
317
+ ]
318
+ },
319
+ plugins: [
320
+ // This gives some necessary context to module not found errors, such as
321
+ // the requesting resource.
322
+ new ModuleNotFoundPlugin(appPath),
323
+ // Makes some environment variables available to the JS code, for example:
324
+ // if (process.env.NODE_ENV === 'production') { ... }. See `./env.js`.
325
+ // It is absolutely essential that NODE_ENV is set to production
326
+ // during a production build.
327
+ // Otherwise React will be compiled in the very slow development mode.
328
+ isEnvProduction &&
329
+ new webpack.DefinePlugin({
330
+ PRODUCTION: JSON.stringify(true)
331
+ }),
332
+ isEnvProduction &&
333
+ new MiniCssExtractPlugin({
334
+ // Options similar to the same options in webpackOptions.output
335
+ // both options are optional
336
+ filename: `${componentKey}/css/${componentKey}.[contenthash:8].css`,
337
+ chunkFilename: `${componentKey}/css/${componentKey}.[contenthash:8].chunk.css`
338
+ }),
339
+ // Moment.js is an extremely popular library that bundles large locale files
340
+ // by default due to how webpack interprets its code. This is a practical
341
+ // solution that requires the user to opt into importing specific locales.
342
+ // https://github.com/jmblog/how-to-optimize-momentjs-with-webpack
343
+ // You can remove this if you don't use Moment.js:
344
+ new webpack.IgnorePlugin({
345
+ resourceRegExp: /^\.\/locale$/,
346
+ contextRegExp: /moment$/
347
+ }),
348
+ /* Ignore cosmos icons */
349
+ new webpack.IgnorePlugin({
350
+ resourceRegExp: /^\.\/icons$/,
351
+ contextRegExp: /@pega\/cosmos-react-core\/lib\/components\/Icon$/
352
+ }),
353
+
354
+ /* Ignore cosmos icons - windows */
355
+ new webpack.IgnorePlugin({
356
+ resourceRegExp: /^\.\/icons$/,
357
+ contextRegExp: /@pega\\cosmos-react-core\\lib\\components\\Icon$/
358
+ }),
359
+
360
+ new webpack.optimize.LimitChunkCountPlugin({
361
+ maxChunks: 1
362
+ }),
363
+ new webpack.optimize.MinChunkSizePlugin({
364
+ minChunkSize: 100000 // Minimum number of characters
365
+ }),
366
+ !devBuild && new CompressionPlugin(compressionBRConfObj)
367
+
368
+ /* Don't generate gzip file */
369
+ /* isEnvProduction && new CompressionPlugin(compressionGZConfObj) */
370
+ ].filter(Boolean),
371
+ performance: {
372
+ hints: 'warning'
373
+ },
374
+ externals
375
+ };
376
+ };
@@ -191,7 +191,16 @@ export const publishComponentToServer = async data => {
191
191
  'Error occurred in authentication. Please regenerate using authenticate'
192
192
  )}`
193
193
  );
194
- } else {
194
+ }
195
+ else if (status === 403) {
196
+ // eslint-disable-next-line prefer-promise-reject-errors
197
+ Promise.reject(
198
+ `${chalk.bold.red(
199
+ 'Error forbidden: User does not have privileges to Publish.'
200
+ )}`
201
+ );
202
+ }
203
+ else {
195
204
  // eslint-disable-next-line prefer-promise-reject-errors
196
205
  Promise.reject(`${chalk.bold.red(e)}`);
197
206
  }
@@ -190,7 +190,16 @@ export const publishComponentToServer = async data => {
190
190
  'Error occurred in authentication. Please regenerate using authenticate'
191
191
  )}`
192
192
  );
193
- } else {
193
+ }
194
+ else if (status === 403) {
195
+ // eslint-disable-next-line prefer-promise-reject-errors
196
+ Promise.reject(
197
+ `${chalk.bold.red(
198
+ 'Error forbidden: User does not have privileges to Publish.'
199
+ )}`
200
+ );
201
+ }
202
+ else {
194
203
  // eslint-disable-next-line prefer-promise-reject-errors
195
204
  Promise.reject(`${chalk.bold.red(e)}`);
196
205
  }
@@ -0,0 +1,71 @@
1
+
2
+ import fs from 'fs';
3
+ import path from 'path';
4
+ import { join } from 'path';
5
+ import { URL, fileURLToPath } from 'url';
6
+ import chalk from 'chalk';
7
+
8
+ import {
9
+ convertIntoPascalCase,
10
+ showVersion
11
+ } from '../../util.js';
12
+
13
+ import {
14
+ WEBPACK_CONFIG_JS_FILENAME,
15
+ BUILDER_INDEX_FILE_PATH
16
+ } from '../../constants.js';
17
+ import build from '@pega/custom-dx-components/src/tasks/build/index.js';
18
+ import { up } from 'inquirer/lib/utils/readline.js';
19
+
20
+
21
+
22
+ export const renamePromotedWebPack = async () => {
23
+
24
+ // call this function from top level
25
+ //fs.copyFileSync("./webpack.config.js", "webpack.config.js")
26
+
27
+ const promoteWebPackDir = path.resolve(WEBPACK_CONFIG_JS_FILENAME);
28
+ const renamedPromoteWebPackDir = path.resolve(WEBPACK_CONFIG_JS_FILENAME + ".notused");
29
+
30
+ try {
31
+ fs.renameSync(promoteWebPackDir, renamedPromoteWebPackDir);
32
+ }
33
+ catch (ex) {
34
+ console.log(chalk.bold.red(`File ${promoteWebPackDir} not found.`));
35
+ process.exit(1);
36
+ }
37
+
38
+ console.log(chalk.bold.green(`File ${promoteWebPackDir} marked as not used.`));
39
+
40
+ }
41
+
42
+ export const revertBuilder = async () => {
43
+
44
+ const builderIndexDir = fileURLToPath(new URL(BUILDER_INDEX_FILE_PATH, import.meta.url));
45
+
46
+ let indexFileJS = fs.readFileSync(builderIndexDir, { encoding: 'utf8' });
47
+
48
+ if (indexFileJS.length > 0) {
49
+ // uncomment out original webpack reference
50
+ indexFileJS = indexFileJS.replaceAll("//import configFactory from './webpack.config.js';", "import configFactory from './webpack.config.js';");
51
+
52
+ // comment out promoted webpack reference
53
+ if (indexFileJS.indexOf("//import configFactory from '../../../../../../../webpack.config.js';") < 0) {
54
+ indexFileJS = indexFileJS.replaceAll("import configFactory from '../../../../../../../webpack.config.js';", "//import configFactory from '../../../../../../../webpack.config.js';");
55
+ }
56
+
57
+ fs.writeFileSync(builderIndexDir, indexFileJS, { encoding: 'utf8' });
58
+
59
+ console.log(chalk.bold.green(`Bundler reverted to using internal webpack.config.js.`));
60
+ }
61
+
62
+
63
+ }
64
+
65
+ export default async options => {
66
+ showVersion();
67
+
68
+ await renamePromotedWebPack();
69
+ await revertBuilder();
70
+
71
+ };
package/src/util.js CHANGED
@@ -69,6 +69,8 @@ export const deleteServerComponent = async componentKey => {
69
69
  try {
70
70
  const OauthData = fs.readFileSync(TOKEN_PATH, 'utf8');
71
71
 
72
+ let status = 500;
73
+
72
74
  if (OauthData) {
73
75
  const {
74
76
  access_token: accessToken,
@@ -82,7 +84,10 @@ export const deleteServerComponent = async componentKey => {
82
84
  Authorization: `${tokenType} ${accessToken}`
83
85
  }
84
86
  })
85
- .then(response => response.text())
87
+ .then(response => {
88
+ status = response.status;
89
+ return response.text();
90
+ })
86
91
  .then(resp => {
87
92
  let respData;
88
93
  try {
@@ -102,7 +107,21 @@ export const deleteServerComponent = async componentKey => {
102
107
 
103
108
 
104
109
  })
105
- .catch(e => Promise.reject(`${chalk.bold.red(e)}`));
110
+ .catch(e => {
111
+ if (status === 403) {
112
+ // eslint-disable-next-line prefer-promise-reject-errors
113
+ Promise.reject(
114
+ `${chalk.bold.red(
115
+ 'Error forbidden: User does not have privileges to Delete.'
116
+ )}`
117
+ );
118
+ }
119
+ else {
120
+ // eslint-disable-next-line prefer-promise-reject-errors
121
+ Promise.reject(`${chalk.bold.red(e)}`)
122
+ }
123
+
124
+ });
106
125
  }
107
126
  } catch (error) {
108
127
  console.log(`\n${chalk.bold.red(error)}`);