本文整理汇总了TypeScript中fs-extra.ensureDir函数的典型用法代码示例。如果您正苦于以下问题:TypeScript ensureDir函数的具体用法?TypeScript ensureDir怎么用?TypeScript ensureDir使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ensureDir函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: copyFileToTaro
copyFileToTaro (from: string, to: string, options?: fs.CopyOptionsSync) {
const filename = path.basename(from)
if (fs.statSync(from).isFile() && !path.extname(to)) {
fs.ensureDir(to)
return fs.copySync(from, path.join(to, filename), options)
}
fs.ensureDir(path.dirname(to))
return fs.copySync(from, to, options)
}
示例2: reject
return new Promise<FirefoxProfile>(async (resolve, reject) => {
if (config.srcProfileDir) {
FirefoxProfile.copy({
profileDirectory: config.srcProfileDir,
destinationDirectory: config.profileDir
},
(err, profile) => {
if (err || !profile) {
reject(err);
} else {
profile.shouldDeleteOnExit(false);
resolve(profile);
}
});
} else {
await fs.ensureDir(config.profileDir);
let profile = new FirefoxProfile({
destinationDirectory: config.profileDir
});
profile.shouldDeleteOnExit(false);
resolve(profile);
}
});
示例3: shouldGenerateAssets
shouldGenerateAssets(generator).then(res => {
if (res) {
fs.ensureDir(generator.vscodeFolder, err => {
addAssets(generator, operations);
});
}
});
示例4: join
(async () => {
const jsonDir = join(__dirname, "dist"),
magGarden = new MagGarden();
console.info("Starting to crawl MagGarden...");
await magGarden.crawl();
await ensureDir(jsonDir);
await Promise.all([
writeFile(join(jsonDir, "CNAME"), "api.comicstand.phanective.org"),
writeFile(join(jsonDir, "comics.json"), JSON.stringify(magGarden.Magazines)),
]);
return new Promise((resolve, reject) => {
publish("dist", {
repo: "git@github.com:phanect/static-comicstand-data.git",
}, (err: Error) => {
if (err) {
reject(err);
} else {
resolve();
}
});
});
})();
示例5: updateFixture
async function updateFixture(options: UpdateFixtureOptions) {
const fixturesDir =
path.resolve(__dirname, '../../fixtures/packages/', options.folder);
const sourceDir = path.join(fixturesDir, 'source');
const convertedDir = path.join(fixturesDir, 'expected');
if (!options.skipSourceUpdate) {
const branch = options.branch || 'master';
console.log(`Cloning ${options.repoUrl} #${branch} to ${sourceDir}...`);
await fs.ensureDir(fixturesDir);
await fs.remove(sourceDir);
await exec(
`git clone ${options.repoUrl} ${sourceDir} --branch=${
branch} --depth=1`,
{cwd: fixturesDir});
await fs.remove(path.join(sourceDir, '.git'));
await fs.remove(path.join(sourceDir, '.github'));
await fs.remove(path.join(sourceDir, '.gitignore'));
await overridePolymer(sourceDir);
await exec('bower install', {cwd: sourceDir});
}
const testConfig = require(path.join(fixturesDir, 'test.js')) as TestConfig;
await runFixture(sourceDir, convertedDir, testConfig);
// Our integration tests always skip bower_components when comparing, so
// there's no reason to check them into git.
await fs.remove(path.join(convertedDir, 'bower_components'));
console.log(`Done.`);
}
示例6: createApp
async function createApp(verbose: boolean, version: string) {
checkAppName(appName)
await fs.ensureDir(root)
const isSafe = await isSafeToCreateProjectIn(root)
if (!isSafe) {
console.log(
`The directory ${chalk.green(
appName
)} contains files that could conflict.`
)
console.log('Try using a new directory name.')
process.exit(1)
}
console.log(`Creating a new React app in ${chalk.green(root)}.`)
console.log()
const packageJson = {
name: appName,
version: '0.1.0',
private: true,
}
await fs.writeFile(
path.join(root, 'package.json'),
JSON.stringify(packageJson, null, 2)
)
process.chdir(root)
await run(appName, version, verbose)
}
示例7: AssetGenerator
return this.checkWorkspaceInformationMatchesWorkspaceFolder(folder).then(async workspaceMatches => {
const generator = new AssetGenerator(info);
if (workspaceMatches && containsDotNetCoreProjects(info)) {
const dotVscodeFolder: string = path.join(folder.uri.fsPath, '.vscode');
const tasksJsonPath: string = path.join(dotVscodeFolder, 'tasks.json');
// Make sure .vscode folder exists, addTasksJsonIfNecessary will fail to create tasks.json if the folder does not exist.
return fs.ensureDir(dotVscodeFolder).then(async () => {
// Check to see if tasks.json exists.
return fs.pathExists(tasksJsonPath);
}).then(async tasksJsonExists => {
// Enable addTasksJson if it does not exist.
return addTasksJsonIfNecessary(generator, {addTasksJson: !tasksJsonExists});
}).then(() => {
const isWebProject = generator.hasWebServerDependency();
const launchJson: string = generator.createLaunchJson(isWebProject);
// jsonc-parser's parse function parses a JSON string with comments into a JSON object. However, this removes the comments.
return parse(launchJson);
});
}
// Error to be caught in the .catch() below to write default C# configurations
throw new Error("Does not contain .NET Core projects.");
});
示例8: printLog
files.forEach(file => {
let outputFilePath
if (NODE_MODULES_REG.test(file)) {
outputFilePath = file.replace(nodeModulesPath, npmOutputDir)
} else {
outputFilePath = file.replace(sourceDir, outputDir)
}
if (isCopyingFiles.get(outputFilePath)) {
return
}
isCopyingFiles.set(outputFilePath, true)
let modifySrc = file.replace(appPath + path.sep, '')
modifySrc = modifySrc.split(path.sep).join('/')
let modifyOutput = outputFilePath.replace(appPath + path.sep, '')
modifyOutput = modifyOutput.split(path.sep).join('/')
printLog(processTypeEnum.COPY, '文件', modifyOutput)
if (!fs.existsSync(file)) {
printLog(processTypeEnum.ERROR, '文件', `${modifySrc} 不存在`)
} else {
fs.ensureDir(path.dirname(outputFilePath))
if (file === outputFilePath) {
return
}
if (cb) {
cb(file, outputFilePath)
} else {
fs.copySync(file, outputFilePath)
}
}
})
示例9: checkEnv
async checkEnv () {
this.emit('progress', 'checkJava')
await this._checkJava()
this.emit('progress', 'cleanNatives')
await this._cleanNatives()
this._arguments.push(`-Djava.library.path=${this._nativesPath}`)
this.emit('progress', 'resolveLibraries')
await this._setupLibraries()
this.emit('progress', 'resolveNatives')
await fs.mkdir(this._nativesPath)
await this._setupNatives()
if (this._missingLibrary.length !== 0) {
this.emit('missing_all', this._missingLibrary)
let err = new Error('missing library')
err['missing'] = this._missingLibrary
err['launcher'] = this
throw err
}
await fs.ensureDir(this._gameDirectory)
this.emit('progress', 'mergeArguments')
this._arguments.push(this.opts.json['mainClass'])
this._mcArguments()
this.emit('progress', 'envOK')
}
示例10: withAfterEach
withAfterEach(async t => {
await fse.ensureDir('out');
const { stderr } = shell.exec('node dist/src/cp-cli test/assets out');
t.equal(stderr, '');
const stats = fse.statSync('out/foo.txt');
t.true(stats.isFile());
}),