Skip to content

Commit 8a6315c

Browse files
committed
Full netlify cli integration
1 parent 674f714 commit 8a6315c

File tree

3 files changed

+91
-5
lines changed

3 files changed

+91
-5
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,15 @@ Add plugin config to your `config/deploy.js`:
2828
}
2929
```
3030

31-
Optionaly set revision type to `version-commit` to have unified versioning pattern:
31+
Extra config:
32+
33+
- `promoteToProd` (DEFAULT: `true`) - Promote deploy to production
34+
- `functionsDir` - (DEFAULT: `''`) - Specify a functions folder to deploy
35+
- `destDir` (DEFAULT: ember dist) - Specify a folder to deploy
36+
37+
_____
38+
39+
Optionally you can set revision type to `version-commit` to have unified versioning pattern:
3240
```js
3341
{
3442
'revision-data': {

index.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ module.exports = {
1111
name: options.name,
1212

1313
defaultConfig: {
14+
promoteToProd: true,
15+
16+
functionsDir: '',
17+
1418
distDir(context) {
1519
return context.distDir;
1620
},
@@ -25,21 +29,29 @@ module.exports = {
2529
upload() {
2630
const message = this.readConfig('revisionKey');
2731
const distDir = this.readConfig('distDir');
32+
const promoteToProd = this.readConfig('promoteToProd');
33+
const functionsDir = this.readConfig('functionsDir');
2834

29-
this.log('NETLIFY: Deploying...');
30-
this.cliExec(`deploy --prod --dir ${distDir} --message "${message}"`);
35+
const commandOptions = [
36+
promoteToProd ? '--prod' : '',
37+
distDir ? `--dir ${distDir}` : '',
38+
functionsDir ? `--functions ${functionsDir}` : '',
39+
message ? `--message "${message}"` : ''
40+
].filter((option) => option);
3141

42+
this.log('NETLIFY: Deploying...');
43+
this.cliExec('deploy', commandOptions);
3244
this.log('NETLIFY: Deployed!...');
3345
},
3446

35-
cliExec(command) {
47+
cliExec(command, commandOptions = []) {
3648
const authToken = this.readConfig('authToken');
3749
const siteId = this.readConfig('siteId');
3850

3951
return this._exec(
4052
`NETLIFY_AUTH_TOKEN=${authToken} ` +
4153
`NETLIFY_SITE_ID=${siteId} ` +
42-
`node_modules/.bin/netlify ${command}`
54+
`node_modules/.bin/netlify ${command} ${commandOptions.join(' ')}`
4355
);
4456
},
4557

tests/unit/index-nodetest.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,24 @@ describe('netlify-cli', function() {
9696
assert.equal(plugin.readConfig('distDir'), 'my-dist-dir');
9797
});
9898

99+
it('functionsDir', 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('functionsDir'), '');
106+
});
107+
108+
it('promoteToProd', function() {
109+
const plugin = Plugin.createDeployPlugin({ name: 'netlify-cli' });
110+
111+
plugin.beforeHook(this.context);
112+
plugin.configure(this.context);
113+
114+
assert.equal(plugin.readConfig('promoteToProd'), true);
115+
});
116+
99117
it('revisionKey', function() {
100118
const plugin = Plugin.createDeployPlugin({ name: 'netlify-cli' });
101119

@@ -121,5 +139,53 @@ describe('netlify-cli', function() {
121139
'NETLIFY_SITE_ID=my-project ' +
122140
'node_modules/.bin/netlify deploy --prod --dir my-dist-dir --message "v1.0.0+1234567"');
123141
});
142+
143+
it('deploys to netlify with functions', function() {
144+
const plugin = Plugin.createDeployPlugin({ name: 'netlify-cli' });
145+
const stub = this.sinon.stub(plugin, '_exec');
146+
const context = {
147+
...this.context,
148+
149+
config: {
150+
'netlify-cli': {
151+
...this.context.config['netlify-cli'],
152+
functionsDir: 'my-functions-dir'
153+
}
154+
}
155+
};
156+
157+
plugin.beforeHook(context);
158+
plugin.configure(context);
159+
plugin.upload();
160+
161+
this.sinon.assert.calledWithExactly(stub,
162+
'NETLIFY_AUTH_TOKEN=my-auth-token ' +
163+
'NETLIFY_SITE_ID=my-project ' +
164+
'node_modules/.bin/netlify deploy --prod --dir my-dist-dir --functions my-functions-dir --message "v1.0.0+1234567"');
165+
});
166+
167+
it('deploys to netlify without promoting to prod', function() {
168+
const plugin = Plugin.createDeployPlugin({ name: 'netlify-cli' });
169+
const stub = this.sinon.stub(plugin, '_exec');
170+
const context = {
171+
...this.context,
172+
173+
config: {
174+
'netlify-cli': {
175+
...this.context.config['netlify-cli'],
176+
promoteToProd: false
177+
}
178+
}
179+
};
180+
181+
plugin.beforeHook(context);
182+
plugin.configure(context);
183+
plugin.upload();
184+
185+
this.sinon.assert.calledWithExactly(stub,
186+
'NETLIFY_AUTH_TOKEN=my-auth-token ' +
187+
'NETLIFY_SITE_ID=my-project ' +
188+
'node_modules/.bin/netlify deploy --dir my-dist-dir --message "v1.0.0+1234567"');
189+
});
124190
});
125191
});

0 commit comments

Comments
 (0)