@percy/cli-config 1.0.0-beta.69 → 1.0.0-beta.72
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 +59 -41
- package/dist/config.js +24 -0
- package/dist/create.js +93 -0
- package/dist/index.js +42 -14
- package/dist/migrate.js +97 -0
- package/dist/validate.js +46 -0
- package/package.json +18 -26
- package/dist/commands/config/create.js +0 -109
- package/dist/commands/config/migrate.js +0 -130
- package/dist/commands/config/validate.js +0 -52
- package/oclif.manifest.json +0 -1
package/README.md
CHANGED
|
@@ -5,29 +5,35 @@ Percy configuration files.
|
|
|
5
5
|
|
|
6
6
|
## Commands
|
|
7
7
|
<!-- commands -->
|
|
8
|
-
* [`percy config:create
|
|
9
|
-
* [`percy config:
|
|
10
|
-
* [`percy config:
|
|
8
|
+
* [`percy config:create`](#percy-configcreate)
|
|
9
|
+
* [`percy config:validate`](#percy-configvalidate)
|
|
10
|
+
* [`percy config:migrate`](#percy-configmigrate)
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
### `percy config:create`
|
|
13
13
|
|
|
14
14
|
Create a Percy config file
|
|
15
15
|
|
|
16
16
|
```
|
|
17
|
-
|
|
18
|
-
$ percy config:create [
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
--
|
|
25
|
-
--
|
|
26
|
-
--
|
|
27
|
-
--
|
|
28
|
-
--
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
|
|
45
|
+
### `percy config:validate`
|
|
40
46
|
|
|
41
|
-
|
|
47
|
+
Validate a Percy config file
|
|
42
48
|
|
|
43
49
|
```
|
|
44
|
-
|
|
45
|
-
$ percy config:
|
|
50
|
+
Usage:
|
|
51
|
+
$ percy config:validate [options] [filepath]
|
|
46
52
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
OUTPUT new config filepath to write to, defaults to FILEPATH
|
|
53
|
+
Arguments:
|
|
54
|
+
filepath Config filepath, detected by default
|
|
50
55
|
|
|
51
|
-
|
|
52
|
-
-
|
|
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
|
-
|
|
55
|
-
$ percy config:
|
|
56
|
-
$ percy config:
|
|
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
|
-
|
|
67
|
+
### `percy config:migrate`
|
|
62
68
|
|
|
63
|
-
|
|
69
|
+
Migrate a Percy config file to the latest version
|
|
64
70
|
|
|
65
71
|
```
|
|
66
|
-
|
|
67
|
-
$ percy config:
|
|
72
|
+
Usage:
|
|
73
|
+
$ percy config:migrate [options] [filepath] [output]
|
|
68
74
|
|
|
69
|
-
|
|
70
|
-
|
|
75
|
+
Arguments:
|
|
76
|
+
filepath Current config filepath, detected by default
|
|
77
|
+
output New config filepath to write to, defaults to 'filepath'
|
|
71
78
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = exports.config = void 0;
|
|
7
|
+
|
|
8
|
+
var _cliCommand = _interopRequireDefault(require("@percy/cli-command"));
|
|
9
|
+
|
|
10
|
+
var _create = _interopRequireDefault(require("./create"));
|
|
11
|
+
|
|
12
|
+
var _validate = _interopRequireDefault(require("./validate"));
|
|
13
|
+
|
|
14
|
+
var _migrate = _interopRequireDefault(require("./migrate"));
|
|
15
|
+
|
|
16
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
+
|
|
18
|
+
const config = (0, _cliCommand.default)('config', {
|
|
19
|
+
description: 'Manage Percy config files',
|
|
20
|
+
commands: [_create.default, _validate.default, _migrate.default]
|
|
21
|
+
});
|
|
22
|
+
exports.config = config;
|
|
23
|
+
var _default = config;
|
|
24
|
+
exports.default = _default;
|
package/dist/create.js
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = exports.create = void 0;
|
|
7
|
+
|
|
8
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
9
|
+
|
|
10
|
+
var _path = _interopRequireDefault(require("path"));
|
|
11
|
+
|
|
12
|
+
var _cliCommand = _interopRequireDefault(require("@percy/cli-command"));
|
|
13
|
+
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
+
|
|
16
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
17
|
+
|
|
18
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && 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; }
|
|
19
|
+
|
|
20
|
+
const DEFAULT_FILES = {
|
|
21
|
+
rc: '.percyrc',
|
|
22
|
+
yaml: '.percy.yaml',
|
|
23
|
+
yml: '.percy.yml',
|
|
24
|
+
json: '.percy.json',
|
|
25
|
+
js: '.percy.js'
|
|
26
|
+
};
|
|
27
|
+
const FILETYPES = Object.keys(DEFAULT_FILES);
|
|
28
|
+
const create = (0, _cliCommand.default)('create', {
|
|
29
|
+
description: 'Create a Percy config file',
|
|
30
|
+
args: [{
|
|
31
|
+
name: 'filepath',
|
|
32
|
+
description: 'Optional config filepath'
|
|
33
|
+
}],
|
|
34
|
+
flags: [{
|
|
35
|
+
name: 'rc',
|
|
36
|
+
description: 'Create a .percyrc file',
|
|
37
|
+
conflicts: FILETYPES.filter(t => t !== 'rc'),
|
|
38
|
+
type: 'boolean'
|
|
39
|
+
}, {
|
|
40
|
+
name: 'yaml',
|
|
41
|
+
description: 'Create a .percy.yaml file',
|
|
42
|
+
conflicts: FILETYPES.filter(t => t !== 'yaml'),
|
|
43
|
+
type: 'boolean'
|
|
44
|
+
}, {
|
|
45
|
+
name: 'yml',
|
|
46
|
+
description: 'Create a .percy.yml file',
|
|
47
|
+
conflicts: FILETYPES.filter(t => t !== 'yml'),
|
|
48
|
+
type: 'boolean'
|
|
49
|
+
}, {
|
|
50
|
+
name: 'json',
|
|
51
|
+
description: 'Create a .percy.json file',
|
|
52
|
+
conflicts: FILETYPES.filter(t => t !== 'json'),
|
|
53
|
+
type: 'boolean'
|
|
54
|
+
}, {
|
|
55
|
+
name: 'js',
|
|
56
|
+
description: 'Create a .percy.js file',
|
|
57
|
+
conflicts: FILETYPES.filter(t => t !== 'js'),
|
|
58
|
+
type: 'boolean'
|
|
59
|
+
}],
|
|
60
|
+
examples: ['$0', '$0 --yaml', '$0 --json', '$0 --js', '$0 --rc', '$0 ./config/percy.yml']
|
|
61
|
+
}, async ({
|
|
62
|
+
flags,
|
|
63
|
+
args,
|
|
64
|
+
log,
|
|
65
|
+
exit
|
|
66
|
+
}) => {
|
|
67
|
+
var _FILETYPES$find;
|
|
68
|
+
|
|
69
|
+
let PercyConfig = await Promise.resolve().then(() => _interopRequireWildcard(require('@percy/config'))); // discern the filetype
|
|
70
|
+
|
|
71
|
+
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'; // verify the filetype is supported
|
|
72
|
+
|
|
73
|
+
if (!DEFAULT_FILES[filetype]) {
|
|
74
|
+
exit(1, `Unsupported filetype: ${filetype}`);
|
|
75
|
+
} // default filepath based on filetype
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
let filepath = args.filepath || DEFAULT_FILES[filetype]; // verify the file does not already exist
|
|
79
|
+
|
|
80
|
+
if (_fs.default.existsSync(filepath)) {
|
|
81
|
+
exit(1, `Percy config already exists: ${filepath}`);
|
|
82
|
+
} // write stringified default config options to the filepath
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
let format = ['rc', 'yaml', 'yml'].includes(filetype) ? 'yaml' : filetype;
|
|
86
|
+
|
|
87
|
+
_fs.default.writeFileSync(filepath, PercyConfig.stringify(format));
|
|
88
|
+
|
|
89
|
+
log.info(`Created Percy config: ${filepath}`);
|
|
90
|
+
});
|
|
91
|
+
exports.create = create;
|
|
92
|
+
var _default = create;
|
|
93
|
+
exports.default = _default;
|
package/dist/index.js
CHANGED
|
@@ -1,19 +1,47 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "config", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _config.config;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "create", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _create.create;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "default", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _config.default;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "migrate", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return _migrate.migrate;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
Object.defineProperty(exports, "validate", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () {
|
|
33
|
+
return _validate.validate;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
6
36
|
|
|
7
|
-
|
|
8
|
-
Migrate
|
|
9
|
-
} = require('./commands/config/migrate');
|
|
37
|
+
var _config = _interopRequireWildcard(require("./config"));
|
|
10
38
|
|
|
11
|
-
|
|
12
|
-
Validate
|
|
13
|
-
} = require('./commands/config/validate');
|
|
39
|
+
var _create = require("./create");
|
|
14
40
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
};
|
|
41
|
+
var _validate = require("./validate");
|
|
42
|
+
|
|
43
|
+
var _migrate = require("./migrate");
|
|
44
|
+
|
|
45
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
46
|
+
|
|
47
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && 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; }
|
package/dist/migrate.js
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.migrate = exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
9
|
+
|
|
10
|
+
var _path = _interopRequireDefault(require("path"));
|
|
11
|
+
|
|
12
|
+
var _cliCommand = _interopRequireDefault(require("@percy/cli-command"));
|
|
13
|
+
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
+
|
|
16
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
17
|
+
|
|
18
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && 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; }
|
|
19
|
+
|
|
20
|
+
const migrate = (0, _cliCommand.default)('migrate', {
|
|
21
|
+
description: 'Migrate a Percy config file to the latest version',
|
|
22
|
+
args: [{
|
|
23
|
+
name: 'filepath',
|
|
24
|
+
description: 'Current config filepath, detected by default'
|
|
25
|
+
}, {
|
|
26
|
+
name: 'output',
|
|
27
|
+
description: 'New config filepath to write to, defaults to \'filepath\''
|
|
28
|
+
}],
|
|
29
|
+
flags: [{
|
|
30
|
+
name: 'dry-run',
|
|
31
|
+
description: 'Print the new config without writing it',
|
|
32
|
+
short: 'd'
|
|
33
|
+
}],
|
|
34
|
+
examples: ['$0', '$0 --dry-run', '$0 ./config/percy.yml', '$0 .percy.yml .percy.js']
|
|
35
|
+
}, async ({
|
|
36
|
+
args,
|
|
37
|
+
flags,
|
|
38
|
+
log,
|
|
39
|
+
exit
|
|
40
|
+
}) => {
|
|
41
|
+
let PercyConfig = await Promise.resolve().then(() => _interopRequireWildcard(require('@percy/config')));
|
|
42
|
+
let {
|
|
43
|
+
config,
|
|
44
|
+
filepath: input
|
|
45
|
+
} = PercyConfig.search(args.filepath);
|
|
46
|
+
let output = args.output ? _path.default.resolve(args.output) : input;
|
|
47
|
+
if (!config) exit(1, 'Config file not found');
|
|
48
|
+
log.info(`Found config file: ${_path.default.relative('', input)}`); // if migrating versions, warn when latest
|
|
49
|
+
|
|
50
|
+
if (input === output && config.version === 2) {
|
|
51
|
+
exit(0, 'Config is already the latest version');
|
|
52
|
+
} // migrate config
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
log.info('Migrating config file...');
|
|
56
|
+
let format = _path.default.extname(output).replace(/^./, '') || 'yaml';
|
|
57
|
+
let migrated = PercyConfig.migrate(config); // prefer kebab-case for yaml
|
|
58
|
+
|
|
59
|
+
if (/^ya?ml$/.test(format)) {
|
|
60
|
+
migrated = PercyConfig.normalize(migrated, {
|
|
61
|
+
schema: '/config',
|
|
62
|
+
kebab: true
|
|
63
|
+
});
|
|
64
|
+
} // stringify to the desired format
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
let body = PercyConfig.stringify(format, migrated);
|
|
68
|
+
|
|
69
|
+
if (!flags.dryRun) {
|
|
70
|
+
let content = body;
|
|
71
|
+
|
|
72
|
+
if (_path.default.basename(output) === 'package.json') {
|
|
73
|
+
// update the package.json entry by reading and modifying it
|
|
74
|
+
let pkg = JSON.parse(_fs.default.readFileSync(output));
|
|
75
|
+
content = PercyConfig.stringify(format, { ...pkg,
|
|
76
|
+
percy: migrated
|
|
77
|
+
});
|
|
78
|
+
} else if (input === output) {
|
|
79
|
+
// rename input if it is the output
|
|
80
|
+
let old = input.replace(_path.default.extname(input), '.old$&');
|
|
81
|
+
|
|
82
|
+
_fs.default.renameSync(input, old);
|
|
83
|
+
} // write to output
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
_fs.default.writeFileSync(output, content);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
log.info('Config file migrated!'); // when dry-running, print config to stdout when finished
|
|
90
|
+
|
|
91
|
+
if (flags.dryRun) {
|
|
92
|
+
log.stdout.write('\n' + body);
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
exports.migrate = migrate;
|
|
96
|
+
var _default = migrate;
|
|
97
|
+
exports.default = _default;
|
package/dist/validate.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.validate = exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _cliCommand = _interopRequireDefault(require("@percy/cli-command"));
|
|
9
|
+
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
|
|
12
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
13
|
+
|
|
14
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && 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; }
|
|
15
|
+
|
|
16
|
+
const validate = (0, _cliCommand.default)('validate', {
|
|
17
|
+
description: 'Validate a Percy config file',
|
|
18
|
+
args: [{
|
|
19
|
+
name: 'filepath',
|
|
20
|
+
description: 'Config filepath, detected by default'
|
|
21
|
+
}],
|
|
22
|
+
examples: ['$0', '$0 ./config/percy.yml']
|
|
23
|
+
}, async ({
|
|
24
|
+
args,
|
|
25
|
+
log,
|
|
26
|
+
exit
|
|
27
|
+
}) => {
|
|
28
|
+
let PercyConfig = await Promise.resolve().then(() => _interopRequireWildcard(require('@percy/config'))); // verify a config file can be located
|
|
29
|
+
|
|
30
|
+
let {
|
|
31
|
+
config,
|
|
32
|
+
filepath
|
|
33
|
+
} = PercyConfig.search(args.filepath);
|
|
34
|
+
if (!config) exit(1, 'Config file not found'); // when `bail` is true, .load() returns undefined when validation fails
|
|
35
|
+
|
|
36
|
+
let result = PercyConfig.load({
|
|
37
|
+
path: filepath,
|
|
38
|
+
print: true,
|
|
39
|
+
bail: true
|
|
40
|
+
}); // exit 1 when config is empty
|
|
41
|
+
|
|
42
|
+
if (!result) exit(1);
|
|
43
|
+
});
|
|
44
|
+
exports.validate = validate;
|
|
45
|
+
var _default = validate;
|
|
46
|
+
exports.default = _default;
|
package/package.json
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@percy/cli-config",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.72",
|
|
4
4
|
"license": "MIT",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/percy/cli",
|
|
8
|
+
"directory": "packages/cli-config"
|
|
9
|
+
},
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"access": "public"
|
|
12
|
+
},
|
|
5
13
|
"main": "dist/index.js",
|
|
6
14
|
"files": [
|
|
7
|
-
"dist"
|
|
8
|
-
"oclif.manifest.json"
|
|
15
|
+
"dist"
|
|
9
16
|
],
|
|
10
17
|
"engines": {
|
|
11
18
|
"node": ">=12"
|
|
@@ -13,33 +20,18 @@
|
|
|
13
20
|
"scripts": {
|
|
14
21
|
"build": "node ../../scripts/build",
|
|
15
22
|
"lint": "eslint --ignore-path ../../.gitignore .",
|
|
16
|
-
"
|
|
17
|
-
"readme": "oclif-dev readme",
|
|
23
|
+
"readme": "percy-cli-readme",
|
|
18
24
|
"test": "node ../../scripts/test",
|
|
19
25
|
"test:coverage": "yarn test --coverage"
|
|
20
26
|
},
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
"bin": "percy",
|
|
26
|
-
"commands": "./dist/commands",
|
|
27
|
-
"topics": {
|
|
28
|
-
"config": {
|
|
29
|
-
"description": "manage Percy config files"
|
|
30
|
-
}
|
|
31
|
-
}
|
|
27
|
+
"@percy/cli": {
|
|
28
|
+
"commands": [
|
|
29
|
+
"./dist/config.js"
|
|
30
|
+
]
|
|
32
31
|
},
|
|
33
32
|
"dependencies": {
|
|
34
|
-
"@
|
|
35
|
-
"@
|
|
36
|
-
"@percy/config": "1.0.0-beta.69",
|
|
37
|
-
"@percy/logger": "1.0.0-beta.69"
|
|
38
|
-
},
|
|
39
|
-
"repository": {
|
|
40
|
-
"type": "git",
|
|
41
|
-
"url": "https://github.com/percy/cli",
|
|
42
|
-
"directory": "packages/cli-config"
|
|
33
|
+
"@percy/cli-command": "1.0.0-beta.72",
|
|
34
|
+
"@percy/config": "1.0.0-beta.72"
|
|
43
35
|
},
|
|
44
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "6219287e18a0cacb609d0c2696a5785abc9009b9"
|
|
45
37
|
}
|
|
@@ -1,109 +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(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
19
|
-
|
|
20
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && 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
|
-
constructor(...args) {
|
|
30
|
-
super(...args);
|
|
31
|
-
|
|
32
|
-
_defineProperty(this, "log", (0, _logger.default)('cli:config:create'));
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
async run() {
|
|
36
|
-
var _FILETYPES$find;
|
|
37
|
-
|
|
38
|
-
let {
|
|
39
|
-
flags,
|
|
40
|
-
args
|
|
41
|
-
} = this.parse();
|
|
42
|
-
|
|
43
|
-
_logger.default.loglevel('info'); // discern the filetype
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
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
|
|
47
|
-
|
|
48
|
-
if (!FILETYPES.includes(filetype)) {
|
|
49
|
-
this.log.error(`Unsupported filetype: ${filetype}`);
|
|
50
|
-
return this.exit(1);
|
|
51
|
-
} // discern the appropriate filename
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
let filepath = args.filepath || {
|
|
55
|
-
rc: '.percyrc',
|
|
56
|
-
yaml: '.percy.yaml',
|
|
57
|
-
yml: '.percy.yml',
|
|
58
|
-
json: '.percy.json',
|
|
59
|
-
js: '.percy.js'
|
|
60
|
-
}[filetype]; // validate the file does not already exist
|
|
61
|
-
|
|
62
|
-
if (_fs.default.existsSync(filepath)) {
|
|
63
|
-
this.log.error(`Percy config already exists: ${filepath}`);
|
|
64
|
-
return this.exit(1);
|
|
65
|
-
} // discern the file format
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
let format = ['rc', 'yaml', 'yml'].includes(filetype) ? 'yaml' : filetype; // write stringified default config options to the filepath
|
|
69
|
-
|
|
70
|
-
_fs.default.writeFileSync(filepath, _config.default.stringify(format));
|
|
71
|
-
|
|
72
|
-
this.log.info(`Created Percy config: ${filepath}`);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
exports.Create = Create;
|
|
78
|
-
|
|
79
|
-
_defineProperty(Create, "description", 'Create a Percy config file');
|
|
80
|
-
|
|
81
|
-
_defineProperty(Create, "flags", {
|
|
82
|
-
rc: _command.flags.boolean({
|
|
83
|
-
description: 'create a .percyrc file',
|
|
84
|
-
exclusive: FILETYPES.filter(t => t !== 'rc')
|
|
85
|
-
}),
|
|
86
|
-
yaml: _command.flags.boolean({
|
|
87
|
-
description: 'create a .percy.yaml file',
|
|
88
|
-
exclusive: FILETYPES.filter(t => t !== 'yaml')
|
|
89
|
-
}),
|
|
90
|
-
yml: _command.flags.boolean({
|
|
91
|
-
description: 'create a .percy.yml file',
|
|
92
|
-
exclusive: FILETYPES.filter(t => t !== 'yml')
|
|
93
|
-
}),
|
|
94
|
-
json: _command.flags.boolean({
|
|
95
|
-
description: 'create a .percy.json file',
|
|
96
|
-
exclusive: FILETYPES.filter(t => t !== 'json')
|
|
97
|
-
}),
|
|
98
|
-
js: _command.flags.boolean({
|
|
99
|
-
description: 'create a .percy.js file',
|
|
100
|
-
exclusive: FILETYPES.filter(t => t !== 'js')
|
|
101
|
-
})
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
_defineProperty(Create, "args", [{
|
|
105
|
-
name: 'filepath',
|
|
106
|
-
description: 'config filepath'
|
|
107
|
-
}]);
|
|
108
|
-
|
|
109
|
-
_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,130 +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 _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(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
19
|
-
|
|
20
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && 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
|
-
class Migrate extends _command.default {
|
|
27
|
-
constructor(...args) {
|
|
28
|
-
super(...args);
|
|
29
|
-
|
|
30
|
-
_defineProperty(this, "log", (0, _logger.default)('cli:config:migrate'));
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
async run() {
|
|
34
|
-
let config;
|
|
35
|
-
let {
|
|
36
|
-
args: {
|
|
37
|
-
filepath: input,
|
|
38
|
-
output
|
|
39
|
-
},
|
|
40
|
-
flags: {
|
|
41
|
-
'dry-run': dry
|
|
42
|
-
}
|
|
43
|
-
} = this.parse();
|
|
44
|
-
|
|
45
|
-
try {
|
|
46
|
-
({
|
|
47
|
-
config,
|
|
48
|
-
filepath: input
|
|
49
|
-
} = _config.default.search(input));
|
|
50
|
-
} catch (error) {
|
|
51
|
-
this.log.error(error);
|
|
52
|
-
this.exit(1);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (config) {
|
|
56
|
-
this.log.info(`Found config file: ${_path.default.relative('', input)}`);
|
|
57
|
-
output = output ? _path.default.resolve(output) : input;
|
|
58
|
-
} else {
|
|
59
|
-
this.log.error('Config file not found');
|
|
60
|
-
this.exit(1);
|
|
61
|
-
} // if migrating versions, warn when latest
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
if (input === output && config.version === 2) {
|
|
65
|
-
this.log.warn('Config is already the latest version');
|
|
66
|
-
return;
|
|
67
|
-
} // migrate config
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
this.log.info('Migrating config file...');
|
|
71
|
-
let format = _path.default.extname(output).replace(/^./, '') || 'yaml';
|
|
72
|
-
|
|
73
|
-
let migrated = _config.default.migrate(config); // prefer kebab-case for yaml
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
if (/^ya?ml$/.test(format)) {
|
|
77
|
-
migrated = _config.default.normalize(migrated, {
|
|
78
|
-
schema: '/config',
|
|
79
|
-
kebab: true
|
|
80
|
-
});
|
|
81
|
-
} // stringify to the desired format
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
let body = _config.default.stringify(format, migrated);
|
|
85
|
-
|
|
86
|
-
if (!dry) {
|
|
87
|
-
let content = body; // update the package.json entry by requiring it and modifying it
|
|
88
|
-
|
|
89
|
-
if (_path.default.basename(output) === 'package.json') {
|
|
90
|
-
let pkg = JSON.parse(_fs.default.readFileSync(output));
|
|
91
|
-
content = _config.default.stringify(format, { ...pkg,
|
|
92
|
-
percy: migrated
|
|
93
|
-
}); // rename input if it is the output
|
|
94
|
-
} else if (input === output) {
|
|
95
|
-
let old = input.replace(_path.default.extname(input), '.old$&');
|
|
96
|
-
|
|
97
|
-
_fs.default.renameSync(input, old);
|
|
98
|
-
} // write to output
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
_fs.default.writeFileSync(output, content);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
this.log.info('Config file migrated!'); // when dry-running, print config to stdout when finished
|
|
105
|
-
|
|
106
|
-
if (dry) _logger.default.stdout.write('\n' + body);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
exports.Migrate = Migrate;
|
|
112
|
-
|
|
113
|
-
_defineProperty(Migrate, "description", 'Migrate a Percy config file to the latest version');
|
|
114
|
-
|
|
115
|
-
_defineProperty(Migrate, "args", [{
|
|
116
|
-
name: 'filepath',
|
|
117
|
-
description: 'current config filepath, detected by default'
|
|
118
|
-
}, {
|
|
119
|
-
name: 'output',
|
|
120
|
-
description: 'new config filepath to write to, defaults to FILEPATH'
|
|
121
|
-
}]);
|
|
122
|
-
|
|
123
|
-
_defineProperty(Migrate, "flags", {
|
|
124
|
-
'dry-run': _command.flags.boolean({
|
|
125
|
-
char: 'd',
|
|
126
|
-
description: 'prints the new config rather than writing it'
|
|
127
|
-
})
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
_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,52 +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
|
-
constructor(...args) {
|
|
20
|
-
super(...args);
|
|
21
|
-
|
|
22
|
-
_defineProperty(this, "log", (0, _logger.default)('cli:config:validate'));
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
async run() {
|
|
26
|
-
let {
|
|
27
|
-
args: {
|
|
28
|
-
filepath: path
|
|
29
|
-
}
|
|
30
|
-
} = this.parse(); // when `bail` is true, #load() returns undefined on validation warnings
|
|
31
|
-
|
|
32
|
-
let config = _config.default.load({
|
|
33
|
-
path,
|
|
34
|
-
bail: true,
|
|
35
|
-
print: true
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
if (!config) this.exit(1);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
exports.Validate = Validate;
|
|
44
|
-
|
|
45
|
-
_defineProperty(Validate, "description", 'Validate a Percy config file');
|
|
46
|
-
|
|
47
|
-
_defineProperty(Validate, "args", [{
|
|
48
|
-
name: 'filepath',
|
|
49
|
-
description: 'config filepath, detected by default'
|
|
50
|
-
}]);
|
|
51
|
-
|
|
52
|
-
_defineProperty(Validate, "examples", ['$ percy config:validate', '$ percy config:validate ./config/percy.yml']);
|
package/oclif.manifest.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":"1.0.0-beta.69","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"}]}}}
|