// export current crontab db so that user can download it app.get(routes.export, function(req, res) { var file = crontab.crontab_db_file; var filename = path.basename(file); var mimetype = mime.lookup(file); res.setHeader('Content-disposition', 'attachment; filename=' + filename); res.setHeader('Content-type', mimetype); var filestream = fs.createReadStream(file); filestream.pipe(res); });
/* * Helper to traverse up directories from a start point */ const traverseUp = file => _(_.range(path.dirname(file).split(path.sep).length)) .map(end => _.dropRight(path.dirname(file).split(path.sep), end).join(path.sep)) .map(dir => path.join(dir, path.basename(file))) .value()
/* * Helper to parse a command into useful metadataz */ const parseCmd = meta => _.merge({}, meta, { bin: _.trimEnd(path.basename(_.first(meta._), '"')), cmd: meta._[1], args: _.drop(meta._, 2), })
fs .readdirSync(dir, { withFileTypes: true }) .filter(file => file.isFile()) .reduce((acc, file) => { const key = path.basename(file.name, path.extname(file.name)); acc[key] = loadFile(path.resolve(dir, file.name)); return acc; }, {})
function copyAsset( assetPath, targetName ) { if ( ! targetName ) { targetName = basename( assetPath ); } const target = join( __dirname, '..', 'src', '__color-studio', targetName ); if ( ! existsSync( dirname( target ) ) ) { mkdirSync( dirname( target ), { recursive: true } ); } copyFileSync( require.resolve( assetPath ), join( target ) ); }
/** * Whether or not this attachment has been marked as a spoiler * @type {boolean} * @readonly */ get spoiler() { return Util.basename(this.url).startsWith('SPOILER_'); }
static load(luFile: string, targetFileName: string, dialogPath: string, luisSettings: Settings, existingRecognizer: any, schema?: string): Recognizer { if (existingRecognizer) { let recognizer = new Recognizer(luFile, targetFileName, schema) recognizer.dialogPath = dialogPath Object.assign(recognizer, existingRecognizer) recognizer.setAppId(luisSettings.luis[path.basename(luFile).split('.').join('_')]) return recognizer } let recognizer = new Recognizer(luFile, targetFileName, schema) recognizer.dialogPath = dialogPath return recognizer }
function test_folder( dir ) { const testFiles = fs .readdirSync( dir ) .filter( ( f ) => ! f.endsWith( '.spec.js' ) && f.endsWith( '.js' ) ); testFiles.forEach( ( filename ) => { const filepath = path.join( dir, filename ); test( filename, () => { const result = api.runCodemodDry( path.basename( dir ), filepath ); expect( result ).toMatchSnapshot(); } ); } ); }
const prepareFile = _filePath => { const filePath = path.resolve(`packages/fields/src/types/File/test-files/${_filePath}`); const upload = new Upload(); upload.resolve({ createReadStream: () => fs.createReadStream(filePath), filename: path.basename(filePath), mimetype: mime.getType(filePath), encoding: 'utf-8', }); return upload; }
function help(status) { const print = (status === 0) ? console.log : console.error print("usage: " + basename(process.argv[1]) + " [--ecma3|--ecma5|--ecma6|--ecma7|--ecma8|--ecma9|...|--ecma2015|--ecma2016|--ecma2017|--ecma2018|...]") print(" [--tokenize] [--locations] [---allow-hash-bang] [--compact] [--silent] [--module] [--help] [--] [infile]") process.exit(status) }
async findPackage(dir) { // Find the nearest package.json file within the current node_modules folder let root = path.parse(dir).root; while (dir !== root && path.basename(dir) !== "node_modules") { try { return await this.readPackage(dir); } catch (err) { // ignore } dir = path.dirname(dir); } }
// Read all files from that path and load into modules fs.readdirSync(dir).forEach(function (file) { if (file.indexOf('.js') < 0) return; var mod = require(path.join(dir, file)); var name = path.basename(file, '.js'); loaded[name] = mod; });
function getExternalPlayerName () { const playerPath = this.saved.prefs.externalPlayerPath if (!playerPath) return 'VLC' return path.basename(playerPath).split('.')[0] }
/** * Deletes the API folder of a contentType * @param {string} uid content type uid */ async function clear(uid) { const { apiName, __filename__ } = strapi.contentTypes[uid]; const apiFolder = path.join(strapi.dir, 'api', apiName); // base name of the model file that will be use as comparator const baseName = path.basename(__filename__, '.settings.json'); await recursiveRemoveFiles(apiFolder, createDeleteApiFunction(baseName)); await deleteBackup(uid); }
test('multiple negative patterns should act as positive patterns', async t => { const cwd = path.join(__dirname, 'fixtures', 'gitignore-multiple-negation'); const {results} = await fn.lintFiles('**/*', {cwd}); const paths = results.map(r => path.basename(r.filePath)); paths.sort(); t.deepEqual(paths, ['!!unicorn.js', '!unicorn.js']); });