const copy = (source, dest) => { if (source && fs.existsSync(source) && fs.existsSync(dest)) { fs.unlinkSync(dest); fs.createReadStream(source).pipe(fs.createWriteStream(dest)); return; } throw new Error("not match"); }
function readConfig(storage) { var dataDir = getDataDir(); var configFile = path.join(dataDir, encodeURIComponent('#' + (storage ? storage + '#' : ''))); if (!fs.existsSync(configFile)) { return; } try { return fse.readJsonSync(configFile); } catch(e) {} }
// Resolve file paths in the same order as webpack const resolveModule = (resolveFn, filePath) => { const extension = moduleFileExtensions.find(extension => fs.existsSync(resolveFn(`${filePath}.${extension}`)) ); if (extension) { return resolveFn(`${filePath}.${extension}`); } return resolveFn(`${filePath}.js`); }
targetBuildModules.forEach(function (name) { if (name != '.git' && name != 'build' && name != 'publicMethods' && name != 'dist') { shell.cd(`${modulesPath}/${name}`); shell.exec(`${envSetStr} NODE_ENV=production && npm run build`); if (!fs.existsSync(`${modulesPath}/dist/${name}`)) { shell.mkdir('-p', `${modulesPath}/dist/${name}`); } else { shell.rm('-rf', `${modulesPath}/dist/${name}/*`); } shell.cp('-R', `${modulesPath}/${name}/dist/*`, `${modulesPath}/dist/${name}`); console.info(`module ${name} build success!`); } });
function removeDir(installPath) { if (fs.existsSync(installPath)) { fse.removeSync(installPath); } }
function getFilename({ lang, parentPaths, slug, isDir }) { let filename = ''; if (isDir) { filename = path.join(docsDir, lang, parentPaths.join('/'), isDir ? slug : '', 'README.md'); if (fs.existsSync(filename)) { return filename; } } filename = path.join(docsDir, lang, parentPaths.join('/'), `${slug}.md`); if (fs.existsSync(filename)) { return filename; } return ''; }
async copyThemeToStaticForder(ctx, app, tempAlias, DOWNLOAD_DIR) { let temp_static_forder = app.config.temp_static_forder; let fromPath = app.config.temp_view_forder + tempAlias + '/dist/*'; let assetsPath = app.config.temp_view_forder + tempAlias + '/assets/'; let targetPath = temp_static_forder + tempAlias; let targetAssetPath = path.join(app.config.baseDir, `app/assets/${tempAlias}`); // 拷贝静态资源 if (!fs.existsSync(targetPath)) { shell.mkdir('-p', targetPath); } shell.cp('-R', fromPath, targetPath); if (!fs.existsSync(targetAssetPath)) { shell.mkdir('-p', targetAssetPath); } shell.cp('-R', assetsPath, targetAssetPath); // 拷贝静态资源源文件 // ctx.helper.copyForder(fromPath, targetPath); // ctx.helper.copyForder(assetsPath, targetAssetPath); await ctx.helper.deleteFolder(DOWNLOAD_DIR + `${tempAlias}.zip`); let macFile = DOWNLOAD_DIR + '__MACOSX'; if (fs.existsSync(macFile)) { await ctx.helper.deleteFolder(macFile); } }
before(app, server) { if (fs.existsSync(paths.proxySetup)) { // This registers user provided middleware for proxy reasons require(paths.proxySetup)(app); } // This lets us fetch source contents from webpack for the error overlay app.use(evalSourceMapMiddleware(server)); // This lets us open files from the runtime error overlay. app.use(errorOverlayMiddleware()); // This service worker file is effectively a 'no-op' that will reset any // previous service worker registered for the same host:port combination. // We do this in development to avoid hitting the production cache if // it used the same host and port. // https://github.com/facebook/create-react-app/issues/2272#issuecomment-302832432 app.use(noopServiceWorkerMiddleware()); }
// 扫描某路径下文件夹是否存在 checkExistFile(targetPath, forderArr) { let distPath = true; for (let i = 0; i < forderArr.length; i++) { const forder = forderArr[i]; if (!fs.existsSync(`${targetPath}/${forder}`)) { distPath = false; break; } } return distPath; }
const fileName = path.join(__dirname, './test-excel.xlsx'); await analyzer.generateExcel(fileName, analysis); const exists = fs.existsSync(fileName); expect(exists).toBeTruthy(); if (exists) {
downloadTempFile(ctx, file_url, DOWNLOAD_DIR) { return new Promise(async (resolve, reject) => { if (!fs.existsSync(DOWNLOAD_DIR)) { fs.mkdirSync(DOWNLOAD_DIR); } let file_name = url.parse(file_url).pathname.split('/').pop(); const res = await ctx.curl(file_url, { streaming: true, }); let stream = res.res; const writeStream = fs.createWriteStream(DOWNLOAD_DIR + file_name) try { await awaitWriteStream(stream.pipe(writeStream)) setTimeout(() => { resolve(); }, 5000) } catch (err) { // 必须将上传的文件流消费掉,要不然浏览器响应会卡死 await sendToWormhole(stream) reject(err); } }) }
static ensureDir(dirPath, recursive = true) { if (!fs.existsSync(dirPath)) { fs.mkdirSync(dirPath, { recursive }); } }
// Load environment variables from .env* files. Suppress warnings using silent // if this file is missing. dotenv will never modify any environment variables // that have already been set. Variable expansion is supported in .env files. // https://github.com/motdotla/dotenv // https://github.com/motdotla/dotenv-expand dotenvFiles.forEach(dotenvFile => { if (fs.existsSync(dotenvFile)) { require('dotenv-expand')( require('dotenv').config({ path: dotenvFile, }) ); } });
function existsSync(fileName) { return fs.existsSync(fileName); }
function mkdir(path) { !fs.existsSync(path) && fs.mkdirSync(path); return path; }