Skip to content

Commit

Permalink
Autofix and add comments/ignore a few issues
Browse files Browse the repository at this point in the history
  • Loading branch information
XhmikosR committed Oct 18, 2021
1 parent c6dc3b3 commit 20e5474
Show file tree
Hide file tree
Showing 33 changed files with 385 additions and 253 deletions.
127 changes: 65 additions & 62 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,21 @@ const rollupCommon = require('@rollup/plugin-commonjs');
const rollupReplace = require('@rollup/plugin-replace');
const { terser: rollupTerser } = require('rollup-plugin-terser');

const readJSON = async filePath => {
const readJSON = async (filePath) => {
const content = await fs.readFile(filePath, 'utf-8');
return JSON.parse(content);
};

function css() {
const boundSass = gulpSass(sass);
return gulp.src('src/css/*.scss')
return gulp
.src('src/css/*.scss')
.pipe(gulpSourcemaps.init())
.pipe(boundSass.sync({ outputStyle: 'compressed' }).on('error', boundSass.logError))
.pipe(
boundSass
.sync({ outputStyle: 'compressed' })
.on('error', boundSass.logError),
)
.pipe(gulpSourcemaps.write('./'))
.pipe(gulp.dest('build/'));
}
Expand All @@ -32,44 +37,51 @@ async function html() {
const [config, changelog, headCSS] = await Promise.all([
readJSON(path.join(__dirname, 'src', 'config.json')),
readJSON(path.join(__dirname, 'src', 'changelog.json')),
fs.readFile(path.join(__dirname, 'build', 'head.css'), 'utf-8')
fs.readFile(path.join(__dirname, 'build', 'head.css'), 'utf-8'),
]);

return gulp.src('src/*.html')
.pipe(gulpNunjucks.compile({
plugins: config.plugins,
headCSS,
changelog,
SVGO_VERSION: svgoPkg.version,
liveBaseUrl: 'https://jakearchibald.github.io/svgomg/',
title: `SVGOMG - SVGO's Missing GUI`,
description: 'Easy & visual compression of SVG images.',
iconPath: 'imgs/icon.png',
}))
.pipe(gulpHtmlmin({
collapseBooleanAttributes: true,
collapseInlineTagWhitespace: false,
collapseWhitespace: true,
decodeEntities: true,
minifyCSS: false,
minifyJS: true,
removeAttributeQuotes: true,
removeComments: true,
removeOptionalTags: true,
removeRedundantAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
sortAttributes: true,
sortClassName: true
}))
return gulp
.src('src/*.html')
.pipe(
gulpNunjucks.compile({
plugins: config.plugins,
headCSS,
changelog,
SVGO_VERSION: svgoPkg.version,
liveBaseUrl: 'https://jakearchibald.github.io/svgomg/',
title: `SVGOMG - SVGO's Missing GUI`,
description: 'Easy & visual compression of SVG images.',
iconPath: 'imgs/icon.png',
}),
)
.pipe(
gulpHtmlmin({
collapseBooleanAttributes: true,
collapseInlineTagWhitespace: false,
collapseWhitespace: true,
decodeEntities: true,
minifyCSS: false,
minifyJS: true,
removeAttributeQuotes: true,
removeComments: true,
removeOptionalTags: true,
removeRedundantAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
sortAttributes: true,
sortClassName: true,
}),
)
.pipe(gulp.dest('build'));
}

const rollupCaches = new Map();

async function js(entry, outputPath) {
const name = path.basename(path.dirname(entry));
const changelog = await readJSON(path.join(__dirname, 'src', 'changelog.json'));
const changelog = await readJSON(
path.join(__dirname, 'src', 'changelog.json'),
);
const bundle = await rollup.rollup({
cache: rollupCaches.get(entry),
input: `src/${entry}`,
Expand All @@ -80,14 +92,14 @@ async function js(entry, outputPath) {
}),
rollupResolve({ browser: true }),
rollupCommon({ include: /node_modules/ }),
rollupTerser()
]
rollupTerser(),
],
});
rollupCaches.set(entry, bundle.cache);
await bundle.write({
sourcemap: true,
format: 'iife',
file: `build/${outputPath}/${name}.js`
file: `build/${outputPath}/${name}.js`,
});
}

Expand All @@ -96,41 +108,42 @@ const allJs = gulp.parallel(
js.bind(null, 'js/gzip-worker/index.js', 'js/'),
js.bind(null, 'js/svgo-worker/index.js', 'js/'),
js.bind(null, 'js/sw/index.js', ''),
js.bind(null, 'js/page/index.js', 'js/')
js.bind(null, 'js/page/index.js', 'js/'),
);

function copy() {
return gulp.src([
'src/{.well-known,imgs,test-svgs,fonts}/**',
// Exclude the test-svgs files except for `car-lite.svg`
// which is used in the demo
'!src/test-svgs/!(car-lite.svg)',
'src/*.json'
]).pipe(gulp.dest('build'));
return gulp
.src([
'src/{.well-known,imgs,test-svgs,fonts}/**',
// Exclude the test-svgs files except for `car-lite.svg`
// which is used in the demo
'!src/test-svgs/!(car-lite.svg)',
'src/*.json',
])
.pipe(gulp.dest('build'));
}

function clean() {
return fs.rm('build', { force: true, recursive: true });
}

const mainBuild = gulp.parallel(
gulp.series(css, html),
allJs,
copy
);
const mainBuild = gulp.parallel(gulp.series(css, html), allJs, copy);

function watch() {
gulp.watch(['src/css/**/*.scss'], gulp.series(css, html));
gulp.watch(['src/js/**/*.js'], allJs);
gulp.watch(['src/*.{html,json}', 'src/**/*.{svg,woff2}'], gulp.parallel(html, copy, allJs));
gulp.watch(
['src/*.{html,json}', 'src/**/*.{svg,woff2}'],
gulp.parallel(html, copy, allJs),
);
}

function serve() {
sirv('build', {
host: 'localhost',
port: 8080,
dev: true,
clear: false
clear: false,
});
}

Expand All @@ -141,16 +154,6 @@ exports.html = html;
exports.copy = copy;
exports.build = mainBuild;

exports['clean-build'] = gulp.series(
clean,
mainBuild
);
exports['clean-build'] = gulp.series(clean, mainBuild);

exports.dev = gulp.series(
clean,
mainBuild,
gulp.parallel(
watch,
serve
)
);
exports.dev = gulp.series(clean, mainBuild, gulp.parallel(watch, serve));
4 changes: 2 additions & 2 deletions src/js/gzip-worker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ self.onmessage = (event) => {
const result = gzip(event.data.data).buffer;
self.postMessage({
id: event.data.id,
result
result,
});
} catch (error) {
self.postMessage({
id: event.data.id,
error: error.message
error: error.message,
});
}
};
2 changes: 1 addition & 1 deletion src/js/page/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import { trackFocusMethod } from './utils.js';
import MainController from './main-controller.js';

trackFocusMethod();
new MainController();
new MainController(); // eslint-disable-line no-new
Loading

0 comments on commit 20e5474

Please sign in to comment.