Skip to content

Commit

Permalink
chore: update tooling
Browse files Browse the repository at this point in the history
BREAKING CHANGE: support for node 8 was dropped
  • Loading branch information
erezrokah committed Jul 13, 2020
1 parent 4f05353 commit d9608a2
Show file tree
Hide file tree
Showing 17 changed files with 12,594 additions and 235 deletions.
16 changes: 16 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
env: {
commonjs: true,
es6: true,
node: true,
jest: true,
},
extends: 'eslint:recommended',
globals: {
Atomics: 'readonly',
SharedArrayBuffer: 'readonly',
},
parserOptions: {
ecmaVersion: 11,
},
};
46 changes: 46 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Node CI

on:
push:
branches:
- master
tags:
- '*'

pull_request:
types: [opened, synchronize, reopened]

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]
node-version: [10.x, 12.x, 13.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Get npm cache directory
id: npm-cache
run: |
echo "::set-output name=dir::$(npm config get cache)"
- uses: actions/cache@v2
with:
path: ${{ steps.npm-cache.outputs.dir }}
key: ${{ runner.os }}-node-${{ matrix.node-version }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-${{ matrix.node-version }}-
- name: log versions
run: node --version && npm --version && yarn --version
- name: install dependencies
run: npm ci
- name: run linter
run: npm run lint
- name: check formatting
run: yarn format:ci
- name: run tests
run: npm test
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
node_modules/
.vscode/
*.swp
package-lock.json
.temp
16 changes: 15 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
{}
{
"printWidth": 80,
"tabWidth": 2,
"semi": true,
"singleQuote": true,
"trailingComma": "all",
"useTabs": false,
"overrides": [
{
"files": "*.json",
"options": { "printWidth": 200 }
}
]
}

80 changes: 40 additions & 40 deletions bin/cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,61 +4,61 @@
* Module dependencies.
*/

var program = require("commander");
var fs = require("fs");
var path = require("path");
var program = require('commander');
var fs = require('fs');
var path = require('path');
var pkg = JSON.parse(
fs.readFileSync(path.join(__dirname, "..", "package.json"))
fs.readFileSync(path.join(__dirname, '..', 'package.json')),
);
var build = require("../lib/build");
var serve = require("../lib/serve");
var install = require("../lib/install");
var build = require('../lib/build');
var serve = require('../lib/serve');
var install = require('../lib/install');

program.version(pkg.version);

const stringBooleanToBoolean = val => {
const stringBooleanToBoolean = (val) => {
console.log({ val });
if (typeof val !== "string" && (val !== "true" || val !== "false")) {
if (typeof val !== 'string' && (val !== 'true' || val !== 'false')) {
throw Error(`Incorrect string value: ${val}`);
}

return val === "true";
return val === 'true';
};

program
.option("-c --config <webpack-config>", "additional webpack configuration")
.option("-p --port <port>", "port to serve from (default: 9000)")
.option('-c --config <webpack-config>', 'additional webpack configuration')
.option('-p --port <port>', 'port to serve from (default: 9000)')
.option(
"-b --babelrc <babelrc>",
"use .babelrc in root (default: true)",
stringBooleanToBoolean
'-b --babelrc <babelrc>',
'use .babelrc in root (default: true)',
stringBooleanToBoolean,
)
.option(
"-t --timeout <timeout>",
"function invocation timeout in seconds (default: 10)"
'-t --timeout <timeout>',
'function invocation timeout in seconds (default: 10)',
)
.option("-s --static", "serve pre-built lambda files");
.option('-s --static', 'serve pre-built lambda files');

program
.command("serve <dir>")
.description("serve and watch functions")
.action(function(cmd, options) {
console.log("netlify-lambda: Starting server");
.command('serve <dir>')
.description('serve and watch functions')
.action(function (cmd) {
console.log('netlify-lambda: Starting server');
var static = Boolean(program.static);
var server;
var startServer = function() {
var startServer = function () {
server = serve.listen(
program.port || 9000,
static,
Number(program.timeout) || 10
Number(program.timeout) || 10,
);
};
if (static) {
startServer();
return; // early terminate, don't build
}
const { config: userWebpackConfig, babelrc: useBabelrc = true } = program;
build.watch(cmd, { userWebpackConfig, useBabelrc }, function(err, stats) {
build.watch(cmd, { userWebpackConfig, useBabelrc }, function (err, stats) {
if (err) {
console.error(err);
return;
Expand All @@ -67,47 +67,47 @@ program
if (!server) {
startServer();
}
stats.compilation.chunks.forEach(function(chunk) {
stats.compilation.chunks.forEach(function (chunk) {
server.clearCache(chunk.name || chunk.id.toString());
});
});
});

program
.command("build <dir>")
.description("build functions")
.action(function(cmd, options) {
console.log("netlify-lambda: Building functions");
.command('build <dir>')
.description('build functions')
.action(function (cmd) {
console.log('netlify-lambda: Building functions');

const { config: userWebpackConfig, babelrc: useBabelrc = true } = program;
build
.run(cmd, { userWebpackConfig, useBabelrc })
.then(function(stats) {
.then(function (stats) {
console.log(stats.toString(stats.compilation.options.stats));
})
.catch(function(err) {
.catch(function (err) {
console.error(err);
process.exit(1);
});
});

program
.command("install [dir]")
.description("install functions")
.action(function(cmd, options) {
console.log("netlify-lambda: installing function dependencies");
install.run(cmd).catch(function(err) {
.command('install [dir]')
.description('install functions')
.action(function (cmd) {
console.log('netlify-lambda: installing function dependencies');
install.run(cmd).catch(function (err) {
console.error(err);
process.exit(1);
});
});

// error on unknown commands
// ref: https://github.com/tj/commander.js#custom-event-listeners
program.on("command:*", function() {
program.on('command:*', function () {
console.error(
"Invalid command: %s\nSee --help for a list of available commands.",
program.args.join(" ")
'Invalid command: %s\nSee --help for a list of available commands.',
program.args.join(' '),
);
process.exit(1);
});
Expand Down
1 change: 1 addition & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = { extends: ['@commitlint/config-conventional'] };
Loading

0 comments on commit d9608a2

Please sign in to comment.