Skip to content

Commit

Permalink
remove deprecated config simplify API
Browse files Browse the repository at this point in the history
  • Loading branch information
joemaller committed Jan 8, 2022
1 parent 68df62b commit da53926
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 332 deletions.
23 changes: 21 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ The file should export a simple JS object and look something like this:
```js
module.exports = {
files: ["README.md", "example_wordpress_plugin.php", "styles.css"],
prefix: /* a string, regexp literal or mixed array of either */
json: {
/* optional json config object, keys pass directly to JSON.stringify */
},
Expand Down Expand Up @@ -123,23 +124,41 @@ Files with the following extensions will be recognized as structured text and pa

### versionEverything(files, [options])

All keys are optional. Files is _practically_ required, without a list of files there's nothing to do.

#### files

Type: `array`

An array containing the files which will be versioned.

#### prefix

Type: `string|RegExp|[string|RegExp]`

A string, RegExp, or a mixed array of either. Will be added to the list of standard version patterns to be replaced in plain-text files.

#### options

Type: `object`
All keys are optional.

##### json
#### json

Type: `object`
Three keys from the `json` object will be passed directly to [`JSON.parse`][jsonparse] or [`JSON.stringify`][stringify]: **`space`** which sets indentation from an integer or string, a **[`reviver`][reviver]** function and a **[`replacer`][replacer]** function/array. See the [JSON docs][stringify] for more info.

##### xml
Default JSON Options:

```js
{
space: 2,
replacer: null,
reviver: null,
}
```

#### xml

Type: `object`
Merged with a minimal set of defaults, then passed to the [xml-js `js2xml` converter][xml-js convert]. See [xml-js docs][] for available options.
Expand Down
57 changes: 0 additions & 57 deletions app/get-version-files.js

This file was deleted.

2 changes: 1 addition & 1 deletion app/update-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const updateFile = async (file, version, options = {}) => {
prefixes: [],
};

const config = Object.assign({}, defaultOptions, options);
const config = {...defaultOptions, ...options};
const log = logInit(config.quiet);

// first pass tries file extensions, if those don't match, try parsing
Expand Down
1 change: 1 addition & 0 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const getConfig = (yargsObject = { _: [] }) => {
config["version-everything"].options.quiet = yargsObject.quiet;
}
if (yargsObject.prefix) {
// TODO: this might be extraneous? Yargs should force this to be an array
if (typeof yargsObject.prefix === "string") {
yargsObject.prefix = [yargsObject.prefix];
}
Expand Down
38 changes: 29 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@

const readPkgUp = require("read-pkg-up");

const getVersionFiles = require("./app/get-version-files");
const { cosmiconfigSync } = require("cosmiconfig");

// const getVersionFiles = require("./app/get-version-files");
const updateFile = require("./app/update-file");

/**
* The version-everything object should contain a files array and an optional options object
* The args object should contain a files array any other documented options
*
* "version-everything": {
* "{
* files: ["file1.js", "file2.json"],
* options: {
* quiet: false
* }
* prefix: ['namespace/img:'],
* quiet: false,
* json: {space: 4}
* }
*
*/
Expand All @@ -26,8 +28,26 @@ const updateFile = require("./app/update-file");
module.exports = function (args = {}) {
const { packageJson } = readPkgUp.sync({ normalize: false });
const version = args.version || packageJson.version;
const options =
(args["version-everything"] && args["version-everything"].options) || {};
if (!version) {
throw "No version found in args or package.json";
}

const explorerSync = cosmiconfigSync("version-everything");
const configFile = explorerSync.search() || { config: {} };

const options = { ...configFile.config, ...args };

if (options.prefix) {
if (typeof options.prefix === "string") {
options.prefix = [options.prefix];
}
options.prefixes = options.prefixes || [];
options.prefixes = [...options.prefix, ...options.prefixes];
delete options.prefix;
delete options.config;
}
const versionFiles = options?.files || [];
delete options.files;

getVersionFiles(args).forEach((f) => updateFile(f, version, options));
versionFiles.forEach((f) => updateFile(f, version, options));
};
12 changes: 0 additions & 12 deletions test/fixture/old-package-versionFiles/package.json

This file was deleted.

12 changes: 0 additions & 12 deletions test/fixture/old-package-version_files/package.json

This file was deleted.

Loading

0 comments on commit da53926

Please sign in to comment.