• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript fs-extra.ensureDirSync函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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)
  }
}
开发者ID:YangShaoQun,项目名称:taro,代码行数:30,代码来源:rn.ts


示例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 });
        });
    }
});
开发者ID:geeklearningio,项目名称:gl-vsts-tasks-build-scripts,代码行数:27,代码来源:prebuild.ts


示例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)
}
开发者ID:YangShaoQun,项目名称:taro,代码行数:15,代码来源:index.ts


示例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)
     })
   }
 })
开发者ID:YangShaoQun,项目名称:taro,代码行数:29,代码来源:index.ts


示例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)
  }
}
开发者ID:YangShaoQun,项目名称:taro,代码行数:35,代码来源:ui.ts


示例6: getTaroPath

export function getTaroPath (): string {
  const taroPath = path.join(homedir(), '.taro')
  if (!fs.existsSync(taroPath)) {
    fs.ensureDirSync(taroPath)
  }
  return taroPath
}
开发者ID:YangShaoQun,项目名称:taro,代码行数:7,代码来源:index.ts


示例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="&quot;${workspace_loc:/${ProjName}/CopiedSources/' + include + '}&quot;"/>';
		}
		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 });
		}
	}
开发者ID:hammeron-art,项目名称:koremake,代码行数:31,代码来源:TizenExporter.ts


示例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)
   }
 }))
开发者ID:YangShaoQun,项目名称:taro,代码行数:7,代码来源:plugin.ts


示例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)
    })
  )
}
开发者ID:alexsandrocruz,项目名称:botpress,代码行数:30,代码来源:pkg-fs.ts


示例10: it

 it('creates working directory', () => {
     log.silence();
     fse.ensureDirSync('mocha-tests');
     process.chdir('mocha-tests');
     objdir = path.join('.jerk', 'objects');
     fs = FS.fs();
 });
开发者ID:ssyp-ru,项目名称:ssyp16-ws13,代码行数:7,代码来源:fs.test.ts



注:本文中的fs-extra.ensureDirSync函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript fs-extra.ensureFile函数代码示例发布时间:2022-05-25
下一篇:
TypeScript fs-extra.ensureDir函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap