Skip to content

Commit 3981455

Browse files
authored
feat(deploy): must run hlx build (#241)
1 parent 6e05a13 commit 3981455

File tree

9 files changed

+82
-58
lines changed

9 files changed

+82
-58
lines changed

src/deploy.cmd.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class DeployCommand extends AbstractCommand {
4646
this._fastly_namespace = null;
4747
this._fastly_auth = null;
4848
this._target = null;
49+
this._files = null;
4950
this._prefix = null;
5051
this._default = null;
5152
this._enableDirty = false;
@@ -110,6 +111,11 @@ class DeployCommand extends AbstractCommand {
110111
return this;
111112
}
112113

114+
withFiles(value) {
115+
this._files = value;
116+
return this;
117+
}
118+
113119
withDefault(value) {
114120
this._default = value;
115121
return this;
@@ -340,6 +346,7 @@ Alternatively you can auto-add one using the {grey --add <name>} option.`);
340346
if (this._createPackages !== 'ignore') {
341347
const pgkCommand = new PackageCommand(this.log)
342348
.withTarget(this._target)
349+
.withFiles(this._files)
343350
.withDirectory(this.directory)
344351
.withOnlyModified(this._createPackages === 'auto')
345352
.withMinify(this._enableMinify);

src/deploy.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
const yargsOpenwhisk = require('./yargs-openwhisk.js');
1616
const yargsFastly = require('./yargs-fastly.js');
17+
const yargsBuild = require('./yargs-build.js');
1718
const { makeLogger } = require('./log-common.js');
1819

1920
module.exports = function deploy() {
@@ -28,6 +29,7 @@ module.exports = function deploy() {
2829
builder: (yargs) => {
2930
yargsOpenwhisk(yargs);
3031
yargsFastly(yargs);
32+
yargsBuild(yargs);
3133
yargs
3234
.option('auto', {
3335
describe: 'Enable auto-deployment',
@@ -155,6 +157,7 @@ module.exports = function deploy() {
155157
.withLogglyHost(argv.logglyHost)
156158
.withLogglyAuth(argv.logglyAuth)
157159
.withTarget(argv.target)
160+
.withFiles(argv.files)
158161
.withDefault(argv.default)
159162
.withDryRun(argv.dryRun)
160163
.withCircleciAuth(argv.circleciAuth)

src/package.cmd.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const fs = require('fs-extra');
1616
const ProgressBar = require('progress');
1717
const archiver = require('archiver');
1818
const AbstractCommand = require('./abstract.cmd.js');
19+
const BuildCommand = require('./build.cmd.js');
1920
const ActionBundler = require('./parcel/ActionBundler.js');
2021
const { flattenDependencies } = require('./packager-utils.js');
2122

@@ -43,6 +44,7 @@ class PackageCommand extends AbstractCommand {
4344
constructor(logger) {
4445
super(logger);
4546
this._target = null;
47+
this._files = null;
4648
this._onlyModified = false;
4749
this._enableMinify = false;
4850
}
@@ -57,6 +59,11 @@ class PackageCommand extends AbstractCommand {
5759
return this;
5860
}
5961

62+
withFiles(value) {
63+
this._files = value;
64+
return this;
65+
}
66+
6067
withOnlyModified(value) {
6168
this._onlyModified = value;
6269
return this;
@@ -193,6 +200,12 @@ class PackageCommand extends AbstractCommand {
193200
async run() {
194201
await this.init();
195202

203+
// always run build first to make sure scripts are up to date
204+
await new BuildCommand(this.log)
205+
.withFiles(this._files)
206+
.withTargetDir(this._target)
207+
.run();
208+
196209
// get the list of scripts from the info files
197210
const infos = [...glob.sync(`${this._target}/**/*.info.json`)];
198211
const scriptInfos = await Promise.all(infos.map(info => fs.readJSON(info)));

src/package.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
'use strict';
1414

1515
const { makeLogger } = require('./log-common.js');
16+
const yargsBuild = require('./yargs-build.js');
1617

17-
module.exports = function deploy() {
18+
module.exports = function pack() {
1819
let executor;
1920

2021
return {
@@ -24,6 +25,7 @@ module.exports = function deploy() {
2425
command: 'package',
2526
desc: 'Create Adobe I/O runtime packages',
2627
builder: (yargs) => {
28+
yargsBuild(yargs);
2729
// eslint-disable-next-line global-require
2830
yargs
2931
.option('force', {
@@ -54,6 +56,7 @@ module.exports = function deploy() {
5456

5557
await executor
5658
.withTarget(argv.target)
59+
.withFiles(argv.files)
5760
.withOnlyModified(!argv.force)
5861
.withMinify(argv.minify)
5962
.run();

src/yargs-build.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module.exports = function commonArgs(yargs) {
2424
type: 'string',
2525
})
2626
// allow for comma separated values
27-
.coerce('files', value => value.reduce((acc, curr) => {
27+
.coerce('files', value => (!Array.isArray(value) ? [value] : value).reduce((acc, curr) => {
2828
acc.push(...curr.split(/\s*,\s*/));
2929
return acc;
3030
}, []));

test/testDeployCli.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ describe('hlx deploy', () => {
3939
mockDeploy.withLogglyHost.returnsThis();
4040
mockDeploy.withLogglyAuth.returnsThis();
4141
mockDeploy.withTarget.returnsThis();
42+
mockDeploy.withFiles.returnsThis();
4243
mockDeploy.withDefault.returnsThis();
4344
mockDeploy.withEnableDirty.returnsThis();
4445
mockDeploy.withDryRun.returnsThis();
@@ -123,6 +124,7 @@ OpenWhisk Namespace is required`);
123124
sinon.assert.calledWith(mockDeploy.withFastlyAuth, '');
124125
sinon.assert.calledWith(mockDeploy.withFastlyNamespace, undefined);
125126
sinon.assert.calledWith(mockDeploy.withTarget, '.hlx/build');
127+
sinon.assert.calledWith(mockDeploy.withFiles, ['src/**/*.htl', 'src/**/*.js', 'src/**/*.jsx', 'cgi-bin/**/*.js']);
126128
sinon.assert.calledWith(mockDeploy.withDefault, undefined);
127129
sinon.assert.calledWith(mockDeploy.withCreatePackages, 'auto');
128130
sinon.assert.calledWith(mockDeploy.withCircleciAuth, '');
@@ -148,6 +150,7 @@ OpenWhisk Namespace is required`);
148150
sinon.assert.calledWith(mockDeploy.withFastlyAuth, 'foobar');
149151
sinon.assert.calledWith(mockDeploy.withFastlyNamespace, '1234');
150152
sinon.assert.calledWith(mockDeploy.withTarget, 'foo');
153+
sinon.assert.calledWith(mockDeploy.withFiles, ['*.htl', '*.js']);
151154
sinon.assert.calledWith(mockDeploy.withDefault, undefined);
152155
sinon.assert.calledWith(mockDeploy.withCircleciAuth, 'foobar');
153156
sinon.assert.calledWith(mockDeploy.withDryRun, true);

test/testDeployCmd.js

Lines changed: 29 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ const { setupMocha: setupPolly } = require('@pollyjs/core');
2222
const { HelixConfig, Logger } = require('@adobe/helix-shared');
2323
const { initGit, createTestRoot } = require('./utils.js');
2424
const GitUtils = require('../src/git-utils');
25-
const BuildCommand = require('../src/build.cmd.js');
2625
const DeployCommand = require('../src/deploy.cmd.js');
2726

2827
const CI_TOKEN = 'nope';
@@ -347,18 +346,6 @@ describe('hlx deploy (Integration)', () => {
347346
initGit(testRoot, 'git@github.com:adobe/project-helix.io.git');
348347
const logger = Logger.getTestLogger();
349348

350-
await new BuildCommand(logger)
351-
.withDirectory(testRoot)
352-
.withFiles([
353-
path.resolve(testRoot, 'src/html.htl'),
354-
path.resolve(testRoot, 'src/html.pre.js'),
355-
path.resolve(testRoot, 'src/helper.js'),
356-
path.resolve(testRoot, 'src/utils/another_helper.js'),
357-
path.resolve(testRoot, 'src/third_helper.js'),
358-
])
359-
.withTargetDir(buildDir)
360-
.run();
361-
362349
const cmd = await new DeployCommand(logger)
363350
.withDirectory(testRoot)
364351
.withWskHost('adobeioruntime.net')
@@ -368,6 +355,13 @@ describe('hlx deploy (Integration)', () => {
368355
.withEnableDirty(false)
369356
.withDryRun(true)
370357
.withTarget(buildDir)
358+
.withFiles([
359+
path.resolve(testRoot, 'src/html.htl'),
360+
path.resolve(testRoot, 'src/html.pre.js'),
361+
path.resolve(testRoot, 'src/helper.js'),
362+
path.resolve(testRoot, 'src/utils/another_helper.js'),
363+
path.resolve(testRoot, 'src/third_helper.js'),
364+
])
371365
.withMinify(false)
372366
.run();
373367

@@ -386,19 +380,6 @@ describe('hlx deploy (Integration)', () => {
386380
initGit(testRoot, 'git@github.com:adobe/project-helix.io.git');
387381
const logger = Logger.getTestLogger();
388382

389-
await new BuildCommand(logger)
390-
.withDirectory(testRoot)
391-
.withFiles([
392-
path.resolve(testRoot, 'src/html.htl'),
393-
path.resolve(testRoot, 'src/html.pre.js'),
394-
path.resolve(testRoot, 'src/helper.js'),
395-
path.resolve(testRoot, 'src/utils/another_helper.js'),
396-
path.resolve(testRoot, 'src/third_helper.js'),
397-
path.resolve(testRoot, 'cgi-bin/hello.js'),
398-
])
399-
.withTargetDir(buildDir)
400-
.run();
401-
402383
const cmd = await new DeployCommand(logger)
403384
.withDirectory(testRoot)
404385
.withWskHost('adobeioruntime.net')
@@ -409,6 +390,14 @@ describe('hlx deploy (Integration)', () => {
409390
.withDryRun(true)
410391
.withMinify(false)
411392
.withTarget(buildDir)
393+
.withFiles([
394+
path.resolve(testRoot, 'src/html.htl'),
395+
path.resolve(testRoot, 'src/html.pre.js'),
396+
path.resolve(testRoot, 'src/helper.js'),
397+
path.resolve(testRoot, 'src/utils/another_helper.js'),
398+
path.resolve(testRoot, 'src/third_helper.js'),
399+
path.resolve(testRoot, 'cgi-bin/hello.js'),
400+
])
412401
.run();
413402

414403
const ref = await GitUtils.getCurrentRevision(testRoot);
@@ -429,18 +418,6 @@ describe('hlx deploy (Integration)', () => {
429418
initGit(testRoot, 'git@github.com:adobe/project-helix.io.git');
430419
const logger = Logger.getTestLogger();
431420

432-
await new BuildCommand(logger)
433-
.withDirectory(testRoot)
434-
.withFiles([
435-
path.resolve(testRoot, 'src/html.htl'),
436-
path.resolve(testRoot, 'src/html.pre.js'),
437-
path.resolve(testRoot, 'src/helper.js'),
438-
path.resolve(testRoot, 'src/utils/another_helper.js'),
439-
path.resolve(testRoot, 'src/third_helper.js'),
440-
])
441-
.withTargetDir(buildDir)
442-
.run();
443-
444421
const ref = await GitUtils.getCurrentRevision(testRoot);
445422

446423
this.polly.server.any().on('beforeResponse', (req, res) => {
@@ -503,6 +480,13 @@ describe('hlx deploy (Integration)', () => {
503480
.withEnableDirty(false)
504481
.withDryRun(false)
505482
.withTarget(buildDir)
483+
.withFiles([
484+
path.resolve(testRoot, 'src/html.htl'),
485+
path.resolve(testRoot, 'src/html.pre.js'),
486+
path.resolve(testRoot, 'src/helper.js'),
487+
path.resolve(testRoot, 'src/utils/another_helper.js'),
488+
path.resolve(testRoot, 'src/third_helper.js'),
489+
])
506490
.withMinify(false)
507491
.withLogglyAuth('loggly-auth')
508492
.withLogglyHost('loggly-host')
@@ -562,6 +546,13 @@ describe('hlx deploy (Integration)', () => {
562546
.withDryRun(false)
563547
.withMinify(false)
564548
.withTarget(buildDir)
549+
.withFiles([
550+
path.resolve(testRoot, 'src/html.htl'),
551+
path.resolve(testRoot, 'src/html.pre.js'),
552+
path.resolve(testRoot, 'src/helper.js'),
553+
path.resolve(testRoot, 'src/utils/another_helper.js'),
554+
path.resolve(testRoot, 'src/third_helper.js'),
555+
])
565556
.run();
566557
assert.fail('Expected deploy to fail.');
567558
} catch (e) {

test/testPackageCli.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ describe('hlx package', () => {
2929
clearHelixEnv();
3030
mockPackage = sinon.createStubInstance(PackageCommand);
3131
mockPackage.withTarget.returnsThis();
32+
mockPackage.withFiles.returnsThis();
3233
mockPackage.withOnlyModified.returnsThis();
3334
mockPackage.withMinify.returnsThis();
3435
mockPackage.run.returnsThis();
@@ -45,6 +46,7 @@ describe('hlx package', () => {
4546

4647
sinon.assert.calledWith(mockPackage.withOnlyModified, true);
4748
sinon.assert.calledWith(mockPackage.withTarget, '.hlx/build');
49+
sinon.assert.calledWith(mockPackage.withFiles, ['src/**/*.htl', 'src/**/*.js', 'src/**/*.jsx', 'cgi-bin/**/*.js']);
4850
sinon.assert.calledWith(mockPackage.withMinify, false);
4951
sinon.assert.calledOnce(mockPackage.run);
5052
});
@@ -55,6 +57,7 @@ describe('hlx package', () => {
5557
.withCommandExecutor('package', mockPackage)
5658
.run(['package']);
5759
sinon.assert.calledWith(mockPackage.withTarget, 'foo');
60+
sinon.assert.calledWith(mockPackage.withFiles, ['*.htl', '*.js']);
5861
sinon.assert.calledWith(mockPackage.withOnlyModified, false);
5962
sinon.assert.calledWith(mockPackage.withMinify, true);
6063
sinon.assert.calledOnce(mockPackage.run);

test/testPackageCmd.js

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ const assert = require('assert');
1616
const fs = require('fs-extra');
1717
const path = require('path');
1818
const { Logger } = require('@adobe/helix-shared');
19-
const { createTestRoot, assertZipEntries } = require('./utils.js');
20-
const BuildCommand = require('../src/build.cmd.js');
19+
const { createTestRoot, assertFile, assertZipEntries } = require('./utils.js');
2120
const PackageCommand = require('../src/package.cmd.js');
2221

2322
describe('hlx package (Integration)', () => {
@@ -36,22 +35,18 @@ describe('hlx package (Integration)', () => {
3635
});
3736

3837
it('package creates correct package', async () => {
39-
await new BuildCommand()
38+
const created = {};
39+
const ignored = {};
40+
await new PackageCommand()
41+
.withDirectory(testRoot)
42+
.withTarget(buildDir)
4043
.withFiles([
4144
'test/integration/src/html.htl',
4245
'test/integration/src/html.pre.js',
4346
'test/integration/src/helper.js',
4447
'test/integration/src/utils/another_helper.js',
4548
'test/integration/src/third_helper.js',
4649
])
47-
.withTargetDir(buildDir)
48-
.run();
49-
50-
const created = {};
51-
const ignored = {};
52-
await new PackageCommand()
53-
.withDirectory(testRoot)
54-
.withTarget(buildDir)
5550
.withOnlyModified(false)
5651
.withMinify(false)
5752
.on('create-package', (info) => {
@@ -62,6 +57,16 @@ describe('hlx package (Integration)', () => {
6257
})
6358
.run();
6459

60+
// verify build output
61+
assertFile(path.resolve(buildDir, 'html.js'));
62+
assertFile(path.resolve(buildDir, 'html.js.map'));
63+
assertFile(path.resolve(buildDir, 'helper.js'));
64+
assertFile(path.resolve(buildDir, 'helper.js.map'));
65+
assertFile(path.resolve(buildDir, 'utils/another_helper.js'));
66+
assertFile(path.resolve(buildDir, 'utils/another_helper.js.map'));
67+
assertFile(path.resolve(buildDir, 'third_helper.js'));
68+
assertFile(path.resolve(buildDir, 'third_helper.js.map'));
69+
6570
assert.deepEqual(created, {
6671
html: true,
6772
}, 'created packages');
@@ -100,16 +105,12 @@ describe('hlx package (Integration)', () => {
100105

101106
it('package reports bundling errors and warnings', async () => {
102107
const logger = Logger.getTestLogger();
103-
await new BuildCommand()
104-
.withFiles([
105-
'test/integration/src/broken_html.pre.js',
106-
])
107-
.withTargetDir(buildDir)
108-
.run();
109-
110108
await new PackageCommand(logger)
111109
.withDirectory(testRoot)
112110
.withTarget(buildDir)
111+
.withFiles([
112+
'test/integration/src/broken_html.pre.js',
113+
])
113114
.withOnlyModified(true)
114115
.withMinify(false)
115116
.run();

0 commit comments

Comments
 (0)