Skip to content
This repository was archived by the owner on Sep 8, 2021. It is now read-only.

Commit 2218768

Browse files
authored
Merge pull request #3 from cruzdanilo/master
expose netlify-lambda configuration option/parameter
2 parents dd35efd + b4539d8 commit 2218768

File tree

4 files changed

+55
-30
lines changed

4 files changed

+55
-30
lines changed

Diff for: index.js

+14-14
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@ module.exports = (api, projectOptions) => {
66
const {build, serve} = api.service.commands;
77
const buildFn = build.fn;
88
const serveFn = serve.fn;
9+
const webpackConfig = projectOptions.pluginOptions && projectOptions.pluginOptions.netlify && projectOptions.pluginOptions.netlify.webpackConfig;
910

10-
build.fn = (...args) => {
11-
return buildFn(...args).then((res) => {
12-
return lambdaBuild
13-
.run("src/lambda")
14-
.then(function(stats) {
15-
console.log(stats.toString({ color: true }))
16-
return res
17-
})
18-
.catch(function(err) {
19-
console.error(err)
20-
process.exit(1)
21-
})
22-
})
11+
build.fn = async (...args) => {
12+
try {
13+
const [res, stats] = await Promise.all([
14+
buildFn(...args),
15+
lambdaBuild.run('src/lambda', webpackConfig),
16+
]);
17+
console.log(stats.toString({ color: true }));
18+
return res;
19+
} catch (err) {
20+
console.error(err);
21+
process.exit(1);
22+
}
2323
}
2424

2525
serve.fn = (...args) => {
@@ -34,7 +34,7 @@ module.exports = (api, projectOptions) => {
3434
}
3535
}
3636

37-
const forked = fork(path.join(__dirname, 'serve.js'))
37+
fork(require.resolve('netlify-lambda'), ['serve', 'src/lambda', ...(webpackConfig ? ['-c', webpackConfig] : [])]);
3838
return serveFn(...args)
3939
}
4040
}

Diff for: package.json

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
},
1919
"author": "Netlify",
2020
"license": "MIT",
21+
"repository": "netlify/vue-cli-plugin-netlify-lambda",
2122
"dependencies": {
2223
"@vue/cli": "^3.0.1",
2324
"@vue/cli-plugin-babel": "^3.0.1",

Diff for: serve.js

-16
This file was deleted.

Diff for: ui.js

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
4+
function getConfigData(data) {
5+
return (data.vue && data.vue.pluginOptions && data.vue.pluginOptions.netlify) || {};
6+
}
7+
8+
module.exports = api => api.describeConfig({
9+
id: 'com.netlify.netlify-lambda',
10+
name: 'Netlify configuration',
11+
description: 'Configure Netlify Functions',
12+
link: 'https://github.com/netlify/vue-cli-plugin-netlify-lambda',
13+
files: {
14+
vue: {
15+
js: ['vue.config.js'],
16+
},
17+
},
18+
onRead({ data, cwd }) {
19+
return {
20+
prompts: [
21+
{
22+
name: 'webpackConfig',
23+
type: 'input',
24+
default: null,
25+
value: getConfigData(data).webpackConfig,
26+
validate: input => fs.existsSync(path.join(cwd, input)),
27+
message: 'Webpack config module',
28+
description: 'Additional webpack configuration',
29+
},
30+
],
31+
};
32+
},
33+
async onWrite({ api: writeApi, prompts }) {
34+
const result = {};
35+
for (const prompt of prompts) {
36+
result[`pluginOptions.netlify.${prompt.id}`] = await writeApi.getAnswer(prompt.id);
37+
}
38+
writeApi.setData('vue', result);
39+
},
40+
});

0 commit comments

Comments
 (0)