本文整理汇总了TypeScript中fs-extra.ensureDirSync函数的典型用法代码示例。如果您正苦于以下问题:TypeScript ensureDirSync函数的具体用法?TypeScript ensureDirSync怎么用?TypeScript ensureDirSync使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ensureDirSync函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: processFile
async function processFile(filePath) {
if (!fs.existsSync(filePath)) {
return
}
const dirname = path.dirname(filePath)
const distDirname = dirname.replace(sourceDir, tempDir)
let distPath = path.format({dir: distDirname, base: path.basename(filePath)})
const code = fs.readFileSync(filePath, 'utf-8')
if (REG_STYLE.test(filePath)) {
// do something
} else if (REG_SCRIPTS.test(filePath)) {
if (REG_TYPESCRIPT.test(filePath)) {
distPath = distPath.replace(/\.(tsx|ts)(\?.*)?$/, '.js')
}
Util.printLog(processTypeEnum.COMPILE, _.camelCase(path.extname(filePath)).toUpperCase(), filePath)
// transformJSCode
const transformResult = transformJSCode({code, filePath, isEntryFile: isEntryFile(filePath), projectConfig})
const jsCode = transformResult.code
fs.ensureDirSync(distDirname)
fs.writeFileSync(distPath, Buffer.from(jsCode))
// compileDepStyles
const styleFiles = transformResult.styleFiles
depTree[filePath] = styleFiles
await compileDepStyles(filePath, styleFiles)
} else {
fs.ensureDirSync(distDirname)
fs.copySync(filePath, distPath)
Util.printLog(processTypeEnum.COPY, _.camelCase(path.extname(filePath)).toUpperCase(), filePath)
}
}
示例2: forEach
forEach(tasks.getTasks(), (task) => {
const targetNodeCommonDir = path.join(task.directory, "common");
const taskNodeModules = path.join(task.directory, "node_modules");
const targetPowershellCommonDir = path.join(task.directory, "ps_modules");
const taskFilePath = path.join(task.directory, "task.json");
const taskFile = fs.existsSync(taskFilePath) ? fs.readJsonSync(taskFilePath) : {};
if (taskFile.execution.Node) {
fs.ensureDirSync(targetNodeCommonDir);
fs.ensureDirSync(taskNodeModules);
forEach(nodeFiles, (commonFile) => {
const targetFile = path.join(targetNodeCommonDir, commonFile);
console.log(targetFile);
fs.copySync(path.join(nodeCommonFilesRoot, commonFile), targetFile, { overwrite: true });
});
}
if (taskFile.execution.PowerShell3) {
fs.ensureDirSync(targetPowershellCommonDir);
forEach(powershellFiles, (commonFile) => {
const targetFile = path.join(targetPowershellCommonDir, commonFile);
console.log(targetFile);
fs.copySync(path.join(powershellCommonFilesRoot, commonFile), targetFile, { overwrite: true });
});
}
});
示例3: copyFileSync
export function copyFileSync (from: string, to: string, options?: ICopyArgOptions) {
const filename = path.basename(from)
if (fs.statSync(from).isFile() && !path.extname(to)) {
fs.ensureDirSync(to)
if (from === path.join(to, filename)) {
return
}
return fs.copySync(from, path.join(to, filename), options)
}
if (from === to) {
return
}
fs.ensureDirSync(path.dirname(to))
return fs.copySync(from, to, options)
}
示例4: Transform
zipfile.on('entry', entry => {
if (/\/$/.test(entry.fileName)) {
const fileNameArr = entry.fileName.replace(/\\/g, '/').split('/')
fileNameArr.shift()
const fileName = fileNameArr.join('/')
fs.ensureDirSync(path.join(path.dirname(zipPath), fileName))
zipfile.readEntry()
} else {
zipfile.openReadStream(entry, (err, readStream) => {
if (err) throw err
const filter = new Transform()
filter._transform = function (chunk, encoding, cb) {
cb(undefined, chunk)
}
filter._flush = function (cb) {
cb()
zipfile.readEntry()
}
const fileNameArr = entry.fileName.replace(/\\/g, '/').split('/')
fileNameArr.shift()
const fileName = fileNameArr.join('/')
const writeStream = fs.createWriteStream(path.join(path.dirname(zipPath), fileName))
writeStream.on('close', () => {})
readStream
.pipe(filter)
.pipe(writeStream)
})
}
})
示例5: buildH5Lib
async function buildH5Lib () {
try {
const { appPath, outputDirName, tempPath } = buildData
const outputDir = path.join(appPath, outputDirName, h5OutputName)
const tempEntryFilePath = resolveScriptPath(path.join(tempPath, 'index'))
const outputEntryFilePath = path.join(outputDir, path.basename(tempEntryFilePath))
const code = fs.readFileSync(tempEntryFilePath).toString()
const transformResult = wxTransformer({
code,
sourcePath: tempEntryFilePath,
outputPath: outputEntryFilePath,
isNormal: true,
isTyped: REG_TYPESCRIPT.test(tempEntryFilePath)
})
const { styleFiles, components, code: generateCode } = parseEntryAst(transformResult.ast, tempEntryFilePath)
const relativePath = path.relative(appPath, tempEntryFilePath)
printLog(processTypeEnum.COPY, '发现文件', relativePath)
fs.ensureDirSync(path.dirname(outputEntryFilePath))
fs.writeFileSync(outputEntryFilePath, generateCode)
if (components.length) {
components.forEach(item => {
copyFileToDist(item.path as string, tempPath, outputDir)
})
analyzeFiles(components.map(item => item.path as string), tempPath, outputDir)
}
if (styleFiles.length) {
styleFiles.forEach(item => {
copyFileToDist(item, tempPath, path.join(appPath, outputDirName))
})
analyzeStyleFilesImport(styleFiles, tempPath, path.join(appPath, outputDirName))
}
} catch (err) {
console.log(err)
}
}
示例6: getTaroPath
export function getTaroPath (): string {
const taroPath = path.join(homedir(), '.taro')
if (!fs.existsSync(taroPath)) {
fs.ensureDirSync(taroPath)
}
return taroPath
}
示例7: exportSolution
exportSolution(project: Project, from: string, to: string, platform: string) {
if (project.getDebugDir() !== '') fs.copySync(path.resolve(from, project.getDebugDir()), path.resolve(to, 'data'), { clobber: true });
let dotcproject = fs.readFileSync(path.resolve(__dirname, 'Data', 'tizen', '.cproject'), 'utf8');
dotcproject = dotcproject.replace(/{ProjectName}/g, project.getName());
let includes = '';
for (let include of project.getIncludeDirs()) {
includes += '<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/CopiedSources/' + include + '}""/>';
}
dotcproject = dotcproject.replace(/{includes}/g, includes);
let defines = '';
for (let define of project.getDefines()) {
defines += '<listOptionValue builtIn="false" value="' + define + '"/>';
}
dotcproject = dotcproject.replace(/{defines}/g, defines);
fs.writeFileSync(path.resolve(to, '.cproject'), dotcproject);
let dotproject = fs.readFileSync(path.resolve(__dirname, 'Data', 'tizen', '.project'), 'utf8');
dotproject = dotproject.replace(/{ProjectName}/g, project.getName());
fs.writeFileSync(path.resolve(to, '.project'), dotproject);
let manifest = fs.readFileSync(path.resolve(__dirname, 'Data', 'tizen', 'manifest.xml'), 'utf8');
manifest = manifest.replace(/{ProjectName}/g, project.getName());
fs.writeFileSync(path.resolve(to, 'manifest.xml'), manifest);
for (let file of project.getFiles()) {
let target = path.resolve(to, 'CopiedSources', file);
fs.ensureDirSync(path.join(target.substr(0, target.lastIndexOf('/'))));
fs.copySync(path.resolve(from, file), target, { clobber: true });
}
}
示例8:
await Promise.all(names.map(async from => {
if (fs.existsSync(from) && fs.statSync(from).isFile()) {
const to = from.replace(outputDir, appPath)
fs.ensureDirSync(path.dirname(to))
await fs.copyFile(from, to)
}
}))
示例9: copyDir
export async function copyDir(src: string, dest: string, filter: CopyFilter = defaultFilter) {
if (!path.isAbsolute(dest)) {
dest = path.resolve(process.PROJECT_LOCATION, dest)
}
ensureDirSync(dest)
let files = glob.sync('**/*', { cwd: src, nodir: true, dot: true })
if (filter) {
files = files.filter(filter)
}
return Promise.mapSeries(files, f =>
Promise.fromCallback(async cb => {
const fileDest = path.join(dest, f)
const fileDir = path.dirname(fileDest)
if (fileDir.length) {
ensureDirSync(fileDir)
}
const buffer = await Promise.fromCallback(cb => {
fs.readFile(path.join(src, f), cb)
})
fs.writeFile(fileDest, buffer, cb)
})
)
}
示例10: it
it('creates working directory', () => {
log.silence();
fse.ensureDirSync('mocha-tests');
process.chdir('mocha-tests');
objdir = path.join('.jerk', 'objects');
fs = FS.fs();
});