Skip to content

Conversation

@gitgrimbo
Copy link
Contributor

@gitgrimbo gitgrimbo commented Jun 6, 2020

Allows the config file to return a Promise.

The change basically wraps bin/cli.js in an async function and awaits the result of calling loadConfig().


Sample command:

replace-in-file --configFile=replace-in-file.config.js

Sample replace-in-file.config.js file:

const simplegit = require("simple-git/promise");
const git = simplegit();

async function latestVersion() {
  const opts = {
    // latest single entry
    "-1": null,
  };
  const log = await git.log(opts);
  const { latest } = log;
  return latest.hash.substring(0, 8);
}

async function makeConfig() {
  const codeVersion = await latestVersion();
  return {
    files: "public/**/*",
    from: /@CODE_VERSION@/g,
    to: codeVersion,
  };
}

module.exports = makeConfig();

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 68558c3 on gitgrimbo:async-config into f94e466 on adamreisnz:master.

@adamreisnz adamreisnz merged commit 13e1c5e into adamreisnz:master Jun 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants