Skip to content

Commit

Permalink
Add jest support for webstorm IDE, reformat all code using our own rules
Browse files Browse the repository at this point in the history
  • Loading branch information
Vadorequest committed Aug 29, 2019
1 parent 63abf82 commit 54f5aba
Show file tree
Hide file tree
Showing 16 changed files with 399 additions and 141 deletions.
110 changes: 108 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,109 @@
coverage
# Created by https://www.gitignore.io/api/webstorm

### WebStorm ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/modules.xml
# .idea/*.iml
# .idea/modules

# CMake
cmake-build-*/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

### WebStorm Patch ###
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721

# *.iml
# modules.xml
# .idea/misc.xml
# *.ipr

# Sonarlint plugin
.idea/sonarlint


# End of https://www.gitignore.io/api/webstorm

######################### CUSTOM/MANUAL #############################

# See https://help.github.com/ignore-files/ for more about ignoring files.

# IDE plugins
.idea/markdown-navigator*/**

# package directories
node_modules
*.log
jspm_packages

# Serverless directories
.serverless
.webpack
.next
dist

.DS_Store
.sls-simulate-registry

# Builds
build
.firebase
coverage/

# Sensitive values, do not share (staging is fine, development is for personal use)
.env.production
!.env

# Epsagon generated files
epsagon_handlers/
2 changes: 2 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

101 changes: 101 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/jsLibraryMappings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions .idea/serverless-env-copy-plugin.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 34 additions & 34 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,67 +1,67 @@
'use strict'
'use strict';

const fs = require('fs')
const mkdirp = require('mkdirp')
const path = require('path')
const fs = require('fs');
const mkdirp = require('mkdirp');
const path = require('path');

const collectFunctionEnvVariables = require('./lib/collectFunctionEnvVariables.js')
const collectOfflineEnvVariables = require('./lib/collectOfflineEnvVariables.js')
const transformEnvVarsToString = require('./lib/transformEnvVarsToString.js')
const collectFunctionEnvVariables = require('./lib/collectFunctionEnvVariables.js');
const collectOfflineEnvVariables = require('./lib/collectOfflineEnvVariables.js');
const transformEnvVarsToString = require('./lib/transformEnvVarsToString.js');

class ServerlessDotenvPlugin {
constructor (serverless, options) {
this.serverless = serverless
this.options = options
constructor(serverless, options) {
this.serverless = serverless;
this.options = options;

this.commands = {
dotenv: {
usage: 'Create .env file with serverless environment variables',
lifecycleEvents: [
'dotenvHandler'
]
}
}
'dotenvHandler',
],
},
};

this.hooks = {
'before:offline:start:init': this.initOfflineHook.bind(this),
'before:offline:start': this.initOfflineHook.bind(this),
'dotenv:dotenvHandler': this.dotenvHandler.bind(this)
}
'dotenv:dotenvHandler': this.dotenvHandler.bind(this),
};

this.environmentVariables = {}
this.environmentVariables = {};
}

initOfflineHook () {
this.IS_HOOKED = true
initOfflineHook() {
this.IS_HOOKED = true;

this.serverless.pluginManager.run(['dotenv'])
this.serverless.pluginManager.run(['dotenv']);
}

dotenvHandler () {
this.serverless.cli.log('Creating .env file...')
dotenvHandler() {
this.serverless.cli.log('Creating .env file...');

// collect global environment variables
const globalEnvironment = this.serverless.service.provider.environment
this.environmentVariables = Object.assign(this.environmentVariables, globalEnvironment)
const globalEnvironment = this.serverless.service.provider.environment;
this.environmentVariables = Object.assign(this.environmentVariables, globalEnvironment);

// collect environment variables of functions
const functionEnvironment = collectFunctionEnvVariables(this.serverless)
this.environmentVariables = Object.assign(this.environmentVariables, functionEnvironment)
const functionEnvironment = collectFunctionEnvVariables(this.serverless);
this.environmentVariables = Object.assign(this.environmentVariables, functionEnvironment);

// collect environment variables for serverless offline
if (this.IS_HOOKED) {
const offlineEnvVars = collectOfflineEnvVariables(this.serverless, this.options)
this.environmentVariables = Object.assign(this.environmentVariables, offlineEnvVars)
const offlineEnvVars = collectOfflineEnvVariables(this.serverless, this.options);
this.environmentVariables = Object.assign(this.environmentVariables, offlineEnvVars);
}

// write .env file
const dotEnvPath = path.join(this.serverless.config.servicePath, '.serverless')
const dotEnvFile = path.join(this.serverless.config.servicePath, '.serverless/.env')
const dotEnvDocument = transformEnvVarsToString(this.environmentVariables)
const dotEnvPath = path.join(this.serverless.config.servicePath, '.serverless');
const dotEnvFile = path.join(this.serverless.config.servicePath, '.serverless/.env');
const dotEnvDocument = transformEnvVarsToString(this.environmentVariables);

mkdirp.sync(dotEnvPath)
fs.writeFileSync(dotEnvFile, dotEnvDocument)
mkdirp.sync(dotEnvPath);
fs.writeFileSync(dotEnvFile, dotEnvDocument);
}
}

module.exports = ServerlessDotenvPlugin
module.exports = ServerlessDotenvPlugin;
Loading

0 comments on commit 54f5aba

Please sign in to comment.