const mkdirsSync = function(dirname) { if (fs.existsSync(dirname)) { return true; } if (mkdirsSync(path.dirname(dirname))) { fs.mkdirSync(dirname); return true; } }
function writeFile(directory, pathname, buffer, dirs) { pathname = path.join.apply(path, [].concat(directory.split('/'), pathname.split('/'))); let paths = pathname.split(path.sep); for (let i = 1; i < paths.length; i++) { let dirpath = path.join.apply(path, [process.cwd()].concat(paths.slice(0, i))); if (!dirs[dirpath]) { !fs.existsSync(dirpath) && fs.mkdirSync(dirpath); dirs[dirpath] = true; } } fs.writeFileSync(path.join(process.cwd(), pathname), buffer, {mode: 0o777}); return dirs; }
function initLogs( timestamp ) { const dir = path.join( E2E_DIR, 'logs', `${ timestamp }` ); mkdirSync( dir, { recursive: true } ); const appLogPath = path.join( dir, `app-${ timestamp }.log` ); const driverLogPath = path.join( dir, `chromedriver-${ timestamp }.log` ); const appLogFd = openSync( appLogPath, 'a' ); const driverLogFd = openSync( driverLogPath, 'a' ); if ( ! appLogFd || ! driverLogFd ) { throw 'failed to initialize logs'; } const appLog = { path: appLogPath, fd: appLogFd }; const driverLog = { path: driverLogPath, fd: driverLogFd }; return { appLog, driverLog }; }
fs.readdir("./icons", function (err, files) { extract(files); if (!fs.existsSync("./dist")) { fs.mkdirSync("./dist"); } fs.writeFile('./dist/icons.json', JSON.stringify(svgObject), (err) => { if (err) throw err; console.log(chalk.whiteBright.bgBlack.bold("Created [JSON] for SVG Icons !! ")); }); });
/** * Make directories recursively * @param {String} p - directory path */ makeDirs(p) { p.split(path.sep) .reduce((prevPath, folder) => { const currentPath = path.join(prevPath, folder, path.sep); if (!fs.existsSync(currentPath)) { fs.mkdirSync(currentPath); } return currentPath; }, ""); }
modules.getTempfromHandlebar( `${modules.config.templatesDir}/component.hbs`, options, code => { if ( !fs.existsSync(`${modules.config.componentsDir}/${options.filename}`) ) { fs.mkdirSync(`${modules.config.componentsDir}/${options.filename}`); } fs.writeFile( `${modules.config.componentsDir}/${options.filename}/index.js`, code, { flag: 'wx' }, _err => { if (_err) throw _err; callback(); } ); } );
/** * save app.config to `run/${type}_config.json` * @private */ dumpConfig() { const rundir = this.config.rundir; try { /* istanbul ignore if */ if (!fs.existsSync(rundir)) fs.mkdirSync(rundir); // get dumpped object const { config, meta } = this.dumpConfigToObject(); // dump config const dumpFile = path.join(rundir, `${this.type}_config.json`); fs.writeFileSync(dumpFile, CircularJSON.stringify(config, null, 2)); // dump config meta const dumpMetaFile = path.join(rundir, `${this.type}_config_meta.json`); fs.writeFileSync(dumpMetaFile, CircularJSON.stringify(meta, null, 2)); } catch (err) { this.coreLogger.warn(`dumpConfig error: ${err.message}`); } }
function createDir(dirpath) { if (!fs.existsSync(dirpath)) { var pathtmp; dirpath.split(path.sep).forEach(function(dirname) { if(!dirname) { pathtmp=path.sep; return; } if (pathtmp) { pathtmp = path.join(pathtmp, dirname); } else { pathtmp = dirname; } if (!fs.existsSync(pathtmp)) { if (!fs.mkdirSync(pathtmp)) { return false; } } }); console.log("目录创建成功"); } return true; }
let relpath = pathname.split(path.sep).slice(0, i + 1).join(path.sep); try { !fs.existsSync(relpath) && fs.mkdirSync(relpath); } catch (e) { console.error(e);
let relpath = pathname.split(path.sep).slice(0, i + 1).join(path.sep); try { !fs.existsSync(relpath) && fs.mkdirSync(relpath); } catch (e) { console.error(e); let relpath = outputPath.split(path.sep).slice(0, i + 1).join(path.sep); try { !fs.existsSync(relpath) && fs.mkdirSync(relpath); } catch (e) { console.error(e);