本文整理汇总了TypeScript中fs-extra.writeFileSync函数的典型用法代码示例。如果您正苦于以下问题:TypeScript writeFileSync函数的具体用法?TypeScript writeFileSync怎么用?TypeScript writeFileSync使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了writeFileSync函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: it
it('can commit when a delete is staged and the untracked file exists', async () => {
let status,
files = null
const repo = await setupEmptyRepository()
const firstPath = path.join(repo.path, 'first')
fs.writeFileSync(firstPath, 'line1\n')
await GitProcess.exec(['add', 'first'], repo.path)
await GitProcess.exec(['commit', '-am', 'commit first file'], repo.path)
await GitProcess.exec(['rm', '--cached', 'first'], repo.path)
// if the text is now different, everything is fine
fs.writeFileSync(firstPath, 'line2\n')
status = await getStatus(repo)
files = status.workingDirectory.files
expect(files.length).to.equal(1)
expect(files[0].path).to.contain('first')
expect(files[0].status).to.equal(AppFileStatus.New)
const toCommit = status.workingDirectory.withIncludeAllFiles(true)
await createCommit(repo, 'commit again!', toCommit.files)
status = await getStatus(repo)
files = status.workingDirectory.files
expect(files).to.be.empty
const commit = await getCommit(repo, 'HEAD')
expect(commit).to.not.be.null
expect(commit!.summary).to.equal('commit again!')
})
示例2: exportSolution
exportSolution(project: Project, from: string, to: string, platform: string) {
if (project.getDebugDir() !== '') fs.copySync(path.resolve(from, project.getDebugDir()), path.resolve(to, 'data'), { clobber: true });
let dotcproject = fs.readFileSync(path.resolve(__dirname, 'Data', 'tizen', '.cproject'), 'utf8');
dotcproject = dotcproject.replace(/{ProjectName}/g, project.getName());
let includes = '';
for (let include of project.getIncludeDirs()) {
includes += '<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/CopiedSources/' + include + '}""/>';
}
dotcproject = dotcproject.replace(/{includes}/g, includes);
let defines = '';
for (let define of project.getDefines()) {
defines += '<listOptionValue builtIn="false" value="' + define + '"/>';
}
dotcproject = dotcproject.replace(/{defines}/g, defines);
fs.writeFileSync(path.resolve(to, '.cproject'), dotcproject);
let dotproject = fs.readFileSync(path.resolve(__dirname, 'Data', 'tizen', '.project'), 'utf8');
dotproject = dotproject.replace(/{ProjectName}/g, project.getName());
fs.writeFileSync(path.resolve(to, '.project'), dotproject);
let manifest = fs.readFileSync(path.resolve(__dirname, 'Data', 'tizen', 'manifest.xml'), 'utf8');
manifest = manifest.replace(/{ProjectName}/g, project.getName());
fs.writeFileSync(path.resolve(to, 'manifest.xml'), manifest);
for (let file of project.getFiles()) {
let target = path.resolve(to, 'CopiedSources', file);
fs.ensureDirSync(path.join(target.substr(0, target.lastIndexOf('/'))));
fs.copySync(path.resolve(from, file), target, { clobber: true });
}
}
示例3: function
walk.filesSync(dataDirectory, function(dir: string, file: string, stat: any) {
// If the file isn't a JSON, skip it.
if (!file.match(/\.json$/)) { return; }
// Combine them together into the relevant filenames.
var distDir = dir.replace(dataDirectory, distDirectory);
var dataFilename = path.join(dir, file);
var distFilename = path.join(distDir, file);
console.log("file", distFilename.replace(distDirectory, "").substr(1));
// Load the file into memory.
var fileData = fs.readFileSync(dataFilename).toString();
var stripData = stripJsonComments(fileData, {whitespace: true});
var data = JSON.parse(stripData);
var minData = JSON.stringify(data, null, 0);
// Write out the two versions.
fs.writeFileSync(distFilename, stripData);
fs.writeFileSync(distFilename.replace(".json", ".min.json"), minData);
// Add the full object to the combined list.
combined[data.id] = data;
// Create an index-only version.
index[data.id] = {
id: data.id,
type: data.type,
version: data.version
};
if (data.description) { index[data.id].description = data.description; }
});
示例4: exportResources
exportResources() {
this.createDirectory(path.join(this.options.to, this.sysdir() + '-build', 'shaders'));
fs.writeFileSync(path.join(this.options.to, this.sysdir() + '-build', 'shaders', 'Simple.fcg'),
'void main(float4 out Color : COLOR, uniform float4 MaterialColor) {\n'
+ '\tColor = MaterialColor;\n'
+ '}\n');
fs.writeFileSync(path.join(this.options.to, this.sysdir() + '-build', 'shaders', 'Simple.vcg'),
'void main(float4 in a_Position : POSITION, float4 out v_Position : POSITION, uniform float4x4 WorldViewProj) {\n'
+ '\tv_Position = mul(a_Position, WorldViewProj);\n'
+ '}\n');
fs.writeFileSync(path.join(this.options.to, this.sysdir() + '-build', 'shaders', 'Texture.fcg'),
'void main(float2 in v_TexCoord : TEXCOORD0, float4 out Color : COLOR, uniform sampler2D Texture0 : TEXUNIT0) {\n'
+ '\tColor = tex2D(Texture0, v_TexCoord);\n'
+ '}\n');
fs.writeFileSync(path.join(this.options.to, this.sysdir() + '-build', 'shaders', 'Texture.vcg'),
'void main(float4 in a_Position : POSITION, float2 in a_TexCoord : TEXCOORD0, float4 out v_Position : POSITION, float2 out v_TexCoord : TEXCOORD0, uniform float4x4 WorldViewProj) {\n'
+ '\tv_Position = mul(a_Position, WorldViewProj);\n'
+ '\tv_TexCoord = a_TexCoord;\n'
+ '}\n');
let appxml = path.join(this.options.to, this.sysdir() + '-build', 'app.xml');
if (!fs.existsSync(appxml)) {
let appxmltext = fs.readFileSync(path.join(__dirname, 'Data', 'psm', 'app.xml'), {encoding: 'utf8'});
fs.writeFileSync(appxml.toString(), appxmltext);
}
}
示例5: it
it('only shows modifications after move for a renamed and modified file', async () => {
const repo = await setupEmptyRepository()
fs.writeFileSync(path.join(repo.path, 'foo'), 'foo\n')
await GitProcess.exec(['add', 'foo'], repo.path)
await GitProcess.exec(['commit', '-m', 'Initial commit'], repo.path)
await GitProcess.exec(['mv', 'foo', 'bar'], repo.path)
fs.writeFileSync(path.join(repo.path, 'bar'), 'bar\n')
const status = await getStatus(repo)
const files = status.workingDirectory.files
expect(files.length).to.equal(1)
const diff = await getTextDiff(repo, files[0])
expect(diff.hunks.length).to.equal(1)
const first = diff.hunks[0]
expect(first.lines.length).to.equal(3)
expect(first.lines[1].text).to.equal('-foo')
expect(first.lines[2].text).to.equal('+bar')
})
示例6: initProjectFile
function initProjectFile() {
// generator app.json
const appJsonObject = Object.assign({
name: _.camelCase(require(path.join(process.cwd(), 'package.json')).name)
}, rnConfig.appJson)
// generator .${tempPath}/package.json TODO JSON.parse 这种写法可能会有隐患
const pkgTempObj = JSON.parse(
ejs.render(pkgTmpl, {
projectName: _.camelCase(projectConfig.projectName),
version: Util.getPkgVersion()
}
).replace(/(\r\n|\n|\r|\s+)/gm, '')
)
const dependencies = require(path.join(process.cwd(), 'package.json')).dependencies
pkgTempObj.dependencies = Object.assign({}, pkgTempObj.dependencies, dependencies)
const indexJsStr = `
import {AppRegistry} from 'react-native';
import App from './${entryBaseName}';
import {name as appName} from './app.json';
AppRegistry.registerComponent(appName, () => App);`
fs.writeFileSync(path.join(tempDir, 'index.js'), indexJsStr)
Util.printLog(processTypeEnum.GENERATE, 'index.js', path.join(tempPath, 'index.js'))
fs.writeFileSync(path.join(tempDir, 'app.json'), JSON.stringify(appJsonObject, null, 2))
Util.printLog(processTypeEnum.GENERATE, 'app.json', path.join(tempPath, 'app.json'))
fs.writeFileSync(path.join(tempDir, 'package.json'), JSON.stringify(pkgTempObj, null, 2))
Util.printLog(processTypeEnum.GENERATE, 'package.json', path.join(tempPath, 'package.json'))
}
示例7: exportCLion
exportCLion(project: Project, from: string, to: string, platform: string, vrApi: any, nokrafix: boolean, options: any) {
let name = project.getName().replace(/ /g, '_');
const indir = path.join(__dirname, '..', '..', 'Data', 'linux');
fs.ensureDirSync(path.resolve(to, project.getName(), '.idea'));
let misc = fs.readFileSync(path.join(indir, 'idea', 'misc.xml'), 'utf8');
misc = misc.replace(/{root}/g, path.resolve(from));
fs.writeFileSync(path.join(to, project.getName(), '.idea', 'misc.xml'), misc, 'utf8');
let workspace = fs.readFileSync(path.join(indir, 'idea', 'workspace.xml'), 'utf8');
workspace = workspace.replace(/{workingdir}/g, path.resolve(project.getDebugDir()));
workspace = workspace.replace(/{project}/g, project.getName());
workspace = workspace.replace(/{target}/g, name);
fs.writeFileSync(path.join(to, project.getName(), '.idea', 'workspace.xml'), workspace, 'utf8');
this.writeFile(path.resolve(to, project.getName(), 'CMakeLists.txt'));
this.p('cmake_minimum_required(VERSION 3.6)');
this.p('project(' + name + ')');
if (project.cpp11) {
this.p('set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pthread -static-libgcc -static-libstdc++")');
}
else {
this.p('set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -static-libgcc -static-libstdc++")');
}
let defines = '';
for (let def of project.getDefines()) {
defines += ' -D' + def + '\n';
}
this.p('add_definitions(\n' + defines + ')');
let includes = '';
for (let inc of project.getIncludeDirs()) {
includes += ' "' + path.resolve(inc).replace(/\\/g, '/') + '"\n';
}
this.p('include_directories(\n' + includes + ')');
let files = '';
for (let file of project.getFiles()) {
if (file.file.endsWith('.c') || file.file.endsWith('.cc') || file.file.endsWith('.cpp') || file.file.endsWith('.h')) {
files += ' "' + path.resolve(file.file).replace(/\\/g, '/') + '"\n';
}
}
this.p('set(SOURCE_FILES\n' + files + ')');
this.p('add_executable(' + name + ' ${SOURCE_FILES})');
let libraries = '';
for (let lib of project.getLibs()) {
libraries += ' ' + lib + '\n';
}
this.p('target_link_libraries(' + name + '\n' + libraries + ')');
this.closeFile();
}
示例8: uglifyFile
/** Minifies a JavaScript file using UglifyJS2. Also writes sourcemaps to the output. */
function uglifyFile(inputPath: string, outputPath: string) {
let sourcemapOut = `${outputPath}.map`;
let result = uglify.minify(inputPath, {
preserveComments: 'license',
outSourceMap: sourcemapOut
});
writeFileSync(outputPath, result.code);
writeFileSync(sourcemapOut, result.map);
}