@tywalk/pcf-helper-run 1.1.29 → 1.2.0
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 +219 -100
- package/dist/package.json +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -33,121 +33,240 @@ 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
|
-
|
|
43
|
-
const
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
-
|
|
99
|
+
return options.environment || '';
|
|
69
100
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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
|
-
|
|
115
|
-
logger.
|
|
116
|
-
process.exit(1);
|
|
117
|
+
else {
|
|
118
|
+
logger.log(`[PCF Helper Run] ${taskName} completed with errors.`);
|
|
117
119
|
}
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
return 1;
|
|
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));
|
|
121
122
|
}
|
|
122
|
-
if (
|
|
123
|
-
|
|
124
|
-
tasks.runSession(config.remoteEnvironmentUrl, config.remoteScriptToIntercept, config.remoteStylesheetToIntercept, config.localBundlePath, config.localCssPath);
|
|
123
|
+
if (taskName !== 'session' || result === 1) {
|
|
124
|
+
process.exit(result);
|
|
125
125
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
if (
|
|
133
|
-
|
|
134
|
-
|
|
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
|
-
|
|
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
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
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);
|
|
247
|
+
}
|
|
248
|
+
catch (e) {
|
|
249
|
+
logger.error('[PCF Helper Run] One or more tasks failed while initializing: ', (e && e.message) || 'unknown error');
|
|
250
|
+
result = 1;
|
|
149
251
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
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
|
+
.action((options) => {
|
|
258
|
+
const { logger, tick } = setupExecutionContext(options);
|
|
259
|
+
let result = 0;
|
|
260
|
+
try {
|
|
261
|
+
logger.log('[PCF Helper Run] ' + (0, performanceUtil_1.formatTime)(new Date()) + ' session started.\n');
|
|
262
|
+
const config = tasks.loadConfig();
|
|
263
|
+
tasks.runSession(config.remoteEnvironmentUrl, config.remoteScriptToIntercept, config.remoteStylesheetToIntercept, config.localBundlePath, config.localCssPath);
|
|
264
|
+
}
|
|
265
|
+
catch (e) {
|
|
266
|
+
logger.error('[PCF Helper Run] One or more tasks failed during session: ', (e && e.message) || 'unknown error');
|
|
267
|
+
result = 1;
|
|
268
|
+
}
|
|
269
|
+
executeTask('session', logger, tick, result);
|
|
270
|
+
});
|
|
271
|
+
// Parse the command line arguments
|
|
272
|
+
commander_1.program.parse();
|
package/dist/package.json
CHANGED