@percy/cli-config
Advanced tools
Comparing version 1.12.0 to 1.13.0
@@ -52,16 +52,18 @@ import fs from 'fs'; | ||
// discern the filetype | ||
let filetype = args.filepath ? path.extname(args.filepath).replace(/^./, '') : FILETYPES.find(t => flags[t]) ?? 'yml'; // verify the filetype is supported | ||
let filetype = args.filepath ? path.extname(args.filepath).replace(/^./, '') : FILETYPES.find(t => flags[t]) ?? 'yml'; | ||
// verify the filetype is supported | ||
if (!DEFAULT_FILES[filetype]) { | ||
exit(1, `Unsupported filetype: ${filetype}`); | ||
} // default filepath based on filetype | ||
} | ||
// default filepath based on filetype | ||
let filepath = args.filepath || DEFAULT_FILES[filetype]; | ||
let filepath = args.filepath || DEFAULT_FILES[filetype]; // verify the file does not already exist | ||
// verify the file does not already exist | ||
if (fs.existsSync(filepath)) { | ||
exit(1, `Percy config already exists: ${filepath}`); | ||
} // write stringified default config options to the filepath | ||
} | ||
// write stringified default config options to the filepath | ||
let format = ['rc', 'yaml', 'yml'].includes(filetype) ? 'yaml' : filetype; | ||
@@ -68,0 +70,0 @@ fs.mkdirSync(path.dirname(filepath), { |
@@ -31,13 +31,15 @@ import fs from 'fs'; | ||
if (!config) exit(1, 'Config file not found'); | ||
log.info(`Found config file: ${path.relative('', input)}`); // if migrating versions, warn when latest | ||
log.info(`Found config file: ${path.relative('', input)}`); | ||
// if migrating versions, warn when latest | ||
if (input === output && config.version === 2) { | ||
exit(0, 'Config is already the latest version'); | ||
} // migrate config | ||
} | ||
// migrate config | ||
log.info('Migrating config file...'); | ||
let format = path.extname(output).replace(/^./, '') || 'yaml'; | ||
let migrated = PercyConfig.migrate(config); // prefer kebab-case for yaml | ||
let migrated = PercyConfig.migrate(config); | ||
// prefer kebab-case for yaml | ||
if (/^ya?ml$/.test(format)) { | ||
@@ -48,14 +50,13 @@ migrated = PercyConfig.normalize(migrated, { | ||
}); | ||
} // stringify to the desired format | ||
} | ||
// stringify to the desired format | ||
let body = PercyConfig.stringify(format, migrated); | ||
if (!flags.dryRun) { | ||
let content = body; | ||
if (path.basename(output) === 'package.json') { | ||
// update the package.json entry by reading and modifying it | ||
let pkg = JSON.parse(fs.readFileSync(output)); | ||
content = PercyConfig.stringify(format, { ...pkg, | ||
content = PercyConfig.stringify(format, { | ||
...pkg, | ||
percy: migrated | ||
@@ -71,10 +72,10 @@ }); | ||
fs.renameSync(input, path.join(dir, `${name}.old${ext}`)); | ||
} // write to output | ||
} | ||
// write to output | ||
fs.writeFileSync(output, content); | ||
} | ||
log.info('Config file migrated!'); | ||
log.info('Config file migrated!'); // when dry-running, print config to stdout when finished | ||
// when dry-running, print config to stdout when finished | ||
if (flags.dryRun) { | ||
@@ -81,0 +82,0 @@ log.stdout.write('\n' + body); |
@@ -19,4 +19,5 @@ import command, { PercyConfig } from '@percy/cli-command'; | ||
} = PercyConfig.search(args.filepath); | ||
if (!config) exit(1, 'Config file not found'); // when `bail` is true, .load() returns undefined when validation fails | ||
if (!config) exit(1, 'Config file not found'); | ||
// when `bail` is true, .load() returns undefined when validation fails | ||
let result = PercyConfig.load({ | ||
@@ -26,6 +27,7 @@ path: filepath, | ||
bail: true | ||
}); // exit 1 when config is empty | ||
}); | ||
// exit 1 when config is empty | ||
if (!result) exit(1); | ||
}); | ||
export default validate; |
{ | ||
"name": "@percy/cli-config", | ||
"version": "1.12.0", | ||
"version": "1.13.0", | ||
"license": "MIT", | ||
@@ -35,5 +35,5 @@ "repository": { | ||
"dependencies": { | ||
"@percy/cli-command": "1.12.0" | ||
"@percy/cli-command": "1.13.0" | ||
}, | ||
"gitHead": "4303b74df91f60e36065141289d2ef2277d1d6fc" | ||
"gitHead": "d2e812d14aa446fa580ffa75144a6280627b5a27" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9768
184
+ Added@percy/cli-command@1.13.0(transitive)
+ Added@percy/client@1.13.0(transitive)
+ Added@percy/config@1.13.0(transitive)
+ Added@percy/core@1.13.0(transitive)
+ Added@percy/dom@1.13.0(transitive)
+ Added@percy/env@1.13.0(transitive)
+ Added@percy/logger@1.13.0(transitive)
- Removed@percy/cli-command@1.12.0(transitive)
- Removed@percy/client@1.12.0(transitive)
- Removed@percy/config@1.12.0(transitive)
- Removed@percy/core@1.12.0(transitive)
- Removed@percy/dom@1.12.0(transitive)
- Removed@percy/env@1.12.0(transitive)
- Removed@percy/logger@1.12.0(transitive)
Updated@percy/cli-command@1.13.0