Skip to content

Commit 3322075

Browse files
committed
Switch to Node 4
Fixes #75
1 parent 4e0b75f commit 3322075

13 files changed

+343
-348
lines changed

.eslintrc

+3-7
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,9 @@
1919
"one-var": [2, { "uninitialized": "always", "initialized": "never" }],
2020
"space-before-function-paren": 0,
2121
"vars-on-top": 0,
22+
"arrow-parens": 0,
23+
"strict": 0,
2224

23-
"import/no-dynamic-require": 0,
24-
25-
// Disable until using node 4 as base
26-
"no-var": 0,
27-
"prefer-arrow-callback": 0,
28-
"object-shorthand": 0,
29-
"prefer-template": 0
25+
"import/no-dynamic-require": 0
3026
}
3127
}

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ language: node_js
22
sudo: required
33
node_js:
44
- "4"
5-
- "5"
65
- "6"
6+
- "stable"
77
addons:
88
apt:
99
packages:

appveyor.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
environment:
44
matrix:
5+
- nodejs_version: 7
56
- nodejs_version: 6
6-
- nodejs_version: 5
77
- nodejs_version: 4
88

99
version: "{build}"

bin/suitcss

+40-38
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
#!/usr/bin/env node
22

3-
var fs = require('fs-extra');
4-
var assign = require('object-assign-deep');
5-
var logger = require('./logger');
6-
var suitcss = require('..');
7-
var path = require('path');
8-
var program = require('commander');
9-
var read = require('read-file-stdin');
10-
var chokidar = require('chokidar');
11-
12-
var exists = fs.existsSync;
13-
var resolve = path.resolve;
14-
var writeFileSync = fs.outputFileSync;
3+
'use strict';
4+
5+
const fs = require('fs-extra');
6+
const assign = require('object-assign-deep');
7+
const logger = require('./logger');
8+
const suitcss = require('..');
9+
const path = require('path');
10+
const program = require('commander');
11+
const read = require('read-file-stdin');
12+
const chokidar = require('chokidar');
13+
14+
const exists = fs.existsSync;
15+
const resolve = path.resolve;
16+
const writeFileSync = fs.outputFileSync;
1517

1618
/**
1719
* Usage.
@@ -34,7 +36,7 @@ program
3436
* Examples.
3537
*/
3638

37-
program.on('--help', function() {
39+
program.on('--help', () => {
3840
console.log(' Examples:');
3941
console.log();
4042
console.log(' # pass an input and output file:');
@@ -65,17 +67,17 @@ program.parse(process.argv);
6567
*/
6668

6769
function requireOrParse(configFile) {
68-
var configPath = resolve(configFile);
69-
var ext = path.extname(configPath);
70-
var readFn = /js|json/.test(ext) ? require : fs.readJsonSync;
70+
const configPath = resolve(configFile);
71+
const ext = path.extname(configPath);
72+
const readFn = /js|json/.test(ext) ? require : fs.readJsonSync;
7173
return readFn(configPath);
7274
}
7375

74-
var input = program.args[0] ? resolve(program.args[0]) : null;
75-
var output = program.args[1] ? resolve(program.args[1]) : null;
76-
var config = program.config ? requireOrParse(program.config) : {};
77-
var verbose = program.verbose;
78-
var regen = program.watch && input && output;
76+
const input = program.args[0] ? resolve(program.args[0]) : null;
77+
const output = program.args[1] ? resolve(program.args[1]) : null;
78+
const config = program.config ? requireOrParse(program.config) : {};
79+
const verbose = program.verbose;
80+
const regen = program.watch && input && output;
7981

8082
/**
8183
* Exists?
@@ -93,18 +95,18 @@ run();
9395
* Watch
9496
*/
9597

96-
var currentWatchedFiles;
98+
let currentWatchedFiles;
9799
if (regen) {
98-
var watcher = chokidar.watch(input);
100+
const watcher = chokidar.watch(input);
99101
watcher.on('change', run);
100-
watcher.on('change', function(file) {
101-
if (verbose) logger.log(path.basename(file) + ' changed');
102+
watcher.on('change', file => {
103+
if (verbose) logger.log(`${path.basename(file)} changed`);
102104
});
103-
watcher.on('ready', function() {
104-
if (verbose) logger.log('Watching ' + path.basename(input));
105+
watcher.on('ready', () => {
106+
if (verbose) logger.log(`Watching ${path.basename(input)}`);
105107
});
106108

107-
global.watchCSS = function(imported) {
109+
global.watchCSS = imported => {
108110
watcher.unwatch(currentWatchedFiles);
109111
watcher.add(imported);
110112
currentWatchedFiles = imported;
@@ -115,25 +117,25 @@ if (regen) {
115117
* Run for the given input and output.
116118
*/
117119
function run() {
118-
read(input, function(err, buffer) {
120+
read(input, (err, buffer) => {
119121
if (err) logger.throw(err);
120-
var css = buffer.toString();
121-
var optsAliases = {
122+
const css = buffer.toString();
123+
const optsAliases = {
122124
importRoot: 'root'
123125
};
124-
var flags = [
126+
const flags = [
125127
'minify',
126128
'encapsulate',
127129
'importRoot',
128130
'lint'
129-
].reduce(function(acc, inFlag) {
131+
].reduce((acc, inFlag) => {
130132
if (({}).hasOwnProperty.call(program, inFlag)) {
131-
var flag = optsAliases[inFlag] || inFlag;
133+
const flag = optsAliases[inFlag] || inFlag;
132134
acc[flag] = program[inFlag];
133135
}
134136
return acc;
135137
}, {});
136-
var opts = assign({}, config, flags);
138+
const opts = assign({}, config, flags);
137139

138140
if (program.throwError) {
139141
assign(opts, {
@@ -143,14 +145,14 @@ function run() {
143145
});
144146
}
145147

146-
suitcss(css, opts, input).then(function(result) {
148+
suitcss(css, opts, input).then(result => {
147149
if (output) {
148-
writeFileSync(output, result.css + '\n');
150+
writeFileSync(output, `${result.css}\n`);
149151
} else {
150152
console.log(result.css);
151153
}
152154
if (verbose && output) logger.log('write', output);
153-
}).catch(function(e) {
155+
}).catch(e => {
154156
logger.throw(e);
155157
});
156158
});

lib/encapsulation.js

+11-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
'use strict';
2+
13
/* eslint-disable quote-props */
2-
var autoreset = require('postcss-autoreset');
4+
const autoreset = require('postcss-autoreset');
35

4-
var rules = {
6+
const rules = {
57
inherited: {
68
'border-collapse': 'separate',
79
'border-spacing': 0,
@@ -101,10 +103,10 @@ var rules = {
101103
// This applies only to the Component Root
102104
// to stop inheritance and ensure
103105
// styles encapsulation
104-
var resetInherited = autoreset({
106+
const resetInherited = autoreset({
105107
reset: rules.inherited,
106-
rulesMatcher: function (rule) {
107-
var selector = rule.selector;
108+
rulesMatcher(rule) {
109+
const selector = rule.selector;
108110
return (
109111
selector.charAt(0) === '.' &&
110112
/^\.(?:[a-z0-9]*-)?[A-Z](?:[a-zA-Z0-9]+)$/.test(selector)
@@ -115,14 +117,15 @@ var resetInherited = autoreset({
115117
resetInherited.postcssPlugin = 'autoreset-suitcss-encapsulation-inherited';
116118

117119
// This applies to the Component Root and Descendants
118-
var resetGeneric = autoreset({
120+
const resetGeneric = autoreset({
119121
reset: rules.nonInherited,
120122
rulesMatcher: 'suit'
121123
});
122124

123125
resetGeneric.postcssPlugin = 'autoreset-suitcss-encapsulation-nonInherited';
124126

125127
module.exports = {
126-
resetInherited: resetInherited,
127-
resetGeneric: resetGeneric
128+
resetInherited,
129+
resetGeneric
128130
};
131+

lib/index.js

+36-39
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
var assign = require('object-assign-deep');
2-
var autoprefixer = require('autoprefixer');
3-
var bemLinter = require('postcss-bem-linter');
4-
var cssnano = require('cssnano');
5-
var difference = require('lodash.difference');
6-
var encapsulationPlugins = require('./encapsulation');
7-
var isEmpty = require('lodash.isempty');
8-
var postcss = require('postcss');
9-
var postcssEasyImport = require('postcss-easy-import');
10-
var reporter = require('postcss-reporter');
11-
var stylelint = require('stylelint');
12-
var stylelintConfigSuit = require('stylelint-config-suitcss');
1+
'use strict';
2+
3+
const assign = require('object-assign-deep');
4+
const autoprefixer = require('autoprefixer');
5+
const bemLinter = require('postcss-bem-linter');
6+
const cssnano = require('cssnano');
7+
const difference = require('lodash.difference');
8+
const encapsulationPlugins = require('./encapsulation');
9+
const isEmpty = require('lodash.isempty');
10+
const postcssEasyImport = require('postcss-easy-import');
11+
const reporter = require('postcss-reporter');
12+
const stylelint = require('stylelint');
13+
const stylelintConfigSuit = require('stylelint-config-suitcss');
14+
let postcss = require('postcss'); // eslint-disable-line prefer-const
1315

1416
module.exports = preprocessor;
1517

@@ -18,7 +20,7 @@ module.exports = preprocessor;
1820
* and options to PostCSS plugins
1921
*/
2022

21-
var defaults = {
23+
const defaults = {
2224
debug: identity,
2325
lint: true,
2426
minify: false,
@@ -31,8 +33,8 @@ var defaults = {
3133
'postcss-apply'
3234
],
3335
autoprefixer: {
34-
browsers: '> 1%, last 2 versions, safari > 6, ie > 9, ' +
35-
'ios > 6, android > 4.3, samsung > 3, chromeandroid > 50'
36+
browsers: `> 1%, last 2 versions, safari > 6, ie > 9,
37+
ios > 6, android > 4.3, samsung > 3, chromeandroid > 50`
3638
},
3739
'postcss-easy-import': {
3840
transform: identity,
@@ -62,14 +64,14 @@ var defaults = {
6264
function preprocessor(css, options, filename) {
6365
options = mergeOptions(options);
6466

65-
var plugins = [
67+
let plugins = [
6668
postcssEasyImport(options['postcss-easy-import'])
6769
];
6870

6971
plugins = plugins.concat(
70-
options.use.map(function(p) {
71-
var plugin = require(p);
72-
var settings = options[p];
72+
options.use.map(p => {
73+
const plugin = require(p);
74+
const settings = options[p];
7375
return settings ? plugin(settings) : plugin;
7476
})
7577
);
@@ -88,15 +90,14 @@ function preprocessor(css, options, filename) {
8890
reporter(options['postcss-reporter'])
8991
]);
9092

91-
var processor = postcss(options.debug(plugins));
93+
const processor = postcss(options.debug(plugins));
9294

9395
if (options.minify) {
9496
processor.use(cssnano(options.cssnano));
9597
}
9698

97-
return lintFile(css, options, filename).then(function(result) {
98-
return processor.process(result.css, options.postcss);
99-
});
99+
return lintFile(css, options, filename)
100+
.then(result => processor.process(result.css, options.postcss));
100101
}
101102

102103
/**
@@ -108,33 +109,31 @@ function preprocessor(css, options, filename) {
108109

109110
function mergeOptions(options) {
110111
options = options || {};
111-
var mergedOpts = assign({}, defaults, options);
112-
var easyImportOpts = mergedOpts['postcss-easy-import'];
113-
var origTransform = easyImportOpts.transform;
114-
var origOnImport = easyImportOpts.onImport;
112+
const mergedOpts = assign({}, defaults, options);
113+
const easyImportOpts = mergedOpts['postcss-easy-import'];
114+
const origTransform = easyImportOpts.transform;
115+
const origOnImport = easyImportOpts.onImport;
115116

116117
if (mergedOpts.root) {
117118
easyImportOpts.root = mergedOpts.root;
118119
}
119120

120-
easyImportOpts.transform = function(css, filename) {
121-
var transformedCss = origTransform(css);
122-
return lintFile(transformedCss, mergedOpts, filename).then(function(result) {
123-
return result.css;
124-
});
121+
easyImportOpts.transform = (css, filename) => {
122+
const transformedCss = origTransform(css);
123+
return lintFile(transformedCss, mergedOpts, filename).then(result => result.css);
125124
};
126125

127-
easyImportOpts.onImport = function(importedFiles) {
126+
easyImportOpts.onImport = importedFiles => {
128127
updateWatchTaskFiles(importedFiles);
129128
origOnImport(importedFiles);
130129
};
131130

132131
// Allow additional plugins to be merged with the defaults
133132
// but remove any duplicates so that it respects the new order
134133
if (!isEmpty(options.use)) {
135-
var plugins = difference(mergedOpts.use, options.use);
134+
const plugins = difference(mergedOpts.use, options.use);
136135
// Remove core plugins. Can't reorder them
137-
var userPlugins = difference(options.use, [
136+
const userPlugins = difference(options.use, [
138137
'postcss-easy-import',
139138
'autoprefixer',
140139
'postcss-reporter'
@@ -153,7 +152,7 @@ function mergeOptions(options) {
153152
* @returns {Promise} Used by postcss-import transform
154153
*/
155154
function lintFile(css, options, filename) {
156-
var processor = postcss();
155+
const processor = postcss();
157156

158157
if (options.lint) {
159158
processor
@@ -170,9 +169,7 @@ function lintFile(css, options, filename) {
170169
.use(reporter(options['postcss-reporter']));
171170

172171
if (isPromise(css)) {
173-
return css.then(function(css) { // eslint-disable-line no-shadow
174-
return processor.process(css, options.postcss);
175-
});
172+
return css.then(css => processor.process(css, options.postcss)); // eslint-disable-line no-shadow
176173
}
177174

178175
return processor.process(css, options.postcss);

0 commit comments

Comments
 (0)