function mkdirs(dirname){ if(fs.existsSync(dirname)){ return true; }else{ if(mkdirs(path.dirname(dirname))){ fs.mkdirSync(dirname); return true; } } }
function getTestRoot(currentPath) { if (!currentPath) currentPath = '.'; if (!path.isAbsolute(currentPath)) currentPath = path.join(process.cwd(), currentPath); currentPath = fs.lstatSync(currentPath).isDirectory() || !path.extname(currentPath) ? currentPath : path.dirname(currentPath); return currentPath; }
function prepareMiddleware() { const tinymcePath = dirname(require.resolve('tinymce')); const app = express(); app.use('/tinymce-assets', express.static(tinymcePath)); return app; }
_(files) .flatMap(file => traverseUp(path.resolve(startFrom, file))) .sortBy().reverse() .filter(file => fs.existsSync(file) && path.isAbsolute(file)) .thru(files => _.isEmpty(files) ? [] : [_.first(files)]) .flatMap(dirFile => _.map(files, file => path.join(path.dirname(dirFile), file))) .filter(file => fs.existsSync(file)) .value()
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); } }
static from(request, forceOptions) { let dirPath = "." if (typeof request === "string") { dirPath = builtinLookup.has(request) ? "" : dirname(request) } else { dirPath = getModuleDirname(request) } return Package.get(dirPath, forceOptions) }
ipcMain.on('rename', (event, itemPath, newName) => { fs.rename(itemPath, path.join(path.dirname(itemPath), newName), (err) => { if(err) console.log(err); }); });
beforeAll(async function(state) { const DEVTOOLS_DIR = path.dirname( require.resolve('chrome-devtools-frontend/front_end/shell.json')); const frontendFolder = await fsMkdtemp(path.join(os.tmpdir(), 'ndb-test-frontend-')); await new ReleaseBuilder([ path.join(__dirname, '..', 'front_end'), DEVTOOLS_DIR, path.join(__dirname, '..'), path.join(__dirname, '..', '..', '..') ], frontendFolder).buildApp('integration_test_runner'); state.frontendFolder = frontendFolder; });
test("__dirname correctly set", () => { //expect.assertions(1); return get("/api/dirname", { json: true }).then(data => { expect(data.dirname.endsWith("api")).toBe(true); }); });
function getConfigPath () { if (IS_PORTABLE) { return PORTABLE_PATH } else { return path.dirname(appConfig.filePath) } }
test('use relative path with \'..\' chars', async t => { const pathViaParentDir = path.join('..', path.basename(path.dirname(__dirname)), 'test', 'fixtures', 'noop'); const {stdout} = await execa(pathViaParentDir, ['foo']); t.is(stdout, 'foo'); });
const loadHookDependencies = async (installedHooks, hooks) => { for (let hook of installedHooks) { const hookDir = path.dirname(require.resolve(`strapi-hook-${hook}`)); const files = await glob('*(index|defaults).*(js|json)', { cwd: hookDir, absolute: true, }); mountHooks(hook, files, hooks); } }
// const {cmder, rmDirFiles} = require('../utils/cmd'); // const fileTool = require('fs-extra'); const mkdirsSync = function(dirname) { if (fs.existsSync(dirname)) { return true; } if (mkdirsSync(path.dirname(dirname))) { fs.mkdirSync(dirname); return true; } }
const loadHookDependencies = async (installedHooks, hooks) => { for (let hook of installedHooks) { const hookDir = path.dirname(require.resolve(`strapi-hook-${hook}`)); const files = await glob('*(index|defaults).*(js|json)', { cwd: hookDir, absolute: true, }); mountHooks(hook, files, hooks); } }