function hotReloadService(service) { const relPath = path.relative(process.cwd(), service.__filename); broker.logger.info(`Hot reload '${service.name}' service...`, kleur.grey(relPath)); return broker.destroyService(service) .then(() => { if (fs.existsSync(service.__filename)) { return broker.loadService(service.__filename); } }); }
_onRemove(filePath) { filePath = slash(filePath); const relativePath = path.relative(this.sourcePath, filePath); if ( relativePath.indexOf("node_modules") !== -1 || relativePath.indexOf("zero-builds") !== -1 ) { return; } debug("[REM]".yellow, filePath); if (this.isWatching) this._emitFileChange("remove", filePath); }
/** * Get jest aliases based on the baseUrl of a compilerOptions object. * * @param {*} options */ function getJestAliases(options = {}) { const baseUrl = options.baseUrl; if (!baseUrl) { return {}; } const baseUrlResolved = path.resolve(paths.appPath, baseUrl); if (path.relative(paths.appPath, baseUrlResolved) === '') { return { '^src/(.*)$': '<rootDir>/src/$1', }; } }
const relativePath = p => path.relative(process.env.SOURCEPATH, p)
async fileHashes(directory) { directory = directory || this.directory; let result = {}; const files = await fs.readdir(directory); // eslint-disable-next-line no-restricted-syntax for (const file of files) { const filePath = path.resolve(directory, file); if (!this.filter(filePath)) { // eslint-disable-next-line no-continue continue; } const stat = await fs.stat(filePath); if (stat.isDirectory()) { result = { ...result, ...await this.fileHashes(filePath) }; } else { result[path.relative(this.directory, filePath)] = { hash: await this.fileHash(filePath) }; } } return result; }
task.plugin('zip', { every:false }, function * (files, opts) { opts = Object.assign({ file:'archive.zip' }, opts); let curr; for (const file of files) { if (file.data) { curr = p.relative(task.root, p.format(file)); zip.file(curr, file.data, { base64:true }); } } const outdata = yield zip.generateAsync({ type:'nodebuffer' }); // if an alt `dest` was given if (opts.dest !== void 0) { // write file without overwriting files const outfile = p.resolve(task.root, opts.dest, opts.file); yield utils.write(outfile, outdata); } else { // overwrite with the archive this._.files = [{ dir: files[0].dir, base: opts.file, data: outdata }]; } });
const relPath = obj => p.relative(obj.dir, p.format(obj))
_onAdd(filePath) { filePath = slash(filePath); const relativePath = path.relative(this.sourcePath, filePath); if ( relativePath.indexOf("node_modules") !== -1 || relativePath.indexOf(".git") !== -1 || relativePath === "yarn.lock" || relativePath === "package.json" // pkg.json is generated by installPackages.js ) { return; } // don't trigger for zero-builds folder (only in dev mode) if (ISDEV && relativePath.indexOf("zero-builds") !== -1) { return; } debug("[ADD]".yellow, filePath); if (this.isWatching) this._emitFileChange("add", filePath); }
/** * Get webpack aliases based on the baseUrl of a compilerOptions object. * * @param {*} options */ function getWebpackAliases(options = {}) { const baseUrl = options.baseUrl; if (!baseUrl) { return {}; } const baseUrlResolved = path.resolve(paths.appPath, baseUrl); if (path.relative(paths.appPath, baseUrlResolved) === '') { return { src: paths.appSrc, }; } }
_onRemove(filePath) { filePath = slash(filePath); const relativePath = path.relative(this.sourcePath, filePath); if ( relativePath.indexOf("node_modules") !== -1 || relativePath.indexOf("zero-builds") !== -1 ) { return; } debug("[REM]".yellow, filePath); if (this.isWatching) this._emitFileChange("remove", filePath); }
/** * Get jest aliases based on the baseUrl of a compilerOptions object. * * @param {*} options */ function getJestAliases(options = {}) { const baseUrl = options.baseUrl; if (!baseUrl) { return {}; } const baseUrlResolved = path.resolve(paths.appPath, baseUrl); if (path.relative(paths.appPath, baseUrlResolved) === '') { return { '^src/(.*)$': '<rootDir>/src/$1', }; } }
const relPath = obj => p.relative(obj.dir, p.format(obj))
const relativePath = p => path.relative(process.env.SOURCEPATH, p)
/** * Get webpack aliases based on the baseUrl of a compilerOptions object. * * @param {*} options */ function getWebpackAliases(options = {}) { const baseUrl = options.baseUrl; if (!baseUrl) { return {}; } const baseUrlResolved = path.resolve(paths.appPath, baseUrl); if (path.relative(paths.appPath, baseUrlResolved) === '') { return { src: paths.appSrc, }; } }
_onAdd(filePath) { filePath = slash(filePath); const relativePath = path.relative(this.sourcePath, filePath); if ( relativePath.indexOf("node_modules") !== -1 || relativePath.indexOf(".git") !== -1 || relativePath === "yarn.lock" || relativePath === "package.json" // pkg.json is generated by installPackages.js ) { return; } // don't trigger for zero-builds folder (only in dev mode) if (ISDEV && relativePath.indexOf("zero-builds") !== -1) { return; } debug("[ADD]".yellow, filePath); if (this.isWatching) this._emitFileChange("add", filePath); }