Skip to content

Commit 848255a

Browse files
committed
Netlify
1 parent e8cffd2 commit 848255a

File tree

3 files changed

+107
-8
lines changed

3 files changed

+107
-8
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# ember-cli-deploy-netlify-cli
22

3-
Integrate your deploy pipeline with netlify.
3+
Integrate your deploy pipeline with netlify manual deploys using netlify-cli.
44

55

66
# Compatibility

index.js

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
/* eslint-disable max-len, max-lines-per-function */
21
'use strict';
32

3+
const { execSync } = require('child_process');
44
const BasePlugin = require('ember-cli-deploy-plugin');
55

66
module.exports = {
@@ -11,17 +11,40 @@ module.exports = {
1111
name: options.name,
1212

1313
defaultConfig: {
14+
distDir(context) {
15+
return context.distDir;
16+
},
17+
18+
revisionKey(context) {
19+
return context.revisionData && context.revisionData.revisionKey;
20+
}
1421
},
1522

16-
requiredConfig: [],
23+
requiredConfig: ['siteId', 'authToken'],
24+
25+
upload() {
26+
const message = this.readConfig('revisionKey');
27+
const distDir = this.readConfig('distDir');
1728

18-
didPrepare() {
29+
this.log('NETLIFY: Deploying...');
30+
this.cliExec(`deploy --prod --dir ${distDir} --message ${message}`);
31+
32+
this.log('NETLIFY: Deployed!...');
1933
},
2034

21-
didDeploy() {
35+
cliExec(command) {
36+
const authToken = this.readConfig('authToken');
37+
const siteId = this.readConfig('siteId');
38+
39+
return this._exec(
40+
`NETLIFY_AUTH_TOKEN=${authToken} ` +
41+
`NETLIFY_SITE_ID=${siteId} ` +
42+
`node_modules/.bin/netlify ${command}`
43+
);
2244
},
2345

24-
didFail() {
46+
_exec(command = '') {
47+
return execSync(command, { cwd: this.project.root });
2548
}
2649
});
2750

tests/unit/index-nodetest.js

Lines changed: 78 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,91 @@ describe('netlify-cli', function() {
3535
this.context = {
3636
ui: mockUi,
3737
project: stubProject,
38-
distDir: 'my-dest-dir',
38+
distDir: 'my-dist-dir',
3939
revisionData: {
40-
revisionKey: 'v1.0.0@1234567'
40+
revisionKey: 'v1.0.0+1234567'
4141
},
4242
deployTarget: 'my-production',
4343
config: {
4444
'netlify-cli': {
45+
siteId: 'my-project',
46+
authToken: 'my-auth-token'
4547
}
4648
}
4749
};
4850
});
51+
52+
it('has a name', function() {
53+
const plugin = Plugin.createDeployPlugin({ name: 'netlify-cli' });
54+
55+
assert.equal(plugin.name, 'netlify-cli');
56+
});
57+
58+
describe('implements correct hooks', function() {
59+
it('upload', function() {
60+
const plugin = Plugin.createDeployPlugin({ name: 'netlify-cli' });
61+
62+
assert.equal(typeof plugin.upload, 'function', 'Implements didPrepare');
63+
});
64+
});
65+
66+
describe('configure', function() {
67+
describe('requires config', function() {
68+
it('siteId', function() {
69+
const plugin = Plugin.createDeployPlugin({ name: 'netlify-cli' });
70+
71+
this.context.config['netlify-cli'].siteId = undefined;
72+
73+
plugin.beforeHook(this.context);
74+
75+
assert.throws(() => plugin.configure(this.context), 'Missing required config: `siteId`');
76+
});
77+
78+
it('authToken', function() {
79+
const plugin = Plugin.createDeployPlugin({ name: 'netlify-cli' });
80+
81+
this.context.config['netlify-cli'].authToken = undefined;
82+
83+
plugin.beforeHook(this.context);
84+
85+
assert.throws(() => plugin.configure(this.context), 'Missing required config: `authToken`');
86+
});
87+
});
88+
89+
describe('has default config', function() {
90+
it('distDir', function() {
91+
const plugin = Plugin.createDeployPlugin({ name: 'netlify-cli' });
92+
93+
plugin.beforeHook(this.context);
94+
plugin.configure(this.context);
95+
96+
assert.equal(plugin.readConfig('distDir'), 'my-dist-dir');
97+
});
98+
99+
it('revisionKey', function() {
100+
const plugin = Plugin.createDeployPlugin({ name: 'netlify-cli' });
101+
102+
plugin.beforeHook(this.context);
103+
plugin.configure(this.context);
104+
105+
assert.equal(plugin.readConfig('revisionKey'), 'v1.0.0+1234567');
106+
});
107+
});
108+
});
109+
110+
describe('upload', function() {
111+
it('deploys to netlify', function() {
112+
const plugin = Plugin.createDeployPlugin({ name: 'netlify-cli' });
113+
const stub = this.sinon.stub(plugin, '_exec');
114+
115+
plugin.beforeHook(this.context);
116+
plugin.configure(this.context);
117+
plugin.upload();
118+
119+
this.sinon.assert.calledWithExactly(stub,
120+
'NETLIFY_AUTH_TOKEN=my-auth-token ' +
121+
'NETLIFY_SITE_ID=my-project ' +
122+
'node_modules/.bin/netlify deploy --prod --dir my-dist-dir --message v1.0.0+1234567');
123+
});
124+
});
49125
});

0 commit comments

Comments
 (0)