From 0f3607ff415ade6efdce19989b64837209ecc985 Mon Sep 17 00:00:00 2001 From: jgraff Date: Fri, 3 Aug 2018 12:35:34 -0700 Subject: [PATCH 1/2] make isPublished arg work with "npm run deploy" --- README.md | 5 ++--- bin/deploy.js | 21 ++++++++------------- package.json | 2 +- 3 files changed, 11 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 333461b..f6023b5 100644 --- a/README.md +++ b/README.md @@ -173,11 +173,10 @@ It is highly recommended to put the entire project under source control, e.g. gi Upload your brand new sample generator template into an instance of Refocus. Note: Upload should run test and build and validate before actually uploading. ``` -$ npm run deploy TEMPLATE_FILE REFOCUS_URL REFOCUS_TOKEN --isPublished= +$ npm run deploy +$ npm run deploy my-sgt.json isPublished=true www.example.com abcdefghijklmnopqrstuvwxyz ``` -Use `--isPublished ` to specify whether you want your new sample generator template to be posted with "isPublished" set to true or false. - ## Maintenance ### Versioning diff --git a/bin/deploy.js b/bin/deploy.js index 3a0c9ba..991465a 100755 --- a/bin/deploy.js +++ b/bin/deploy.js @@ -16,29 +16,24 @@ const startTime = Date.now(); const commander = require('commander'); commander -.arguments(' ') -.option('--isPublished ', 'set isPublished to true|false') +.arguments(' ') .parse(process.argv); -if (commander.args.length < 3) { - console.error('\nError: args are required.\n'); +if (commander.args.length < 4) { + console.error('\nError: args are required.\n'); process.exit(1); } -if (!commander.hasOwnProperty('isPublished')) { - console.error('\nError: --isPublished is required.\n'); - process.exit(1); -} +let [templateFile, isPublished, refocusUrl, refocusToken] = commander.args; -if (!['true', 'false'].includes(commander.isPublished.toLowerCase())) { - console.error('\nError: --isPublished is required.\n'); +if (!['isPublished=true', 'isPublished=false'].includes(isPublished)) { + console.error('\nError: isPublished must be "isPublished=".\n'); process.exit(1); } -const [templateFile, refocusUrl, refocusToken] = commander.args; -const isPublished = commander.isPublished.toLowerCase() === 'true'; +isPublished = isPublished === 'isPublished=true'; console.log(`Deploying ${templateFile} to ${refocusUrl} with ` + - `isPublished=${isPublished}...`); + `isPublished: ${isPublished}`); u.deploy(templateFile, refocusUrl, refocusToken, isPublished) .then(() => console.log(`Done deploying ${templateFile} to ${refocusUrl} ` + diff --git a/package.json b/package.json index 93a5452..52ef3ef 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@salesforce/refocus-sample-generator-template-utils", - "version": "1.1.0", + "version": "1.1.1", "description": "Refocus Sample Generator Template Utilities", "main": "index.js", "dependencies": { From 61c507de62492b97c82801379fd1c5fb1aa369a0 Mon Sep 17 00:00:00 2001 From: jgraff Date: Fri, 3 Aug 2018 14:02:04 -0700 Subject: [PATCH 2/2] make isPublished arg work with "npm run deploy" --- bin/deploy.js | 5 ++- .../transform/basicBySubject/testTransform.js | 2 +- runExample.sh | 2 +- test/bin/deploy.js | 38 ++++++++----------- 4 files changed, 22 insertions(+), 25 deletions(-) diff --git a/bin/deploy.js b/bin/deploy.js index 991465a..56ad275 100755 --- a/bin/deploy.js +++ b/bin/deploy.js @@ -20,7 +20,10 @@ commander .parse(process.argv); if (commander.args.length < 4) { - console.error('\nError: args are required.\n'); + console.error( + '\nError: ' + + ' args are required.\n' + ); process.exit(1); } diff --git a/examples/transform/basicBySubject/testTransform.js b/examples/transform/basicBySubject/testTransform.js index 8512145..2b1906f 100644 --- a/examples/transform/basicBySubject/testTransform.js +++ b/examples/transform/basicBySubject/testTransform.js @@ -100,7 +100,7 @@ describe('transform tests >', () => { }, }; - expect(() => tu.validateResponse(res)).to.not.throw(); + expect(() => tu.validateResponse(res)).to.throw(); }); }); diff --git a/runExample.sh b/runExample.sh index 21c880b..eeac396 100755 --- a/runExample.sh +++ b/runExample.sh @@ -17,7 +17,7 @@ function runExample { sgtu-init $newProject $1 $2 cd $newProject npm run test - if [ $? != 0 ]; then exit; fi + if [ $? != 0 ]; then exit 1; fi cd .. cd $baseDir rm -rf $newProject diff --git a/test/bin/deploy.js b/test/bin/deploy.js index 01f5bd9..44d1c33 100644 --- a/test/bin/deploy.js +++ b/test/bin/deploy.js @@ -35,14 +35,15 @@ describe('test/bin/deploy.js >', function () { */ it('provide 3 args and isPublished flag set to false', (done) => { const templateFile = `./${projectName}/${projectName}.json`; + const isPublished = 'isPublished=false'; const refocusUrl = 'http://localhost'; const refocusToken = 'abcdefg'; - const args = [templateFile, refocusUrl, refocusToken, '--isPublished=false']; + const args = [templateFile, isPublished, 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...'); + 'isPublished: false'); }); forkedProcess.stderr.on('data', (data) => { expect(data.toString()).to.include('Error: connect ECONNREFUSED'); @@ -52,53 +53,46 @@ describe('test/bin/deploy.js >', function () { it('missing args', (done) => { const templateFile = `./${projectName}/${projectName}.json`; + const isPublished = 'isPublished=false'; const refocusUrl = 'http://localhost'; const refocusToken = 'abcdefg'; - const args = [templateFile, refocusUrl]; + const args = [templateFile, isPublished, refocusUrl]; const forkedProcess = fork('./bin/deploy.js', args, { silent: true }); forkedProcess.stderr.on('data', (data) => { expect(data.toString()) - .to.include('Error: args are required.'); + .to.include( + 'Error: ' + + ' args are required.' + ); done(); }); }); - it('missing isPublished', (done) => { + it('set isPublished', (done) => { const templateFile = `./${projectName}/${projectName}.json`; + const isPublished = 'isPublished=true'; const refocusUrl = 'http://localhost'; const refocusToken = 'abcdefg'; - const args = [templateFile, refocusUrl, refocusToken]; - const forkedProcess = fork('./bin/deploy.js', args, { silent: true }); - forkedProcess.stderr.on('data', (data) => { - expect(data.toString()) - .to.include('Error: --isPublished is required.'); - 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, '--isPublished=true']; + const args = [templateFile, isPublished, 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=true...'); + 'isPublished: true'); done(); }); }); it('invalid value for isPublished', (done) => { const templateFile = `./${projectName}/${projectName}.json`; + const isPublished = 'isPublished=foo'; const refocusUrl = 'http://localhost'; const refocusToken = 'abcdefg'; - const args = [templateFile, refocusUrl, refocusToken, '--isPublished foo']; + const args = [templateFile, isPublished, refocusUrl, refocusToken]; const forkedProcess = fork('./bin/deploy.js', args, { silent: true }); forkedProcess.stderr.on('data', (data) => { expect(data.toString()) - .to.include('Error: --isPublished is required.'); + .to.include('Error: isPublished must be "isPublished=".'); done(); }); });