@tywalk/pcf-helper 1.4.26 → 1.5.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/bin/build.js CHANGED
@@ -36,34 +36,29 @@ var __importStar = (this && this.__importStar) || (function () {
36
36
  var __importDefault = (this && this.__importDefault) || function (mod) {
37
37
  return (mod && mod.__esModule) ? mod : { "default": mod };
38
38
  };
39
- var _a, _b;
40
39
  Object.defineProperty(exports, "__esModule", { value: true });
41
40
  const task = __importStar(require("../tasks/build-pcf"));
42
41
  const package_json_1 = require("../package.json");
43
42
  const color_logger_1 = __importDefault(require("@tywalk/color-logger"));
44
- const argumentUtil_1 = require("../util/argumentUtil");
45
- const [, , ...args] = process.argv;
46
- const commandArgument = (_b = (_a = args.at(0)) === null || _a === void 0 ? void 0 : _a.toLowerCase()) !== null && _b !== void 0 ? _b : '';
47
- if (['-v', '--version'].includes(commandArgument)) {
48
- console.log('v%s', package_json_1.version);
49
- process.exit(0);
50
- }
51
- const timeout = (0, argumentUtil_1.getArgValue)(args, ['-t', '--timeout']);
52
- if (typeof timeout !== 'undefined') {
53
- const timeoutNumber = Number(timeout);
54
- if (isNaN(timeoutNumber) || timeoutNumber <= 0) {
55
- color_logger_1.default.error('Timeout argument must be a positive number representing milliseconds.');
56
- process.exit(1);
43
+ const commander_1 = require("commander");
44
+ const program = new commander_1.Command();
45
+ program
46
+ .name('pcf-helper-build')
47
+ .description('Build PCF controls')
48
+ .version(package_json_1.version, '-v, --version')
49
+ .option('-V, --verbose', 'enable verbose logging')
50
+ .option('-t, --timeout <milliseconds>', 'timeout in milliseconds', (value) => {
51
+ const num = Number(value);
52
+ if (isNaN(num) || num <= 0) {
53
+ throw new Error('Timeout must be a positive number');
57
54
  }
58
- }
59
- const verboseArgument = args.find(a => ['-v', '--verbose'].includes(a));
60
- if (typeof verboseArgument !== 'undefined') {
55
+ return value;
56
+ })
57
+ .requiredOption('-p, --path <path>', 'path to solution folder')
58
+ .parse();
59
+ const options = program.opts();
60
+ if (options.verbose) {
61
61
  color_logger_1.default.setDebug(true);
62
62
  }
63
63
  color_logger_1.default.log('PCF Helper version', package_json_1.version);
64
- const path = (0, argumentUtil_1.getArgValue)(args, ['-p', '--path']);
65
- if (typeof path === 'undefined') {
66
- color_logger_1.default.error('Path argument is required. Use --path to specify the path to solution folder.');
67
- process.exit(1);
68
- }
69
- task.runBuild(path, verboseArgument !== undefined, typeof timeout !== 'undefined' ? Number(timeout) : undefined);
64
+ task.runBuild(options.path, options.verbose || false, options.timeout ? Number(options.timeout) : undefined);
@@ -36,7 +36,6 @@ var __importStar = (this && this.__importStar) || (function () {
36
36
  var __importDefault = (this && this.__importDefault) || function (mod) {
37
37
  return (mod && mod.__esModule) ? mod : { "default": mod };
38
38
  };
39
- var _a, _b, _c;
40
39
  Object.defineProperty(exports, "__esModule", { value: true });
41
40
  const upgradeTask = __importStar(require("../tasks/upgrade-pcf"));
42
41
  const buildTask = __importStar(require("../tasks/build-pcf"));
@@ -44,47 +43,29 @@ const importTask = __importStar(require("../tasks/import-pcf"));
44
43
  const performanceUtil_1 = require("../util/performanceUtil");
45
44
  const package_json_1 = require("../package.json");
46
45
  const color_logger_1 = __importDefault(require("@tywalk/color-logger"));
46
+ const commander_1 = require("commander");
47
47
  const argumentUtil_1 = require("../util/argumentUtil");
48
- const [, , ...args] = process.argv;
49
- const commandArgument = (_b = (_a = args.at(0)) === null || _a === void 0 ? void 0 : _a.toLowerCase()) !== null && _b !== void 0 ? _b : '';
50
- if (['-v', '--version'].includes(commandArgument)) {
51
- console.log('v%s', package_json_1.version);
52
- process.exit(0);
53
- }
54
- const timeout = (0, argumentUtil_1.getArgValue)(args, ['-t', '--timeout']);
55
- if (typeof timeout !== 'undefined') {
56
- const timeoutNumber = Number(timeout);
57
- if (isNaN(timeoutNumber) || timeoutNumber <= 0) {
58
- color_logger_1.default.error('Timeout argument must be a positive number representing milliseconds.');
59
- process.exit(1);
60
- }
61
- }
62
- const verboseArgument = args.find(a => ['-v', '--verbose'].includes(a));
63
- if (typeof verboseArgument !== 'undefined') {
64
- color_logger_1.default.setDebug(true);
65
- }
48
+ // Apply argument preprocessing for backward compatibility
49
+ const { hadDeprecatedEnv } = (0, argumentUtil_1.applyArgumentPreprocessing)(process.argv);
50
+ const program = new commander_1.Command();
51
+ (0, argumentUtil_1.addPathAndEnvironmentOptions)(program)
52
+ .name('pcf-helper-deploy')
53
+ .description('Deploy PCF controls (runs upgrade, build, and import)')
54
+ .version(package_json_1.version, '-v, --version')
55
+ .parse();
56
+ const options = program.opts();
57
+ (0, argumentUtil_1.setupLogging)(options.verbose);
66
58
  color_logger_1.default.log('PCF Helper version', package_json_1.version);
67
- const pathArgument = args.find(a => ['-p', '--path'].includes(a));
68
- if (typeof pathArgument === 'undefined') {
69
- color_logger_1.default.error('Path argument is required. Use --path to specify the path to solution folder.');
70
- process.exit(1);
71
- }
72
- const pathIndex = args.indexOf(pathArgument) + 1;
73
- const path = args.at(pathIndex);
74
- if (typeof path === 'undefined') {
75
- color_logger_1.default.error('Path argument is required. Use --path to specify the path to solution folder.');
76
- process.exit(1);
77
- }
59
+ const env = (0, argumentUtil_1.resolveEnvironment)(options, hadDeprecatedEnv);
78
60
  const tick = performance.now();
79
- const env = (_c = (0, argumentUtil_1.getArgValue)(args, ['-env', '--environment'])) !== null && _c !== void 0 ? _c : '';
80
61
  function executeTasks() {
81
- const upgradeResult = upgradeTask.runUpgrade(path, typeof verboseArgument !== 'undefined');
62
+ const upgradeResult = upgradeTask.runUpgrade(options.path, options.verbose || false);
82
63
  if (upgradeResult === 1)
83
64
  return 1;
84
- const buildResult = buildTask.runBuild(path, typeof verboseArgument !== 'undefined', typeof timeout !== 'undefined' ? Number(timeout) : undefined);
65
+ const buildResult = buildTask.runBuild(options.path, options.verbose || false, options.timeout ? Number(options.timeout) : undefined);
85
66
  if (buildResult === 1)
86
67
  return 1;
87
- const importResult = importTask.runImport(path, env, typeof verboseArgument !== 'undefined', typeof timeout !== 'undefined' ? Number(timeout) : undefined);
68
+ const importResult = importTask.runImport(options.path, env, options.verbose || false, options.timeout ? Number(options.timeout) : undefined);
88
69
  if (importResult === 1)
89
70
  return 1;
90
71
  return 0;
@@ -97,7 +78,7 @@ try {
97
78
  }
98
79
  }
99
80
  catch (e) {
100
- color_logger_1.default.error('One or more tasks failed while deploying: ', (e && e.message) || 'unkown error');
81
+ color_logger_1.default.error('One or more tasks failed while deploying: ', (e && e.message) || 'unknown error');
101
82
  result = 1;
102
83
  }
103
84
  finally {
@@ -36,35 +36,22 @@ var __importStar = (this && this.__importStar) || (function () {
36
36
  var __importDefault = (this && this.__importDefault) || function (mod) {
37
37
  return (mod && mod.__esModule) ? mod : { "default": mod };
38
38
  };
39
- var _a, _b, _c;
40
39
  Object.defineProperty(exports, "__esModule", { value: true });
41
40
  const task = __importStar(require("../tasks/import-pcf"));
42
41
  const package_json_1 = require("../package.json");
43
42
  const color_logger_1 = __importDefault(require("@tywalk/color-logger"));
43
+ const commander_1 = require("commander");
44
44
  const argumentUtil_1 = require("../util/argumentUtil");
45
- const [, , ...args] = process.argv;
46
- const commandArgument = (_b = (_a = args.at(0)) === null || _a === void 0 ? void 0 : _a.toLowerCase()) !== null && _b !== void 0 ? _b : '';
47
- if (['-v', '--version'].includes(commandArgument)) {
48
- console.log('v%s', package_json_1.version);
49
- process.exit(0);
50
- }
51
- const timeout = (0, argumentUtil_1.getArgValue)(args, ['-t', '--timeout']);
52
- if (typeof timeout !== 'undefined') {
53
- const timeoutNumber = Number(timeout);
54
- if (isNaN(timeoutNumber) || timeoutNumber <= 0) {
55
- color_logger_1.default.error('Timeout argument must be a positive number representing milliseconds.');
56
- process.exit(1);
57
- }
58
- }
59
- const verboseArgument = args.find(a => ['-v', '--verbose'].includes(a));
60
- if (typeof verboseArgument !== 'undefined') {
61
- color_logger_1.default.setDebug(true);
62
- }
45
+ // Apply argument preprocessing for backward compatibility
46
+ const { hadDeprecatedEnv } = (0, argumentUtil_1.applyArgumentPreprocessing)(process.argv);
47
+ const program = new commander_1.Command();
48
+ (0, argumentUtil_1.addPathAndEnvironmentOptions)(program)
49
+ .name('pcf-helper-import')
50
+ .description('Import PCF controls to Dataverse')
51
+ .version(package_json_1.version, '-v, --version')
52
+ .parse();
53
+ const options = program.opts();
54
+ (0, argumentUtil_1.setupLogging)(options.verbose);
63
55
  color_logger_1.default.log('PCF Helper version', package_json_1.version);
64
- const path = (0, argumentUtil_1.getArgValue)(args, ['-p', '--path']);
65
- if (typeof path === 'undefined') {
66
- color_logger_1.default.error('Path argument is required. Use --path to specify the path to solution folder.');
67
- process.exit(1);
68
- }
69
- const env = (_c = (0, argumentUtil_1.getArgValue)(args, ['-env', '--environment'])) !== null && _c !== void 0 ? _c : '';
70
- task.runImport(path, env, verboseArgument !== undefined, typeof timeout !== 'undefined' ? Number(timeout) : undefined);
56
+ const env = (0, argumentUtil_1.resolveEnvironment)(options, hadDeprecatedEnv);
57
+ task.runImport(options.path, env, options.verbose || false, options.timeout ? Number(options.timeout) : undefined);
package/dist/bin/init.js CHANGED
@@ -36,30 +36,26 @@ var __importStar = (this && this.__importStar) || (function () {
36
36
  var __importDefault = (this && this.__importDefault) || function (mod) {
37
37
  return (mod && mod.__esModule) ? mod : { "default": mod };
38
38
  };
39
- var _a, _b, _c, _d, _e;
40
39
  Object.defineProperty(exports, "__esModule", { value: true });
41
40
  const task = __importStar(require("../tasks/init-pcf"));
42
41
  const package_json_1 = require("../package.json");
43
42
  const color_logger_1 = __importDefault(require("@tywalk/color-logger"));
44
- const argumentUtil_1 = require("../util/argumentUtil");
45
- const [, , ...args] = process.argv;
46
- const commandArgument = (_b = (_a = args.at(0)) === null || _a === void 0 ? void 0 : _a.toLowerCase()) !== null && _b !== void 0 ? _b : '';
47
- if (['-v', '--version'].includes(commandArgument)) {
48
- console.log('v%s', package_json_1.version);
49
- process.exit(0);
50
- }
51
- const verboseArgument = args.find(a => ['-v', '--verbose'].includes(a));
52
- if (typeof verboseArgument !== 'undefined') {
43
+ const commander_1 = require("commander");
44
+ const program = new commander_1.Command();
45
+ program
46
+ .name('pcf-helper-init')
47
+ .description('Initialize a new PCF project')
48
+ .version(package_json_1.version, '-v, --version')
49
+ .option('-V, --verbose', 'enable verbose logging')
50
+ .requiredOption('-n, --name <name>', 'name of the PCF control')
51
+ .option('--publisher-name <publisherName>', 'publisher name')
52
+ .option('--publisher-prefix <publisherPrefix>', 'publisher prefix')
53
+ .option('-p, --path <path>', 'path to create the PCF project')
54
+ .option('--run-npm-install', 'run npm install after initialization', true)
55
+ .parse();
56
+ const options = program.opts();
57
+ if (options.verbose) {
53
58
  color_logger_1.default.setDebug(true);
54
59
  }
55
60
  color_logger_1.default.log('PCF Helper version', package_json_1.version);
56
- const name = (0, argumentUtil_1.getArgValue)(args, ['-n', '--name']);
57
- if (typeof name === 'undefined') {
58
- color_logger_1.default.error('Name argument is required. Use --name to specify the name of the PCF control.');
59
- process.exit(1);
60
- }
61
- const publisherName = (_c = (0, argumentUtil_1.getArgValue)(args, ['-pn', '--publisher-name'])) !== null && _c !== void 0 ? _c : '';
62
- const publisherPrefix = (_d = (0, argumentUtil_1.getArgValue)(args, ['-pp', '--publisher-prefix'])) !== null && _d !== void 0 ? _d : '';
63
- const path = (_e = (0, argumentUtil_1.getArgValue)(args, ['-p', '--path'])) !== null && _e !== void 0 ? _e : '';
64
- const npm = (0, argumentUtil_1.getArgValue)(args, ['-npm', '--run-npm-install'], 'true');
65
- task.runInit(path, name, publisherName, publisherPrefix, npm === 'true', verboseArgument !== undefined);
61
+ task.runInit(options.path || '', options.name, options.publisherName || '', options.publisherPrefix || '', options.runNpmInstall !== false, options.verbose || false);
@@ -43,18 +43,22 @@ const color_logger_1 = __importDefault(require("@tywalk/color-logger"));
43
43
  const commander_1 = require("commander");
44
44
  const program = new commander_1.Command();
45
45
  program
46
- .option('-v, --version', 'output the version number')
47
- .option('-vv, --verbose', 'enable verbose logging')
46
+ .name('pcf-helper-session')
47
+ .description('Run development session')
48
+ .version(package_json_1.version, '-v, --version')
49
+ .option('-V, --verbose', 'enable verbose logging')
50
+ .option('-u, --url <url>', 'remote environment URL')
51
+ .option('-s, --script <script>', 'remote script to intercept')
52
+ .option('-t, --stylesheet <stylesheet>', 'remote stylesheet to intercept')
53
+ .option('-b, --bundle <path>', 'local bundle path')
54
+ .option('-c, --css <path>', 'local CSS path')
55
+ .option('-f, --config <path>', 'config file path', 'dev-config.json')
48
56
  .parse();
49
57
  const options = program.opts();
50
- if (options.version) {
51
- console.log('v%s', package_json_1.version);
52
- process.exit(0);
53
- }
54
58
  if (options.verbose) {
55
- color_logger_1.default.setLevel('debug');
59
+ color_logger_1.default.setDebug(true);
56
60
  color_logger_1.default.debug('Verbose logging enabled');
57
61
  }
58
62
  color_logger_1.default.log('PCF Helper version', package_json_1.version);
59
- const config = task.loadConfig();
63
+ const config = task.loadConfig(options.config);
60
64
  task.runSession(config.remoteEnvironmentUrl, config.remoteScriptToIntercept, config.remoteStylesheetToIntercept, config.localBundlePath, config.localCssPath);
@@ -36,26 +36,22 @@ var __importStar = (this && this.__importStar) || (function () {
36
36
  var __importDefault = (this && this.__importDefault) || function (mod) {
37
37
  return (mod && mod.__esModule) ? mod : { "default": mod };
38
38
  };
39
- var _a, _b;
40
39
  Object.defineProperty(exports, "__esModule", { value: true });
41
40
  const task = __importStar(require("../tasks/upgrade-pcf"));
42
41
  const package_json_1 = require("../package.json");
43
42
  const color_logger_1 = __importDefault(require("@tywalk/color-logger"));
44
- const argumentUtil_1 = require("../util/argumentUtil");
45
- const [, , ...args] = process.argv;
46
- const commandArgument = (_b = (_a = args.at(0)) === null || _a === void 0 ? void 0 : _a.toLowerCase()) !== null && _b !== void 0 ? _b : '';
47
- if (['-v', '--version'].includes(commandArgument)) {
48
- console.log('v%s', package_json_1.version);
49
- process.exit(0);
50
- }
51
- const verboseArgument = args.find(a => ['-v', '--verbose'].includes(a));
52
- if (typeof verboseArgument !== 'undefined') {
43
+ const commander_1 = require("commander");
44
+ const program = new commander_1.Command();
45
+ program
46
+ .name('pcf-helper-upgrade')
47
+ .description('Upgrade PCF controls')
48
+ .version(package_json_1.version, '-v, --version')
49
+ .option('-V, --verbose', 'enable verbose logging')
50
+ .requiredOption('-p, --path <path>', 'path to solution folder')
51
+ .parse();
52
+ const options = program.opts();
53
+ if (options.verbose) {
53
54
  color_logger_1.default.setDebug(true);
54
55
  }
55
56
  color_logger_1.default.log('PCF Helper version', package_json_1.version);
56
- const path = (0, argumentUtil_1.getArgValue)(args, ['-p', '--path']);
57
- if (typeof path === 'undefined') {
58
- color_logger_1.default.error('Path argument is required. Use --path to specify the path to solution folder.');
59
- process.exit(1);
60
- }
61
- task.runUpgrade(path, verboseArgument !== undefined);
57
+ task.runUpgrade(options.path, options.verbose || false);
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tywalk/pcf-helper",
3
- "version": "1.4.26",
3
+ "version": "1.5.0",
4
4
  "description": "Command line helper for building and publishing PCF controls to Dataverse.",
5
5
  "main": "dist/index.js",
6
6
  "types": "./types/",
@@ -18,21 +18,10 @@ const color_logger_1 = __importDefault(require("@tywalk/color-logger"));
18
18
  const path_1 = __importDefault(require("path"));
19
19
  const fs_1 = __importDefault(require("fs"));
20
20
  const playwright_1 = require("playwright");
21
- const commander_1 = require("commander");
22
- function loadConfig() {
23
- const program = new commander_1.Command();
24
- program
25
- .option('-u, --url <url>', 'remote environment URL')
26
- .option('-s, --script <script>', 'remote script to intercept')
27
- .option('-t, --stylesheet <stylesheet>', 'remote stylesheet to intercept')
28
- .option('-b, --bundle <path>', 'local bundle path')
29
- .option('-c, --css <path>', 'local CSS path')
30
- .option('-f, --config <path>', 'config file path', 'dev-config.json')
31
- .parse();
32
- const options = program.opts();
21
+ function loadConfig(config) {
33
22
  // Load file config if exists
34
23
  let fileConfig = {};
35
- const configPath = path_1.default.join(__dirname, options.config);
24
+ const configPath = path_1.default.join(__dirname, config || 'dev-config.json');
36
25
  console.log(`📁 Looking for config file at: ${configPath}`);
37
26
  if (fs_1.default.existsSync(configPath)) {
38
27
  fileConfig = JSON.parse(fs_1.default.readFileSync(configPath, 'utf8'));
@@ -42,13 +31,11 @@ function loadConfig() {
42
31
  console.log(`⚠️ Config file not found, using defaults or CLI/env options.`);
43
32
  }
44
33
  // Get the base URL first
45
- const remoteEnvironmentUrl = options.url ||
46
- process.env.REMOTE_ENVIRONMENT_URL ||
34
+ const remoteEnvironmentUrl = process.env.REMOTE_ENVIRONMENT_URL ||
47
35
  fileConfig.remoteEnvironmentUrl ||
48
36
  'https://app.your-remote-environment.com';
49
37
  // Handle script argument - support both relative paths and full URLs
50
- let remoteScriptToIntercept = options.script ||
51
- process.env.REMOTE_SCRIPT_TO_INTERCEPT ||
38
+ let remoteScriptToIntercept = process.env.REMOTE_SCRIPT_TO_INTERCEPT ||
52
39
  fileConfig.remoteScriptToIntercept ||
53
40
  'https://app.your-remote-environment.com/static/js/remote-control-bundle.js';
54
41
  // If script is a relative path (doesn't start with http/https), combine with base URL
@@ -61,8 +48,7 @@ function loadConfig() {
61
48
  : '/' + remoteScriptToIntercept;
62
49
  remoteScriptToIntercept = `${baseUrl}${scriptPath}`;
63
50
  }
64
- let remoteStylesheetToIntercept = options.stylesheet ||
65
- process.env.REMOTE_STYLESHEET_TO_INTERCEPT ||
51
+ let remoteStylesheetToIntercept = process.env.REMOTE_STYLESHEET_TO_INTERCEPT ||
66
52
  fileConfig.remoteStylesheetToIntercept ||
67
53
  'https://app.your-remote-environment.com/static/css/remote-control-styles.css';
68
54
  // If stylesheet is a relative path (doesn't start with http/https), combine with base URL
@@ -80,12 +66,10 @@ function loadConfig() {
80
66
  remoteEnvironmentUrl: remoteEnvironmentUrl,
81
67
  remoteScriptToIntercept: remoteScriptToIntercept,
82
68
  remoteStylesheetToIntercept: remoteStylesheetToIntercept,
83
- localCssPath: options.css ||
84
- process.env.LOCAL_CSS_PATH ||
69
+ localCssPath: process.env.LOCAL_CSS_PATH ||
85
70
  fileConfig.localCssPath ||
86
71
  path_1.default.join(__dirname, 'dist', 'local-control-styles.css'),
87
- localBundlePath: options.bundle ||
88
- process.env.LOCAL_BUNDLE_PATH ||
72
+ localBundlePath: process.env.LOCAL_BUNDLE_PATH ||
89
73
  fileConfig.localBundlePath ||
90
74
  path_1.default.join(__dirname, 'dist', 'local-control-bundle.js')
91
75
  };
@@ -1,7 +1,17 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.getArg = getArg;
4
7
  exports.getArgValue = getArgValue;
8
+ exports.preprocessArgs = preprocessArgs;
9
+ exports.resolveEnvironment = resolveEnvironment;
10
+ exports.applyArgumentPreprocessing = applyArgumentPreprocessing;
11
+ exports.addCommonOptions = addCommonOptions;
12
+ exports.addPathAndEnvironmentOptions = addPathAndEnvironmentOptions;
13
+ exports.setupLogging = setupLogging;
14
+ const color_logger_1 = __importDefault(require("@tywalk/color-logger"));
5
15
  function getArg(args, arg) {
6
16
  const index = args.indexOf(arg);
7
17
  if (index !== -1 && index + 1 < args.length) {
@@ -18,3 +28,90 @@ function getArgValue(args, argOpts, defaultIfExists) {
18
28
  const argIndex = args.indexOf(arg) + 1;
19
29
  return (_a = args.at(argIndex)) !== null && _a !== void 0 ? _a : defaultIfExists;
20
30
  }
31
+ /**
32
+ * Preprocesses command line arguments to handle deprecated flags
33
+ * @param args - Raw command line arguments
34
+ * @returns Object containing processed args and deprecation flags
35
+ */
36
+ function preprocessArgs(args) {
37
+ const processed = [...args];
38
+ let hadDeprecatedEnv = false;
39
+ // Handle deprecated -env flag (single dash) by converting to --env (double dash)
40
+ for (let i = 0; i < processed.length; i++) {
41
+ if (processed[i] === '-env') {
42
+ hadDeprecatedEnv = true;
43
+ processed[i] = '--env';
44
+ }
45
+ }
46
+ return { args: processed, hadDeprecatedEnv };
47
+ }
48
+ /**
49
+ * Resolves environment value from options with proper deprecation warnings
50
+ * @param options - Parsed Commander.js options
51
+ * @param hadDeprecatedEnv - Whether the deprecated -env flag was used
52
+ * @returns Resolved environment string
53
+ */
54
+ function resolveEnvironment(options, hadDeprecatedEnv) {
55
+ // Check if deprecated --env flag was used
56
+ if (options.env && options.environment) {
57
+ color_logger_1.default.warn('⚠️ Both --env (deprecated) and --environment flags provided. Using --environment value.');
58
+ return options.environment;
59
+ }
60
+ else if (options.env) {
61
+ if (hadDeprecatedEnv) {
62
+ color_logger_1.default.warn('⚠️ The -env flag is DEPRECATED. Please use -e or --environment instead.');
63
+ }
64
+ else {
65
+ color_logger_1.default.warn('⚠️ The --env flag is DEPRECATED. Please use -e or --environment instead.');
66
+ }
67
+ return options.env;
68
+ }
69
+ else {
70
+ return options.environment || '';
71
+ }
72
+ }
73
+ /**
74
+ * Applies argument preprocessing for backward compatibility
75
+ * @param originalArgv - The original process.argv
76
+ */
77
+ function applyArgumentPreprocessing(originalArgv) {
78
+ const { args: processedArgs, hadDeprecatedEnv } = preprocessArgs(originalArgv.slice(2));
79
+ process.argv = [...originalArgv.slice(0, 2), ...processedArgs];
80
+ return { hadDeprecatedEnv };
81
+ }
82
+ /**
83
+ * Adds common CLI options to a Commander.js command
84
+ * @param command - Commander.js command instance
85
+ * @returns The command with common options added
86
+ */
87
+ function addCommonOptions(command) {
88
+ return command
89
+ .option('-V, --verbose', 'enable verbose logging')
90
+ .option('-t, --timeout <milliseconds>', 'timeout in milliseconds', (value) => {
91
+ const num = Number(value);
92
+ if (isNaN(num) || num <= 0) {
93
+ throw new Error('Timeout must be a positive number');
94
+ }
95
+ return value;
96
+ });
97
+ }
98
+ /**
99
+ * Adds path and environment options to a Commander.js command
100
+ * @param command - Commander.js command instance
101
+ * @returns The command with path and environment options added
102
+ */
103
+ function addPathAndEnvironmentOptions(command) {
104
+ return addCommonOptions(command)
105
+ .requiredOption('-p, --path <path>', 'path to solution folder')
106
+ .option('-e, --environment <environment>', 'environment name')
107
+ .option('--env <environment>', '[DEPRECATED: use -e/--environment] environment name (deprecated)');
108
+ }
109
+ /**
110
+ * Sets up logging based on verbose option
111
+ * @param verbose - Whether verbose logging is enabled
112
+ */
113
+ function setupLogging(verbose) {
114
+ if (verbose) {
115
+ color_logger_1.default.setDebug(true);
116
+ }
117
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tywalk/pcf-helper",
3
- "version": "1.4.26",
3
+ "version": "1.5.0",
4
4
  "description": "Command line helper for building and publishing PCF controls to Dataverse.",
5
5
  "main": "dist/index.js",
6
6
  "types": "./types/",
@@ -1,4 +1,4 @@
1
- declare function loadConfig(): {
1
+ declare function loadConfig(config?: string): {
2
2
  remoteEnvironmentUrl: any;
3
3
  remoteScriptToIntercept: any;
4
4
  remoteStylesheetToIntercept: any;
@@ -1,2 +1,46 @@
1
+ import { Command } from 'commander';
1
2
  export declare function getArg(args: string[], arg: string): string | undefined;
2
3
  export declare function getArgValue(args: string[], argOpts: string[], defaultIfExists?: any): string | undefined;
4
+ /**
5
+ * Preprocesses command line arguments to handle deprecated flags
6
+ * @param args - Raw command line arguments
7
+ * @returns Object containing processed args and deprecation flags
8
+ */
9
+ export declare function preprocessArgs(args: string[]): {
10
+ args: string[];
11
+ hadDeprecatedEnv: boolean;
12
+ };
13
+ /**
14
+ * Resolves environment value from options with proper deprecation warnings
15
+ * @param options - Parsed Commander.js options
16
+ * @param hadDeprecatedEnv - Whether the deprecated -env flag was used
17
+ * @returns Resolved environment string
18
+ */
19
+ export declare function resolveEnvironment(options: {
20
+ env?: string;
21
+ environment?: string;
22
+ }, hadDeprecatedEnv: boolean): string;
23
+ /**
24
+ * Applies argument preprocessing for backward compatibility
25
+ * @param originalArgv - The original process.argv
26
+ */
27
+ export declare function applyArgumentPreprocessing(originalArgv: string[]): {
28
+ hadDeprecatedEnv: boolean;
29
+ };
30
+ /**
31
+ * Adds common CLI options to a Commander.js command
32
+ * @param command - Commander.js command instance
33
+ * @returns The command with common options added
34
+ */
35
+ export declare function addCommonOptions(command: Command): Command;
36
+ /**
37
+ * Adds path and environment options to a Commander.js command
38
+ * @param command - Commander.js command instance
39
+ * @returns The command with path and environment options added
40
+ */
41
+ export declare function addPathAndEnvironmentOptions(command: Command): Command;
42
+ /**
43
+ * Sets up logging based on verbose option
44
+ * @param verbose - Whether verbose logging is enabled
45
+ */
46
+ export declare function setupLogging(verbose?: boolean): void;