本文整理汇总了TypeScript中fs-extra-p.writeJson函数的典型用法代码示例。如果您正苦于以下问题:TypeScript writeJson函数的具体用法?TypeScript writeJson怎么用?TypeScript writeJson使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了writeJson函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: async
}, true, async (projectDir) => {
const file = path.join(projectDir, "package.json")
const data = await readJson(file)
data.productName = "Test App"
return await writeJson(file, data)
})
示例2: setPackageVersions
async function setPackageVersions(packages: Array<string>, packageData: Array<any>) {
const versions = await BluebirdPromise.map(packages, it => exec("yarn", ["info", "--json", it, "dist-tags"])
.then((it: string) => {
if (it === "") {
// {"type":"error","data":"Received invalid response from npm."}
// not yet published to npm
return "0.0.1"
}
try {
return JSON.parse(it).data
}
catch (e) {
throw new Error(`Cannot parse ${it}: ${e.stack || e}`)
}
}))
for (let i = 0; i < packages.length; i++) {
const packageName = packages[i]
const packageJson = packageData[i]
const versionInfo = versions[i]
const latestVersion = versionInfo.next || versionInfo.latest
if (latestVersion == null || packageJson.version == latestVersion || semver.lt(latestVersion, packageJson.version)) {
continue
}
packageJson.version = latestVersion
console.log(`Set ${packageName} version to ${latestVersion}`)
await writeJson(path.join(packageDir, packageName, "package.json"), packageJson, {spaces: 2})
}
}
示例3: setPackageVersions
async function setPackageVersions(packageData: Array<any>) {
const versions = await getLatestVersions(packageData)
let publishScript = `#!/usr/bin/env bash
set -e
ln -f README.md packages/electron-builder/README.md
`
for (let i = 0; i < packageData.length; i++) {
const packageMetadata = packageData[i]
const packageName = packageMetadata.name
const versionInfo = versions[i]
const latestVersion = versionInfo.next || versionInfo.latest
if (latestVersion == null || packageMetadata.version === latestVersion || semver.lt(latestVersion, packageMetadata.version)) {
continue
}
packageMetadata.version = latestVersion
console.log(`Set ${packageName} version to ${latestVersion}`)
await writeJson(path.join(packageDir, packageName, "package.json"), packageMetadata, {spaces: 2})
}
for (let i = 0; i < packageData.length; i++) {
const packageMetadata = packageData[i]
const versionInfo = versions[i]
const latestVersion = versionInfo.next || versionInfo.latest
if (latestVersion != null && semver.gt(packageMetadata.version, latestVersion)) {
publishScript += `npm publish packages/${packageMetadata.name}\n`
}
}
await writeFile(path.join(rootDir, "__publish.sh"), publishScript)
}
示例4: setDepVersions
async function setDepVersions(packages: Array<string>, packageData: Array<any>) {
const versions = packageData.map(it => it.version)
for (let i = 0; i < packages.length; i++) {
const packageName = packages[i]
const packageJson = packageData[i]
let changed = false
for (let depIndex = 0; depIndex < packages.length; depIndex++) {
const depPackageName = packages[depIndex]
let oldVersion = packageJson.dependencies == null ? null : packageJson.dependencies[depPackageName]
if (oldVersion == null) {
continue
}
let range = ""
if (oldVersion.startsWith("~") || oldVersion.startsWith("^")) {
range = oldVersion[0]
oldVersion = oldVersion.substring(1)
}
const newVersion = versions[depIndex]
if (oldVersion == newVersion || newVersion === "0.0.0-semantic-release") {
console.log(`Skip ${depPackageName} for ${packageName} â version ${newVersion} is actual`)
continue
}
changed = true
packageJson.dependencies[depPackageName] = range + newVersion
console.log(`Set ${depPackageName} to ${newVersion} from ${oldVersion} for ${packageName}`)
}
if (changed) {
await writeJson(path.join(packageDir, packageName, "package.json"), packageJson, {spaces: 2})
}
}
}
示例5: modifyPackageJson
export async function modifyPackageJson(projectDir: string, task: (data: any) => void, isApp = false): Promise<any> {
const file = isApp ? path.join(projectDir, "app", "package.json") : path.join(projectDir, "package.json")
const data = await readJson(file)
task(data)
// because copied as hard link
await unlink(file)
return await writeJson(file, data)
}
示例6: modifyPackageJson
export async function modifyPackageJson(projectDir: string, task: (data: any) => void, isApp: boolean = false): Promise<any> {
const file = isApp ? path.join(projectDir, "app", "package.json") : path.join(projectDir, "package.json")
const data = await readJson(file)
task(data)
return await writeJson(file, data)
}
示例7: modifyPackageJson
export async function modifyPackageJson(projectDir: string, task: (data: any) => void): Promise<any> {
const file = path.join(projectDir, "package.json")
const data = await readJson(file)
task(data)
return await writeJson(file, data)
}