Skip to content

Commit

Permalink
refactor get-version-files
Browse files Browse the repository at this point in the history
  • Loading branch information
joemaller committed May 3, 2020
1 parent c907133 commit 991c06a
Showing 1 changed file with 28 additions and 27 deletions.
55 changes: 28 additions & 27 deletions app/get-version-files.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,42 @@
const readPkgUp = require("read-pkg-up");
const { cosmiconfigSync } = require("cosmiconfig");

const filesFromDeprecated = ({ packageJson }) => {
let outputFiles = [];
if (packageJson.version_files) {
console.log(
'Files loaded from deprecated "version_files" key.',
'Please update this package.json file to use a "version-everything.files" key.'
);
outputFiles = packageJson.version_files;
} else if (packageJson.versionFiles) {
console.log(
"Files loaded from deprecated 'versionFiles' key.",
"Please update this package.json file to use a 'version-everything.files' key."
);
outputFiles = packageJson.versionFiles;
}
return outputFiles;
};
/**
* Returns an array of files to version
* @param {array, object, string} args an array of filenames, an object representing a package.json file
* or an object containing a version-everything.files or files array
* or a string reprenting a filepath. Input isn't validated.
* or a string representing a file path. Input isn't validated.
* @return {array} List of files to version
*/
module.exports = function(args) {
module.exports = function (args) {
let output = [];

if (arguments.length) {
if (args) {
let files = [];
if (args["version-everything"]) {
files = args["version-everything"].files || args;
} else {
files = args.files ? args.files : args;
}
output = Array.isArray(files) && files.length ? files : output;
output = typeof files === "string" ? [files] : output;
if (args) {
let files = [];
if (args["version-everything"]) {
files = args["version-everything"].files || args;
} else {
files = args.files ? args.files : args;
}
output = Array.isArray(files) && files.length ? files : output;
output = typeof files === "string" ? [files] : output;
}

if (!output.length) {
Expand All @@ -33,21 +48,7 @@ module.exports = function(args) {
} else {
const pkg = readPkgUp.sync({ normalize: false });
if (pkg) {
const { packageJson } = pkg;
if (packageJson.version_files) {
console.log(
'Files loaded from deprecated "version_files" key.',
'Please update this package.json file to use a "version-everything.files" key.'
);
output = packageJson.version_files;
} else if (packageJson.versionFiles) {
console.log(
"Files loaded from deprecated 'versionFiles' key.",
"Please update this package.json file to use a 'version-everything.files' key."
);
output = packageJson.versionFiles;
}
// return packageJson.version_files || packageJson.versionFiles || [];
output = filesFromDeprecated(pkg);
}
}
}
Expand Down

0 comments on commit 991c06a

Please sign in to comment.