本文整理汇总了TypeScript中klaw类的典型用法代码示例。如果您正苦于以下问题:TypeScript klaw类的具体用法?TypeScript klaw怎么用?TypeScript klaw使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了klaw类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: Promise
return new Promise((resolve, reject) => {
klaw(sourceDir)
.on('data', file => {
if (!file.stats.isDirectory()) {
processFile(file.path)
}
})
.on('end', () => {
initProjectFile()
if (!fs.existsSync(path.join(tempPath, 'node_modules'))) {
console.log()
console.log(chalk.yellow('开始安装依赖~'))
process.chdir(tempPath)
let command
if (Util.shouldUseYarn()) {
command = 'yarn'
} else if (Util.shouldUseCnpm()) {
command = 'cnpm install'
} else {
command = 'npm install'
}
shelljs.exec(command, {silent: false})
}
resolve()
})
})
示例2: convertToJDReact
export function convertToJDReact ({tempPath, entryBaseName}) {
klaw(tempPath)
.on('data', file => {
const nativeBundlePath = path.join(tempPath, NATIVE_BUNDLES_DIR)
if (file.stats.isDirectory() ||
file.path.startsWith(path.join(tempPath, 'node_modules')) ||
file.path.startsWith(nativeBundlePath) ||
file.path.endsWith('yarn.lock') ||
file.path.endsWith('package-lock.json')
) return
processFile({filePath: file.path, tempPath, entryBaseName})
})
.on('end', () => {
// copy templates under jsbundles/
const templateSrcDirname = path.join(jdreactTmpDirname, 'template')
const indexDistDirPath = path.join(jdreactPath, 'jsbundles')
// not overwrite
fs.copySync(path.join(templateSrcDirname, 'JDReact.version'), path.join(indexDistDirPath, `${moduleName}.version`), {overwrite: false})
fs.copySync(path.join(templateSrcDirname, 'JDReact.web.js'), path.join(indexDistDirPath, `${moduleName}.web.js`), {overwrite: false})
Util.printLog(processTypeEnum.COPY, 'templates', templateSrcDirname)
})
}
示例3: require
import * as klaw from "klaw";
const path = require('path');
// README.md: Streams 1 (push) example:
let items: klaw.Item[] = [] // files, directories, symlinks, etc
klaw('/some/dir')
.on('data', function(item: klaw.Item) {
items.push(item)
})
.on('end', function() {
console.dir(items) // => [ ... array of files]
})
// README.md: Streams 2 & 3 (pull) with error handling
klaw('/some/dir')
.on('readable', function() {
let item: klaw.Item;
while (item = this.read()) {
items.push(item)
}
})
.on('error', function(err: Error, item: klaw.Item) {
console.log(err.message)
console.log(item.path) // the file the error occurred on
})
.on('end', function() {
console.log(items) // => [ ... array of files]
})