From 5179c75d8f8d8607f5cb9baf592be62d2ff6bfee Mon Sep 17 00:00:00 2001 From: fabs Date: Fri, 15 Mar 2019 15:32:42 +0100 Subject: [PATCH 1/6] Add support for the same variable multiple times --- index.js | 20 ++++++++++---------- test/options.js | 14 ++++++++++++++ 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index 90289dd..452d779 100644 --- a/index.js +++ b/index.js @@ -7,7 +7,7 @@ const postcss = require('postcss'); const csswring = require('csswring'); module.exports = postcss.plugin('postcss-extract-media-query', opts => { - + opts = _.merge({ entry: null, output: { @@ -67,8 +67,8 @@ module.exports = postcss.plugin('postcss-extract-media-query', opts => { // or otherwise the query key (converted to kebab case) const hasCustomName = typeof opts.queries[atRule.params] === 'string'; const key = hasCustomName === true - ? opts.queries[atRule.params] - : _.kebabCase(atRule.params); + ? opts.queries[atRule.params] + : _.kebabCase(atRule.params); // extract media atRule and concatenate with existing atRule (same key) // if no whitelist set or if whitelist and atRule has custom query name match @@ -83,12 +83,12 @@ module.exports = postcss.plugin('postcss-extract-media-query', opts => { if (opts.output.path) { const newFile = opts.output.name - .replace('[name]', name) - .replace('[query]', key) - .replace('[ext]', ext); + .replace(/\[name\]/g, name) + .replace(/\[query\]/g, key) + .replace(/\[ext\]/g, ext) const newFilePath = path.join(opts.output.path, newFile); - + // create new root // and append all extracted atRules with current key const newRoot = postcss.root(); @@ -97,9 +97,9 @@ module.exports = postcss.plugin('postcss-extract-media-query', opts => { }); if (opts.minimize === true) { - const newRootMinimized = postcss([ csswring() ]) - .process(newRoot.toString(), { from: newFilePath }) - .root; + const newRootMinimized = postcss([csswring()]) + .process(newRoot.toString(), { from: newFilePath }) + .root; fs.outputFileSync(newFilePath, newRootMinimized.toString()); } else { fs.outputFileSync(newFilePath, newRoot.toString()); diff --git a/test/options.js b/test/options.js index 714f6bd..b564822 100644 --- a/test/options.js +++ b/test/options.js @@ -68,6 +68,7 @@ describe('Options', function() { assert.isTrue(fs.existsSync('test/output/example-screen-and-min-width-1024-px.css')); assert.isTrue(fs.existsSync('test/output/example-screen-and-min-width-1200-px.css')); }); + it('output.name should affect emited filenames', function() { const opts = { output: { @@ -80,6 +81,19 @@ describe('Options', function() { assert.isTrue(fs.existsSync('test/output/screen-and-min-width-1024-px.css')); assert.isTrue(fs.existsSync('test/output/screen-and-min-width-1200-px.css')); }); + + it('output.name can have the same variable multiple times', function () { + const opts = { + output: { + path: path.join(__dirname, 'output'), + name: '[query]-[query].[ext]' + }, + stats: false + }; + postcss([plugin(opts)]).process(exampleFile, { from: 'test/data/example.css' }).css; + assert.isTrue(fs.existsSync('test/output/screen-and-min-width-1024-px-screen-and-min-width-1024-px.css')); + assert.isTrue(fs.existsSync('test/output/screen-and-min-width-1200-px-screen-and-min-width-1200-px.css')); + }); }); describe('queries', function() { From 15bcdf4e23eb6131d907c117dbc0d2eda0bdf043 Mon Sep 17 00:00:00 2001 From: fabs Date: Fri, 15 Mar 2019 16:04:52 +0100 Subject: [PATCH 2/6] Revert formatting stuff --- index.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/index.js b/index.js index 452d779..44ac025 100644 --- a/index.js +++ b/index.js @@ -7,7 +7,6 @@ const postcss = require('postcss'); const csswring = require('csswring'); module.exports = postcss.plugin('postcss-extract-media-query', opts => { - opts = _.merge({ entry: null, output: { @@ -97,7 +96,7 @@ module.exports = postcss.plugin('postcss-extract-media-query', opts => { }); if (opts.minimize === true) { - const newRootMinimized = postcss([csswring()]) + const newRootMinimized = postcss([ csswring() ]) .process(newRoot.toString(), { from: newFilePath }) .root; fs.outputFileSync(newFilePath, newRootMinimized.toString()); From cfe6de0496e53a2f234eef85695a5106d944ae6d Mon Sep 17 00:00:00 2001 From: fabs Date: Fri, 15 Mar 2019 16:07:21 +0100 Subject: [PATCH 3/6] More reverts --- index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 44ac025..31ed886 100644 --- a/index.js +++ b/index.js @@ -7,6 +7,7 @@ const postcss = require('postcss'); const csswring = require('csswring'); module.exports = postcss.plugin('postcss-extract-media-query', opts => { + opts = _.merge({ entry: null, output: { @@ -66,8 +67,8 @@ module.exports = postcss.plugin('postcss-extract-media-query', opts => { // or otherwise the query key (converted to kebab case) const hasCustomName = typeof opts.queries[atRule.params] === 'string'; const key = hasCustomName === true - ? opts.queries[atRule.params] - : _.kebabCase(atRule.params); + ? opts.queries[atRule.params] + : _.kebabCase(atRule.params); // extract media atRule and concatenate with existing atRule (same key) // if no whitelist set or if whitelist and atRule has custom query name match From cbab44db9935c9163086e5c05b50e7d0f6de8954 Mon Sep 17 00:00:00 2001 From: fabs Date: Wed, 20 Mar 2019 16:14:08 +0100 Subject: [PATCH 4/6] Rename test. Readd indentions --- index.js | 15 +++++++-------- test/options.js | 4 +--- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/index.js b/index.js index 31ed886..48c1026 100644 --- a/index.js +++ b/index.js @@ -7,7 +7,6 @@ const postcss = require('postcss'); const csswring = require('csswring'); module.exports = postcss.plugin('postcss-extract-media-query', opts => { - opts = _.merge({ entry: null, output: { @@ -67,8 +66,8 @@ module.exports = postcss.plugin('postcss-extract-media-query', opts => { // or otherwise the query key (converted to kebab case) const hasCustomName = typeof opts.queries[atRule.params] === 'string'; const key = hasCustomName === true - ? opts.queries[atRule.params] - : _.kebabCase(atRule.params); + ? opts.queries[atRule.params] + : _.kebabCase(atRule.params); // extract media atRule and concatenate with existing atRule (same key) // if no whitelist set or if whitelist and atRule has custom query name match @@ -83,9 +82,9 @@ module.exports = postcss.plugin('postcss-extract-media-query', opts => { if (opts.output.path) { const newFile = opts.output.name - .replace(/\[name\]/g, name) - .replace(/\[query\]/g, key) - .replace(/\[ext\]/g, ext) + .replace(/\[name\]/g, name) + .replace(/\[query\]/g, key) + .replace(/\[ext\]/g, ext) const newFilePath = path.join(opts.output.path, newFile); @@ -98,8 +97,8 @@ module.exports = postcss.plugin('postcss-extract-media-query', opts => { if (opts.minimize === true) { const newRootMinimized = postcss([ csswring() ]) - .process(newRoot.toString(), { from: newFilePath }) - .root; + .process(newRoot.toString(), { from: newFilePath }) + .root; fs.outputFileSync(newFilePath, newRootMinimized.toString()); } else { fs.outputFileSync(newFilePath, newRoot.toString()); diff --git a/test/options.js b/test/options.js index b564822..ee01a7a 100644 --- a/test/options.js +++ b/test/options.js @@ -68,7 +68,6 @@ describe('Options', function() { assert.isTrue(fs.existsSync('test/output/example-screen-and-min-width-1024-px.css')); assert.isTrue(fs.existsSync('test/output/example-screen-and-min-width-1200-px.css')); }); - it('output.name should affect emited filenames', function() { const opts = { output: { @@ -81,8 +80,7 @@ describe('Options', function() { assert.isTrue(fs.existsSync('test/output/screen-and-min-width-1024-px.css')); assert.isTrue(fs.existsSync('test/output/screen-and-min-width-1200-px.css')); }); - - it('output.name can have the same variable multiple times', function () { + it('output.name should support using the same placeholder multiple times', function () { const opts = { output: { path: path.join(__dirname, 'output'), From 0352d5bc4887e216922c1a124b68b398c4efb974 Mon Sep 17 00:00:00 2001 From: fabs Date: Wed, 20 Mar 2019 16:16:08 +0100 Subject: [PATCH 5/6] Reapply indentions --- index.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 48c1026..fa4178f 100644 --- a/index.js +++ b/index.js @@ -82,9 +82,9 @@ module.exports = postcss.plugin('postcss-extract-media-query', opts => { if (opts.output.path) { const newFile = opts.output.name - .replace(/\[name\]/g, name) - .replace(/\[query\]/g, key) - .replace(/\[ext\]/g, ext) + .replace(/\[name\]/g, name) + .replace(/\[query\]/g, key) + .replace(/\[ext\]/g, ext) const newFilePath = path.join(opts.output.path, newFile); @@ -97,8 +97,8 @@ module.exports = postcss.plugin('postcss-extract-media-query', opts => { if (opts.minimize === true) { const newRootMinimized = postcss([ csswring() ]) - .process(newRoot.toString(), { from: newFilePath }) - .root; + .process(newRoot.toString(), { from: newFilePath }) + .root; fs.outputFileSync(newFilePath, newRootMinimized.toString()); } else { fs.outputFileSync(newFilePath, newRoot.toString()); From 4c6480909b6374877811445d0bbdceebf1c8e9ce Mon Sep 17 00:00:00 2001 From: fabs Date: Wed, 20 Mar 2019 16:16:48 +0100 Subject: [PATCH 6/6] Readd initial break --- index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/index.js b/index.js index fa4178f..12efbe8 100644 --- a/index.js +++ b/index.js @@ -7,6 +7,7 @@ const postcss = require('postcss'); const csswring = require('csswring'); module.exports = postcss.plugin('postcss-extract-media-query', opts => { + opts = _.merge({ entry: null, output: {