@pega/custom-dx-components 0.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/.eslintrc.json +18 -0
- package/.prettierignore +2 -0
- package/.prettierrc.json +1 -0
- package/.vscode/extensions.json +9 -0
- package/.vscode/settings.json +48 -0
- package/LICENSE +185 -0
- package/README.md +204 -0
- package/bin/index.js +5 -0
- package/cspell.json +26 -0
- package/package.json +67 -0
- package/src/cli.js +92 -0
- package/src/constants.js +92 -0
- package/src/tasks/authenticate/helper.js +60 -0
- package/src/tasks/authenticate/index.js +75 -0
- package/src/tasks/create/index.js +304 -0
- package/src/tasks/create/template/config.json.mustache +67 -0
- package/src/tasks/create/template/demo.stories.jsx.mustache +44 -0
- package/src/tasks/create/template/index.jsx.mustache +55 -0
- package/src/tasks/create/template/styles.js.mustache +7 -0
- package/src/tasks/delete/helper.js +105 -0
- package/src/tasks/delete/index.js +45 -0
- package/src/tasks/index.js +9 -0
- package/src/tasks/init/helper.js +63 -0
- package/src/tasks/init/index.js +165 -0
- package/src/tasks/init/template/.eslintrc.json +10 -0
- package/src/tasks/init/template/.prettierrc.json +1 -0
- package/src/tasks/init/template/.storybook/main.js +6 -0
- package/src/tasks/init/template/.storybook/pega-logo.svg +16 -0
- package/src/tasks/init/template/.storybook/preview.tsx +44 -0
- package/src/tasks/init/template/.storybook/theme.js +44 -0
- package/src/tasks/init/template/.stylelintrc.json +4 -0
- package/src/tasks/init/template/.vscode/extensions.json +9 -0
- package/src/tasks/init/template/.vscode/settings.json +48 -0
- package/src/tasks/init/template/README.md +204 -0
- package/src/tasks/init/template/build.config.json +1 -0
- package/src/tasks/init/template/cspell.json +14 -0
- package/src/tasks/init/template/package.json.mustache +69 -0
- package/src/tasks/init/template/src/components/MBTAList/MBTAList.stories.tsx +10 -0
- package/src/tasks/init/template/src/components/MBTAList/MBTAList.tsx +122 -0
- package/src/tasks/init/template/src/components/MBTAList/icons/accessible.icon.tsx +14 -0
- package/src/tasks/init/template/src/components/MBTAList/icons/bus.icon.tsx +13 -0
- package/src/tasks/init/template/src/components/MBTAList/icons/mbta.icon.tsx +10 -0
- package/src/tasks/init/template/src/components/MBTAList/icons/subway.icon.tsx +14 -0
- package/src/tasks/init/template/src/components/MBTAList/index.ts +2 -0
- package/src/tasks/init/template/src/components/Organization_Library_MediaURL/MediaURL.stories.tsx +19 -0
- package/src/tasks/init/template/src/components/Organization_Library_MediaURL/MediaURL.styles.ts +5 -0
- package/src/tasks/init/template/src/components/Organization_Library_MediaURL/MediaURL.types.ts +10 -0
- package/src/tasks/init/template/src/components/Organization_Library_MediaURL/MediaURLDisplay.tsx +25 -0
- package/src/tasks/init/template/src/components/Organization_Library_MediaURL/MediaURLInput.tsx +24 -0
- package/src/tasks/init/template/src/components/Organization_Library_MediaURL/config.json +13 -0
- package/src/tasks/init/template/src/components/Organization_Library_MediaURL/index.ts +2 -0
- package/src/tasks/init/template/src/components/Organization_Library_VideoPlayer/config.json +44 -0
- package/src/tasks/init/template/src/components/Organization_Library_VideoPlayer/demo.stories.jsx +40 -0
- package/src/tasks/init/template/src/components/Organization_Library_VideoPlayer/index.jsx +42 -0
- package/src/tasks/init/template/src/components/Organization_Library_VideoPlayer/styles.js +5 -0
- package/src/tasks/init/template/tasks.config.json +21 -0
- package/src/tasks/init/template/tsconfig.build.json +16 -0
- package/src/tasks/init/template/tsconfig.json +8 -0
- package/src/tasks/list/helper.js +118 -0
- package/src/tasks/list/index.js +51 -0
- package/src/tasks/publish/bundle/builder/index.js +174 -0
- package/src/tasks/publish/bundle/builder/modules.js +139 -0
- package/src/tasks/publish/bundle/builder/paths.js +50 -0
- package/src/tasks/publish/bundle/builder/webpack.config.js +334 -0
- package/src/tasks/publish/bundle/index.js +65 -0
- package/src/tasks/publish/helper.js +145 -0
- package/src/tasks/publish/index.js +55 -0
- package/src/tasks/update/index.js +5 -0
- package/src/tasks/upgrade/index.js +31 -0
- package/src/tasks/validator/index.js +102 -0
- package/src/util.js +277 -0
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
import { createRequire } from 'module';
|
|
2
|
+
|
|
3
|
+
import webpack from 'webpack';
|
|
4
|
+
import TerserPlugin from 'terser-webpack-plugin';
|
|
5
|
+
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
|
|
6
|
+
import CssMinimizerPlugin from 'css-minimizer-webpack-plugin';
|
|
7
|
+
import getCSSModuleLocalIdent from 'react-dev-utils/getCSSModuleLocalIdent.js';
|
|
8
|
+
import ModuleNotFoundPlugin from 'react-dev-utils/ModuleNotFoundPlugin.js';
|
|
9
|
+
import CompressionPlugin from 'compression-webpack-plugin';
|
|
10
|
+
|
|
11
|
+
import paths from './paths.js';
|
|
12
|
+
|
|
13
|
+
const require = createRequire(import.meta.url);
|
|
14
|
+
|
|
15
|
+
// const appPackageJson = require(paths.appPackageJson);
|
|
16
|
+
|
|
17
|
+
// Source maps are resource heavy and can cause out of memory issue for large source files.
|
|
18
|
+
|
|
19
|
+
const compressionBRConfObj = {
|
|
20
|
+
filename: '[path][base].br',
|
|
21
|
+
algorithm: 'brotliCompress',
|
|
22
|
+
test: /\.(js|css|html|svg|png|jpg|woff|woff2)$/,
|
|
23
|
+
compressionOptions: { level: 11 }
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/* For gzip use below */
|
|
27
|
+
const compressionGZConfObj = {
|
|
28
|
+
filename: '[path][base].gz',
|
|
29
|
+
algorithm: 'gzip',
|
|
30
|
+
test: /\.(js|css|html|svg|png|jpg|woff|woff2)$/,
|
|
31
|
+
compressionOptions: { level: 9 }
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
let shouldUseSourceMap = process.env.SOURCE_MAP;
|
|
35
|
+
|
|
36
|
+
const imageInlineSizeLimit = Number.parseInt(process.env.IMAGE_INLINE_SIZE_LIMIT || '10000', 10);
|
|
37
|
+
|
|
38
|
+
// style files regex
|
|
39
|
+
const cssRegex = /\.css$/;
|
|
40
|
+
const cssModuleRegex = /\.module\.css$/;
|
|
41
|
+
const sassRegex = /\.(scss|sass)$/;
|
|
42
|
+
const sassModuleRegex = /\.module\.(scss|sass)$/;
|
|
43
|
+
|
|
44
|
+
// This is the production and development configuration.
|
|
45
|
+
// It is focused on developer experience, fast rebuilds, and a minimal bundle.
|
|
46
|
+
export default (
|
|
47
|
+
webpackEnv,
|
|
48
|
+
// eslint-disable-next-line no-unused-vars
|
|
49
|
+
{ inputFile, outputFile, componentKey, externals, globals, sourceMap, devBuild }
|
|
50
|
+
) => {
|
|
51
|
+
const isEnvDevelopment = webpackEnv === 'development' || devBuild;
|
|
52
|
+
const isEnvProduction = webpackEnv === 'production';
|
|
53
|
+
sourceMap = sourceMap === 'true';
|
|
54
|
+
shouldUseSourceMap = shouldUseSourceMap || sourceMap;
|
|
55
|
+
|
|
56
|
+
// common function to get style loaders
|
|
57
|
+
const getStyleLoaders = (cssOptions, preProcessor) => {
|
|
58
|
+
const loaders = [
|
|
59
|
+
isEnvProduction && {
|
|
60
|
+
loader: MiniCssExtractPlugin.loader
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
loader: require.resolve('css-loader'),
|
|
64
|
+
options: cssOptions
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
// Options for PostCSS as we reference these options twice
|
|
68
|
+
// Adds vendor prefixing based on your specified browser support in
|
|
69
|
+
// package.json
|
|
70
|
+
loader: require.resolve('postcss-loader'),
|
|
71
|
+
options: {
|
|
72
|
+
postcssOptions: {
|
|
73
|
+
plugins: [
|
|
74
|
+
[
|
|
75
|
+
'postcss-preset-env',
|
|
76
|
+
{
|
|
77
|
+
// Options
|
|
78
|
+
}
|
|
79
|
+
]
|
|
80
|
+
]
|
|
81
|
+
},
|
|
82
|
+
sourceMap: isEnvProduction ? shouldUseSourceMap : isEnvDevelopment
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
].filter(Boolean);
|
|
86
|
+
if (preProcessor) {
|
|
87
|
+
loaders.push(
|
|
88
|
+
{
|
|
89
|
+
loader: require.resolve('resolve-url-loader'),
|
|
90
|
+
options: {
|
|
91
|
+
sourceMap: isEnvProduction ? shouldUseSourceMap : isEnvDevelopment,
|
|
92
|
+
root: paths.appSrc
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
loader: require.resolve(preProcessor),
|
|
97
|
+
options: {
|
|
98
|
+
sourceMap: true
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
return loaders;
|
|
104
|
+
};
|
|
105
|
+
return {
|
|
106
|
+
mode: isEnvDevelopment ? 'development' : 'production',
|
|
107
|
+
// Stop compilation early in production
|
|
108
|
+
bail: isEnvProduction,
|
|
109
|
+
// These are the "entry points" to our application.
|
|
110
|
+
// This means they will be the "root" imports that are included in JS bundle.
|
|
111
|
+
entry: inputFile,
|
|
112
|
+
devtool: shouldUseSourceMap ? 'source-map' : false,
|
|
113
|
+
output: {
|
|
114
|
+
// The build folder.
|
|
115
|
+
path: paths.appBuild,
|
|
116
|
+
// There will be one main bundle, and one file per asynchronous chunk.
|
|
117
|
+
// In development, it does not produce real files.
|
|
118
|
+
filename: isEnvProduction
|
|
119
|
+
? `${componentKey}/${componentKey}.js`
|
|
120
|
+
: isEnvDevelopment && `${componentKey}/${componentKey}.js`,
|
|
121
|
+
chunkFilename: isEnvProduction
|
|
122
|
+
? `${componentKey}/js/[name].[contenthash:8].chunk.js`
|
|
123
|
+
: isEnvDevelopment && `${componentKey}/js/[name].chunk.js`,
|
|
124
|
+
library: {
|
|
125
|
+
name: componentKey,
|
|
126
|
+
type: 'umd',
|
|
127
|
+
export: 'default'
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
optimization: {
|
|
131
|
+
minimize: isEnvProduction,
|
|
132
|
+
minimizer: [new TerserPlugin(), new CssMinimizerPlugin()]
|
|
133
|
+
},
|
|
134
|
+
resolve: {
|
|
135
|
+
plugins: [],
|
|
136
|
+
extensions: ['.tsx', '.ts', '.js']
|
|
137
|
+
},
|
|
138
|
+
resolveLoader: {
|
|
139
|
+
plugins: []
|
|
140
|
+
},
|
|
141
|
+
module: {
|
|
142
|
+
strictExportPresence: true,
|
|
143
|
+
rules: [
|
|
144
|
+
{
|
|
145
|
+
// "oneOf" will traverse all following loaders until one will
|
|
146
|
+
// match the requirements. When no loader matches it will fall
|
|
147
|
+
// back to the "file" loader at the end of the loader list.
|
|
148
|
+
oneOf: [
|
|
149
|
+
// TODO: Merge this config once `image/avif` is in the mime-db
|
|
150
|
+
// https://github.com/jshttp/mime-db
|
|
151
|
+
{
|
|
152
|
+
test: [/\.avif$/],
|
|
153
|
+
loader: require.resolve('url-loader'),
|
|
154
|
+
options: {
|
|
155
|
+
limit: imageInlineSizeLimit,
|
|
156
|
+
mimetype: 'image/avif',
|
|
157
|
+
name: `${componentKey}/media/[name].[hash:8].[ext]`
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
// "url" loader works like "file" loader except that it embeds assets
|
|
161
|
+
// smaller than specified limit in bytes as data URLs to avoid requests.
|
|
162
|
+
// A missing `test` is equivalent to a match.
|
|
163
|
+
{
|
|
164
|
+
test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/, /\.svg$/],
|
|
165
|
+
loader: require.resolve('url-loader'),
|
|
166
|
+
options: {
|
|
167
|
+
limit: imageInlineSizeLimit,
|
|
168
|
+
name: `${componentKey}/media/[name].[hash:8].[ext]`
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
// Process application JS with TS-Loader.
|
|
172
|
+
// The preset includes JSX, Flow, TypeScript, and some ESnext features.
|
|
173
|
+
{
|
|
174
|
+
test: /\.(js|mjs|jsx)$/,
|
|
175
|
+
include: paths.appSrc,
|
|
176
|
+
loader: 'ts-loader',
|
|
177
|
+
options: {
|
|
178
|
+
configFile: 'tsconfig.build.json'
|
|
179
|
+
},
|
|
180
|
+
exclude: /node_modules/
|
|
181
|
+
},
|
|
182
|
+
|
|
183
|
+
{
|
|
184
|
+
test: /\.(ts|tsx)$/,
|
|
185
|
+
loader: 'ts-loader',
|
|
186
|
+
options: {
|
|
187
|
+
configFile: 'tsconfig.build.json'
|
|
188
|
+
},
|
|
189
|
+
exclude: /node_modules/
|
|
190
|
+
},
|
|
191
|
+
// "postcss" loader applies autoprefixer to our CSS.
|
|
192
|
+
// "css" loader resolves paths in CSS and adds assets as dependencies.
|
|
193
|
+
// "style" loader turns CSS into JS modules that inject <style> tags.
|
|
194
|
+
// In production, we use MiniCSSExtractPlugin to extract that CSS
|
|
195
|
+
// to a file, but in development "style" loader enables hot editing
|
|
196
|
+
// of CSS.
|
|
197
|
+
// By default we support CSS Modules with the extension .module.css
|
|
198
|
+
{
|
|
199
|
+
test: cssRegex,
|
|
200
|
+
exclude: cssModuleRegex,
|
|
201
|
+
use: getStyleLoaders({
|
|
202
|
+
importLoaders: 1,
|
|
203
|
+
sourceMap: isEnvProduction ? shouldUseSourceMap : isEnvDevelopment
|
|
204
|
+
}),
|
|
205
|
+
// Don't consider CSS imports dead code even if the
|
|
206
|
+
// containing package claims to have no side effects.
|
|
207
|
+
// Remove this when webpack adds a warning or an error for this.
|
|
208
|
+
// See https://github.com/webpack/webpack/issues/6571
|
|
209
|
+
sideEffects: true
|
|
210
|
+
},
|
|
211
|
+
// Adds support for CSS Modules (https://github.com/css-modules/css-modules)
|
|
212
|
+
// using the extension .module.css
|
|
213
|
+
{
|
|
214
|
+
test: cssModuleRegex,
|
|
215
|
+
use: getStyleLoaders({
|
|
216
|
+
importLoaders: 1,
|
|
217
|
+
sourceMap: isEnvProduction ? shouldUseSourceMap : isEnvDevelopment,
|
|
218
|
+
modules: {
|
|
219
|
+
getLocalIdent: getCSSModuleLocalIdent
|
|
220
|
+
}
|
|
221
|
+
})
|
|
222
|
+
},
|
|
223
|
+
// Opt-in support for SASS (using .scss or .sass extensions).
|
|
224
|
+
// By default we support SASS Modules with the
|
|
225
|
+
// extensions .module.scss or .module.sass
|
|
226
|
+
{
|
|
227
|
+
test: sassRegex,
|
|
228
|
+
exclude: sassModuleRegex,
|
|
229
|
+
use: getStyleLoaders(
|
|
230
|
+
{
|
|
231
|
+
importLoaders: 3,
|
|
232
|
+
sourceMap: isEnvProduction ? shouldUseSourceMap : isEnvDevelopment
|
|
233
|
+
},
|
|
234
|
+
'sass-loader'
|
|
235
|
+
),
|
|
236
|
+
// Don't consider CSS imports dead code even if the
|
|
237
|
+
// containing package claims to have no side effects.
|
|
238
|
+
// Remove this when webpack adds a warning or an error for this.
|
|
239
|
+
// See https://github.com/webpack/webpack/issues/6571
|
|
240
|
+
sideEffects: true
|
|
241
|
+
},
|
|
242
|
+
// Adds support for CSS Modules, but using SASS
|
|
243
|
+
// using the extension .module.scss or .module.sass
|
|
244
|
+
{
|
|
245
|
+
test: sassModuleRegex,
|
|
246
|
+
use: getStyleLoaders(
|
|
247
|
+
{
|
|
248
|
+
importLoaders: 3,
|
|
249
|
+
sourceMap: isEnvProduction ? shouldUseSourceMap : isEnvDevelopment,
|
|
250
|
+
modules: {
|
|
251
|
+
getLocalIdent: getCSSModuleLocalIdent
|
|
252
|
+
}
|
|
253
|
+
},
|
|
254
|
+
'sass-loader'
|
|
255
|
+
)
|
|
256
|
+
},
|
|
257
|
+
// "file" loader makes sure those assets get served by WebpackDevServer.
|
|
258
|
+
// When you `import` an asset, you get its (virtual) filename.
|
|
259
|
+
// In production, they would get copied to the `build` folder.
|
|
260
|
+
// This loader doesn't use a "test" so it will catch all modules
|
|
261
|
+
// that fall through the other loaders.
|
|
262
|
+
{
|
|
263
|
+
loader: require.resolve('file-loader'),
|
|
264
|
+
// Exclude `js` files to keep "css" loader working as it injects
|
|
265
|
+
// its runtime that would otherwise be processed through "file" loader.
|
|
266
|
+
// Also exclude `html` and `json` extensions so they get processed
|
|
267
|
+
// by webpack's internal loaders.
|
|
268
|
+
exclude: [/\.(js|mjs|jsx|ts|tsx)$/, /\.html$/, /\.json$/],
|
|
269
|
+
options: {
|
|
270
|
+
name: `${componentKey}/media/[name].[hash:8].[ext]`
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
// ** STOP ** Are you adding a new loader?
|
|
274
|
+
// Make sure to add the new loader(s) before the "file" loader.
|
|
275
|
+
]
|
|
276
|
+
}
|
|
277
|
+
]
|
|
278
|
+
},
|
|
279
|
+
plugins: [
|
|
280
|
+
// This gives some necessary context to module not found errors, such as
|
|
281
|
+
// the requesting resource.
|
|
282
|
+
new ModuleNotFoundPlugin(paths.appPath),
|
|
283
|
+
// Makes some environment variables available to the JS code, for example:
|
|
284
|
+
// if (process.env.NODE_ENV === 'production') { ... }. See `./env.js`.
|
|
285
|
+
// It is absolutely essential that NODE_ENV is set to production
|
|
286
|
+
// during a production build.
|
|
287
|
+
// Otherwise React will be compiled in the very slow development mode.
|
|
288
|
+
isEnvProduction &&
|
|
289
|
+
new webpack.DefinePlugin({
|
|
290
|
+
PRODUCTION: JSON.stringify(true)
|
|
291
|
+
}),
|
|
292
|
+
isEnvProduction &&
|
|
293
|
+
new MiniCssExtractPlugin({
|
|
294
|
+
// Options similar to the same options in webpackOptions.output
|
|
295
|
+
// both options are optional
|
|
296
|
+
filename: `${componentKey}/css/${componentKey}.[contenthash:8].css`,
|
|
297
|
+
chunkFilename: `${componentKey}/css/${componentKey}.[contenthash:8].chunk.css`
|
|
298
|
+
}),
|
|
299
|
+
// Moment.js is an extremely popular library that bundles large locale files
|
|
300
|
+
// by default due to how webpack interprets its code. This is a practical
|
|
301
|
+
// solution that requires the user to opt into importing specific locales.
|
|
302
|
+
// https://github.com/jmblog/how-to-optimize-momentjs-with-webpack
|
|
303
|
+
// You can remove this if you don't use Moment.js:
|
|
304
|
+
new webpack.IgnorePlugin({
|
|
305
|
+
resourceRegExp: /^\.\/locale$/,
|
|
306
|
+
contextRegExp: /moment$/
|
|
307
|
+
}),
|
|
308
|
+
/* Ignore cosmos icons */
|
|
309
|
+
new webpack.IgnorePlugin({
|
|
310
|
+
resourceRegExp: /^\.\/icons$/,
|
|
311
|
+
contextRegExp: /@pega\/cosmos-react-core\/lib\/components\/Icon$/
|
|
312
|
+
}),
|
|
313
|
+
/* Ignore cosmos icons - windows */
|
|
314
|
+
new webpack.IgnorePlugin({
|
|
315
|
+
resourceRegExp: /^\.\/icons$/,
|
|
316
|
+
contextRegExp: /@pega\\cosmos-react-core\\lib\\components\\Icon$/
|
|
317
|
+
}),
|
|
318
|
+
new webpack.optimize.LimitChunkCountPlugin({
|
|
319
|
+
maxChunks: 5
|
|
320
|
+
}),
|
|
321
|
+
new webpack.optimize.MinChunkSizePlugin({
|
|
322
|
+
minChunkSize: 100000 // Minimum number of characters
|
|
323
|
+
}),
|
|
324
|
+
isEnvProduction && new CompressionPlugin(compressionBRConfObj)
|
|
325
|
+
|
|
326
|
+
/* Dont generate gzip file */
|
|
327
|
+
/* isEnvProduction && new CompressionPlugin(compressionGZConfObj) */
|
|
328
|
+
].filter(Boolean),
|
|
329
|
+
performance: {
|
|
330
|
+
hints: 'warning'
|
|
331
|
+
},
|
|
332
|
+
externals
|
|
333
|
+
};
|
|
334
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import { stat } from 'fs/promises';
|
|
4
|
+
|
|
5
|
+
import { BUILD_CONFIG_JSON_FILENAME } from '../../../constants.js';
|
|
6
|
+
import { getComponentDirectoryPath } from '../../../util.js';
|
|
7
|
+
|
|
8
|
+
import buildComponent from './builder/index.js';
|
|
9
|
+
|
|
10
|
+
const extensions = ['ts', 'tsx', 'js', 'jsx'];
|
|
11
|
+
|
|
12
|
+
const bundleComponent = async (componentKey, sourceMap, devBuild) => {
|
|
13
|
+
const componentDirectory = await getComponentDirectoryPath(componentKey);
|
|
14
|
+
|
|
15
|
+
const idx = (
|
|
16
|
+
await Promise.all(
|
|
17
|
+
extensions.map(ext =>
|
|
18
|
+
stat(path.join(componentDirectory, `index.${ext}`))
|
|
19
|
+
.then(() => true)
|
|
20
|
+
.catch(() => false)
|
|
21
|
+
)
|
|
22
|
+
)
|
|
23
|
+
).findIndex(exists => exists);
|
|
24
|
+
|
|
25
|
+
if (idx === -1) throw new Error('Index file not found.');
|
|
26
|
+
|
|
27
|
+
const inputFile = path.join(componentDirectory, `index.${extensions[idx]}`);
|
|
28
|
+
const outputFile = `${componentKey}.js`;
|
|
29
|
+
|
|
30
|
+
let buildConfig = {};
|
|
31
|
+
|
|
32
|
+
if (fs.existsSync(BUILD_CONFIG_JSON_FILENAME)) {
|
|
33
|
+
buildConfig = JSON.parse(fs.readFileSync(BUILD_CONFIG_JSON_FILENAME, 'utf8'));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
let externals = buildConfig.externals || [];
|
|
37
|
+
externals = {
|
|
38
|
+
react: 'React',
|
|
39
|
+
'react-dom': 'ReactDOM',
|
|
40
|
+
PCore: 'PCore',
|
|
41
|
+
...buildConfig.externals
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
let globals = buildConfig.globals || {};
|
|
45
|
+
|
|
46
|
+
const defaultGlobals = {
|
|
47
|
+
react: 'React',
|
|
48
|
+
'react-dom': 'ReactDOM',
|
|
49
|
+
PCore: 'PCore',
|
|
50
|
+
...buildConfig.globals
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
globals = { ...globals, ...defaultGlobals };
|
|
54
|
+
await buildComponent({
|
|
55
|
+
inputFile,
|
|
56
|
+
outputFile,
|
|
57
|
+
componentKey,
|
|
58
|
+
externals,
|
|
59
|
+
globals,
|
|
60
|
+
sourceMap,
|
|
61
|
+
devBuild
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export default bundleComponent;
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import https from 'https';
|
|
4
|
+
|
|
5
|
+
import fetch from 'node-fetch';
|
|
6
|
+
import AdmZip from 'adm-zip';
|
|
7
|
+
import chalk from 'chalk';
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
constructCompleteUrl,
|
|
11
|
+
getComponentDirectoryPath,
|
|
12
|
+
getComponents,
|
|
13
|
+
getPegaServerConfig,
|
|
14
|
+
validateRulesetVersion
|
|
15
|
+
} from '../../util.js';
|
|
16
|
+
import { PUBLISH_COMPONENT_SERVICE_REST_ENDPOINT, TOKEN_PATH } from '../../constants.js';
|
|
17
|
+
|
|
18
|
+
export const getPublishComponentQuestions = async () => {
|
|
19
|
+
const components = await getComponents();
|
|
20
|
+
const defaultPegaConfig = await getPegaServerConfig();
|
|
21
|
+
|
|
22
|
+
return [
|
|
23
|
+
{
|
|
24
|
+
name: 'componentKey',
|
|
25
|
+
type: 'rawlist',
|
|
26
|
+
message: 'Select component to publish',
|
|
27
|
+
choices: components
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
name: 'rulesetName',
|
|
31
|
+
message: 'Enter ruleset name',
|
|
32
|
+
default: defaultPegaConfig.rulesetName,
|
|
33
|
+
validate: value => {
|
|
34
|
+
if (value.trim()) {
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
return 'Ruleset name cannot be empty';
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
name: 'rulesetVersion',
|
|
42
|
+
message: 'Enter ruleset version',
|
|
43
|
+
default: defaultPegaConfig.rulesetVersion,
|
|
44
|
+
validate: value => {
|
|
45
|
+
if (validateRulesetVersion(value)) {
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
return 'Please provide compatible version e.g 01-01-01';
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
name: 'sourceMap',
|
|
53
|
+
message: 'Generate source map ?',
|
|
54
|
+
default: defaultPegaConfig.sourceMap,
|
|
55
|
+
when: () => false && !process.env.SOURCE_MAP
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
name: 'devBuild',
|
|
59
|
+
message: 'Generate development build ?',
|
|
60
|
+
default: defaultPegaConfig.devBuild
|
|
61
|
+
}
|
|
62
|
+
];
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export const zipComponent = async componentKey => {
|
|
66
|
+
const srcDirectory = await getComponentDirectoryPath(componentKey);
|
|
67
|
+
const buildDirectory = await path.join(path.resolve(), 'dist/components', componentKey);
|
|
68
|
+
const configJson = `${srcDirectory}/config.json`;
|
|
69
|
+
|
|
70
|
+
const zip = new AdmZip();
|
|
71
|
+
|
|
72
|
+
zip.addLocalFolder(srcDirectory, 'src/');
|
|
73
|
+
zip.addLocalFile(configJson);
|
|
74
|
+
zip.addLocalFolder(buildDirectory);
|
|
75
|
+
const zipContent = zip.toBuffer().toString('base64');
|
|
76
|
+
|
|
77
|
+
const configContent = Buffer.from(fs.readFileSync(`${srcDirectory}/config.json`)).toString();
|
|
78
|
+
fs.rmdir('dist', { recursive: true }, err => {
|
|
79
|
+
if (err) {
|
|
80
|
+
throw err;
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
return { zipContent, configContent };
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export const publishComponentToServer = async data => {
|
|
87
|
+
const { configContent, zipContent, componentKey, rulesetName, rulesetVersion } = data;
|
|
88
|
+
|
|
89
|
+
const apiBody = {
|
|
90
|
+
configContent,
|
|
91
|
+
zipContent,
|
|
92
|
+
componentKey: JSON.parse(configContent).componentKey,
|
|
93
|
+
publishFor: 'constellation',
|
|
94
|
+
rulesetName,
|
|
95
|
+
rulesetVersion,
|
|
96
|
+
category: ''
|
|
97
|
+
};
|
|
98
|
+
const defaultPegaConfig = await getPegaServerConfig();
|
|
99
|
+
const url = constructCompleteUrl(
|
|
100
|
+
defaultPegaConfig.server,
|
|
101
|
+
PUBLISH_COMPONENT_SERVICE_REST_ENDPOINT
|
|
102
|
+
);
|
|
103
|
+
try {
|
|
104
|
+
const OauthData = fs.readFileSync(TOKEN_PATH, 'utf8');
|
|
105
|
+
if (OauthData) {
|
|
106
|
+
const {
|
|
107
|
+
access_token: accessToken,
|
|
108
|
+
token_type: tokenType,
|
|
109
|
+
refresh_token: refreshToken
|
|
110
|
+
} = JSON.parse(OauthData);
|
|
111
|
+
let status = 500;
|
|
112
|
+
fetch(url, {
|
|
113
|
+
method: 'POST',
|
|
114
|
+
agent: new https.Agent({ rejectUnauthorized: false }),
|
|
115
|
+
headers: {
|
|
116
|
+
Authorization: `${tokenType} ${accessToken}`
|
|
117
|
+
},
|
|
118
|
+
body: JSON.stringify(apiBody)
|
|
119
|
+
})
|
|
120
|
+
.then(response => {
|
|
121
|
+
status = response.status;
|
|
122
|
+
return response.text();
|
|
123
|
+
})
|
|
124
|
+
.then(resp => {
|
|
125
|
+
const respData = JSON.parse(resp);
|
|
126
|
+
if (status === 401) {
|
|
127
|
+
throw new Error(
|
|
128
|
+
'Error occured in authentication. Please regenerate using authenticate'
|
|
129
|
+
);
|
|
130
|
+
// console.log(accessTokenUri, refreshToken);
|
|
131
|
+
/* TODO - Handle refresh_token */
|
|
132
|
+
} else if (status == 200) {
|
|
133
|
+
console.log(chalk.bold.green(`Success : ${respData.message}`));
|
|
134
|
+
} else {
|
|
135
|
+
throw new Error(`${respData.message}`);
|
|
136
|
+
}
|
|
137
|
+
})
|
|
138
|
+
.catch(e => Promise.reject(`${chalk.bold.red(e)}`));
|
|
139
|
+
} else {
|
|
140
|
+
throw new Error(`Error occured in authentication. Please regenerate using authenticate`);
|
|
141
|
+
}
|
|
142
|
+
} catch (err) {
|
|
143
|
+
throw new Error(`Error occured in authentication. Please regenerate using authenticate`);
|
|
144
|
+
}
|
|
145
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import inquirer from 'inquirer';
|
|
2
|
+
import Listr from 'listr';
|
|
3
|
+
import chalk from 'chalk';
|
|
4
|
+
|
|
5
|
+
import validate from '../validator/index.js';
|
|
6
|
+
|
|
7
|
+
import bundleComponent from './bundle/index.js';
|
|
8
|
+
import { getPublishComponentQuestions, publishComponentToServer, zipComponent } from './helper.js';
|
|
9
|
+
|
|
10
|
+
export default async options => {
|
|
11
|
+
const questions = await getPublishComponentQuestions();
|
|
12
|
+
const answers = await inquirer.prompt(questions);
|
|
13
|
+
const { componentKey, sourceMap, devBuild } = answers;
|
|
14
|
+
|
|
15
|
+
let content = {
|
|
16
|
+
...answers
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const tasks = new Listr(
|
|
20
|
+
[
|
|
21
|
+
{
|
|
22
|
+
title: 'Validate config schema',
|
|
23
|
+
task: async () => {
|
|
24
|
+
await validate(componentKey);
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
title: 'Bundle Component',
|
|
29
|
+
task: async () => await bundleComponent(componentKey, sourceMap, devBuild),
|
|
30
|
+
skip: () => (options.skipBundle ? 'Skipped bundling component' : undefined)
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
title: 'Zip Component',
|
|
34
|
+
task: async () => {
|
|
35
|
+
const output = await zipComponent(componentKey);
|
|
36
|
+
content = { ...content, ...output };
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
title: 'Publish Component',
|
|
41
|
+
task: async () => {
|
|
42
|
+
await publishComponentToServer(content);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
],
|
|
46
|
+
{
|
|
47
|
+
exitOnError: true
|
|
48
|
+
}
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
await tasks.run().catch(err => {
|
|
52
|
+
console.log(chalk.bold.red(err.toString()));
|
|
53
|
+
});
|
|
54
|
+
return true;
|
|
55
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { promisify } from 'util';
|
|
2
|
+
import { exec } from 'child_process';
|
|
3
|
+
|
|
4
|
+
import Listr from 'listr';
|
|
5
|
+
|
|
6
|
+
const execPromise = promisify(exec);
|
|
7
|
+
|
|
8
|
+
export default async options => {
|
|
9
|
+
const installDependenciesText = `Upgrading package to latest version.`;
|
|
10
|
+
|
|
11
|
+
const tasks = new Listr(
|
|
12
|
+
[
|
|
13
|
+
{
|
|
14
|
+
title: installDependenciesText,
|
|
15
|
+
task: async () => {
|
|
16
|
+
await execPromise('npm uninstall --save-dev @pega/custom-dx-components', {
|
|
17
|
+
cwd: options.targetDirectory
|
|
18
|
+
});
|
|
19
|
+
await execPromise('npm install --save-dev @pega/custom-dx-components', {
|
|
20
|
+
cwd: options.targetDirectory
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
],
|
|
25
|
+
{
|
|
26
|
+
exitOnError: false
|
|
27
|
+
}
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
await tasks.run();
|
|
31
|
+
};
|