本文整理匯總了TypeScript中path.format函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript format函數的具體用法?TypeScript format怎麽用?TypeScript format使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了format函數的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: rename
export function rename(p: string, options: {dir?: string, ext?: string}): string {
let {dir, name, ext} = path.parse(p)
if (options.dir != null)
dir = options.dir
if (options.ext != null)
ext = options.ext
return path.format({dir, name, ext})
}
示例3: getDester
/**
* 返回通過新的擴展名與 request.dest的目標絕對路徑生成新的 dest目標絕對路徑 和 destRelative目標相對路徑
*
* @param {string} ext
* @returns
* @memberof WxSFM
*/
getDester (ext: string) {
let ppath = path.parse(this.request.dest)
ppath.base = ppath.name + ext
ppath.ext = ext
let dest = path.format(ppath)
let destRelative = path.relative(config.cwd, dest)
return {
dest,
destRelative
}
}
示例4: copyFileToDist
function copyFileToDist (filePath: string, sourceDir: string, outputDir: string) {
if (!filePath && !path.isAbsolute(filePath)) {
return
}
const { appPath } = buildData
const dirname = path.dirname(filePath)
const distDirname = dirname.replace(sourceDir, outputDir)
const relativePath = path.relative(appPath, filePath)
printLog(processTypeEnum.COPY, '發現文件', relativePath)
fs.ensureDirSync(distDirname)
fs.copyFileSync(filePath, path.format({
dir: distDirname,
base: path.basename(filePath)
}))
}
示例5: processFile
async function processFile ({ filePath, tempPath, entryBaseName }) {
const indexJsStr = `
import {AppRegistry} from 'react-native';
import App from '../${entryBaseName}';
// import {name as appName} from '../app.json';
AppRegistry.registerComponent('${moduleName}', () => App);`
if (!fs.existsSync(filePath)) {
return
}
const dirname = path.dirname(filePath)
const destDirname = dirname.replace(tempPath, jdreactPath)
const destFilePath = path.format({dir: destDirname, base: path.basename(filePath)})
const indexFilePath = path.join(tempPath, 'index.js')
const tempPkgPath = path.join(tempPath, 'package.json')
// generate jsbundles/moduleName.js
if (filePath === indexFilePath) {
const indexDistDirPath = path.join(jdreactPath, 'jsbundles')
const indexDistFilePath = path.join(indexDistDirPath, `${moduleName}.js`)
fs.ensureDirSync(indexDistDirPath)
fs.writeFileSync(indexDistFilePath, indexJsStr)
Util.printLog(processTypeEnum.GENERATE, `${moduleName}.js`, indexDistFilePath)
return
}
// genetate package.json
if (filePath === tempPkgPath) {
const destPkgPath = path.join(jdreactPath, 'package.json')
const templatePkgPath = path.join(jdreactTmpDirname, 'pkg')
const tempPkgObject = fs.readJsonSync(tempPkgPath)
const templatePkgObject = fs.readJsonSync(templatePkgPath)
templatePkgObject.name = `jdreact-jsbundle-${moduleName}`
templatePkgObject.dependencies = Object.assign({}, tempPkgObject.dependencies, templatePkgObject.dependencies)
fs.writeJsonSync(destPkgPath, templatePkgObject, {spaces: 2})
Util.printLog(processTypeEnum.GENERATE, 'package.json', destPkgPath)
return
}
fs.ensureDirSync(destDirname)
fs.copySync(filePath, destFilePath)
Util.printLog(processTypeEnum.COPY, _.camelCase(path.extname(filePath)).toUpperCase(), filePath)
}
示例6: buildForWeapp
async function buildForWeapp () {
const { appPath, entryFilePath, outputDirName, entryFileName, sourceDir } = buildData
console.log()
console.log(chalk.green('開始編譯小程序端組件庫!'))
if (!fs.existsSync(entryFilePath)) {
console.log(chalk.red('入口文件不存在,請檢查!'))
return
}
try {
const outputDir = path.join(appPath, outputDirName, weappOutputName)
const outputEntryFilePath = path.join(outputDir, entryFileName)
const code = fs.readFileSync(entryFilePath).toString()
const transformResult = wxTransformer({
code,
sourcePath: entryFilePath,
outputPath: outputEntryFilePath,
isNormal: true,
isTyped: REG_TYPESCRIPT.test(entryFilePath)
})
const { styleFiles, components } = parseEntryAst(transformResult.ast, entryFilePath)
if (styleFiles.length) {
const outputStylePath = path.join(outputDir, 'css', 'index.css')
await compileDepStyles(outputStylePath, styleFiles)
}
const relativePath = path.relative(appPath, entryFilePath)
printLog(processTypeEnum.COPY, '發現文件', relativePath)
fs.ensureDirSync(path.dirname(outputEntryFilePath))
fs.copyFileSync(entryFilePath, path.format({
dir: path.dirname(outputEntryFilePath),
base: path.basename(outputEntryFilePath)
}))
if (components.length) {
components.forEach(item => {
copyFileToDist(item.path as string, sourceDir, outputDir)
})
analyzeFiles(components.map(item => item.path as string), sourceDir, outputDir)
}
} catch (err) {
console.log(err)
}
}
示例7:
// }
path.parse('C:\\path\\dir\\index.html')
// returns
// {
// root : "C:\",
// dir : "C:\path\dir",
// base : "index.html",
// ext : ".html",
// name : "index"
// }
path.format({
root: "/",
dir: "/home/user/dir",
base: "file.txt",
ext: ".txt",
name: "file"
});
// returns
// '/home/user/dir/file.txt'
}
////////////////////////////////////////////////////
/// readline tests : https://nodejs.org/api/readline.html
////////////////////////////////////////////////////
namespace readline_tests {
let rl: readline.ReadLine;
{