Skip to content

Commit

Permalink
fix(ts-lint): add tslint-config-prettier so tslint doesn't clash with…
Browse files Browse the repository at this point in the history
… prettier
  • Loading branch information
Hotell committed Jun 17, 2017
1 parent baa63ba commit 10a8524
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 45 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -109,6 +109,7 @@
"strip-json-comments-cli": "1.0.1",
"ts-jest": "20.0.6",
"tslint": "5.4.3",
"tslint-config-prettier": "1.1.0",
"tslint-config-standard": "6.0.1",
"tslint-react": "3.0.0",
"typedoc": "0.7.1",
Expand Down
3 changes: 2 additions & 1 deletion tslint.json
@@ -1,7 +1,8 @@
{
"extends": [
"tslint-config-standard",
"tslint-react"
"tslint-react",
"tslint-config-prettier"
],
"rules": {
// tslint-react rules
Expand Down
85 changes: 41 additions & 44 deletions webpack.config.js
@@ -1,18 +1,16 @@
const { resolve } = require('path');
const webpack = require('webpack');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const { resolve } = require('path')
const webpack = require('webpack')
const UglifyJSPlugin = require('uglifyjs-webpack-plugin')

const packageJSON = require('./package.json')
const packageName = normalizePackageName(packageJSON.name)

const packageJSON = require('./package.json');
const packageName = normalizePackageName(packageJSON.name);


const LIB_NAME = pascalCase(packageName);
const LIB_NAME = pascalCase(packageName)
const PATHS = {
entryPoint: resolve(__dirname, 'src/index.ts'),
umd: resolve(__dirname, 'umd'),
fesm: resolve(__dirname, 'lib-fesm')
};
fesm: resolve(__dirname, 'lib-fesm'),
}

const EXTERNALS = {
// lodash: {
Expand All @@ -21,7 +19,7 @@ const EXTERNALS = {
// amd: "lodash",
// root: "_"
// }
};
}

const RULES = {
ts: {
Expand All @@ -36,9 +34,9 @@ const RULES = {
// map already include everything for debugging
// This cannot be set because -> Option 'declarationDir' cannot be specified without specifying option 'declaration'.
// declaration: false,
}
}
]
},
},
],
},
tsNext: {
test: /\.tsx?$/,
Expand All @@ -47,26 +45,25 @@ const RULES = {
{
loader: 'awesome-typescript-loader',
options: {
target: 'es2017'
}
}
]
}
};
target: 'es2017',
},
},
],
},
}

const PLUGINS = [
// enable scope hoisting
new webpack.optimize.ModuleConcatenationPlugin(),
// Apply minification only on the second bundle by using a RegEx on the name, which must end with `.min.js`
new UglifyJSPlugin({
sourceMap: true,
include: /\.min\.js$/
include: /\.min\.js$/,
}),
new webpack.LoaderOptionsPlugin({
minimize: true
})
];

minimize: true,
}),
]

const config = env => {
const UMDConfig = {
Expand All @@ -76,7 +73,7 @@ const config = env => {
// minification via UglifyJS
entry: {
[packageName]: [PATHS.entryPoint],
[`${packageName}.min`]: [PATHS.entryPoint]
[`${packageName}.min`]: [PATHS.entryPoint],
},
// The output defines how and where we want the bundles. The special
// value `[name]` in `filename` tell Webpack to use the name we defined above.
Expand All @@ -89,12 +86,12 @@ const config = env => {
library: LIB_NAME,
// libraryExport: UMD.libName,
// will name the AMD module of the UMD build. Otherwise an anonymous define is used.
umdNamedDefine: true
umdNamedDefine: true,
},
// Add resolve for `tsx` and `ts` files, otherwise Webpack would
// only look for common JavaScript file extension (.js)
resolve: {
extensions: ['.ts', '.tsx', '.js']
extensions: ['.ts', '.tsx', '.js'],
},
// add here all 3rd party libraries that you will use as peerDependncies
// https://webpack.js.org/guides/author-libraries/#add-externals
Expand All @@ -104,14 +101,14 @@ const config = env => {
devtool: 'source-map',
plugins: PLUGINS,
module: {
rules: [RULES.ts]
}
};
rules: [RULES.ts],
},
}

const FESMconfig = Object.assign({}, UMDConfig, {
entry: {
'index': [PATHS.entryPoint],
'index.min': [PATHS.entryPoint]
entry: {
index: [PATHS.entryPoint],
'index.min': [PATHS.entryPoint],
},
output: {
path: PATHS.fesm,
Expand All @@ -120,33 +117,33 @@ const config = env => {
module: {
rules: [RULES.tsNext],
},
});
})

return [UMDConfig, FESMconfig];
};
return [UMDConfig, FESMconfig]
}

module.exports = config;
module.exports = config

// helpers

function camelCaseToDash(myStr) {
return myStr.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
return myStr.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase()
}

function dashToCamelCase(myStr) {
return myStr.replace(/-([a-z])/g, g => g[1].toUpperCase());
return myStr.replace(/-([a-z])/g, g => g[1].toUpperCase())
}

function toUpperCase(myStr) {
return `${myStr.charAt(0).toUpperCase()}${myStr.substr(1)}`;
return `${myStr.charAt(0).toUpperCase()}${myStr.substr(1)}`
}

function pascalCase(myStr) {
return toUpperCase(dashToCamelCase(myStr));
return toUpperCase(dashToCamelCase(myStr))
}

function normalizePackageName(rawPackageName) {
const scopeEnd = rawPackageName.indexOf('/') + 1;
const scopeEnd = rawPackageName.indexOf('/') + 1

return rawPackageName.substring(scopeEnd);
return rawPackageName.substring(scopeEnd)
}
4 changes: 4 additions & 0 deletions yarn.lock
Expand Up @@ -4466,6 +4466,10 @@ tslib@^1.0.0, tslib@^1.7.1:
version "1.7.1"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.7.1.tgz#bc8004164691923a79fe8378bbeb3da2017538ec"

tslint-config-prettier@1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/tslint-config-prettier/-/tslint-config-prettier-1.1.0.tgz#40c026a56e4da27063b3e9bcd71f4f8109fee369"

tslint-config-standard@6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/tslint-config-standard/-/tslint-config-standard-6.0.1.tgz#a04ba0a794759e877287056f549b081e47a56d6c"
Expand Down

0 comments on commit 10a8524

Please sign in to comment.