Skip to content
This repository has been archived by the owner on Jul 19, 2021. It is now read-only.

Commit

Permalink
Add fixes based on feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Berthe committed May 14, 2018
1 parent 262e4e0 commit 6b0f590
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 43 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
packages/slate-cssvar-loader/__tests__/fixtures
packages/slate-theme/dist
packages/slate-theme/src/scripts/**/*.js.liquid
**/node_modules/
Expand Down
8 changes: 4 additions & 4 deletions packages/concat-style-loader/concat.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ const path = require('path');

function concatStyles(content, rootPath, loader) {
const assets = parseImports(content, rootPath, loader).reverse();
let inlinedAssets;
let inlinedAssets = content;

assets.forEach((asset) => {
asset.content = concatStyles(asset.content, asset.path);
inlinedAssets = inlineAsset(content, asset);
inlinedAssets = inlineAsset(inlinedAssets, asset);
});

return inlinedAssets;
Expand All @@ -27,9 +27,9 @@ function parseImports(content, rootPath, loader) {
const url = getImportURL(match[0]);
const assetPath = path.resolve(path.dirname(rootPath), url);

const modifiedContent = fetchAssetContent(assetPath, loader);
const importedContent = fetchAssetContent(assetPath, loader);

return {path: assetPath, modifiedContent, match};
return {path: assetPath, content: importedContent, match};
});
}

Expand Down
4 changes: 2 additions & 2 deletions packages/create-slate-theme/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ function spawn(cmd, options = {stdio: 'inherit'}) {
function splitCommandString(cmd) {
const regexp = /[^\s"]+|"([^"]*)"/gi;
const parts = [];
let match;

do {
// Each call to exec returns the next regex match as an array
const match = regexp.exec(cmd);
match = regexp.exec(cmd);

if (match != null) {
// Index 1 in the array is the captured group if it exists
// Index 0 is the matched text, which we use if no captured group exists
parts.push(match[1] ? match[1] : match[0]);
}
/* eslint-disable-next-line no-undef */
} while (match != null);

return parts;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
module.exports = require('../../node_modules/css-loader/lib/css-base.js')(
false,
);
exports = module.exports = require("../../node_modules/css-loader/lib/css-base.js")(false);
// imports


// module
module.exports.push([
module.id,
".heading {\n color: var(--headings_color);\n background-color: '#FF00FF';\n letter-spacing: var(--letter_spacing);\n}\n\n.title {\n color: var(--headings_color);\n font-weight: var(--font-body-bold-weight);\n}\n\nbody {\n background-color: var(--body_color);\n}",
'',
]);
exports.push([module.id, ".heading {\n color: var(--headings_color);\n background-color: '#FF00FF';\n letter-spacing: var(--letter_spacing);\n}\n\n.title {\n color: var(--headings_color);\n font-weight: var(--font-body-bold-weight);\n}\n\nbody {\n background-color: var(--body_color);\n}", ""]);

// exports
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
module.exports = require('../../node_modules/css-loader/lib/css-base.js')(
false,
);
exports = module.exports = require("../../node_modules/css-loader/lib/css-base.js")(false);
// imports


// module
module.exports.push([
module.id,
".heading {\n color: {{ settings.headings_color }};\n background-color: '#FF00FF';\n}\n\n.title {\n color: {{ settings.headings_color }};\n}\n\nbody {\n background-color: {{ settings.body_color }};\n color: {{ settings.extra_variable }};\n}",
'',
]);
exports.push([module.id, ".heading {\n color: {{ settings.headings_color }};\n background-color: '#FF00FF';\n}\n\n.title {\n color: {{ settings.headings_color }};\n}\n\nbody {\n background-color: {{ settings.body_color }};\n color: {{ settings.extra_variable }};\n}", ""]);

// exports
11 changes: 3 additions & 8 deletions packages/slate-cssvar-loader/__tests__/fixtures/expected.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
module.exports = require('../../node_modules/css-loader/lib/css-base.js')(
false,
);
exports = module.exports = require("../../node_modules/css-loader/lib/css-base.js")(false);
// imports


// module
module.exports.push([
module.id,
'.heading {\n color: {{ settings.headings_color }};\n background-color: \'#FF00FF\';\n letter-spacing: {{ settings.letter_spacing }}px;\n}\n\n.title {\n color: {{ settings.headings_color }};\n font-weight: {{ font_body_bold.weight | default: "bold" }};\n}\n\nbody {\n background-color: {{ settings.body_color }};\n}',
'',
]);
exports.push([module.id, ".heading {\n color: {{ settings.headings_color }};\n background-color: '#FF00FF';\n letter-spacing: {{ settings.letter_spacing }}px;\n}\n\n.title {\n color: {{ settings.headings_color }};\n font-weight: {{ font_body_bold.weight | default: \"bold\" }};\n}\n\nbody {\n background-color: {{ settings.body_color }};\n}", ""]);

// exports
5 changes: 2 additions & 3 deletions packages/slate-tools/cli/commands/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ devServer.compiler.hooks.done.tap('CLI', (stats) => {

devServer.client.hooks.beforeSync.tapPromise('CLI', async (files) => {
if (firstSync && argv.skipFirstDeploy) {
return (devServer.skipDeploy = true);
devServer.skipDeploy = true;
return;
}

if (continueIfPublishedTheme === null) {
Expand All @@ -102,8 +103,6 @@ devServer.client.hooks.beforeSync.tapPromise('CLI', async (files) => {
(file) => !file.endsWith('settings_data.json'),
);
}

return true;
});

devServer.client.hooks.syncSkipped.tap('CLI', () => {
Expand Down
19 changes: 9 additions & 10 deletions packages/slate-tools/tools/webpack/get-chunk-name.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const crypto = require('crypto');

module.exports = function(module, chunks, cacheGroup) {
let containsLayout = false;
const names = chunks
Expand All @@ -24,20 +26,17 @@ module.exports = function(module, chunks, cacheGroup) {
// been set to 100 to prevent `[name].[chunkhash].[ext]` from
// generating a 256+ character string.
if (name.length > 256) {
name = `${name.slice(0, 240)}~${hashString(name)}`;
name = `${name.slice(0, 240)}~${hashFilename(name)}`;
}

/* eslint-disable-next-line consistent-return */
return name;
};

function hashString(text) {
let hash = 5381;
let index = text.length;

while (index) {
hash = (hash * 33) ^ text.charCodeAt(--index);
}

return hash >>> 0;
function hashFilename(name) {
return crypto
.createHash('md4')
.update(name)
.digest('hex')
.slice(0, 8);
}

0 comments on commit 6b0f590

Please sign in to comment.