@tywalk/pcf-helper-run 1.1.29 → 1.2.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/dist/index.js CHANGED
@@ -33,121 +33,253 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  return result;
34
34
  };
35
35
  })();
36
- var _a, _b, _c;
37
36
  Object.defineProperty(exports, "__esModule", { value: true });
37
+ const commander_1 = require("commander");
38
38
  const tasks = __importStar(require("@tywalk/pcf-helper"));
39
39
  const color_logger_1 = require("@tywalk/color-logger");
40
40
  const package_json_1 = require("./package.json");
41
41
  const performanceUtil_1 = require("./util/performanceUtil");
42
- const argumentUtil_1 = require("./util/argumentUtil");
43
- const [, , ...args] = process.argv;
44
- const commandArgument = (_b = (_a = args.at(0)) === null || _a === void 0 ? void 0 : _a.toLowerCase()) !== null && _b !== void 0 ? _b : '';
45
- if (['-v', '--version'].includes(commandArgument)) {
46
- console.log('v%s', package_json_1.version);
47
- process.exit(0);
48
- }
49
- const logger = new color_logger_1.Logger('log');
50
- const verboseArgument = args.find(a => ['-v', '--verbose'].includes(a));
51
- const isVerbose = verboseArgument !== undefined;
52
- if (isVerbose) {
53
- logger.setDebug(true);
54
- }
55
- logger.log('PCF Helper Run version\n', package_json_1.version);
56
- if (typeof commandArgument === 'undefined' || !['upgrade', 'build', 'import', 'deploy', 'init'].includes(commandArgument)) {
57
- logger.error('Command [command] (upgrade, build, import, deploy, init) is required.');
58
- process.exit(1);
59
- }
60
- const runAll = commandArgument === 'deploy';
61
- const runInit = commandArgument === 'init';
62
- const path = (0, argumentUtil_1.getArgValue)(args, ['-p', '--path']);
63
- if (typeof path === 'undefined') {
64
- if (runInit) {
65
- logger.error('Path argument is required. Use --path to specify the PCF folder.');
42
+ // Preprocess arguments to handle deprecated flags
43
+ const preprocessArgs = (args) => {
44
+ const processed = [...args];
45
+ let hadDeprecatedEnv = false;
46
+ // Handle deprecated -env flag (single dash) by converting to --env (double dash)
47
+ for (let i = 0; i < processed.length; i++) {
48
+ if (processed[i] === '-env') {
49
+ hadDeprecatedEnv = true;
50
+ processed[i] = '--env';
51
+ }
52
+ }
53
+ return { args: processed, hadDeprecatedEnv };
54
+ };
55
+ // Preprocess arguments and track if deprecated flags were used
56
+ const { args: processedArgs, hadDeprecatedEnv } = preprocessArgs(process.argv.slice(2));
57
+ process.argv = [...process.argv.slice(0, 2), ...processedArgs];
58
+ // Configure the CLI program
59
+ commander_1.program
60
+ .name('pcf-helper-run')
61
+ .description('A simple command-line utility for building and publishing PCF controls to Dataverse.')
62
+ .version(package_json_1.version);
63
+ // Global options for commands that need them
64
+ const addCommonOptions = (command) => {
65
+ return command
66
+ .option('-v, --verbose', 'enable verbose logging')
67
+ .option('-t, --timeout <milliseconds>', 'timeout in milliseconds', (value) => {
68
+ const num = Number(value);
69
+ if (isNaN(num) || num <= 0) {
70
+ throw new Error('Timeout must be a positive number');
71
+ }
72
+ return value;
73
+ });
74
+ };
75
+ const addPathOptions = (command) => {
76
+ return addCommonOptions(command)
77
+ .option('-p, --path <path>', 'path to solution folder')
78
+ .option('-e, --environment <environment>', 'environment name')
79
+ .option('--env <environment>', '[DEPRECATED: use -e/--environment] environment name (deprecated)');
80
+ };
81
+ // Helper function to resolve environment value with deprecation warning
82
+ const resolveEnvironment = (options, logger) => {
83
+ // Check if deprecated --env flag was used
84
+ if (options.env && options.environment) {
85
+ logger.warn('⚠️ Both --env (deprecated) and --environment flags provided. Using --environment value.');
86
+ return options.environment;
87
+ }
88
+ else if (options.env) {
89
+ // Show deprecation warning using the proper logger
90
+ if (hadDeprecatedEnv) {
91
+ logger.warn('⚠️ The -env flag is DEPRECATED. Please use -e or --environment instead.');
92
+ }
93
+ else {
94
+ logger.warn('⚠️ The --env flag is DEPRECATED. Please use -e or --environment instead.');
95
+ }
96
+ return options.env;
66
97
  }
67
98
  else {
68
- logger.error('Path argument is required. Use --path to specify the path to solution folder.');
99
+ return options.environment || '';
69
100
  }
70
- process.exit(1);
71
- }
72
- const timeout = (0, argumentUtil_1.getArgValue)(args, ['-t', '--timeout']);
73
- if (typeof timeout !== 'undefined') {
74
- const timeoutNumber = Number(timeout);
75
- if (isNaN(timeoutNumber) || timeoutNumber <= 0) {
76
- logger.error('Timeout argument must be a positive number representing milliseconds.');
77
- process.exit(1);
101
+ };
102
+ // Helper function to setup logger and performance tracking
103
+ const setupExecutionContext = (options) => {
104
+ const logger = new color_logger_1.Logger('log');
105
+ if (options.verbose) {
106
+ logger.setDebug(true);
78
107
  }
79
- }
80
- const tick = performance.now();
81
- const env = (_c = (0, argumentUtil_1.getArgValue)(args, ['-env', '--environment'])) !== null && _c !== void 0 ? _c : '';
82
- if (env === '' && !runInit) {
83
- logger.warn('No environment specified. Defaulting to "local".');
84
- }
85
- function executeTasks() {
86
- if (commandArgument === 'upgrade' || runAll) {
87
- const upgradeResult = tasks.runUpgrade(path, isVerbose);
88
- if (upgradeResult === 1)
89
- return 1;
90
- }
91
- if (commandArgument === 'build' || runAll) {
92
- const buildResult = tasks.runBuild(path, isVerbose, timeout ? Number(timeout) : undefined);
93
- if (buildResult === 1)
94
- return 1;
95
- }
96
- if (commandArgument === 'import' || runAll) {
97
- const importResult = tasks.runImport(path, env, isVerbose, timeout ? Number(timeout) : undefined);
98
- if (importResult === 1)
99
- return 1;
100
- }
101
- if (commandArgument === 'init') {
102
- const name = (0, argumentUtil_1.getArgValue)(args, ['-n', '--name']);
103
- const publisherName = (0, argumentUtil_1.getArgValue)(args, ['-pn', '--publisher-name']);
104
- const publisherPrefix = (0, argumentUtil_1.getArgValue)(args, ['-pp', '--publisher-prefix']);
105
- const npm = (0, argumentUtil_1.getArgValue)(args, ['-npm', '--run-npm-install'], 'true');
106
- if (typeof name === 'undefined') {
107
- logger.error('Name argument is required. Use --name to specify the name of the control.');
108
- process.exit(1);
109
- }
110
- if (typeof publisherName === 'undefined') {
111
- logger.error('Publisher Name argument is required. Use --publisher-name to specify the name of the control.');
112
- process.exit(1);
108
+ logger.log('PCF Helper Run version\n', package_json_1.version);
109
+ return { logger, tick: performance.now() };
110
+ };
111
+ // Helper function to execute tasks and handle results
112
+ const executeTask = (taskName, logger, tick, result) => {
113
+ if (taskName !== 'session') {
114
+ if (result === 0) {
115
+ logger.log(`[PCF Helper Run] ${taskName} completed successfully!`);
113
116
  }
114
- if (typeof publisherPrefix === 'undefined') {
115
- logger.error('Publisher Prefix argument is required. Use --publisher-prefix to specify the name of the control.');
116
- process.exit(1);
117
+ else {
118
+ logger.log(`[PCF Helper Run] ${taskName} completed with errors.`);
117
119
  }
118
- const initResult = tasks.runInit(path, name, publisherName, publisherPrefix, npm === 'true', isVerbose);
119
- if (initResult === 1)
120
- return 1;
121
- }
122
- if (commandArgument === 'session') {
123
- const config = tasks.loadConfig();
124
- tasks.runSession(config.remoteEnvironmentUrl, config.remoteScriptToIntercept, config.remoteStylesheetToIntercept, config.localBundlePath, config.localCssPath);
125
- }
126
- return 0;
127
- }
128
- var result = 0;
129
- try {
130
- logger.log('[PCF Helper Run] ' + (0, performanceUtil_1.formatTime)(new Date()) + ' ' + commandArgument + ' started.\n');
131
- result = executeTasks();
132
- if (commandArgument !== 'session') {
133
- if (result === 0) {
134
- logger.log('[PCF Helper Run] ' + commandArgument + ' completed successfully!');
120
+ const tock = performance.now();
121
+ logger.log((0, performanceUtil_1.formatMsToSec)(`[PCF Helper Run] ${(0, performanceUtil_1.formatTime)(new Date())} ${taskName} finished in %is.`, tock - tick));
122
+ }
123
+ if (taskName !== 'session' || result === 1) {
124
+ process.exit(result);
125
+ }
126
+ };
127
+ // Define the upgrade command
128
+ addPathOptions(commander_1.program.command('upgrade'))
129
+ .description('upgrade PCF controls')
130
+ .action((options) => {
131
+ const { logger, tick } = setupExecutionContext(options);
132
+ if (!options.path) {
133
+ logger.error('Path argument is required. Use --path to specify the path to solution folder.');
134
+ process.exit(1);
135
+ }
136
+ let result = 0;
137
+ try {
138
+ logger.log('[PCF Helper Run] ' + (0, performanceUtil_1.formatTime)(new Date()) + ' upgrade started.\n');
139
+ result = tasks.runUpgrade(options.path, options.verbose || false);
140
+ }
141
+ catch (e) {
142
+ logger.error('[PCF Helper Run] One or more tasks failed while upgrading: ', (e && e.message) || 'unknown error');
143
+ result = 1;
144
+ }
145
+ executeTask('upgrade', logger, tick, result);
146
+ });
147
+ // Define the build command
148
+ addPathOptions(commander_1.program.command('build'))
149
+ .description('build PCF controls')
150
+ .action((options) => {
151
+ const { logger, tick } = setupExecutionContext(options);
152
+ if (!options.path) {
153
+ logger.error('Path argument is required. Use --path to specify the path to solution folder.');
154
+ process.exit(1);
155
+ }
156
+ let result = 0;
157
+ try {
158
+ logger.log('[PCF Helper Run] ' + (0, performanceUtil_1.formatTime)(new Date()) + ' build started.\n');
159
+ result = tasks.runBuild(options.path, options.verbose || false, options.timeout ? Number(options.timeout) : undefined);
160
+ }
161
+ catch (e) {
162
+ logger.error('[PCF Helper Run] One or more tasks failed while building: ', (e && e.message) || 'unknown error');
163
+ result = 1;
164
+ }
165
+ executeTask('build', logger, tick, result);
166
+ });
167
+ // Define the import command
168
+ addPathOptions(commander_1.program.command('import'))
169
+ .description('import PCF controls')
170
+ .action((options) => {
171
+ const { logger, tick } = setupExecutionContext(options);
172
+ if (!options.path) {
173
+ logger.error('Path argument is required. Use --path to specify the path to solution folder.');
174
+ process.exit(1);
175
+ }
176
+ const env = resolveEnvironment(options, logger);
177
+ if (env === '') {
178
+ logger.warn('No environment specified. Defaulting to "local".');
179
+ }
180
+ let result = 0;
181
+ try {
182
+ logger.log('[PCF Helper Run] ' + (0, performanceUtil_1.formatTime)(new Date()) + ' import started.\n');
183
+ result = tasks.runImport(options.path, env, options.verbose || false, options.timeout ? Number(options.timeout) : undefined);
184
+ }
185
+ catch (e) {
186
+ logger.error('[PCF Helper Run] One or more tasks failed while importing: ', (e && e.message) || 'unknown error');
187
+ result = 1;
188
+ }
189
+ executeTask('import', logger, tick, result);
190
+ });
191
+ // Define the deploy command (runs upgrade, build, and import)
192
+ addPathOptions(commander_1.program.command('deploy'))
193
+ .description('deploy PCF controls (runs upgrade, build, and import)')
194
+ .action((options) => {
195
+ const { logger, tick } = setupExecutionContext(options);
196
+ if (!options.path) {
197
+ logger.error('Path argument is required. Use --path to specify the path to solution folder.');
198
+ process.exit(1);
199
+ }
200
+ const env = resolveEnvironment(options, logger);
201
+ if (env === '') {
202
+ logger.warn('No environment specified. Defaulting to "local".');
203
+ }
204
+ let result = 0;
205
+ try {
206
+ logger.log('[PCF Helper Run] ' + (0, performanceUtil_1.formatTime)(new Date()) + ' deploy started.\n');
207
+ // Run upgrade
208
+ const upgradeResult = tasks.runUpgrade(options.path, options.verbose || false);
209
+ if (upgradeResult === 1) {
210
+ result = 1;
135
211
  }
136
212
  else {
137
- logger.log('[PCF Helper Run] ' + commandArgument + ' completed with errors.');
213
+ // Run build
214
+ const buildResult = tasks.runBuild(options.path, options.verbose || false, options.timeout ? Number(options.timeout) : undefined);
215
+ if (buildResult === 1) {
216
+ result = 1;
217
+ }
218
+ else {
219
+ // Run import
220
+ const importResult = tasks.runImport(options.path, env, options.verbose || false, options.timeout ? Number(options.timeout) : undefined);
221
+ if (importResult === 1) {
222
+ result = 1;
223
+ }
224
+ }
138
225
  }
139
226
  }
140
- }
141
- catch (e) {
142
- logger.error('[PCF Helper Run] One or more tasks failed while deploying: ', (e && e.message) || 'unkown error');
143
- result = 1;
144
- }
145
- finally {
146
- if (commandArgument !== 'session' || result === 1) {
147
- const tock = performance.now();
148
- logger.log((0, performanceUtil_1.formatMsToSec)('[PCF Helper Run] ' + (0, performanceUtil_1.formatTime)(new Date()) + ' ' + commandArgument + ' finished in %is.', tock - tick));
227
+ catch (e) {
228
+ logger.error('[PCF Helper Run] One or more tasks failed while deploying: ', (e && e.message) || 'unknown error');
229
+ result = 1;
230
+ }
231
+ executeTask('deploy', logger, tick, result);
232
+ });
233
+ // Define the init command
234
+ addCommonOptions(commander_1.program.command('init'))
235
+ .description('initialize a new PCF project')
236
+ .requiredOption('-p, --path <path>', 'path to PCF folder')
237
+ .requiredOption('-n, --name <name>', 'name of the control')
238
+ .requiredOption('--publisher-name <publisherName>', 'publisher name')
239
+ .requiredOption('--publisher-prefix <publisherPrefix>', 'publisher prefix')
240
+ .option('--run-npm-install', 'run npm install after initialization', true)
241
+ .action((options) => {
242
+ const { logger, tick } = setupExecutionContext(options);
243
+ let result = 0;
244
+ try {
245
+ logger.log('[PCF Helper Run] ' + (0, performanceUtil_1.formatTime)(new Date()) + ' init started.\n');
246
+ result = tasks.runInit(options.path, options.name, options.publisherName, options.publisherPrefix, options.runNpmInstall !== false, options.verbose || false);
149
247
  }
150
- }
151
- if (commandArgument !== 'session' || result === 1) {
152
- process.exit(result);
153
- }
248
+ catch (e) {
249
+ logger.error('[PCF Helper Run] One or more tasks failed while initializing: ', (e && e.message) || 'unknown error');
250
+ result = 1;
251
+ }
252
+ executeTask('init', logger, tick, result);
253
+ });
254
+ // Define the session command
255
+ addCommonOptions(commander_1.program.command('session'))
256
+ .description('run development session')
257
+ .option('-u, --url <url>', 'remote environment URL')
258
+ .option('-s, --script <script>', 'remote script to intercept')
259
+ .option('-t, --stylesheet <stylesheet>', 'remote stylesheet to intercept')
260
+ .option('-b, --bundle <path>', 'local bundle path')
261
+ .option('-c, --css <path>', 'local CSS path')
262
+ .option('-f, --config <path>', 'config file path', 'dev-config.json')
263
+ .action((options) => {
264
+ const { logger, tick } = setupExecutionContext(options);
265
+ let result = 0;
266
+ try {
267
+ logger.log('[PCF Helper Run] ' + (0, performanceUtil_1.formatTime)(new Date()) + ' session started.\n');
268
+ if (!options.url) {
269
+ const config = tasks.loadConfig(options.config || 'dev-config.json');
270
+ options.url = config.remoteEnvironmentUrl;
271
+ options.script = config.remoteScriptToIntercept;
272
+ options.stylesheet = config.remoteStylesheetToIntercept;
273
+ options.bundle = config.localBundlePath;
274
+ options.css = config.localCssPath;
275
+ }
276
+ tasks.runSession(options.url, options.script, options.stylesheet, options.bundle, options.css);
277
+ }
278
+ catch (e) {
279
+ logger.error('[PCF Helper Run] One or more tasks failed during session: ', (e && e.message) || 'unknown error');
280
+ result = 1;
281
+ }
282
+ executeTask('session', logger, tick, result);
283
+ });
284
+ // Parse the command line arguments
285
+ commander_1.program.parse();
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tywalk/pcf-helper-run",
3
- "version": "1.1.27",
3
+ "version": "1.2.1",
4
4
  "description": "A simple command-line utility for building and publishing PCF controls to Dataverse.",
5
5
  "types": "./types/",
6
6
  "files": [
@@ -25,7 +25,7 @@
25
25
  },
26
26
  "dependencies": {
27
27
  "@tywalk/color-logger": "^1.0.3",
28
- "@tywalk/pcf-helper": "^1.4.26"
28
+ "@tywalk/pcf-helper": "^1.5.0"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@types/jest": "^29.5.14",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tywalk/pcf-helper-run",
3
- "version": "1.1.29",
3
+ "version": "1.2.1",
4
4
  "description": "A simple command-line utility for building and publishing PCF controls to Dataverse.",
5
5
  "types": "./types/",
6
6
  "files": [
@@ -25,7 +25,7 @@
25
25
  },
26
26
  "dependencies": {
27
27
  "@tywalk/color-logger": "^1.0.3",
28
- "@tywalk/pcf-helper": "^1.4.26"
28
+ "@tywalk/pcf-helper": "^1.5.0"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@types/jest": "^29.5.14",