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

expose netlify-lambda configuration option/parameter #3

Merged
merged 4 commits into from
Jan 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ module.exports = (api, projectOptions) => {
const {build, serve} = api.service.commands;
const buildFn = build.fn;
const serveFn = serve.fn;
const webpackConfig = projectOptions.pluginOptions && projectOptions.pluginOptions.netlify && projectOptions.pluginOptions.netlify.webpackConfig;

build.fn = (...args) => {
return buildFn(...args).then((res) => {
return lambdaBuild
.run("src/lambda")
.then(function(stats) {
console.log(stats.toString({ color: true }))
return res
})
.catch(function(err) {
console.error(err)
process.exit(1)
})
})
build.fn = async (...args) => {
try {
const [res, stats] = await Promise.all([
buildFn(...args),
lambdaBuild.run('src/lambda', webpackConfig),
]);
console.log(stats.toString({ color: true }));
return res;
} catch (err) {
console.error(err);
process.exit(1);
}
}

serve.fn = (...args) => {
Expand All @@ -34,7 +34,7 @@ module.exports = (api, projectOptions) => {
}
}

const forked = fork(path.join(__dirname, 'serve.js'))
fork(require.resolve('netlify-lambda'), ['serve', 'src/lambda', ...(webpackConfig ? ['-c', webpackConfig] : [])]);
return serveFn(...args)
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
},
"author": "Netlify",
"license": "MIT",
"repository": "netlify/vue-cli-plugin-netlify-lambda",
"dependencies": {
"netlify-lambda": "1.0.0-babel-7-beta"
}
Expand Down
16 changes: 0 additions & 16 deletions serve.js

This file was deleted.

40 changes: 40 additions & 0 deletions ui.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const fs = require('fs');
const path = require('path');

function getConfigData(data) {
return (data.vue && data.vue.pluginOptions && data.vue.pluginOptions.netlify) || {};
}

module.exports = api => api.describeConfig({
id: 'com.netlify.netlify-lambda',
name: 'Netlify configuration',
description: 'Configure Netlify Functions',
link: 'https://github.com/netlify/vue-cli-plugin-netlify-lambda',
files: {
vue: {
js: ['vue.config.js'],
},
},
onRead({ data, cwd }) {
return {
prompts: [
{
name: 'webpackConfig',
type: 'input',
default: null,
value: getConfigData(data).webpackConfig,
validate: input => fs.existsSync(path.join(cwd, input)),
message: 'Webpack config module',
description: 'Additional webpack configuration',
},
],
};
},
async onWrite({ api: writeApi, prompts }) {
const result = {};
for (const prompt of prompts) {
result[`pluginOptions.netlify.${prompt.id}`] = await writeApi.getAnswer(prompt.id);
}
writeApi.setData('vue', result);
},
});