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

Simplify Slate assets #850

Merged
merged 1 commit into from
Oct 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions packages/html-webpack-liquid-asset-tags-plugin/README.md

This file was deleted.

42 changes: 0 additions & 42 deletions packages/html-webpack-liquid-asset-tags-plugin/index.js

This file was deleted.

13 changes: 0 additions & 13 deletions packages/html-webpack-liquid-asset-tags-plugin/package.json

This file was deleted.

36 changes: 20 additions & 16 deletions packages/slate-config/common/paths.schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,16 @@ module.exports = {
// Source directory of theme
'paths.theme.src': (config) => path.join(config.get('paths.theme'), 'src'),

// Source directory of assets folder
'paths.theme.src.assets': (config) =>
path.join(config.get('paths.theme.src'), 'assets'),

// Source of theme configuration files
'paths.theme.src.config': (config) =>
path.join(config.get('paths.theme.src'), 'config'),

// Source font directory for theme
'paths.theme.src.fonts': (config) =>
path.join(config.get('paths.theme.src'), 'assets', 'fonts'),

// Source of images directory
'paths.theme.src.images': (config) =>
path.join(config.get('paths.theme.src'), 'assets', 'images'),

// Source of theme liquid layout files
'paths.theme.src.layouts': (config) =>
'paths.theme.src.layout': (config) =>
path.join(config.get('paths.theme.src'), 'layout'),

// Source of translation locales
Expand All @@ -37,19 +33,15 @@ module.exports = {

// Source scripts directory for theme
'paths.theme.src.scripts': (config) =>
path.join(config.get('paths.theme.src'), 'assets', 'scripts'),
path.join(config.get('paths.theme.src'), 'scripts'),

// Source snippets directory
'paths.theme.src.snippets': (config) =>
path.join(config.get('paths.theme.src'), 'snippets'),

// Static asset directory for files that statically copied to paths.theme.dist.assets
'paths.theme.src.static': (config) =>
path.join(config.get('paths.theme.src'), 'assets', 'static'),

// Main SVG source directory for theme
'paths.theme.src.svgs': (config) =>
path.join(config.get('paths.theme.src'), 'assets', 'svg'),
'paths.theme.src.sections': (config) =>
path.join(config.get('paths.theme.src'), 'sections'),

// Source liquid template directory
'paths.theme.src.templates': (config) =>
Expand All @@ -70,6 +62,10 @@ module.exports = {
'paths.theme.dist.config': (config) =>
path.join(config.get('paths.theme.dist'), 'config'),

// Distribution of theme liquid layout files
'paths.theme.dist.layout': (config) =>
path.join(config.get('paths.theme.dist'), 'layout'),

// Distribution snippets directory
'paths.theme.dist.snippets': (config) =>
path.join(config.get('paths.theme.dist'), 'snippets'),
Expand All @@ -78,6 +74,14 @@ module.exports = {
'paths.theme.dist.locales': (config) =>
path.join(config.get('paths.theme.dist'), 'locales'),

// Distribution sections directory
'paths.theme.dist.sections': (config) =>
path.join(config.get('paths.theme.dist'), 'sections'),

// Distribution templates directory
'paths.theme.dist.templates': (config) =>
path.join(config.get('paths.theme.dist'), 'templates'),

// Directory for storing all temporary and/or cache files
'paths.theme.cache': (config) =>
path.join(config.get('paths.theme'), '.cache'),
Expand Down
3 changes: 0 additions & 3 deletions packages/slate-liquid-asset-loader/README.md

This file was deleted.

76 changes: 0 additions & 76 deletions packages/slate-liquid-asset-loader/index.js

This file was deleted.

17 changes: 0 additions & 17 deletions packages/slate-liquid-asset-loader/package.json

This file was deleted.

4 changes: 1 addition & 3 deletions packages/slate-tools/slate-tools.schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,5 @@ module.exports = {
'webpack.cssnano.settings': {zindex: false, reduceIdents: false},

// Object which contains entrypoints used in webpack's config.entry key
'webpack.entrypoints': {
static: path.resolve(__dirname, 'tools/webpack/static-files-glob.js'),
},
'webpack.entrypoints': {},
};
5 changes: 5 additions & 0 deletions packages/slate-tools/tools/asset-server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@ const webpackHotMiddleware = require('webpack-hot-middleware');
const corsMiddleware = require('cors');
const express = require('express');

const {isHotUpdateFile} = require('../utilities');

module.exports = class App {
constructor(compiler) {
const app = express();

app.webpackDevMiddleware = webpackDevMiddleware(compiler, {
logLevel: 'silent',
reload: true,
writeToDisk: (filePath) => {
return !isHotUpdateFile(filePath);
},
});
app.webpackHotMiddleware = webpackHotMiddleware(compiler, {
log: false,
Expand Down
22 changes: 11 additions & 11 deletions packages/slate-tools/tools/asset-server/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,32 @@ module.exports = class Client {
this.skipNextSync = false;
this.files = [];
this.hooks = {
beforeSync: new AsyncSeriesHook(['files']),
sync: new SyncHook(['files']),
syncDone: new SyncHook(['files']),
afterSync: new AsyncSeriesHook(['files']),
syncSkipped: new SyncHook(['files']),
beforeSync: new AsyncSeriesHook(['files', 'stats']),
sync: new SyncHook(['files', 'stats']),
syncDone: new SyncHook(['files', 'stats']),
afterSync: new AsyncSeriesHook(['files', 'stats']),
syncSkipped: new SyncHook(['files', 'stats']),
};
}

async sync(files) {
async sync(files, stats) {
this.files = files;

await this.hooks.beforeSync.promise(this.files);
await this.hooks.beforeSync.promise(this.files, stats);

if (this.files.length === 0) {
this.skipNextSync = true;
}

if (this.skipNextSync) {
this.hooks.syncSkipped.call(this.files);
this.hooks.syncSkipped.call(this.files, stats);
} else {
this.hooks.sync.call(this.files);
this.hooks.sync.call(this.files, stats);
await sync(this.files);
this.hooks.syncDone.call(this.files);
this.hooks.syncDone.call(this.files, stats);
}

this.hooks.afterSync.promise(this.files);
this.hooks.afterSync.promise(this.files, stats);

this.skipNextSync = false;
}
Expand Down
34 changes: 23 additions & 11 deletions packages/slate-tools/tools/asset-server/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
const fs = require('fs');
const webpack = require('webpack');
const {createServer} = require('https');
const createHash = require('crypto').createHash;
const SlateConfig = require('@shopify/slate-config');

const App = require('./app');
const Client = require('./client');
const {sslKeyCert} = require('../utilities');
const {sslKeyCert, isHotUpdateFile} = require('../utilities');
const config = new SlateConfig(require('../../slate-tools.schema'));

module.exports = class DevServer {
Expand Down Expand Up @@ -48,9 +47,9 @@ module.exports = class DevServer {
}

_onCompileDone(stats) {
const files = this._getChangedLiquidFiles(stats);
const files = this._getAssetsToUpload(stats);

return this.client.sync(files);
return this.client.sync(files, stats);
}

_onAfterSync(files) {
Expand All @@ -60,20 +59,33 @@ module.exports = class DevServer {
});
}

_getChangedLiquidFiles(stats) {
_isChunk(key, chunks) {
return (
chunks.filter((chunk) => {
return key.indexOf(chunk.id) > -1;
}).length > 0
);
}

_hasAssetChanged(key, asset) {
const oldHash = this.assetHashes[key];
const newHash = this._updateAssetHash(key, asset);

return oldHash !== newHash;
}

_getAssetsToUpload(stats) {
const assets = Object.entries(stats.compilation.assets);
const chunks = stats.compilation.chunks;

return (
assets
.filter(([key, asset]) => {
const oldHash = this.assetHashes[key];
const newHash = this._updateAssetHash(key, asset);

return (
asset.emitted &&
(/\.liquid$/.test(key) || /\.json$/.test(key)) &&
fs.existsSync(asset.existsAt) &&
oldHash !== newHash
!this._isChunk(key, chunks) &&
!isHotUpdateFile(key) &&
this._hasAssetChanged(key, asset)
);
})
/* eslint-disable-next-line no-unused-vars */
Expand Down
Loading