@percy/cli-config 1.12.0 → 1.13.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/create.js CHANGED
@@ -49,20 +49,22 @@ export const create = command('create', {
49
49
  exit
50
50
  }) => {
51
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
52
+ let filetype = args.filepath ? path.extname(args.filepath).replace(/^./, '') : FILETYPES.find(t => flags[t]) ?? 'yml';
53
53
 
54
+ // verify the filetype is supported
54
55
  if (!DEFAULT_FILES[filetype]) {
55
56
  exit(1, `Unsupported filetype: ${filetype}`);
56
- } // default filepath based on filetype
57
+ }
57
58
 
59
+ // default filepath based on filetype
60
+ let filepath = args.filepath || DEFAULT_FILES[filetype];
58
61
 
59
- let filepath = args.filepath || DEFAULT_FILES[filetype]; // verify the file does not already exist
60
-
62
+ // verify the file does not already exist
61
63
  if (fs.existsSync(filepath)) {
62
64
  exit(1, `Percy config already exists: ${filepath}`);
63
- } // write stringified default config options to the filepath
64
-
65
+ }
65
66
 
67
+ // write stringified default config options to the filepath
66
68
  let format = ['rc', 'yaml', 'yml'].includes(filetype) ? 'yaml' : filetype;
67
69
  fs.mkdirSync(path.dirname(filepath), {
68
70
  recursive: true
package/dist/migrate.js CHANGED
@@ -28,34 +28,35 @@ export const migrate = command('migrate', {
28
28
  } = PercyConfig.search(args.filepath);
29
29
  let output = args.output ? path.resolve(args.output) : input;
30
30
  if (!config) exit(1, 'Config file not found');
31
- log.info(`Found config file: ${path.relative('', input)}`); // if migrating versions, warn when latest
31
+ log.info(`Found config file: ${path.relative('', input)}`);
32
32
 
33
+ // if migrating versions, warn when latest
33
34
  if (input === output && config.version === 2) {
34
35
  exit(0, 'Config is already the latest version');
35
- } // migrate config
36
-
36
+ }
37
37
 
38
+ // migrate config
38
39
  log.info('Migrating config file...');
39
40
  let format = path.extname(output).replace(/^./, '') || 'yaml';
40
- let migrated = PercyConfig.migrate(config); // prefer kebab-case for yaml
41
+ let migrated = PercyConfig.migrate(config);
41
42
 
43
+ // prefer kebab-case for yaml
42
44
  if (/^ya?ml$/.test(format)) {
43
45
  migrated = PercyConfig.normalize(migrated, {
44
46
  schema: '/config',
45
47
  kebab: true
46
48
  });
47
- } // stringify to the desired format
48
-
49
+ }
49
50
 
51
+ // stringify to the desired format
50
52
  let body = PercyConfig.stringify(format, migrated);
51
-
52
53
  if (!flags.dryRun) {
53
54
  let content = body;
54
-
55
55
  if (path.basename(output) === 'package.json') {
56
56
  // update the package.json entry by reading and modifying it
57
57
  let pkg = JSON.parse(fs.readFileSync(output));
58
- content = PercyConfig.stringify(format, { ...pkg,
58
+ content = PercyConfig.stringify(format, {
59
+ ...pkg,
59
60
  percy: migrated
60
61
  });
61
62
  } else if (input === output) {
@@ -66,14 +67,14 @@ export const migrate = command('migrate', {
66
67
  ext
67
68
  } = path.parse(input);
68
69
  fs.renameSync(input, path.join(dir, `${name}.old${ext}`));
69
- } // write to output
70
-
70
+ }
71
71
 
72
+ // write to output
72
73
  fs.writeFileSync(output, content);
73
74
  }
75
+ log.info('Config file migrated!');
74
76
 
75
- log.info('Config file migrated!'); // when dry-running, print config to stdout when finished
76
-
77
+ // when dry-running, print config to stdout when finished
77
78
  if (flags.dryRun) {
78
79
  log.stdout.write('\n' + body);
79
80
  }
package/dist/validate.js CHANGED
@@ -16,14 +16,16 @@ export const validate = command('validate', {
16
16
  config,
17
17
  filepath
18
18
  } = PercyConfig.search(args.filepath);
19
- if (!config) exit(1, 'Config file not found'); // when `bail` is true, .load() returns undefined when validation fails
19
+ if (!config) exit(1, 'Config file not found');
20
20
 
21
+ // when `bail` is true, .load() returns undefined when validation fails
21
22
  let result = PercyConfig.load({
22
23
  path: filepath,
23
24
  print: true,
24
25
  bail: true
25
- }); // exit 1 when config is empty
26
+ });
26
27
 
28
+ // exit 1 when config is empty
27
29
  if (!result) exit(1);
28
30
  });
29
31
  export default validate;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@percy/cli-config",
3
- "version": "1.12.0",
3
+ "version": "1.13.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -32,7 +32,7 @@
32
32
  ]
33
33
  },
34
34
  "dependencies": {
35
- "@percy/cli-command": "1.12.0"
35
+ "@percy/cli-command": "1.13.0"
36
36
  },
37
- "gitHead": "4303b74df91f60e36065141289d2ef2277d1d6fc"
37
+ "gitHead": "d2e812d14aa446fa580ffa75144a6280627b5a27"
38
38
  }