mirror of
https://github.com/locomotivemtl/locomotive-boilerplate.git
synced 2026-01-15 00:55:08 +08:00
Fix support for undefined tasks
For example, if there are no `concats` tasks defined in 'loconfig.json', avoid throwing an error.
This commit is contained in:
@@ -95,7 +95,7 @@ export default async function concatFiles(globOptions = null, concatOptions = nu
|
|||||||
* Defaults to the outfile name.
|
* Defaults to the outfile name.
|
||||||
* @return {Promise}
|
* @return {Promise}
|
||||||
*/
|
*/
|
||||||
loconfig.tasks.concats.forEach(async ({
|
loconfig.tasks.concats?.forEach(async ({
|
||||||
includes,
|
includes,
|
||||||
outfile,
|
outfile,
|
||||||
label = null
|
label = null
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ export default async function compileScripts(esBuildOptions = null) {
|
|||||||
* @throws {TypeError} If outdir and outfile are missing.
|
* @throws {TypeError} If outdir and outfile are missing.
|
||||||
* @return {Promise}
|
* @return {Promise}
|
||||||
*/
|
*/
|
||||||
loconfig.tasks.scripts.forEach(async ({
|
loconfig.tasks.scripts?.forEach(async ({
|
||||||
includes,
|
includes,
|
||||||
outdir = '',
|
outdir = '',
|
||||||
outfile = '',
|
outfile = '',
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ export default async function compileStyles(sassOptions = null, postcssOptions =
|
|||||||
* Defaults to the outfile name.
|
* Defaults to the outfile name.
|
||||||
* @return {Promise}
|
* @return {Promise}
|
||||||
*/
|
*/
|
||||||
loconfig.tasks.styles.forEach(async ({
|
loconfig.tasks.styles?.forEach(async ({
|
||||||
infile,
|
infile,
|
||||||
outfile,
|
outfile,
|
||||||
label = null
|
label = null
|
||||||
@@ -216,15 +216,18 @@ export default async function compileStyles(sassOptions = null, postcssOptions =
|
|||||||
* @return {Promise}
|
* @return {Promise}
|
||||||
*/
|
*/
|
||||||
async function purgeUnusedCSS(outfile, label) {
|
async function purgeUnusedCSS(outfile, label) {
|
||||||
|
const contentFiles = loconfig.tasks.purgeCSS?.content;
|
||||||
|
if (!Array.isArray(contentFiles) || !contentFiles.length) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
label = label ?? basename(outfile);
|
label = label ?? basename(outfile);
|
||||||
|
|
||||||
const timeLabel = `${label} purged in`;
|
const timeLabel = `${label} purged in`;
|
||||||
console.time(timeLabel);
|
console.time(timeLabel);
|
||||||
|
|
||||||
const purgeCSSContentFiles = Array.from(loconfig.tasks.purgeCSS.content);
|
|
||||||
|
|
||||||
const purgeCSSResults = await (new PurgeCSS()).purge({
|
const purgeCSSResults = await (new PurgeCSS()).purge({
|
||||||
content: purgeCSSContentFiles,
|
content: contentFiles,
|
||||||
css: [ outfile ],
|
css: [ outfile ],
|
||||||
rejected: true,
|
rejected: true,
|
||||||
defaultExtractor: (content) => content.match(/[a-z0-9_\-\\\/\@]+/gi) || [],
|
defaultExtractor: (content) => content.match(/[a-z0-9_\-\\\/\@]+/gi) || [],
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ export default async function compileSVGs(mixerOptions = null) {
|
|||||||
* Defaults to the outfile name.
|
* Defaults to the outfile name.
|
||||||
* @return {Promise}
|
* @return {Promise}
|
||||||
*/
|
*/
|
||||||
loconfig.tasks.svgs.forEach(async ({
|
loconfig.tasks.svgs?.forEach(async ({
|
||||||
includes,
|
includes,
|
||||||
outfile,
|
outfile,
|
||||||
label = null
|
label = null
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ export default async function bumpVersions(versionOptions = null) {
|
|||||||
* @param {?string|number} [entry.pretty] - The white space to use to format the JSON file.
|
* @param {?string|number} [entry.pretty] - The white space to use to format the JSON file.
|
||||||
* @return {Promise}
|
* @return {Promise}
|
||||||
*/
|
*/
|
||||||
loconfig.tasks.versions.forEach(({
|
loconfig.tasks.versions?.forEach(({
|
||||||
outfile,
|
outfile,
|
||||||
label = null,
|
label = null,
|
||||||
...options
|
...options
|
||||||
|
|||||||
Reference in New Issue
Block a user