本文整理匯總了TypeScript中fs-extra.writeFile函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript writeFile函數的具體用法?TypeScript writeFile怎麽用?TypeScript writeFile使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了writeFile函數的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: it
it('can discard modified change cleanly', async () => {
const path = await setupFixtureRepository('repository-with-HEAD-file')
const repo = new Repository(path, 1, null, false)
const gitStore = new GitStore(repo, shell)
const file = 'README.md'
const filePath = Path.join(repo.path, file)
await FSE.writeFile(filePath, 'SOME WORDS GO HERE\n')
let status = await getStatusOrThrow(repo!)
let files = status.workingDirectory.files
expect(files.length).to.equal(1)
await gitStore.discardChanges([files[0]])
status = await getStatusOrThrow(repo)
files = status.workingDirectory.files
expect(files.length).to.equal(0)
})
示例2: main
// Main function
async function main(version: string, milestone: string): Promise<void> {
if (!milestone) {
throw new Error('You should input \'milestone\'.');
}
const prs = await getAllPullRequestsForMilestone(milestone);
// Read changelogs and update
const CHANGELOGS_JSON_FILE = path.resolve(__dirname, '../changelogs.json');
let changelogs: ChangelogOfVersion[] = await readJson(CHANGELOGS_JSON_FILE, { throws: true });
changelogs = updateChangelogs(changelogs, version, prs);
await writeJson(CHANGELOGS_JSON_FILE, changelogs);
// Write changelog markdown.
const CHANGELOG_MARKDOWN_FILE = path.resolve(__dirname, '../CHANGELOG.md');
const content = getMarkdownFromChangelogs(changelogs);
await writeFile(CHANGELOG_MARKDOWN_FILE, content);
}
示例3: it
it('commit does not strip commentary by default', async () => {
await FSE.writeFile(
path.join(repository!.path, 'README.md'),
'Hi world\n'
)
const status = await getStatusOrThrow(repository!)
const files = status.workingDirectory.files
expect(files.length).to.equal(1)
const message = `Special commit
# this is a comment`
await createCommit(repository!, message, files)
const commit = await getCommit(repository!, 'HEAD')
expect(commit).to.not.be.null
expect(commit!.summary).to.equal('Special commit')
expect(commit!.body).to.equal('# this is a comment\n')
})
示例4: it
it('can ignore a file in a repository', async () => {
const repo = await setupEmptyRepository()
const sut = new RepositorySettingsStore(repo)
const path = repo.path
// Ignore txt files
await sut.saveGitIgnore('*.txt\n')
await GitProcess.exec(['add', '.gitignore'], path)
await GitProcess.exec(['commit', '-m', 'create the ignore file'], path)
// Create a txt file
const file = Path.join(repo.path, 'a.txt')
await FSE.writeFile(file, 'thrvbnmerkl;,iuw')
// Check status of repo
const status = await getStatusOrThrow(repo)
const files = status.workingDirectory.files
expect(files.length).to.equal(0)
})
示例5: getFileOutputInfo
saveFileContent: (path, content, callback) => {
// Make content optional with an empty string as a default
if (typeof content === "function") {
callback = content;
content = "";
}
// Open file for writing. Fails if file doesn't exist
fs.writeFile(path, content, {flag: "w"}, (err) => {
if (err) return callback(err);
// If we've written successfully to the file, return the info object
getFileOutputInfo(path, (err, info) => {
if (err) return callback(err);
callback(null, info);
});
});
},
示例6: it
it('should redownload when force=true', async () => {
const zipPath = await download('2.0.9', {
cacheRoot,
force: true,
});
const hash = crypto
.createHash('sha256')
.update(await fs.readFile(zipPath))
.digest('hex');
await fs.writeFile(zipPath, 'bad content');
const zipPath2 = await download('2.0.9', {
cacheRoot,
force: true,
});
expect(zipPath).toEqual(zipPath2);
const hash2 = crypto
.createHash('sha256')
.update(await fs.readFile(zipPath2))
.digest('hex');
expect(hash).toEqual(hash2);
});
示例7: function
export default async function() {
const corePkg = require(path.join(process.cwd(), 'package.json'));
for (const w of await getWorkspaces()) {
let pkg = { ...pkgDefault, ...w.config };
pkg = Object.keys(pkg)
.sort()
.reduce((prev, next) => {
prev[next] = pkg[next];
return prev;
}, {}) as Pkg;
// Copy these from the main package.json.
['author', 'bugs', 'homepage', 'keywords', 'license', 'repository'].forEach(
key => {
pkg[key] = corePkg[key];
}
);
// If using TypeScript, we automate the output, otherwise just use the source.
if (pkg.source) {
if (pkg.source.match(regexTsSuffix)) {
pkg.browser = 'module/index.js';
pkg.esnext = 'esnext/index.js';
pkg.main = 'main/index.js';
pkg.module = 'module/index.js';
} else {
delete pkg.browser;
delete pkg.esnext;
delete pkg.module;
pkg.main = pkg.source;
}
}
await fs.writeFile(
path.join(w.dir, 'package.json'),
JSON.stringify(pkg, null, 2)
);
}
}
示例8: it
it('commits the given files', async () => {
await FSE.writeFile(
path.join(repository!.path, 'README.md'),
'Hi world\n'
)
let status = await getStatusOrThrow(repository!)
let files = status.workingDirectory.files
expect(files.length).toEqual(1)
const sha = await createCommit(repository!, 'Special commit', files)
expect(sha).toHaveLength(7)
status = await getStatusOrThrow(repository!)
files = status.workingDirectory.files
expect(files.length).toEqual(0)
const commits = await getCommits(repository!, 'HEAD', 100)
expect(commits.length).toEqual(6)
expect(commits[0].summary).toEqual('Special commit')
expect(commits[0].sha.substring(0, 7)).toEqual(sha)
})
示例9: fixDependencies
async function fixDependencies() {
const packagePath = path.join(process.cwd(), 'package.json')
const packageJson = require(packagePath)
if (typeof packageJson.dependencies === 'undefined') {
console.error(chalk.red('Missing dependencies in package.json'))
process.exit(1)
}
const packageVersion = packageJson.dependencies['tux-scripts']
if (typeof packageVersion === 'undefined') {
console.error(chalk.red(`Unable to find tux-scripts in package.json`))
process.exit(1)
}
packageJson.devDependencies = packageJson.devDependencies || {}
packageJson.devDependencies['tux-scripts'] = packageVersion
delete packageJson.dependencies['tux-scripts']
await fs.writeFile(packagePath, JSON.stringify(packageJson, null, 2))
}