Skip .scss files if build not required #1944
This commit is contained in:
parent
d9cf53725a
commit
294d5679d3
6 changed files with 81 additions and 62 deletions
|
@ -17,14 +17,15 @@ if (require.main === module) {
|
||||||
.concat(dirs.map(d => `${d}/**`))
|
.concat(dirs.map(d => `${d}/**`))
|
||||||
.concat([`!${formatDirsForMatcher(dirs)}/**/*.js`])
|
.concat([`!${formatDirsForMatcher(dirs)}/**/*.js`])
|
||||||
.concat([`!${formatDirsForMatcher(dirs)}/**/*.jsx`])
|
.concat([`!${formatDirsForMatcher(dirs)}/**/*.jsx`])
|
||||||
.concat([`!${formatDirsForMatcher(copyDirs)}/**`])
|
.concat([`!${formatDirsForMatcher(dirs)}/**/*.scss`])
|
||||||
|
.concat([`!${formatDirsForMatcher(copyDirs)}/**`]);
|
||||||
|
|
||||||
const signatures = await getSignatures();
|
const signatures = await getSignatures();
|
||||||
const results = await Promise.all([
|
const results = await Promise.all([
|
||||||
getBrowserify(signatures),
|
getBrowserify(signatures),
|
||||||
getCopy(copyDirs.map(d => `${d}/**`), { ignore: ignoreMask }, signatures),
|
getCopy(copyDirs.map(d => `${d}/**`), { ignore: ignoreMask }, signatures),
|
||||||
getJS(jsFiles, { ignore: ignoreMask }, signatures),
|
getJS(jsFiles, { ignore: ignoreMask }, signatures),
|
||||||
getSass(scssFiles, { ignore: ignoreMask }, signatures),
|
...scssFiles.map(scf => getSass(scf, { ignore: ignoreMask }, signatures)),
|
||||||
getSymlinks(symlinks, { nodir: true, ignore: ignoreMask }, signatures),
|
getSymlinks(symlinks, { nodir: true, ignore: ignoreMask }, signatures),
|
||||||
getSymlinks(symlinkDirs, { ignore: ignoreMask }, signatures),
|
getSymlinks(symlinkDirs, { ignore: ignoreMask }, signatures),
|
||||||
cleanUp(signatures)
|
cleanUp(signatures)
|
||||||
|
|
|
@ -50,7 +50,8 @@ const symlinkFiles = [
|
||||||
'resource/ace/theme-chrome.js',
|
'resource/ace/theme-chrome.js',
|
||||||
'resource/ace/theme-monokai.js',
|
'resource/ace/theme-monokai.js',
|
||||||
'resource/ace/worker-javascript.js',
|
'resource/ace/worker-javascript.js',
|
||||||
'update.rdf'
|
'update.rdf',
|
||||||
|
'!chrome/skin/default/zotero/**/*.scss'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
|
@ -89,7 +90,6 @@ const browserifyConfigs = [
|
||||||
// exclude mask used for js, copy, symlink and sass tasks
|
// exclude mask used for js, copy, symlink and sass tasks
|
||||||
const ignoreMask = [
|
const ignoreMask = [
|
||||||
'**/#*',
|
'**/#*',
|
||||||
'**/_*.scss',
|
|
||||||
'resource/schema/global/schema.json.gz'
|
'resource/schema/global/schema.json.gz'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
'use strict';
|
/* eslint-disable no-await-in-loop */
|
||||||
|
|
||||||
const universalify = require('universalify');
|
const universalify = require('universalify');
|
||||||
const sass = require('sass');
|
const sass = require('sass');
|
||||||
|
@ -6,7 +6,7 @@ const globby = require('globby');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const fs = require('fs-extra');
|
const fs = require('fs-extra');
|
||||||
const { getSignatures, writeSignatures, cleanUp, compareSignatures, getFileSignature, onSuccess, onError, onProgress, getPathRelativeTo } = require('./utils');
|
const { getSignatures, writeSignatures, cleanUp, compareSignatures, getFileSignature, onSuccess, onError, onProgress, getPathRelativeTo } = require('./utils');
|
||||||
const { ignoreMask } = require('./config');
|
const { scssFiles, ignoreMask } = require('./config');
|
||||||
const sassRender = universalify.fromCallback(sass.render);
|
const sassRender = universalify.fromCallback(sass.render);
|
||||||
|
|
||||||
const ROOT = path.resolve(__dirname, '..');
|
const ROOT = path.resolve(__dirname, '..');
|
||||||
|
@ -15,14 +15,26 @@ async function getSass(source, options, signatures={}) {
|
||||||
const t1 = Date.now();
|
const t1 = Date.now();
|
||||||
const files = await globby(source, Object.assign({ cwd: ROOT }, options));
|
const files = await globby(source, Object.assign({ cwd: ROOT }, options));
|
||||||
const totalCount = files.length;
|
const totalCount = files.length;
|
||||||
var count = 0;
|
var count = 0, shouldRebuild = false;
|
||||||
var f;
|
|
||||||
|
|
||||||
while ((f = files.pop()) != null) {
|
for (const f of files) {
|
||||||
|
// if any file changed, rebuild all onSuccess
|
||||||
|
let newFileSignature = await getFileSignature(f);
|
||||||
|
if (!compareSignatures(newFileSignature, signatures[f])) {
|
||||||
|
signatures[f] = newFileSignature;
|
||||||
|
shouldRebuild = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var f;
|
||||||
|
if (shouldRebuild) {
|
||||||
|
const filesToBuild = files.filter(f => !path.basename(f).startsWith('_'));
|
||||||
|
while ((f = filesToBuild.pop())) {
|
||||||
let newFileSignature = await getFileSignature(f);
|
let newFileSignature = await getFileSignature(f);
|
||||||
let destFile = getPathRelativeTo(f, 'scss');
|
let destFile = getPathRelativeTo(f, 'scss');
|
||||||
destFile = path.join(path.dirname(destFile), path.basename(destFile, '.scss') + '.css');
|
destFile = path.join(path.dirname(destFile), path.basename(destFile, '.scss') + '.css');
|
||||||
let dest = path.join.apply(this, ['build', 'chrome', 'skin', 'default', 'zotero', destFile]);
|
let dest = path.join.apply(this, ['build', 'chrome', 'skin', 'default', 'zotero', destFile]);
|
||||||
|
|
||||||
if (['win', 'mac', 'unix'].some(platform => f.endsWith(`-${platform}.scss`))) {
|
if (['win', 'mac', 'unix'].some(platform => f.endsWith(`-${platform}.scss`))) {
|
||||||
let platform = f.slice(f.lastIndexOf('-') + 1, f.lastIndexOf('.'));
|
let platform = f.slice(f.lastIndexOf('-') + 1, f.lastIndexOf('.'));
|
||||||
destFile = destFile.slice(0, destFile.lastIndexOf('-'))
|
destFile = destFile.slice(0, destFile.lastIndexOf('-'))
|
||||||
|
@ -30,17 +42,6 @@ async function getSass(source, options, signatures={}) {
|
||||||
dest = path.join.apply(this, ['build', 'chrome', 'content', 'zotero-platform', platform, destFile]);
|
dest = path.join.apply(this, ['build', 'chrome', 'content', 'zotero-platform', platform, destFile]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (f in signatures) {
|
|
||||||
if (compareSignatures(newFileSignature, signatures[f])) {
|
|
||||||
try {
|
|
||||||
await fs.access(dest, fs.constants.F_OK);
|
|
||||||
// TODO: Doesn't recompile on partial scss file changes, so temporarily disabled
|
|
||||||
// continue;
|
|
||||||
} catch (_) {
|
|
||||||
// file does not exists in build, fallback to browserifing
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
const sass = await sassRender({
|
const sass = await sassRender({
|
||||||
file: f,
|
file: f,
|
||||||
|
@ -54,10 +55,12 @@ async function getSass(source, options, signatures={}) {
|
||||||
onProgress(f, dest, 'sass');
|
onProgress(f, dest, 'sass');
|
||||||
signatures[f] = newFileSignature;
|
signatures[f] = newFileSignature;
|
||||||
count++;
|
count++;
|
||||||
} catch (err) {
|
}
|
||||||
|
catch (err) {
|
||||||
throw new Error(`Failed on ${f}: ${err}`);
|
throw new Error(`Failed on ${f}: ${err}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const t2 = Date.now();
|
const t2 = Date.now();
|
||||||
return {
|
return {
|
||||||
|
@ -74,10 +77,13 @@ if (require.main === module) {
|
||||||
(async () => {
|
(async () => {
|
||||||
try {
|
try {
|
||||||
const signatures = await getSignatures();
|
const signatures = await getSignatures();
|
||||||
onSuccess(await getSass('scss/*.scss', { root: 'scss', ignore: ignoreMask }, signatures));
|
for (var i = 0; i < scssFiles.length; i++) {
|
||||||
|
onSuccess(await getSass(scssFiles[i], { ignore: ignoreMask }, signatures));
|
||||||
|
}
|
||||||
onSuccess(await cleanUp(signatures));
|
onSuccess(await cleanUp(signatures));
|
||||||
await writeSignatures(signatures);
|
await writeSignatures(signatures);
|
||||||
} catch (err) {
|
}
|
||||||
|
catch (err) {
|
||||||
process.exitCode = 1;
|
process.exitCode = 1;
|
||||||
global.isError = true;
|
global.isError = true;
|
||||||
onError(err);
|
onError(err);
|
||||||
|
|
|
@ -70,6 +70,8 @@ if (require.main === module) {
|
||||||
const source = symlinkFiles
|
const source = symlinkFiles
|
||||||
.concat(dirs.map(d => `${d}/**`))
|
.concat(dirs.map(d => `${d}/**`))
|
||||||
.concat([`!${formatDirsForMatcher(dirs)}/**/*.js`])
|
.concat([`!${formatDirsForMatcher(dirs)}/**/*.js`])
|
||||||
|
.concat([`!${formatDirsForMatcher(dirs)}/**/*.jsx`])
|
||||||
|
.concat([`!${formatDirsForMatcher(dirs)}/**/*.scss`])
|
||||||
.concat([`!${formatDirsForMatcher(copyDirs)}/**`]);
|
.concat([`!${formatDirsForMatcher(copyDirs)}/**`]);
|
||||||
|
|
||||||
const signatures = await getSignatures();
|
const signatures = await getSignatures();
|
||||||
|
|
|
@ -17,7 +17,7 @@ function onError(err) {
|
||||||
function onSuccess(result) {
|
function onSuccess(result) {
|
||||||
var msg = `${green('Success:')} ${blue(`[${result.action}]`)} ${result.count} files processed`;
|
var msg = `${green('Success:')} ${blue(`[${result.action}]`)} ${result.count} files processed`;
|
||||||
if (result.totalCount) {
|
if (result.totalCount) {
|
||||||
msg += ` (out of total ${result.totalCount} matched)`;
|
msg += ` | ${result.totalCount} checked`;
|
||||||
}
|
}
|
||||||
|
|
||||||
msg += ` [${yellow(`${result.processingTime}ms`)}]`;
|
msg += ` [${yellow(`${result.processingTime}ms`)}]`;
|
||||||
|
|
|
@ -35,6 +35,7 @@ const symlinks = symlinkFiles
|
||||||
.concat(dirs.map(d => `${d}/**`))
|
.concat(dirs.map(d => `${d}/**`))
|
||||||
.concat([`!${formatDirsForMatcher(dirs)}/**/*.js`])
|
.concat([`!${formatDirsForMatcher(dirs)}/**/*.js`])
|
||||||
.concat([`!${formatDirsForMatcher(dirs)}/**/*.jsx`])
|
.concat([`!${formatDirsForMatcher(dirs)}/**/*.jsx`])
|
||||||
|
.concat([`!${formatDirsForMatcher(dirs)}/**/*.scss`])
|
||||||
.concat([`!${formatDirsForMatcher(copyDirs)}/**`]);
|
.concat([`!${formatDirsForMatcher(copyDirs)}/**`]);
|
||||||
|
|
||||||
var signatures;
|
var signatures;
|
||||||
|
@ -48,24 +49,33 @@ function getWatch() {
|
||||||
let watcher = chokidar.watch(source, { cwd: ROOT })
|
let watcher = chokidar.watch(source, { cwd: ROOT })
|
||||||
.on('change', async (path) => {
|
.on('change', async (path) => {
|
||||||
try {
|
try {
|
||||||
|
var matched = false;
|
||||||
if (multimatch(path, jsFiles).length && !multimatch(path, ignoreMask).length) {
|
if (multimatch(path, jsFiles).length && !multimatch(path, ignoreMask).length) {
|
||||||
onSuccess(await getJS(path, { ignore: ignoreMask }, signatures));
|
onSuccess(await getJS(path, { ignore: ignoreMask }, signatures));
|
||||||
} else if (multimatch(path, scssFiles).length) {
|
|
||||||
if (multimatch(path, '**/_*.scss').length) {
|
|
||||||
onSuccess(await getSass(scssFiles, { ignore: ignoreMask }));
|
|
||||||
} else {
|
|
||||||
onSuccess(await getSass(path, {}, signatures));
|
|
||||||
}
|
|
||||||
} else if (multimatch(path, copyDirs.map(d => `${d}/**`)).length) {
|
|
||||||
onSuccess(await getCopy(path, {}, signatures));
|
|
||||||
} else if (multimatch(path, symlinks).length) {
|
|
||||||
onSuccess(await getSymlinks(path, { nodir: true }, signatures));
|
|
||||||
}
|
|
||||||
onSuccess(await cleanUp(signatures));
|
onSuccess(await cleanUp(signatures));
|
||||||
} catch (err) {
|
return;
|
||||||
|
}
|
||||||
|
for (var i = 0; i < scssFiles.length; i++) {
|
||||||
|
if (multimatch(path, scssFiles[i])) {
|
||||||
|
onSuccess(await getSass(scssFiles[i], { ignore: ignoreMask }));
|
||||||
|
onSuccess(await cleanUp(signatures));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (multimatch(path, copyDirs.map(d => `${d}/**`)).length) {
|
||||||
|
onSuccess(await getCopy(path, {}, signatures));
|
||||||
|
onSuccess(await cleanUp(signatures));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (multimatch(path, symlinks).length) {
|
||||||
|
onSuccess(await getSymlinks(path, { nodir: true }, signatures));
|
||||||
|
onSuccess(await cleanUp(signatures));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
onError(err);
|
onError(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
.on('unlink', async () => {
|
.on('unlink', async () => {
|
||||||
const signatures = await getSignatures();
|
const signatures = await getSignatures();
|
||||||
|
|
Loading…
Reference in a new issue