@percy/cli-config 1.0.0-beta.9 → 1.0.2

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/README.md CHANGED
@@ -1,33 +1,39 @@
1
- ## @percy/cli-config
1
+ # @percy/cli-config
2
2
 
3
- Uses [`percy/config`](/packages/config) to add CLI commands for creating, validating, and updating
3
+ Uses [`@percy/config`](/packages/config) to add CLI commands for creating, validating, and updating
4
4
  Percy configuration files.
5
5
 
6
6
  ## Commands
7
7
  <!-- commands -->
8
- * [`percy config:create [FILEPATH]`](#percy-configcreate-filepath)
9
- * [`percy config:migrate [FILEPATH] [OUTPUT]`](#percy-configmigrate-filepath-output)
10
- * [`percy config:validate [FILEPATH]`](#percy-configvalidate-filepath)
8
+ * [`percy config:create`](#percy-configcreate)
9
+ * [`percy config:validate`](#percy-configvalidate)
10
+ * [`percy config:migrate`](#percy-configmigrate)
11
11
 
12
- ## `percy config:create [FILEPATH]`
12
+ ### `percy config:create`
13
13
 
14
14
  Create a Percy config file
15
15
 
16
16
  ```
17
- USAGE
18
- $ percy config:create [FILEPATH]
19
-
20
- ARGUMENTS
21
- FILEPATH config filepath
22
-
23
- OPTIONS
24
- --js create a .percy.js file
25
- --json create a .percy.json file
26
- --rc create a .percyrc file
27
- --yaml create a .percy.yaml file
28
- --yml create a .percy.yml file
29
-
30
- EXAMPLES
17
+ Usage:
18
+ $ percy config:create [options] [filepath]
19
+
20
+ Arguments:
21
+ filepath Optional config filepath
22
+
23
+ Options:
24
+ --rc Create a .percyrc file
25
+ --yaml Create a .percy.yaml file
26
+ --yml Create a .percy.yml file
27
+ --json Create a .percy.json file
28
+ --js Create a .percy.js file
29
+
30
+ Global options:
31
+ -v, --verbose Log everything
32
+ -q, --quiet Log errors only
33
+ -s, --silent Log nothing
34
+ -h, --help Display command help
35
+
36
+ Examples:
31
37
  $ percy config:create
32
38
  $ percy config:create --yaml
33
39
  $ percy config:create --json
@@ -36,41 +42,53 @@ EXAMPLES
36
42
  $ percy config:create ./config/percy.yml
37
43
  ```
38
44
 
39
- ## `percy config:migrate [FILEPATH] [OUTPUT]`
45
+ ### `percy config:validate`
40
46
 
41
- Migrate a Percy config file to the latest version
47
+ Validate a Percy config file
42
48
 
43
49
  ```
44
- USAGE
45
- $ percy config:migrate [FILEPATH] [OUTPUT]
50
+ Usage:
51
+ $ percy config:validate [options] [filepath]
46
52
 
47
- ARGUMENTS
48
- FILEPATH current config filepath, detected by default
49
- OUTPUT new config filepath to write to, defaults to FILEPATH
53
+ Arguments:
54
+ filepath Config filepath, detected by default
50
55
 
51
- OPTIONS
52
- -d, --dry-run prints the new config rather than writing it
56
+ Global options:
57
+ -v, --verbose Log everything
58
+ -q, --quiet Log errors only
59
+ -s, --silent Log nothing
60
+ -h, --help Display command help
53
61
 
54
- EXAMPLES
55
- $ percy config:migrate
56
- $ percy config:migrate --dry-run
57
- $ percy config:migrate ./config/percy.yml
58
- $ percy config:migrate .percy.yml .percy.js
62
+ Examples:
63
+ $ percy config:validate
64
+ $ percy config:validate ./config/percy.yml
59
65
  ```
60
66
 
61
- ## `percy config:validate [FILEPATH]`
67
+ ### `percy config:migrate`
62
68
 
63
- Validate a Percy config file
69
+ Migrate a Percy config file to the latest version
64
70
 
65
71
  ```
66
- USAGE
67
- $ percy config:validate [FILEPATH]
72
+ Usage:
73
+ $ percy config:migrate [options] [filepath] [output]
68
74
 
69
- ARGUMENTS
70
- FILEPATH config filepath, detected by default
75
+ Arguments:
76
+ filepath Current config filepath, detected by default
77
+ output New config filepath to write to, defaults to 'filepath'
71
78
 
72
- EXAMPLES
73
- $ percy config:validate
74
- $ percy config:validate ./config/percy.yml
79
+ Options:
80
+ -d, --dry-run Print the new config without writing it
81
+
82
+ Global options:
83
+ -v, --verbose Log everything
84
+ -q, --quiet Log errors only
85
+ -s, --silent Log nothing
86
+ -h, --help Display command help
87
+
88
+ Examples:
89
+ $ percy config:migrate
90
+ $ percy config:migrate --dry-run
91
+ $ percy config:migrate ./config/percy.yml
92
+ $ percy config:migrate .percy.yml .percy.js
75
93
  ```
76
94
  <!-- commandsstop -->
package/dist/config.js ADDED
@@ -0,0 +1,9 @@
1
+ import command from '@percy/cli-command';
2
+ import create from './create.js';
3
+ import validate from './validate.js';
4
+ import migrate from './migrate.js';
5
+ export const config = command('config', {
6
+ description: 'Manage Percy config files',
7
+ commands: [create, validate, migrate]
8
+ });
9
+ export default config;
package/dist/create.js ADDED
@@ -0,0 +1,73 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import command, { PercyConfig } from '@percy/cli-command';
4
+ const DEFAULT_FILES = {
5
+ rc: '.percyrc',
6
+ yaml: '.percy.yaml',
7
+ yml: '.percy.yml',
8
+ json: '.percy.json',
9
+ js: '.percy.js'
10
+ };
11
+ const FILETYPES = Object.keys(DEFAULT_FILES);
12
+ export const create = command('create', {
13
+ description: 'Create a Percy config file',
14
+ args: [{
15
+ name: 'filepath',
16
+ description: 'Optional config filepath'
17
+ }],
18
+ flags: [{
19
+ name: 'rc',
20
+ description: 'Create a .percyrc file',
21
+ conflicts: FILETYPES.filter(t => t !== 'rc'),
22
+ type: 'boolean'
23
+ }, {
24
+ name: 'yaml',
25
+ description: 'Create a .percy.yaml file',
26
+ conflicts: FILETYPES.filter(t => t !== 'yaml'),
27
+ type: 'boolean'
28
+ }, {
29
+ name: 'yml',
30
+ description: 'Create a .percy.yml file',
31
+ conflicts: FILETYPES.filter(t => t !== 'yml'),
32
+ type: 'boolean'
33
+ }, {
34
+ name: 'json',
35
+ description: 'Create a .percy.json file',
36
+ conflicts: FILETYPES.filter(t => t !== 'json'),
37
+ type: 'boolean'
38
+ }, {
39
+ name: 'js',
40
+ description: 'Create a .percy.js file',
41
+ conflicts: FILETYPES.filter(t => t !== 'js'),
42
+ type: 'boolean'
43
+ }],
44
+ examples: ['$0', '$0 --yaml', '$0 --json', '$0 --js', '$0 --rc', '$0 ./config/percy.yml']
45
+ }, async ({
46
+ flags,
47
+ args,
48
+ log,
49
+ exit
50
+ }) => {
51
+ // discern the filetype
52
+ let filetype = args.filepath ? path.extname(args.filepath).replace(/^./, '') : FILETYPES.find(t => flags[t]) ?? 'yml'; // verify the filetype is supported
53
+
54
+ if (!DEFAULT_FILES[filetype]) {
55
+ exit(1, `Unsupported filetype: ${filetype}`);
56
+ } // default filepath based on filetype
57
+
58
+
59
+ let filepath = args.filepath || DEFAULT_FILES[filetype]; // verify the file does not already exist
60
+
61
+ if (fs.existsSync(filepath)) {
62
+ exit(1, `Percy config already exists: ${filepath}`);
63
+ } // write stringified default config options to the filepath
64
+
65
+
66
+ let format = ['rc', 'yaml', 'yml'].includes(filetype) ? 'yaml' : filetype;
67
+ fs.mkdirSync(path.dirname(filepath), {
68
+ recursive: true
69
+ });
70
+ fs.writeFileSync(filepath, PercyConfig.stringify(format));
71
+ log.info(`Created Percy config: ${filepath}`);
72
+ });
73
+ export default create;
package/dist/index.js CHANGED
@@ -1,8 +1,4 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _default = {};
8
- exports.default = _default;
1
+ export { default, config } from './config.js';
2
+ export { create } from './create.js';
3
+ export { validate } from './validate.js';
4
+ export { migrate } from './migrate.js';
@@ -0,0 +1,81 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import command, { PercyConfig } from '@percy/cli-command';
4
+ export const migrate = command('migrate', {
5
+ description: 'Migrate a Percy config file to the latest version',
6
+ args: [{
7
+ name: 'filepath',
8
+ description: 'Current config filepath, detected by default'
9
+ }, {
10
+ name: 'output',
11
+ description: 'New config filepath to write to, defaults to \'filepath\''
12
+ }],
13
+ flags: [{
14
+ name: 'dry-run',
15
+ description: 'Print the new config without writing it',
16
+ short: 'd'
17
+ }],
18
+ examples: ['$0', '$0 --dry-run', '$0 ./config/percy.yml', '$0 .percy.yml .percy.js']
19
+ }, async ({
20
+ args,
21
+ flags,
22
+ log,
23
+ exit
24
+ }) => {
25
+ let {
26
+ config,
27
+ filepath: input
28
+ } = PercyConfig.search(args.filepath);
29
+ let output = args.output ? path.resolve(args.output) : input;
30
+ if (!config) exit(1, 'Config file not found');
31
+ log.info(`Found config file: ${path.relative('', input)}`); // if migrating versions, warn when latest
32
+
33
+ if (input === output && config.version === 2) {
34
+ exit(0, 'Config is already the latest version');
35
+ } // migrate config
36
+
37
+
38
+ log.info('Migrating config file...');
39
+ let format = path.extname(output).replace(/^./, '') || 'yaml';
40
+ let migrated = PercyConfig.migrate(config); // prefer kebab-case for yaml
41
+
42
+ if (/^ya?ml$/.test(format)) {
43
+ migrated = PercyConfig.normalize(migrated, {
44
+ schema: '/config',
45
+ kebab: true
46
+ });
47
+ } // stringify to the desired format
48
+
49
+
50
+ let body = PercyConfig.stringify(format, migrated);
51
+
52
+ if (!flags.dryRun) {
53
+ let content = body;
54
+
55
+ if (path.basename(output) === 'package.json') {
56
+ // update the package.json entry by reading and modifying it
57
+ let pkg = JSON.parse(fs.readFileSync(output));
58
+ content = PercyConfig.stringify(format, { ...pkg,
59
+ percy: migrated
60
+ });
61
+ } else if (input === output) {
62
+ // rename input if it is the output
63
+ let {
64
+ dir,
65
+ name,
66
+ ext
67
+ } = path.parse(input);
68
+ fs.renameSync(input, path.join(dir, `${name}.old${ext}`));
69
+ } // write to output
70
+
71
+
72
+ fs.writeFileSync(output, content);
73
+ }
74
+
75
+ log.info('Config file migrated!'); // when dry-running, print config to stdout when finished
76
+
77
+ if (flags.dryRun) {
78
+ log.stdout.write('\n' + body);
79
+ }
80
+ });
81
+ export default migrate;
@@ -0,0 +1,29 @@
1
+ import command, { PercyConfig } from '@percy/cli-command';
2
+ export const validate = command('validate', {
3
+ description: 'Validate a Percy config file',
4
+ args: [{
5
+ name: 'filepath',
6
+ description: 'Config filepath, detected by default'
7
+ }],
8
+ examples: ['$0', '$0 ./config/percy.yml']
9
+ }, async ({
10
+ args,
11
+ log,
12
+ exit
13
+ }) => {
14
+ // verify a config file can be located
15
+ let {
16
+ config,
17
+ filepath
18
+ } = PercyConfig.search(args.filepath);
19
+ if (!config) exit(1, 'Config file not found'); // when `bail` is true, .load() returns undefined when validation fails
20
+
21
+ let result = PercyConfig.load({
22
+ path: filepath,
23
+ print: true,
24
+ bail: true
25
+ }); // exit 1 when config is empty
26
+
27
+ if (!result) exit(1);
28
+ });
29
+ export default validate;
package/package.json CHANGED
@@ -1,41 +1,38 @@
1
1
  {
2
2
  "name": "@percy/cli-config",
3
- "version": "1.0.0-beta.9",
3
+ "version": "1.0.2",
4
4
  "license": "MIT",
5
- "main": "dist/index.js",
6
- "files": [
7
- "dist",
8
- "oclif.manifest.json"
9
- ],
10
- "scripts": {
11
- "build": "babel --root-mode upward src --out-dir dist",
12
- "lint": "eslint --ignore-path ../../.gitignore .",
13
- "postbuild": "oclif-dev manifest",
14
- "readme": "oclif-dev readme",
15
- "test": "cross-env NODE_ENV=test mocha",
16
- "test:coverage": "nyc yarn test"
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/percy/cli",
8
+ "directory": "packages/cli-config"
17
9
  },
18
10
  "publishConfig": {
19
11
  "access": "public"
20
12
  },
21
- "mocha": {
22
- "require": "../../scripts/babel-register"
13
+ "engines": {
14
+ "node": ">=14"
15
+ },
16
+ "files": [
17
+ "dist"
18
+ ],
19
+ "main": "./dist/index.js",
20
+ "type": "module",
21
+ "exports": "./dist/index.js",
22
+ "scripts": {
23
+ "build": "node ../../scripts/build",
24
+ "lint": "eslint --ignore-path ../../.gitignore .",
25
+ "readme": "percy-cli-readme",
26
+ "test": "node ../../scripts/test",
27
+ "test:coverage": "yarn test --coverage"
23
28
  },
24
- "oclif": {
25
- "bin": "percy",
26
- "commands": "./dist/commands",
27
- "topics": {
28
- "config": {
29
- "description": "manage Percy config files"
30
- }
31
- }
29
+ "@percy/cli": {
30
+ "commands": [
31
+ "./dist/config.js"
32
+ ]
32
33
  },
33
34
  "dependencies": {
34
- "@oclif/command": "^1.5.19",
35
- "@oclif/config": "^1.14.0",
36
- "@percy/config": "^1.0.0-beta.9",
37
- "@percy/logger": "^1.0.0-beta.9",
38
- "path-type": "^4.0.0"
35
+ "@percy/cli-command": "1.0.2"
39
36
  },
40
- "gitHead": "57a2eeb90c7f5cdf8827c78be1e5c12df581f4b5"
37
+ "gitHead": "7288764b8088e444e853d5d78756959e46516dc7"
41
38
  }
@@ -1,105 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.Create = void 0;
7
-
8
- var _fs = _interopRequireDefault(require("fs"));
9
-
10
- var _path = _interopRequireDefault(require("path"));
11
-
12
- var _command = _interopRequireWildcard(require("@oclif/command"));
13
-
14
- var _config = _interopRequireDefault(require("@percy/config"));
15
-
16
- var _logger = _interopRequireDefault(require("@percy/logger"));
17
-
18
- function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
19
-
20
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
21
-
22
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
-
24
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
25
-
26
- const FILETYPES = ['rc', 'yaml', 'yml', 'json', 'js'];
27
-
28
- class Create extends _command.default {
29
- async run() {
30
- var _FILETYPES$find;
31
-
32
- let {
33
- flags,
34
- args
35
- } = this.parse();
36
-
37
- _logger.default.loglevel('info'); // discern the filetype
38
-
39
-
40
- let filetype = args.filepath ? _path.default.extname(args.filepath).replace(/^./, '') : (_FILETYPES$find = FILETYPES.find(t => flags[t])) !== null && _FILETYPES$find !== void 0 ? _FILETYPES$find : 'yml'; // validate the filetype for filepaths
41
-
42
- if (!FILETYPES.includes(filetype)) {
43
- _logger.default.error(`Unsupported filetype: ${filetype}`);
44
-
45
- return this.exit(1);
46
- } // discern the appropriate filename
47
-
48
-
49
- let filepath = args.filepath || {
50
- rc: '.percyrc',
51
- yaml: '.percy.yaml',
52
- yml: '.percy.yml',
53
- json: '.percy.json',
54
- js: '.percy.js'
55
- }[filetype]; // validate the file does not already exist
56
-
57
- if (_fs.default.existsSync(filepath)) {
58
- _logger.default.error(`Percy config already exists: ${filepath}`);
59
-
60
- return this.exit(1);
61
- } // discern the file format
62
-
63
-
64
- let format = ['rc', 'yaml', 'yml'].includes(filetype) ? 'yaml' : filetype; // write stringified default config options to the filepath
65
-
66
- _fs.default.writeFileSync(filepath, _config.default.stringify(format));
67
-
68
- _logger.default.info(`Created Percy config: ${filepath}`);
69
- }
70
-
71
- }
72
-
73
- exports.Create = Create;
74
-
75
- _defineProperty(Create, "description", 'Create a Percy config file');
76
-
77
- _defineProperty(Create, "flags", {
78
- rc: _command.flags.boolean({
79
- description: 'create a .percyrc file',
80
- exclusive: FILETYPES.filter(t => t !== 'rc')
81
- }),
82
- yaml: _command.flags.boolean({
83
- description: 'create a .percy.yaml file',
84
- exclusive: FILETYPES.filter(t => t !== 'yaml')
85
- }),
86
- yml: _command.flags.boolean({
87
- description: 'create a .percy.yml file',
88
- exclusive: FILETYPES.filter(t => t !== 'yml')
89
- }),
90
- json: _command.flags.boolean({
91
- description: 'create a .percy.json file',
92
- exclusive: FILETYPES.filter(t => t !== 'json')
93
- }),
94
- js: _command.flags.boolean({
95
- description: 'create a .percy.js file',
96
- exclusive: FILETYPES.filter(t => t !== 'js')
97
- })
98
- });
99
-
100
- _defineProperty(Create, "args", [{
101
- name: 'filepath',
102
- description: 'config filepath'
103
- }]);
104
-
105
- _defineProperty(Create, "examples", ['$ percy config:create', '$ percy config:create --yaml', '$ percy config:create --json', '$ percy config:create --js', '$ percy config:create --rc', '$ percy config:create ./config/percy.yml']);
@@ -1,174 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.Migrate = void 0;
7
-
8
- var _fs = _interopRequireDefault(require("fs"));
9
-
10
- var _path = _interopRequireDefault(require("path"));
11
-
12
- var _pathType = require("path-type");
13
-
14
- var _command = _interopRequireWildcard(require("@oclif/command"));
15
-
16
- var _config = _interopRequireDefault(require("@percy/config"));
17
-
18
- var _logger = _interopRequireDefault(require("@percy/logger"));
19
-
20
- function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
21
-
22
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
23
-
24
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
25
-
26
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
27
-
28
- function assignOrCreate(obj, key, value) {
29
- return Object.assign(obj || {}, {
30
- [key]: value
31
- });
32
- }
33
-
34
- class Migrate extends _command.default {
35
- async run() {
36
- let config;
37
- let {
38
- args: {
39
- filepath: input,
40
- output
41
- },
42
- flags: {
43
- 'dry-run': dry
44
- }
45
- } = this.parse();
46
-
47
- _logger.default.loglevel('info'); // load config using the explorer directly rather than the load method to
48
- // better control logs and prevent validation
49
-
50
-
51
- try {
52
- let result = !input || (0, _pathType.isDirectorySync)(input) ? _config.default.explorer.search(input) : _config.default.explorer.load(input);
53
-
54
- if (result && result.config) {
55
- ({
56
- config,
57
- filepath: input
58
- } = result);
59
-
60
- _logger.default.info(`Found config file: ${_path.default.relative('', input)}`);
61
-
62
- output = output ? _path.default.resolve(output) : input;
63
- } else {
64
- _logger.default.error('Config file not found');
65
- }
66
- } catch (error) {
67
- _logger.default.error('Failed to load or parse config file');
68
-
69
- _logger.default.error(error);
70
- } // no config, bail
71
-
72
-
73
- if (!config) return this.exit(1); // if migrating versions, warn when latest
74
-
75
- if (input === output && config.version === 2) {
76
- _logger.default.warn('Config is already the latest version');
77
-
78
- return;
79
- } // migrate config
80
-
81
-
82
- _logger.default.info('Migrating config file...');
83
-
84
- let format = _path.default.extname(output).replace(/^./, '') || 'yaml';
85
- config = _config.default.stringify(format, this.migrate(config)); // update the package.json entry via string replacement
86
-
87
- if (!dry && _path.default.basename(output) === 'package.json') {
88
- _fs.default.writeFileSync(output, _fs.default.readFileSync(output).replace(/(\s+)("percy":\s*){.*\1}/s, `$1$2${config.replace(/\n/g, '$$1')}`)); // write to output
89
-
90
- } else if (!dry) {
91
- // rename input if it is the output
92
- if (input === output) {
93
- let ext = _path.default.extname(input);
94
-
95
- let old = input.replace(ext, `.old${ext}`);
96
-
97
- _fs.default.renameSync(input, old);
98
- }
99
-
100
- _fs.default.writeFileSync(output, config);
101
- }
102
-
103
- _logger.default.info('Config file migrated!'); // when dry-running, print config to stdout when finished
104
-
105
-
106
- if (dry) process.stdout.write('\n' + config);
107
- } // Migrating config options is recursive so no matter which input version is
108
- // provided, the output will be the latest version.
109
-
110
-
111
- migrate(input) {
112
- switch (input.version) {
113
- case 2:
114
- return input;
115
- // latest version
116
-
117
- default:
118
- return this.migrate(this.v1(input));
119
- }
120
- } // Migrate config from v1 to v2.
121
-
122
- /* eslint-disable curly */
123
-
124
-
125
- v1(input) {
126
- var _input$agent, _input$agent$assetDi, _input$agent2, _input$agent2$assetD, _input$agent3, _input$agent3$assetD, _input$agent4, _input$agent4$assetD, _input$agent5, _input$agent5$assetD, _output$upload, _input$staticSnapsho, _input$staticSnapsho2, _input$staticSnapsho3;
127
-
128
- let output = {
129
- version: 2
130
- }; // previous snapshot options map 1:1
131
-
132
- if (input.snapshot != null) output.snapshot = input.snapshot; // request-headers option moved
133
-
134
- if (((_input$agent = input.agent) === null || _input$agent === void 0 ? void 0 : (_input$agent$assetDi = _input$agent['asset-discovery']) === null || _input$agent$assetDi === void 0 ? void 0 : _input$agent$assetDi['request-headers']) != null) output.snapshot = assignOrCreate(output.snapshot, 'request-headers', input.agent['asset-discovery']['request-headers']); // only create discovery options when neccessary
135
-
136
- if (((_input$agent2 = input.agent) === null || _input$agent2 === void 0 ? void 0 : (_input$agent2$assetD = _input$agent2['asset-discovery']) === null || _input$agent2$assetD === void 0 ? void 0 : _input$agent2$assetD['allowed-hostnames']) != null) output.discovery = assignOrCreate(output.discovery, 'allowed-hostnames', input.agent['asset-discovery']['allowed-hostnames']);
137
- if (((_input$agent3 = input.agent) === null || _input$agent3 === void 0 ? void 0 : (_input$agent3$assetD = _input$agent3['asset-discovery']) === null || _input$agent3$assetD === void 0 ? void 0 : _input$agent3$assetD['network-idle-timeout']) != null) output.discovery = assignOrCreate(output.discovery, 'network-idle-timeout', input.agent['asset-discovery']['network-idle-timeout']); // page pooling was rewritten to be a concurrent task queue
138
-
139
- if (((_input$agent4 = input.agent) === null || _input$agent4 === void 0 ? void 0 : (_input$agent4$assetD = _input$agent4['asset-discovery']) === null || _input$agent4$assetD === void 0 ? void 0 : _input$agent4$assetD['page-pool-size-max']) != null) output.discovery = assignOrCreate(output.discovery, 'concurrency', input.agent['asset-discovery']['page-pool-size-max']); // cache-responses was renamed to match the CLI flag
140
-
141
- if (((_input$agent5 = input.agent) === null || _input$agent5 === void 0 ? void 0 : (_input$agent5$assetD = _input$agent5['asset-discovery']) === null || _input$agent5$assetD === void 0 ? void 0 : _input$agent5$assetD['cache-responses']) != null) output.discovery = assignOrCreate(output.discovery, 'disable-asset-cache', !input.agent['asset-discovery']['cache-responses']); // image-snapshots was renamed
142
-
143
- if (input['image-snapshots'] != null) output.upload = input['image-snapshots']; // image-snapshots path was removed
144
-
145
- if (((_output$upload = output.upload) === null || _output$upload === void 0 ? void 0 : _output$upload.path) != null) delete output.upload.path; // static-snapshots and options were renamed
146
-
147
- if (((_input$staticSnapsho = input['static-snapshots']) === null || _input$staticSnapsho === void 0 ? void 0 : _input$staticSnapsho['base-url']) != null) output.static = assignOrCreate(output.static, 'base-url', input['static-snapshots']['base-url']);
148
- if (((_input$staticSnapsho2 = input['static-snapshots']) === null || _input$staticSnapsho2 === void 0 ? void 0 : _input$staticSnapsho2['snapshot-files']) != null) output.static = assignOrCreate(output.static, 'files', input['static-snapshots']['snapshot-files']);
149
- if (((_input$staticSnapsho3 = input['static-snapshots']) === null || _input$staticSnapsho3 === void 0 ? void 0 : _input$staticSnapsho3['ignore-files']) != null) output.static = assignOrCreate(output.static, 'ignore', input['static-snapshots']['ignore-files']);
150
- return output;
151
- }
152
-
153
- }
154
-
155
- exports.Migrate = Migrate;
156
-
157
- _defineProperty(Migrate, "description", 'Migrate a Percy config file to the latest version');
158
-
159
- _defineProperty(Migrate, "args", [{
160
- name: 'filepath',
161
- description: 'current config filepath, detected by default'
162
- }, {
163
- name: 'output',
164
- description: 'new config filepath to write to, defaults to FILEPATH'
165
- }]);
166
-
167
- _defineProperty(Migrate, "flags", {
168
- 'dry-run': _command.flags.boolean({
169
- char: 'd',
170
- description: 'prints the new config rather than writing it'
171
- })
172
- });
173
-
174
- _defineProperty(Migrate, "examples", ['$ percy config:migrate', '$ percy config:migrate --dry-run', '$ percy config:migrate ./config/percy.yml', '$ percy config:migrate .percy.yml .percy.js']);
@@ -1,48 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.Validate = void 0;
7
-
8
- var _command = _interopRequireDefault(require("@oclif/command"));
9
-
10
- var _config = _interopRequireDefault(require("@percy/config"));
11
-
12
- var _logger = _interopRequireDefault(require("@percy/logger"));
13
-
14
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
-
16
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
17
-
18
- class Validate extends _command.default {
19
- async run() {
20
- let {
21
- args: {
22
- filepath: path
23
- }
24
- } = this.parse();
25
-
26
- _logger.default.loglevel('debug'); // when `bail` is true, #load() returns undefined on validation warnings
27
-
28
-
29
- if (!_config.default.load({
30
- path,
31
- bail: true
32
- })) {
33
- this.exit(1);
34
- }
35
- }
36
-
37
- }
38
-
39
- exports.Validate = Validate;
40
-
41
- _defineProperty(Validate, "description", 'Validate a Percy config file');
42
-
43
- _defineProperty(Validate, "args", [{
44
- name: 'filepath',
45
- description: 'config filepath, detected by default'
46
- }]);
47
-
48
- _defineProperty(Validate, "examples", ['$ percy config:validate', '$ percy config:validate ./config/percy.yml']);
@@ -1 +0,0 @@
1
- {"version":"1.0.0-beta.9","commands":{"config:create":{"id":"config:create","description":"Create a Percy config file","pluginName":"@percy/cli-config","pluginType":"core","aliases":[],"examples":["$ percy config:create","$ percy config:create --yaml","$ percy config:create --json","$ percy config:create --js","$ percy config:create --rc","$ percy config:create ./config/percy.yml"],"flags":{"rc":{"name":"rc","type":"boolean","description":"create a .percyrc file","allowNo":false},"yaml":{"name":"yaml","type":"boolean","description":"create a .percy.yaml file","allowNo":false},"yml":{"name":"yml","type":"boolean","description":"create a .percy.yml file","allowNo":false},"json":{"name":"json","type":"boolean","description":"create a .percy.json file","allowNo":false},"js":{"name":"js","type":"boolean","description":"create a .percy.js file","allowNo":false}},"args":[{"name":"filepath","description":"config filepath"}]},"config:migrate":{"id":"config:migrate","description":"Migrate a Percy config file to the latest version","pluginName":"@percy/cli-config","pluginType":"core","aliases":[],"examples":["$ percy config:migrate","$ percy config:migrate --dry-run","$ percy config:migrate ./config/percy.yml","$ percy config:migrate .percy.yml .percy.js"],"flags":{"dry-run":{"name":"dry-run","type":"boolean","char":"d","description":"prints the new config rather than writing it","allowNo":false}},"args":[{"name":"filepath","description":"current config filepath, detected by default"},{"name":"output","description":"new config filepath to write to, defaults to FILEPATH"}]},"config:validate":{"id":"config:validate","description":"Validate a Percy config file","pluginName":"@percy/cli-config","pluginType":"core","aliases":[],"examples":["$ percy config:validate","$ percy config:validate ./config/percy.yml"],"flags":{},"args":[{"name":"filepath","description":"config filepath, detected by default"}]}}}