@pega/dx-component-builder-sdk 0.1.48 → 0.1.49

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.
@@ -17,7 +17,7 @@ let server = null;
17
17
  const generateAccessToken = async config => {
18
18
 
19
19
  let authSuccess = false;
20
- const { serverType, authService, isolationId, grantType, clientId, clientSecret, user, password } = config;
20
+ const { serverType, authService, isolationId, grantType, clientId, clientSecret, user, password, legacyTLS } = config;
21
21
  // Try to gracefully deal with missing trailing slashes for server (and later conditionally for redirectUri)
22
22
  const server = config.server.endsWith('/') ? config.server : `${config.server}/`;
23
23
 
@@ -67,6 +67,7 @@ const generateAccessToken = async config => {
67
67
  clientId: clientId,
68
68
  clientSecret: clientSecret,
69
69
  ignoreInvalidCerts: true,
70
+ useNodeFetch:true,
70
71
  ...authCodeConfig
71
72
  };
72
73
  if (serverType === 'infinity') {
@@ -75,6 +76,9 @@ const generateAccessToken = async config => {
75
76
  authConfig.password = Buffer.from(password).toString('base64');
76
77
  }
77
78
  }
79
+ if (legacyTLS) {
80
+ authConfig.legacyTLS = true;
81
+ }
78
82
  if (serverType === 'launchpad') {
79
83
  authConfig.isolationId = isolationId;
80
84
  authConfig.noPKCE = true;
@@ -148,6 +152,9 @@ export default async options => {
148
152
  serverConfig.server = data[SERVER_CONFIG][serverConfig.serverType === "infinity" ? SERVER_REST_URL : LP_SERVER_REST_URL];
149
153
  serverConfig.authService = data.authConfig?.authService || 'pega';
150
154
  const isPwdNonEmpty = serverConfig['password'] ? true : false;
155
+ if( data[SERVER_CONFIG]['legacyTLS'] ) {
156
+ serverConfig.legacyTLS = true;
157
+ }
151
158
 
152
159
  const questions = await getAuthQuestions(serverConfig);
153
160
  const answers = await inquirer.prompt(questions);
@@ -179,6 +186,9 @@ export default async options => {
179
186
 
180
187
  delete serverConfig.serverType;
181
188
  delete serverConfig.server;
189
+ if( serverConfig.legacyTLS ) {
190
+ delete serverConfig.legacyTLS;
191
+ }
182
192
 
183
193
  if (authOK & bWriteUpdate) {
184
194
  // Don't write password value (unless it already had a value)
@@ -4,7 +4,7 @@ import chalk from 'chalk';
4
4
 
5
5
  import validate from '../validator/index.js';
6
6
 
7
- import { bundleReactComponent, bundleAngularComponent} from '../bundle/index.js';
7
+ import { bundleReactComponent, bundleAngularComponent, bundleAssociatedComponent} from '../bundle/index.js';
8
8
  import lintComponent from '../linter/index.js';
9
9
  import { getBuildComponentQuestions, getBuildCategory, cleanUp } from './helper.js';
10
10
  import { getComponentDirectoryPath, showVersion, getOptionsCategory, getFramework, getLocalComponentKeyFromConfig, convertIntoKebabCase, convertIntoPascalCase } from '../../util.js';
@@ -38,7 +38,7 @@ export default async options => {
38
38
  else {
39
39
  const catQuestion = await getBuildCategory(options);
40
40
  const catAnswers = await inquirer.prompt(catQuestion);
41
-
41
+
42
42
  category = catAnswers.category;
43
43
  if (category == null) {
44
44
  category = getOptionsCategory(options);
@@ -47,7 +47,7 @@ export default async options => {
47
47
  const questions = await getBuildComponentQuestions(category);
48
48
  const answers = await inquirer.prompt(questions);
49
49
  ({ componentKey, sourceMap, devBuild } = answers);
50
-
50
+
51
51
  content = {
52
52
  ...answers
53
53
  };
@@ -108,7 +108,7 @@ export default async options => {
108
108
  },
109
109
  {
110
110
  title: `Bundle associated component ${sDevBuild}`,
111
- task: async () => await bundleReactComponent(associatedComponentKey, sourceMap, devBuild, "constellation")
111
+ task: async () => await bundleAssociatedComponent(associatedComponentKey, sourceMap, devBuild, "constellation")
112
112
  }
113
113
  ],
114
114
  {
@@ -4,7 +4,7 @@ import chalk from 'chalk';
4
4
 
5
5
  import validate from '../validator/index.js';
6
6
 
7
- import { bundleReactComponent, bundleAngularComponent} from '../bundle/index.js';
7
+ import { bundleReactComponent, bundleAngularComponent, bundleAssociatedComponent} from '../bundle/index.js';
8
8
  import lintComponent from '../linter/index.js';
9
9
  import { getBuildComponentQuestions, getBuildCategory, cleanUp } from './helper.js';
10
10
  import { getComponentDirectoryPath, showVersion, getOptionsCategory, getComponentsObj, getFramework, getLocalComponentKeyFromConfig, convertIntoKebabCase, convertIntoPascalCase } from '../../util.js';
@@ -55,7 +55,7 @@ export function getCustomTasks(componentKey, category, sourceMap, devBuild, cont
55
55
  },
56
56
  {
57
57
  title: `Bundle associated component ${sDevBuild}`,
58
- task: async () => await bundleReactComponent(associatedComponentKey, sourceMap, devBuild, "constellation")
58
+ task: async () => await bundleAssociatedComponent(associatedComponentKey, sourceMap, devBuild, "constellation")
59
59
  }
60
60
  ],
61
61
  {
@@ -128,17 +128,17 @@ export default async options => {
128
128
  else {
129
129
  const catQuestion = await getBuildCategory(options);
130
130
  const catAnswers = await inquirer.prompt(catQuestion);
131
-
131
+
132
132
  category = catAnswers.category;
133
133
  if (category == null) {
134
134
  category = getOptionsCategory(options);
135
135
  }
136
-
136
+
137
137
  components = await getComponentsObj(false, category);
138
138
  const questions = await getBuildComponentQuestions(category);
139
139
  const answers = await inquirer.prompt(questions);
140
140
  ({ sourceMap, devBuild } = answers);
141
-
141
+
142
142
  content = {
143
143
  ...answers
144
144
  };
@@ -36,6 +36,7 @@ const resolveModule = (resolveFn, filePath) => {
36
36
  };
37
37
 
38
38
  // config after eject: we're in ./config/
39
+ // building a standard Angular component for Angular SDK, use same ts config as buid:dev
39
40
  export default {
40
41
  dotenv: resolveApp('.env'),
41
42
  appPath: resolveApp('.'),
@@ -0,0 +1,218 @@
1
+ import chalk from 'chalk';
2
+ import fs from 'fs-extra';
3
+ import webpack from 'webpack';
4
+ import FileSizeReporter from 'react-dev-utils/FileSizeReporter.js';
5
+ import printBuildError from 'react-dev-utils/printBuildError.js';
6
+
7
+ import configFactory from './webpack.config.js';
8
+ import paths from './paths.js';
9
+
10
+ // Do this as the first thing so that any code reading it knows the right env.
11
+ let Env = 'production';
12
+ if (process.argv.includes('development')) {
13
+ Env = 'development';
14
+ }
15
+
16
+ if (process.argv.includes('source-map')) {
17
+ process.env.SOURCE_MAP = true;
18
+ }
19
+
20
+ // Do this as the first thing so that any code reading it knows the right env.
21
+ process.env.BABEL_ENV = Env;
22
+ process.env.NODE_ENV = Env;
23
+
24
+ // Makes the script crash on unhandled rejections instead of silently
25
+ // ignoring them. In the future, promise rejections that are not handled will
26
+ // terminate the Node.js process with a non-zero exit code.
27
+ process.on('unhandledRejection', err => {
28
+ console.log(err);
29
+ process.exit(1);
30
+ });
31
+
32
+ const measureFileSizesBeforeBuild = FileSizeReporter.measureFileSizesBeforeBuild;
33
+ const printFileSizesAfterBuild = FileSizeReporter.printFileSizesAfterBuild;
34
+
35
+ // These sizes are pretty large. We'll warn for bundles exceeding them.
36
+ const WARN_AFTER_BUNDLE_GZIP_SIZE = 512 * 1024;
37
+ const WARN_AFTER_CHUNK_GZIP_SIZE = 1024 * 1024;
38
+
39
+ let compilationErrors = null;
40
+
41
+ // Create the build and print the deployment instructions.
42
+ function build(config, previousFileSizes) {
43
+ console.log(`Creating a ${Env} build...`);
44
+
45
+
46
+
47
+ const compiler = webpack(config);
48
+ return new Promise((resolve, reject) => {
49
+ compiler.run((err, stats) => {
50
+
51
+ if (err != null && typeof (err) == "object") {
52
+ if (err.error != undefined) {
53
+ //store and print elsewhere
54
+ compilationErrors = err.error;
55
+ //console.log("err:" + err);
56
+ }
57
+ }
58
+ if (stats != null & typeof(stats) == "object") {
59
+ if (stats.errors != undefined) {
60
+ console.log("stats:" + stats);
61
+ }
62
+ else if (stats.compilation != undefined && stats.compilation.errors != undefined) {
63
+
64
+ //store and print elsewhere
65
+ compilationErrors = stats.compilation.errors;
66
+
67
+ console.log("stats:" + stats);
68
+ }
69
+
70
+ }
71
+
72
+
73
+ let messages;
74
+ if (err) {
75
+ if (!err.message) {
76
+ return reject(err);
77
+ }
78
+
79
+ let errMessage = err.message;
80
+
81
+ // Add additional information for postcss errors
82
+ if (Object.prototype.hasOwnProperty.call(err, 'postcssNode')) {
83
+ errMessage += `\nCompileError: Begins at CSS selector ${err.postcssNode.selector}`;
84
+ }
85
+
86
+ messages = {
87
+ errors: [errMessage],
88
+ warnings: []
89
+ };
90
+ } else {
91
+ messages = stats.toJson({ all: false, warnings: true, errors: true });
92
+ }
93
+ if (messages.errors.length) {
94
+ // Only keep the first error. Others are often indicative
95
+ // of the same problem, but confuse the reader with noise.
96
+ if (messages.errors.length > 1) {
97
+ messages.errors.length = 1;
98
+ }
99
+ return reject(new Error(messages.errors));
100
+ }
101
+ if (
102
+ process.env.CI &&
103
+ (typeof process.env.CI !== 'string' || process.env.CI.toLowerCase() !== 'false') &&
104
+ messages.warnings.length
105
+ ) {
106
+ console.log(
107
+ chalk.yellow(
108
+ '\nTreating warnings as errors because process.env.CI = true.\n' +
109
+ 'Most CI servers set it automatically.\n'
110
+ )
111
+ );
112
+ return reject(new Error(messages.warnings.join('\n\n')));
113
+ }
114
+
115
+ const resolveArgs = {
116
+ stats,
117
+ previousFileSizes,
118
+ warnings: messages.warnings
119
+ };
120
+ return resolve(resolveArgs);
121
+ });
122
+ });
123
+ }
124
+
125
+ export default ({
126
+ inputFile,
127
+ outputFile,
128
+ componentKey,
129
+ externals,
130
+ globals,
131
+ sourceMap,
132
+ devBuild
133
+ }) => {
134
+ // Generate configuration
135
+ const config = configFactory(Env, {
136
+ inputFile,
137
+ outputFile,
138
+ componentKey,
139
+ externals,
140
+ globals,
141
+ sourceMap,
142
+ devBuild
143
+ });
144
+
145
+ if (devBuild) {
146
+ Env = 'development';
147
+ }
148
+
149
+ return new Promise((resolve, reject) => {
150
+ measureFileSizesBeforeBuild(paths.appBuild)
151
+ .then(previousFileSizes => {
152
+ // Remove all content but keep the directory so that
153
+ // if you're in it, you don't end up in Trash
154
+ fs.emptyDirSync(paths.appBuild);
155
+ // Start the webpack build
156
+ return build(config, previousFileSizes);
157
+ })
158
+ .then(
159
+ ({ stats, previousFileSizes, warnings }) => {
160
+ if (warnings.length) {
161
+ //console.log(chalk.yellow('Compiled with warnings.\n'), warnings[0].message);
162
+ console.log(chalk.yellow('Compiled with warnings.\n'));
163
+ for (let warning in warnings) {
164
+ console.log(chalk.yellow("Warning.."), warnings[warning].message);
165
+ }
166
+ } else {
167
+ console.log(chalk.green('Compiled successfully.\n'));
168
+ }
169
+
170
+ console.log('File sizes after gzip:\n');
171
+ printFileSizesAfterBuild(
172
+ stats,
173
+ previousFileSizes,
174
+ paths.appBuild,
175
+ WARN_AFTER_BUNDLE_GZIP_SIZE,
176
+ WARN_AFTER_CHUNK_GZIP_SIZE
177
+ );
178
+ resolve('done emitting');
179
+ },
180
+ err => {
181
+ reject();
182
+ const tscCompileOnError = process.env.TSC_COMPILE_ON_ERROR === 'true';
183
+ if (tscCompileOnError) {
184
+ console.log(
185
+ chalk.yellow(
186
+ 'Compiled with the following type errors (you may want to check these before deploying your app):\n'
187
+ )
188
+ );
189
+ printBuildError(err);
190
+ }
191
+ else if (compilationErrors != null) {
192
+ if (compilationErrors.length == undefined) {
193
+ console.log(chalk.red("Error..."), compilationErrors.message);
194
+ }
195
+ else {
196
+ for (let error in compilationErrors) {
197
+ console.log(chalk.red("Error..."), compilationErrors[error].message);
198
+ }
199
+ }
200
+
201
+ process.exit(1);
202
+ }
203
+ else {
204
+ console.log(chalk.red('Failed to compile.\n'));
205
+ printBuildError(JSON.stringify(err));
206
+
207
+ }
208
+ }
209
+ )
210
+ .catch(err => {
211
+ reject();
212
+ if (err && err.message) {
213
+ console.log(err.message);
214
+ }
215
+ process.exit(1);
216
+ });
217
+ });
218
+ };
@@ -0,0 +1,139 @@
1
+ /* eslint-disable import/no-dynamic-require */
2
+
3
+ import fs from 'fs';
4
+ import path from 'path';
5
+ import { createRequire } from 'module';
6
+
7
+ import chalk from 'chalk';
8
+ import resolve from 'resolve';
9
+
10
+ import paths from './paths.js';
11
+
12
+ const require = createRequire(import.meta.url);
13
+
14
+ /**
15
+ * Get additional module paths based on the baseUrl of a compilerOptions object.
16
+ *
17
+ * @param {Object} options
18
+ */
19
+ function getAdditionalModulePaths(options = {}) {
20
+ const baseUrl = options.baseUrl;
21
+
22
+ if (!baseUrl) {
23
+ return '';
24
+ }
25
+
26
+ const baseUrlResolved = path.resolve(paths.appPath, baseUrl);
27
+
28
+ // We don't need to do anything if `baseUrl` is set to `node_modules`. This is
29
+ // the default behavior.
30
+ if (path.relative(paths.appNodeModules, baseUrlResolved) === '') {
31
+ return null;
32
+ }
33
+
34
+ // Allow the user set the `baseUrl` to `appSrc`.
35
+ if (path.relative(paths.appSrc, baseUrlResolved) === '') {
36
+ return [paths.appSrc];
37
+ }
38
+
39
+ // If the path is equal to the root directory we ignore it here.
40
+ // We don't want to allow importing from the root directly as source files are
41
+ // not transpiled outside of `src`. We do allow importing them with the
42
+ // absolute path (e.g. `src/Components/Button.js`) but we set that up with
43
+ // an alias.
44
+ if (path.relative(paths.appPath, baseUrlResolved) === '') {
45
+ return null;
46
+ }
47
+
48
+ // Otherwise, throw an error.
49
+ throw new Error(
50
+ chalk.red.bold(
51
+ "Your project's `baseUrl` can only be set to `src` or `node_modules`." +
52
+ ' Create React App does not support other values at this time.'
53
+ )
54
+ );
55
+ }
56
+
57
+ /**
58
+ * Get webpack aliases based on the baseUrl of a compilerOptions object.
59
+ *
60
+ * @param {*} options
61
+ */
62
+ function getWebpackAliases(options = {}) {
63
+ const baseUrl = options.baseUrl;
64
+
65
+ if (!baseUrl) {
66
+ return {};
67
+ }
68
+
69
+ const baseUrlResolved = path.resolve(paths.appPath, baseUrl);
70
+
71
+ if (path.relative(paths.appPath, baseUrlResolved) === '') {
72
+ return {
73
+ src: paths.appSrc
74
+ };
75
+ }
76
+ }
77
+
78
+ /**
79
+ * Get jest aliases based on the baseUrl of a compilerOptions object.
80
+ *
81
+ * @param {*} options
82
+ */
83
+ function getJestAliases(options = {}) {
84
+ const baseUrl = options.baseUrl;
85
+
86
+ if (!baseUrl) {
87
+ return {};
88
+ }
89
+
90
+ const baseUrlResolved = path.resolve(paths.appPath, baseUrl);
91
+
92
+ if (path.relative(paths.appPath, baseUrlResolved) === '') {
93
+ return {
94
+ '^src/(.*)$': '<rootDir>/src/$1'
95
+ };
96
+ }
97
+ }
98
+
99
+ function getModules() {
100
+ // Check if TypeScript is setup
101
+ const hasTsConfig = fs.existsSync(paths.appTsConfig);
102
+ const hasJsConfig = fs.existsSync(paths.appJsConfig);
103
+
104
+ if (hasTsConfig && hasJsConfig) {
105
+ throw new Error(
106
+ 'You have both a tsconfig.json and a jsconfig.json. If you are using TypeScript please remove your jsconfig.json file.'
107
+ );
108
+ }
109
+
110
+ let config;
111
+
112
+ // If there's a tsconfig.json we assume it's a
113
+ // TypeScript project and set up the config
114
+ // based on tsconfig.json
115
+ if (hasTsConfig) {
116
+ const ts = require(resolve.sync('typescript', {
117
+ basedir: paths.appNodeModules
118
+ }));
119
+ config = ts.readConfigFile(paths.appTsConfig, ts.sys.readFile).config;
120
+ // Otherwise we'll check if there is jsconfig.json
121
+ // for non TS projects.
122
+ } else if (hasJsConfig) {
123
+ config = require(paths.appJsConfig);
124
+ }
125
+
126
+ config = config || {};
127
+ const options = config.compilerOptions || {};
128
+
129
+ const additionalModulePaths = getAdditionalModulePaths(options);
130
+
131
+ return {
132
+ additionalModulePaths,
133
+ webpackAliases: getWebpackAliases(options),
134
+ jestAliases: getJestAliases(options),
135
+ hasTsConfig
136
+ };
137
+ }
138
+
139
+ module.exports = getModules();
@@ -0,0 +1,51 @@
1
+ import path from 'path';
2
+ import fs from 'fs';
3
+
4
+ // Make sure any symlinks in the project folder are resolved:
5
+ // https://github.com/facebook/create-react-app/issues/637
6
+ const appDirectory = fs.realpathSync(process.cwd());
7
+ const resolveApp = relativePath => path.resolve(appDirectory, relativePath);
8
+
9
+ const buildPath = 'dist/components';
10
+
11
+ export const moduleFileExtensions = [
12
+ 'web.mjs',
13
+ 'mjs',
14
+ 'web.js',
15
+ 'js',
16
+ 'web.ts',
17
+ 'ts',
18
+ 'web.tsx',
19
+ 'tsx',
20
+ 'json',
21
+ 'web.jsx',
22
+ 'jsx'
23
+ ];
24
+
25
+ // Resolve file paths in the same order as webpack
26
+ const resolveModule = (resolveFn, filePath) => {
27
+ const extension = moduleFileExtensions.find(ext =>
28
+ fs.existsSync(resolveFn(`${filePath}.${ext}`))
29
+ );
30
+
31
+ if (extension) {
32
+ return resolveFn(`${filePath}.${extension}`);
33
+ }
34
+
35
+ return resolveFn(`${filePath}.js`);
36
+ };
37
+
38
+ // config after eject: we're in ./config/
39
+ // associated (constellation) components get their tsconfig from the constellation-comp-config directory
40
+ export default {
41
+ dotenv: resolveApp('.env'),
42
+ appPath: resolveApp('.'),
43
+ appBuild: resolveApp(buildPath),
44
+ appPublic: resolveApp('public'),
45
+ appIndexJs: resolveModule(resolveApp, 'src/index'),
46
+ appPackageJson: resolveApp('package.json'),
47
+ appSrc: [resolveApp('src/components'), resolveApp('src/app/_components')],
48
+ appTsConfig: resolveApp('constellation-comp-config/tsconfig.build.json'),
49
+ appJsConfig: resolveApp('jsconfig.json'),
50
+ appNodeModules: resolveApp('node_modules')
51
+ };