UNPKG

vue-build-helper

Version:

Streamline the Vue CLI 3 build process

73 lines (66 loc) 2.28 kB
const { deleteFile } = require('../common/fs-helpers') const FileHound = require('filehound') const filterOn = 'demo.html' // Enable or disable debug output let debug = false // Enable or disable verbose output let verbose = false // Enable or disable quiet mode let quiet = false /** * Custom filter to filter files by (*.common.js). * @param {Object} file - The file object * @returns {boolean} true if the file meets the filter, otherwise false */ // TODO move to shared module function customFilter (file) { return file._pathname.endsWith(filterOn) } /** * Deletes all demo.html files. * @param {Array<String>} files - An array with fully qualified paths to the files to delete */ function processFiles (files) { if (files.length === 0) { !quiet && console.log('No files to delete') } else { files.forEach(filePath => { !quiet && console.log('Deleting file: ' + filePath) deleteFile(filePath) }) } } /** * Retrieve files (buildDestPath) that meet the filename filter (demo.html). It recursively search from this start * directory for any files that match the file filter. * @param {string} buildDestPath - A fully qualified path to the directory to start processing from * @returns {Array} with files to process */ function getFiles (buildDestPath) { const files = FileHound.create() .paths(buildDestPath) .addFilter(customFilter) .findSync() return files } /** * Main entry point to module deletes the demo.html files generated by the Vue CLI build command. * * Takes the following option object: * { * buildDestPath: the start directory to start searching for demo.html files, if not specified it uses a sane * default: dist * verbose: output debugging information, default false * quiet: report errors only, default false * } * * @param {Object} options - See description above */ function deleteDemoHtml (options) { debug = options && options.debug ? options.debug : false verbose = options && options.verbose ? options.verbose : false quiet = options && options.quiet ? options.quiet : false debug && console.log('create-exports', JSON.stringify(options, null, '\t')) processFiles(getFiles(options.buildDestPath)) } module.exports = deleteDemoHtml