Skip to content

Commit

Permalink
Merge pull request serverless-heaven#518 from takeshape/fix-eslint-pr…
Browse files Browse the repository at this point in the history
…ettier

Fix eslint prettier
  • Loading branch information
HyperBrain authored Jun 18, 2019
2 parents e6e158f + 9ba2b35 commit 2d45a80
Show file tree
Hide file tree
Showing 42 changed files with 3,063 additions and 1,584 deletions.
1 change: 0 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ extends:
- plugin:promise/recommended
- plugin:import/errors
- plugin:import/warnings
- prettier
parser: babel-eslint
parserOptions:
sourceType: module
Expand Down
2 changes: 1 addition & 1 deletion .huskyrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"hooks": {
"pre-commit": "lint-staged"
"pre-commit": "lint-staged && npm test"
}
}
5 changes: 2 additions & 3 deletions .lintstagedrc.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
linters:
"*.js":
- "eslint --fix" # Run TSLint
- "prettier --write" # Run Prettier
- "npm test" # Run tests
- "prettier-eslint --write" # Run Prettier
- "eslint" # Run TSLint
- "git add"
177 changes: 84 additions & 93 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const packageModules = require('./lib/packageModules');
const lib = require('./lib');

class ServerlessWebpack {

static get lib() {
return lib;
}
Expand All @@ -28,10 +27,10 @@ class ServerlessWebpack {

if (
(_.has(this.serverless, 'service.custom.webpack') &&
_.isString(this.serverless.service.custom.webpack) &&
_.endsWith(this.serverless.service.custom.webpack, '.ts')) ||
_.isString(this.serverless.service.custom.webpack) &&
_.endsWith(this.serverless.service.custom.webpack, '.ts')) ||
(_.has(this.serverless, 'service.custom.webpack.webpackConfig') &&
_.endsWith(this.serverless.service.custom.webpack.webpackConfig, '.ts'))
_.endsWith(this.serverless.service.custom.webpack.webpackConfig, '.ts'))
) {
require('ts-node/register');
}
Expand All @@ -54,139 +53,131 @@ class ServerlessWebpack {
this.commands = {
webpack: {
usage: 'Bundle with Webpack',
lifecycleEvents: [
'webpack'
],
lifecycleEvents: ['webpack'],
options: {
out: {
usage: 'Path to output directory',
shortcut: 'o',
},
shortcut: 'o'
}
},
commands: {
validate: {
type: 'entrypoint',
lifecycleEvents: [
'validate',
],
lifecycleEvents: ['validate']
},
compile: {
type: 'entrypoint',
lifecycleEvents: [
'compile',
],
lifecycleEvents: ['compile'],
commands: {
watch: {
type: 'entrypoint',
lifecycleEvents: [
'compile'
]
lifecycleEvents: ['compile']
}
}
},
package: {
type: 'entrypoint',
lifecycleEvents: [
'packExternalModules',
'packageModules'
],
},
},
},
lifecycleEvents: [ 'packExternalModules', 'packageModules' ]
}
}
}
};

this.hooks = {
'before:package:createDeploymentArtifacts': () => BbPromise.bind(this)
.then(() => this.serverless.pluginManager.spawn('webpack:validate'))
.then(() => this.serverless.pluginManager.spawn('webpack:compile'))
.then(() => this.serverless.pluginManager.spawn('webpack:package')),

'after:package:createDeploymentArtifacts': () => BbPromise.bind(this)
.then(this.cleanup),

'before:deploy:function:packageFunction': () => BbPromise.bind(this)
.then(() => this.serverless.pluginManager.spawn('webpack:validate'))
.then(() => this.serverless.pluginManager.spawn('webpack:compile'))
.then(() => this.serverless.pluginManager.spawn('webpack:package')),

'before:invoke:local:invoke': () => BbPromise.bind(this)
.then(() => {
lib.webpack.isLocal = true;
// --no-build override
if (this.options.build === false) {
this.skipCompile = true;
}
'before:package:createDeploymentArtifacts': () =>
BbPromise.bind(this)
.then(() => this.serverless.pluginManager.spawn('webpack:validate'))
.then(() => this.serverless.pluginManager.spawn('webpack:compile'))
.then(() => this.serverless.pluginManager.spawn('webpack:package')),

'after:package:createDeploymentArtifacts': () => BbPromise.bind(this).then(this.cleanup),

'before:deploy:function:packageFunction': () =>
BbPromise.bind(this)
.then(() => this.serverless.pluginManager.spawn('webpack:validate'))
.then(() => this.serverless.pluginManager.spawn('webpack:compile'))
.then(() => this.serverless.pluginManager.spawn('webpack:package')),

'before:invoke:local:invoke': () =>
BbPromise.bind(this)
.then(() => {
lib.webpack.isLocal = true;
// --no-build override
if (this.options.build === false) {
this.skipCompile = true;
}

return this.serverless.pluginManager.spawn('webpack:validate');
})
.then(() => this.skipCompile ? BbPromise.resolve() : this.serverless.pluginManager.spawn('webpack:compile'))
.then(this.prepareLocalInvoke),
return this.serverless.pluginManager.spawn('webpack:validate');
})
.then(() => (this.skipCompile ? BbPromise.resolve() : this.serverless.pluginManager.spawn('webpack:compile')))
.then(this.prepareLocalInvoke),

'after:invoke:local:invoke': () => BbPromise.bind(this)
.then(() => {
'after:invoke:local:invoke': () =>
BbPromise.bind(this).then(() => {
if (this.options.watch && !this.isWatching) {
return this.watch('invoke:local');
}
return BbPromise.resolve();
}),

'before:run:run': () => BbPromise.bind(this)
.then(() => _.set(this.serverless, 'service.package.individually', false))
.then(() => this.serverless.pluginManager.spawn('webpack:validate'))
.then(() => this.serverless.pluginManager.spawn('webpack:compile'))
.then(this.packExternalModules)
.then(this.prepareRun),
'before:run:run': () =>
BbPromise.bind(this)
.then(() => _.set(this.serverless, 'service.package.individually', false))
.then(() => this.serverless.pluginManager.spawn('webpack:validate'))
.then(() => this.serverless.pluginManager.spawn('webpack:compile'))
.then(this.packExternalModules)
.then(this.prepareRun),

'after:run:run': () => BbPromise.bind(this)
.then(() => {
'after:run:run': () =>
BbPromise.bind(this).then(() => {
if (this.options.watch && !this.isWatching) {
return this.watch(this.watchRun.bind(this));
}
return BbPromise.resolve();
}),

'webpack:webpack': () => BbPromise.bind(this)
.then(() => this.serverless.pluginManager.spawn('webpack:validate'))
.then(() => this.serverless.pluginManager.spawn('webpack:compile'))
.then(() => this.serverless.pluginManager.spawn('webpack:package')),
'webpack:webpack': () =>
BbPromise.bind(this)
.then(() => this.serverless.pluginManager.spawn('webpack:validate'))
.then(() => this.serverless.pluginManager.spawn('webpack:compile'))
.then(() => this.serverless.pluginManager.spawn('webpack:package')),

/*
* Internal webpack events (can be hooked by plugins)
*/
'webpack:validate:validate': () => BbPromise.bind(this)
.then(this.validate),
'webpack:validate:validate': () => BbPromise.bind(this).then(this.validate),

'webpack:compile:compile': () => BbPromise.bind(this)
.then(this.compile),
'webpack:compile:compile': () => BbPromise.bind(this).then(this.compile),

'webpack:compile:watch:compile': () => BbPromise.resolve(),

'webpack:package:packExternalModules': () => BbPromise.bind(this)
.then(this.packExternalModules),

'webpack:package:packageModules': () => BbPromise.bind(this)
.then(this.packageModules),

'before:offline:start': () => BbPromise.bind(this)
.tap(() => {
lib.webpack.isLocal = true;
})
.then(this.prepareOfflineInvoke)
.then(this.wpwatch),

'before:offline:start:init': () => BbPromise.bind(this)
.tap(() => {
lib.webpack.isLocal = true;
})
.then(this.prepareOfflineInvoke)
.then(this.wpwatch),

'before:step-functions-offline:start': () => BbPromise.bind(this)
.tap(() => {
lib.webpack.isLocal = true;
})
.then(this.prepareStepOfflineInvoke)
.then(() => this.serverless.pluginManager.spawn('webpack:compile')),
'webpack:package:packExternalModules': () => BbPromise.bind(this).then(this.packExternalModules),

'webpack:package:packageModules': () => BbPromise.bind(this).then(this.packageModules),

'before:offline:start': () =>
BbPromise.bind(this)
.tap(() => {
lib.webpack.isLocal = true;
})
.then(this.prepareOfflineInvoke)
.then(this.wpwatch),

'before:offline:start:init': () =>
BbPromise.bind(this)
.tap(() => {
lib.webpack.isLocal = true;
})
.then(this.prepareOfflineInvoke)
.then(this.wpwatch),

'before:step-functions-offline:start': () =>
BbPromise.bind(this)
.tap(() => {
lib.webpack.isLocal = true;
})
.then(this.prepareStepOfflineInvoke)
.then(() => this.serverless.pluginManager.spawn('webpack:compile'))
};
}
}
Expand Down
Loading

0 comments on commit 2d45a80

Please sign in to comment.