Skip to content

Commit

Permalink
Allow setting file path via flags
Browse files Browse the repository at this point in the history
  • Loading branch information
derrickreimer committed Oct 17, 2019
1 parent 9e9146c commit c9b3b82
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/cmds/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ const axios = require('axios');
const ora = require('ora');
const version = require('../../package.json').version;

const readConfigFromFile = () => {
const readConfigFromFile = file => {
try {
return fs.readFileSync('statickit.json', 'utf8');
return fs.readFileSync(file, 'utf8');
} catch (err) {
if (err.code === 'ENOENT') {
return null;
Expand All @@ -27,7 +27,7 @@ const parseConfig = rawConfig => {

const getConfig = args => {
if (args.config) return args.config;
return readConfigFromFile();
return readConfigFromFile(args.file);
};

const getDeployKey = args => {
Expand All @@ -54,6 +54,12 @@ exports.builder = yargs => {
alias: 'e',
describe: 'API endpoint'
});

yargs.option('file', {
alias: 'A',
describe: 'Path to the local `statickit.json` file',
default: 'statickit.json'
});
};

exports.handler = async args => {
Expand Down
15 changes: 15 additions & 0 deletions test/deploy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,18 @@ it('accepts a config from the statickit.json file', async () => {

await fs.unlink('statickit.json');
});

it('accepts a config from a custom file', async () => {
await fs.writeFile('statickit-custom.json', validMinimumConfig, 'utf8');

const { stdout } = await execa(
'bin/statickit',
['deploy', '-A', 'statickit-custom.json'],
{
env: { STATICKIT_DEPLOY_KEY: process.env.STATICKIT_TEST_DEPLOY_KEY }
}
);
expect(stdout).toMatch(/Deployment succeeded/);

await fs.unlink('statickit-custom.json');
});

0 comments on commit c9b3b82

Please sign in to comment.