本文整理匯總了TypeScript中fs-promise.exists函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript exists函數的具體用法?TypeScript exists怎麽用?TypeScript exists使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了exists函數的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: loadModels
/**
* Load all models from plugins.
*
* @param sequelize {Sequelize}
*
* @returns {Promise}
*/
public async loadModels(sequelize: Sequelize) {
if (this.order.length === 0) {
this.determinateOrder();
}
for (let id of this.order) {
if (this.plugins[id].directory) {
var modelDirectory = path.normalize(this.plugins[id].directory + '/models/');
var exists = await fs.exists(modelDirectory);
if (! exists) {
modelDirectory = path.normalize(this.plugins[id].directory + '/Models/');
exists = await fs.exists(modelDirectory);
if (! exists) continue;
}
try {
let list = glob.sync(modelDirectory + '*.js');
if (list.length > 0) {
for (let file of list) {
// Import sequelize model.
let model: any = sequelize.import(file);
// Set in the plugin.
if (! this.plugins[id].models) {
this.plugins[id].models = {};
}
this.plugins[id].models[model.name] = model;
// Set in the global models.
if (! this.app.models.hasOwnProperty(id)) {
this.app.models[id] = {};
}
this.app.models[id][model.name] = model;
}
}
} catch (err) {
this.app.log.warn('Warning, can\'t load models for plugin ' + id, err.stack);
}
}
}
}
示例2: createFromFile
/**
* Creates a server and database from reading a settings file.
*
* @param filePath Path to the settings file.
* @returns A promise for a new running server.
*/
public static async createFromFile(filePath: string): Promise<Server> {
const settings: IAssassinsSettings = await fsp.exists(filePath)
.then(exists => {
if (!exists) {
throw new Error(`'${filePath}' not found.\nMake sure you copied '${filePath.replace(".json", ".default.json")}' to '${filePath}'.`);
}
})
.then(() => fsp.readFile(filePath))
.then((data: Buffer) => JSON.parse(data.toString()));
return await Server.createFromSettings(settings);
}
示例3: locateElectronPrebuilt
(async () => {
const electronPrebuiltPath = argv.e ? path.resolve(process.cwd(), argv.e) : locateElectronPrebuilt();
let electronPrebuiltVersion = argv.v;
if (!electronPrebuiltVersion) {
try {
if (!electronPrebuiltPath) throw new Error("electron-prebuilt not found");
const pkgJson = require(path.join(electronPrebuiltPath, 'package.json'));
electronPrebuiltVersion = pkgJson.version;
} catch (e) {
throw new Error('Unable to find electron-prebuilt\'s version number, either install it or specify an explicit version');
}
}
let rootDirectory = argv.m;
if (!rootDirectory) {
// NB: We assume here that we're going to rebuild the immediate parent's
// node modules, which might not always be the case but it's at least a
// good guess
rootDirectory = path.resolve(__dirname, '../../..');
if (!await fs.exists(rootDirectory) || !await fs.exists(path.resolve(rootDirectory, 'package.json'))) {
// Then we try the CWD
rootDirectory = process.cwd();
if (!await fs.exists(rootDirectory) || !await fs.exists(path.resolve(rootDirectory, 'package.json'))) {
throw new Error('Unable to find parent node_modules directory, specify it via --module-dir, E.g. "--module-dir ." for the current directory');
}
}
} else {
rootDirectory = path.resolve(process.cwd(), rootDirectory);
}
let modulesDone = 0;
let moduleTotal = 0;
const rebuildSpinner = ora('Searching dependency tree').start();
let lastModuleName: string;
const redraw = (moduleName?: string) => {
if (moduleName) lastModuleName = moduleName;
if (argv.p) {
rebuildSpinner.text = `Building modules: ${modulesDone}/${moduleTotal}`;
} else {
rebuildSpinner.text = `Building module: ${lastModuleName}, Completed: ${modulesDone}`;
}
}
const rebuilder = rebuild(rootDirectory, electronPrebuiltVersion, argv.a || process.arch, argv.w ? argv.w.split(',') : [], argv.f, argv.d, argv.t ? argv.t.split(',') : ['prod', 'dev'], argv.p ? 'parallel' : (argv.s ? 'sequential' : undefined));
const lifecycle = rebuilder.lifecycle;
lifecycle.on('module-found', (moduleName: string) => {
moduleTotal += 1;
redraw(moduleName);
});
lifecycle.on('module-done', () => {
modulesDone += 1;
redraw();
});
try {
await rebuilder;
} catch (err) {
rebuildSpinner.text = 'Rebuild Failed';
rebuildSpinner.fail();
throw err;
}
rebuildSpinner.text = 'Rebuild Complete';
rebuildSpinner.succeed();
})();
示例4: it
it('should not have rebuilt top level devDependencies', async () => {
const forgeMeta = path.resolve(testModulePath, 'node_modules', 'ffi', 'build', 'Release', '.forge-meta');
expect(await fs.exists(forgeMeta), 'ffi build meta should not exist').to.equal(false);
});