本文整理汇总了TypeScript中fs-extra.writeJsonSync函数的典型用法代码示例。如果您正苦于以下问题:TypeScript writeJsonSync函数的具体用法?TypeScript writeJsonSync怎么用?TypeScript writeJsonSync使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了writeJsonSync函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: it
it("prefers 'package.json' over 'lerna.json'", function() {
fs.writeJsonSync(path.join(tmpDir, "lerna.json"), {
version: "1.0.0-lerna.0",
changelog: { repo: "foo/lerna", nextVersionFromMetadata: true },
});
fs.writeJsonSync(path.join(tmpDir, "package.json"), {
version: "1.0.0-package.0",
changelog: { repo: "foo/package", nextVersionFromMetadata: true },
});
const result = fromPath(tmpDir);
expect(result.nextVersion).toEqual("v1.0.0-package.0");
expect(result.repo).toEqual("foo/package");
});
示例2: before
before(() => {
file = path.resolve(__dirname, "./tmp.log");
fse.removeSync(file);
fse.writeJsonSync(file, TEST_JSON);
file0dir = path.resolve(__dirname, "./tmp/file/");
fse.removeSync(file0dir);
});
示例3: persistToFile
persistToFile() {
this.debug('Saving configuration to persistent storage: %o', global._ConfigurationPersistence);
try {
return fs.writeJsonSync(this.configFile, global._ConfigurationPersistence, {spaces: 2});
} catch (error) {
this.debug('An error occurred while persisting the configuration: %s', error);
}
}
示例4: verifyMetaFile
export function verifyMetaFile() {
let dir = dirHelper(".meta");
try {
fs.ensureFileSync(dir);
let contents = fs.readJsonSync(dir, {throws: false});
if(!contents) {
fs.writeJsonSync(dir, { settings: {} });
console.log("Initialized meta file")
} else {
console.log("Meta file already exists!");
}
} catch (err) {
console.error("Meta file error:", err);
}
}
示例5: verifyDatabaseFile
export function verifyDatabaseFile() {
let dir = dirHelper("notes.noam");
try {
fs.ensureFileSync(dir);
let contents = fs.readJsonSync(dir, {throws: false});
if(!contents) {
fs.writeJsonSync(dir, { notes: {} });
console.log("Initialied note database!");
} else {
console.log("Note database already exists!");
}
} catch (err) {
console.error("Note database error:", err);
}
}
示例6: 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)
}
示例7: updateDistPackageJson
function updateDistPackageJson(directory: string, newDirectory: string): void {
const srcPkgJsonPath = resolve(directory, "package.json");
const distPkgJsonPath = resolve(newDirectory, "package.json");
const srcPkgJson = readJsonSync(srcPkgJsonPath) as PackageJson;
// update the dist package json
const { version, dependencies, peerDependencies, devDependencies } = srcPkgJson;
const distPkgJson: PackageJson = {
...readJsonSync(distPkgJsonPath),
version,
dependencies,
devDependencies,
peerDependencies
}
writeJsonSync(distPkgJsonPath, distPkgJson, { spaces: 2 });
}
示例8:
// stub
});
fs.writeJSON(file, object).then(() => {
// stub
});
fs.writeJson(file, object, errorCallback);
fs.writeJson(file, object, writeOptions, errorCallback);
fs.writeJSON(file, object, errorCallback);
fs.writeJSON(file, object, writeOptions, errorCallback);
fs.writeJson(file, object, writeOptions).then(() => {
// stub
});
fs.writeJSON(file, object, writeOptions).then(() => {
// stub
});
fs.writeJsonSync(file, object, writeOptions);
fs.writeJSONSync(file, object, writeOptions);
fs.ensureDir(path).then(() => {
// stub
});
fs.ensureDir(path, errorCallback);
fs.ensureDirSync(path);
fs.ensureFile(path).then(() => {
// stub
});
fs.ensureFile(path, errorCallback);
fs.ensureFileSync(path);
fs.ensureLink(path).then(() => {
// stub
示例9: getTasks
getTasks(environmentTasksDirectory).map((taskDirectory) => {
const taskFilePath = path.join(taskDirectory.directory, "task.json");
const task = fs.readJsonSync(taskFilePath) as AzureDevOpsTasksSchema;
task.id = env.TaskIds[taskDirectory.name];
if (task.id) {
task.friendlyName += env.DisplayNamesSuffix;
task.version = {
Major: version.major,
Minor: version.minor,
Patch: version.patch,
};
if (task.helpMarkDown) {
task.helpMarkDown = task.helpMarkDown.replace("#{Version}#", version.getVersionString());
}
if (task.inputs) {
task.inputs.forEach((input) => {
const mappedType = endpointMap[input.type];
if (mappedType) {
input.type = mappedType;
}
});
}
fs.writeJsonSync(taskFilePath, task);
const taskLocFilePath = path.join(taskDirectory.directory, "task.loc.json");
if (fs.existsSync(taskLocFilePath)) {
const taskLoc = fs.readJsonSync(taskLocFilePath);
taskLoc.id = env.TaskIds[taskDirectory.name];
taskLoc.friendlyName += env.DisplayNamesSuffix;
taskLoc.version.Major = version.major;
taskLoc.version.Minor = version.minor;
taskLoc.version.Patch = version.patch;
if (taskLoc.helpMarkDown) {
taskLoc.helpMarkDown = taskLoc.helpMarkDown.replace("#{Version}#", version.getVersionString());
}
fs.writeJsonSync(taskLocFilePath, taskLoc);
const locfilesDirectory = path.join(taskDirectory.directory, "Strings/resources.resjson");
if (fs.existsSync(locfilesDirectory)) {
const langs = fs.readdirSync(locfilesDirectory);
for (const element of langs) {
const resourceFile = path.join(locfilesDirectory, element, "resources.resjson");
if (fs.existsSync(resourceFile)) {
const resource = fs.readJsonSync(resourceFile);
resource["loc.helpMarkDown"] = resource["loc.helpMarkDown"]
.replace("#{Version}#", version.getVersionString());
fs.writeJsonSync(resourceFile, resource);
}
}
}
}
const taskId = taskDirectory.name.replace(/([A-Z])/g, "-$1").toLowerCase().replace(/^[-]+/, "");
extension.contributions.push({
description: task.description,
id: taskId + "-task",
properties: {
name: "Tasks/" + taskDirectory.name,
},
targets: [
"ms.vss-distributed-task.tasks",
],
type: "ms.vss-distributed-task.task",
});
} else {
fs.removeSync(taskDirectory.directory);
}
});