Skip to content

Commit

Permalink
Merge c5783ff into af72c5a
Browse files Browse the repository at this point in the history
  • Loading branch information
iamigo committed Mar 28, 2018
2 parents af72c5a + c5783ff commit 42ae728
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 19 deletions.
6 changes: 6 additions & 0 deletions README.md
Expand Up @@ -172,6 +172,12 @@ Upload your brand new sample generator template into an instance of Refocus. Not
$ npm run deploy TEMPLATE_FILE REFOCUS_URL REFOCUS_TOKEN
```

By default, the new sample generator template is posted with "isPublished" set to false. You can override that by passing the `-p` or `--isPublished` option to set it to true, e.g.

```
$ npm run deploy TEMPLATE_FILE REFOCUS_URL REFOCUS_TOKEN --isPublished
```

## Maintenance

### Versioning
Expand Down
1 change: 0 additions & 1 deletion bin/build.js
Expand Up @@ -19,4 +19,3 @@ cu.buildTransform();
console.log(`Done building transform (${Date.now() - startTime}ms)`);
cu.buildConnection();
console.log(`Done building connection (${Date.now() - startTime}ms)`);

1 change: 0 additions & 1 deletion bin/buildTransform.js
Expand Up @@ -16,4 +16,3 @@ const startTime = Date.now();

cu.buildTransform();
console.log(`Done building transform (${Date.now() - startTime}ms)`);

21 changes: 12 additions & 9 deletions bin/deploy.js
Expand Up @@ -14,20 +14,23 @@
const u = require('../src/deployUtils');
const startTime = Date.now();
const commander = require('commander');
let templateFile;
let refocusUrl;
let refocusToken;

commander
.arguments('<templateFile> <refocusUrl> <refocusToken>')
.action((tf, ru, rt) => {
templateFile = tf;
refocusUrl = ru;
refocusToken = rt;
})
.option('-p, --isPublished', 'set isPublished=true')
.parse(process.argv);

u.deploy(templateFile, refocusUrl, refocusToken)
if (commander.args.length < 3) {
console.error('\nError: <templateFile> <refocusUrl> <refocusToken> args are required.\n');
process.exit(1);
}

const [templateFile, refocusUrl, refocusToken] = commander.args;
const isPublished = commander.isPublished || false;
console.log(`Deploying ${templateFile} to ${refocusUrl} with ` +
`isPublished=${isPublished}...`);

u.deploy(templateFile, refocusUrl, refocusToken, isPublished)
.then(() => console.log(`Done deploying ${templateFile} to ${refocusUrl} ` +
` (${Date.now() - startTime}ms)`))
.catch((err) => console.error(err));
9 changes: 5 additions & 4 deletions src/deployUtils.js
Expand Up @@ -27,13 +27,13 @@ const cwd = process.cwd();
* @returns {Promise} which resolves to the http response from Refocus or an
* error
*/
function deploy(template, url, token) {
function deploy(template, url, token, isPublished = false) {
if (typeof template === 'string') {
return fs.readJson(template)
.then((contents) => deployTemplate(contents, url, token));
.then((contents) => deployTemplate(contents, url, token, isPublished));
}

return deployTemplate(template, url, token);
return deployTemplate(template, url, token, isPublished);
} // deploy

/**
Expand All @@ -46,7 +46,8 @@ function deploy(template, url, token) {
* @returns {Promise} which resolves to the http response from Refocus or an
* error
*/
function deployTemplate(templateJson, url, token) {
function deployTemplate(templateJson, url, token, isPublished = false) {
templateJson.isPublished = isPublished;
return req.post(`${url}${path}`)
.send(templateJson)
.set({
Expand Down
67 changes: 63 additions & 4 deletions test/bin/deploy.js
Expand Up @@ -15,6 +15,7 @@ const fs = require('fs-extra');
const fork = require('child_process').fork;
const projectName = 'reserved-project-name-for-automated-tests';

// use "function" syntax because we're setting this.timeout
describe('test/bin/deploy.js >', function () {
this.timeout(5000);
before((done) => {
Expand All @@ -29,17 +30,75 @@ describe('test/bin/deploy.js >', function () {
after(() => fs.remove(`./${projectName}`));

/*
nock doesn't work for a forked process, so the best we can do here is send
the request to localhost and expect an error.
*/
it('deploy', (done) => {
* nock doesn't work for a forked process, so the best we can do here is send
* the request to localhost and expect an error.
*/
it('provide 3 args but no isPublished flag', (done) => {
const templateFile = `./${projectName}/${projectName}.json`;
const refocusUrl = 'http://localhost';
const refocusToken = 'abcdefg';
const args = [templateFile, refocusUrl, refocusToken];
const forkedProcess = fork('./bin/deploy.js', args, { silent: true });
forkedProcess.stdout.on('data', (data) => {
expect(data.toString())
.to.include(`Deploying ${templateFile} to ${refocusUrl} with ` +
'isPublished=false...');
});
forkedProcess.stderr.on('data', (data) => {
expect(data.toString()).to.include('Error: connect ECONNREFUSED');
});
forkedProcess.on('exit', (code) => {
expect(code).to.equal(0);
done();
});
});

it('missing args', (done) => {
const templateFile = `./${projectName}/${projectName}.json`;
const refocusUrl = 'http://localhost';
const refocusToken = 'abcdefg';
const args = [templateFile, refocusUrl];
const forkedProcess = fork('./bin/deploy.js', args, { silent: true });
forkedProcess.stderr.on('data', (data) => {
expect(data.toString())
.to.include('Error: <templateFile> <refocusUrl> <refocusToken> args are required.');
});
forkedProcess.on('exit', (code) => {
expect(code).to.equal(1);
done();
});
});

it('set isPublished using short option -p', (done) => {
const templateFile = `./${projectName}/${projectName}.json`;
const refocusUrl = 'http://localhost';
const refocusToken = 'abcdefg';
const args = [templateFile, refocusUrl, refocusToken, '-p'];
const forkedProcess = fork('./bin/deploy.js', args, { silent: true });
forkedProcess.stdout.on('data', (data) => {
expect(data.toString())
.to.include(`Deploying ${templateFile} to ${refocusUrl} with ` +
'isPublished=true...');
});
forkedProcess.on('exit', (code) => {
expect(code).to.equal(0);
done();
});
});

it('set isPublished using long option --isPublished', (done) => {
const templateFile = `./${projectName}/${projectName}.json`;
const refocusUrl = 'http://localhost';
const refocusToken = 'abcdefg';
const args = [templateFile, refocusUrl, refocusToken, '-p'];
const forkedProcess = fork('./bin/deploy.js', args, { silent: true });
forkedProcess.stdout.on('data', (data) => {
expect(data.toString())
.to.include(`Deploying ${templateFile} to ${refocusUrl} with ` +
'isPublished=true...');
});
forkedProcess.on('exit', (code) => {
expect(code).to.equal(0);
done();
});
});
Expand Down

0 comments on commit 42ae728

Please sign in to comment.