本文整理汇总了TypeScript中fs-extra.mkdirp函数的典型用法代码示例。如果您正苦于以下问题:TypeScript mkdirp函数的具体用法?TypeScript mkdirp怎么用?TypeScript mkdirp使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mkdirp函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: downloadAllGoldsAndCompare
/** Download golds screenshots. */
function downloadAllGoldsAndCompare(
files: any[], database: admin.database.Database,
prNumber: string) {
mkdirp(path.join(SCREENSHOT_DIR, `golds`));
mkdirp(path.join(SCREENSHOT_DIR, `diff`));
return Promise.all(files.map((file: any) => {
return downloadGold(file).then(() => diffScreenshot(file.name, database, prNumber));
})).then((results: boolean[]) => results.every((value: boolean) => value == true));
}
示例2: syncDatasetToGitRepo
export async function syncDatasetToGitRepo(datasetId: number, options: { transaction?: db.TransactionContext, oldDatasetName?: string, commitName?: string, commitEmail?: string, commitOnly?: boolean } = {}) {
const { oldDatasetName, commitName, commitEmail, commitOnly } = options
const oldDatasetFilename = oldDatasetName ? filenamify(oldDatasetName) : undefined
const datasetRepo = options.transaction ? options.transaction.manager.getRepository(Dataset) : Dataset.getRepository()
const dataset = await datasetRepo.findOne({ id: datasetId })
if (!dataset) {
throw new JsonError(`No such dataset ${datasetId}`, 404)
}
if (dataset.isPrivate) {
// Private dataset doesn't go in git repo
return removeDatasetFromGitRepo(oldDatasetName||dataset.name, dataset.namespace, options)
}
// Not doing bulk imports for now
if (dataset.namespace !== 'owid')
return
// Base repository directory for this dataspace
const repoDir = path.join(GIT_DATASETS_DIR, dataset.namespace)
if (!fs.existsSync(path.join(repoDir, '.git'))) {
await fs.mkdirp(repoDir)
await execFormatted(`cd %s && git init && git config user.name %s && git config user.email %s`, [repoDir, GIT_DEFAULT_USERNAME, GIT_DEFAULT_EMAIL])
}
// Output dataset to temporary directory
const tmpDatasetDir = path.join(TMP_DIR, dataset.filename)
await fs.mkdirp(tmpDatasetDir)
await Promise.all([
fs.writeFile(path.join(tmpDatasetDir, `${dataset.filename}.csv`), await dataset.toCSV()),
fs.writeFile(path.join(tmpDatasetDir, `datapackage.json`), JSON.stringify(await dataset.toDatapackage(), null, 2)),
fs.writeFile(path.join(tmpDatasetDir, `README.md`), await datasetToReadme(dataset))
])
const datasetsDir = path.join(repoDir, "datasets")
await fs.mkdirp(datasetsDir)
const finalDatasetDir = path.join(datasetsDir, dataset.filename)
const isNew = !fs.existsSync(finalDatasetDir)
await execFormatted(`cd %s && rm -rf %s && mv %s %s && git add -A %s`, [repoDir, finalDatasetDir, tmpDatasetDir, finalDatasetDir, finalDatasetDir])
if (oldDatasetFilename && oldDatasetFilename !== dataset.filename) {
const oldDatasetDir = path.join(datasetsDir, oldDatasetFilename)
await execFormatted(`cd %s && rm -rf %s && git add -A %s`, [repoDir, oldDatasetDir, oldDatasetDir])
}
const commitMsg = isNew ? `Adding ${dataset.filename}` : `Updating ${dataset.filename}`
await execFormatted(`cd %s && (git diff-index --quiet HEAD || (git commit -m %s --quiet --author="${commitName||GIT_DEFAULT_USERNAME} <${commitEmail||GIT_DEFAULT_EMAIL}>"${commitOnly ? "" : " && git push))"}`, [repoDir, commitMsg])
}
示例3: async
const writeSnapshot = async (diff: Snapshot, dir: string) => {
for (const key in diff) {
if (diff[key] instanceof Snap) {
await fs.mkdirp(path.dirname(path.resolve(dir, key)));
await fs.writeFile(path.resolve(dir, key), (diff[key] as Snap).data);
} else {
await fs.mkdirp(path.resolve(dir, key));
await writeSnapshot(diff[key] as Snapshot, dir);
}
}
};
示例4: it
it('should create dry run hash JSON files', async () => {
expect(makeStub.callCount).to.equal(2);
const dryRunFolder = path.resolve(dir, 'out', 'publish-dry-run');
expect(await fs.pathExists(dryRunFolder)).to.equal(true);
const hashFolders = await fs.readdir(dryRunFolder);
expect(hashFolders).to.have.length(2, 'Should contain two hashes (two publishes)');
for (const hashFolderName of hashFolders) {
const hashFolder = path.resolve(dryRunFolder, hashFolderName);
const makes = await fs.readdir(hashFolder);
expect(makes).to.have.length(3, 'Should contain the results of three makes');
for (const makeJson of makes) {
const jsonPath = path.resolve(hashFolder, makeJson);
const contents = await fs.readFile(jsonPath, 'utf8');
expect(() => JSON.parse(contents), 'Should be valid JSON').to.not.throw();
const data = JSON.parse(contents);
expect(data).to.have.property('artifacts');
expect(data).to.have.property('platform');
expect(data).to.have.property('arch');
expect(data).to.have.property('packageJSON');
// Make the artifacts for later
for (const artifactPath of data.artifacts) {
await fs.mkdirp(path.dirname(path.resolve(dir, artifactPath)));
await fs.writeFile(path.resolve(dir, artifactPath), artifactPath);
}
}
}
});
示例5: async
const copyApp = async (newDir: string, fixture = 'initial') => {
const appBundlePath = path.resolve(process.execPath, '../../..')
const newPath = path.resolve(newDir, 'Electron.app')
cp.spawnSync('cp', ['-R', appBundlePath, path.dirname(newPath)])
const appDir = path.resolve(newPath, 'Contents/Resources/app')
await fs.mkdirp(appDir)
await fs.copy(path.resolve(fixturesPath, 'auto-update', fixture), appDir)
const plistPath = path.resolve(newPath, 'Contents', 'Info.plist')
await fs.writeFile(
plistPath,
(await fs.readFile(plistPath, 'utf8')).replace('<key>BuildMachineOSBuild</key>', `<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSExceptionDomains</key>
<dict>
<key>localhost</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
</dict>
</dict><key>BuildMachineOSBuild</key>`)
)
return newPath
}
示例6: getScreenshotFiles
/** Get a list of filenames from firebase database. */
function getScreenshotFiles(database: firebase.database.Database) {
mkdirp(LOCAL_GOLDENS);
mkdirp(LOCAL_DIFFS);
return database.ref(FIREBASE_DATA_GOLDENS).once('value')
.then((snapshot: firebase.database.DataSnapshot) => {
let counter = 0;
snapshot.forEach((childSnapshot: firebase.database.DataSnapshot) => {
let key = childSnapshot.key;
let binaryData = new Buffer(childSnapshot.val(), 'base64').toString('binary');
writeFileSync(`${LOCAL_GOLDENS}/${key}.screenshot.png`, binaryData, 'binary');
counter++;
if (counter == snapshot.numChildren()) {
return true;
}
});
}).catch((error: any) => console.log(error));
}
示例7: run
async function run() {
await fs.mkdirp(cacheDir)
const { lat, lon } = await getLatLon()
debug('lat %o, lon: %o', lat, lon)
const weather = await getWeather({ lat, lon })
debug('got weather: %s', weather.daily.summary)
console.log(`${getIcon(weather.currently)} ${temp(weather.currently)}`)
}
示例8: Promise
return new Promise((resolve, reject) => {
fse.mkdirp(path.dirname(destination), error => {
if (error) {
reject(error);
} else {
fse.writeFileSync(destination, license + content);
resolve(destination);
}
});
});
示例9: initCache
protected async initCache(
token : string,
userId : string,
): Promise<void> {
log.verbose('PuppetPadchatManager', 'initCache(%s, %s)', token, userId)
if ( this.cacheContactRawPayload
|| this.cacheRoomMemberRawPayload
|| this.cacheRoomRawPayload
) {
throw new Error('cache exists')
}
const baseDir = path.join(
os.homedir(),
path.sep,
'.wechaty',
'puppet-padchat-cache',
path.sep,
token,
path.sep,
userId,
)
const baseDirExist = await fs.pathExists(baseDir)
if (!baseDirExist) {
await fs.mkdirp(baseDir)
}
this.cacheContactRawPayload = new FlashStoreSync(path.join(baseDir, 'contact-raw-payload'))
this.cacheRoomMemberRawPayload = new FlashStoreSync(path.join(baseDir, 'room-member-raw-payload'))
this.cacheRoomRawPayload = new FlashStoreSync(path.join(baseDir, 'room-raw-payload'))
await Promise.all([
this.cacheContactRawPayload.ready(),
this.cacheRoomMemberRawPayload.ready(),
this.cacheRoomRawPayload.ready(),
])
const roomMemberTotalNum = [...this.cacheRoomMemberRawPayload.values()].reduce(
(accuVal, currVal) => {
return accuVal + Object.keys(currVal).length
},
0,
)
log.verbose('PuppetPadchatManager', 'initCache() inited %d Contacts, %d RoomMembers, %d Rooms, cachedir="%s"',
this.cacheContactRawPayload.size,
roomMemberTotalNum,
this.cacheRoomRawPayload.size,
baseDir,
)
}