本文整理汇总了TypeScript中fs.writeFileSync函数的典型用法代码示例。如果您正苦于以下问题:TypeScript writeFileSync函数的具体用法?TypeScript writeFileSync怎么用?TypeScript writeFileSync使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了writeFileSync函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: readFileSync
const copyFile = (name: string, from: string, to: string, mod: any = (f: string) => f) => {
const file = readFileSync(join(from, name));
writeFileSync(join(to, name), mod(file.toString()));
};
示例2: function
let ext = infile.split('.').pop()
// Skip .html and pass-through inputs.
if (!(ext === 'html' || (pass && infile === STDIN))) {
options.callback = function (message): void {
let msg = message.type + ': ' + infile + ': ' + message.text
if (msg.length > 120) {
msg = msg.slice(0, 117) + '...'
}
console.error(msg)
if (message.type === 'error') {
errors += 1
}
}
source = rimu.render(source, options)
}
source = source.trim()
if (source !== '') {
output += source + '\n'
}
}
output = output.trim()
if (!outfile || outfile === '-') {
process.stdout.write(output)
}
else {
fs.writeFileSync(outfile, output)
}
if (errors) {
process.exit(1)
}
示例3: writeTestConfigFile
// used to pass data from jake command line directly to run.js
function writeTestConfigFile(tests: string, light: boolean, taskConfigsFolder?: string, workerCount?: number, stackTraceLimit?: string) {
const testConfigContents = JSON.stringify({ test: tests ? [tests] : undefined, light, workerCount, stackTraceLimit, taskConfigsFolder });
console.log("Running tests with config: " + testConfigContents);
fs.writeFileSync("test.config", testConfigContents);
}
示例4: writeTextFile
export function writeTextFile(name: string, value: string) {
mkdirRecursiveSync(PATH.dirname(name));
FS.writeFileSync(name, value, "utf8");
}
示例5: writeFileSync
promises.push(Promise.resolve(codegen.emit()).then((code) => {
writeFileSync(outDir + file + '.ts', code);
}));
示例6: build
function build()
{
let path = pathlib.resolve(BUILD_PATH);
let option_file_path = pathlib.join(path, 'buildoption.json');
watch_file_list = [option_file_path];
let info = JSON.parse(fs.readFileSync(option_file_path, 'utf8'));
let body_files = info.body.map(x => pathlib.join(path, x));
let css_files = info.css.map(x => pathlib.join(path, x));
let javascript_files = info.javascript.map(x => pathlib.join(path, x));
let webworker_files = info.webworker.map(x => pathlib.join(path, x));
watch_file_list = watch_file_list.concat(body_files, css_files, javascript_files, webworker_files);
let body = concat(body_files);
let css = concat(css_files);
let javascript = concat(javascript_files);
webworker_result = concat(webworker_files);
javascript += `
function __GET_GAME_CONFIG()
{
return ${JSON.stringify(getBuildConfigObject())};
}
`
webworker_result += `
function __GET_GAME_CONFIG()
{
return ${JSON.stringify(getBuildConfigObject())};
}
`
if (0)
{
let options = {
fromString: true,
warnings: false,
mangleProperties: false
};
{
let new_javascript = UglifyJS.minify(javascript, options);
console.log(`compress javascript from ${javascript.length / 1024}KB to ${new_javascript.code.length / 1024}KB`);
javascript = new_javascript.code;
}
{
let new_webworker_result = UglifyJS.minify(webworker_result, options);
console.log(`compress webworker js from ${webworker_result.length / 1024}KB to ${new_webworker_result.code.length / 1024}KB`);
webworker_result = new_webworker_result.code;
}
}
fs.writeFileSync(joinpath(path, '__bundle.js'), javascript, { encoding: 'utf8' });
fs.writeFileSync(joinpath(path, '__worker_bundle.js'), webworker_result, { encoding: 'utf8' });
/*
javascript += `
window.FILE_VERSIONS = ${JSON.stringify(genImageVersions())}
`;*/
return { body, css, javascript };
}
示例7: require
declare const require: any;
declare const process: any;
const fs = require('fs');
const args = process.argv;
const outputPath = args[2];
args.splice(0, 3);
let bundle = '';
args.forEach(file => {
let content = fs.readFileSync(file, {encoding: 'utf-8'});
bundle += '\n\n' + content;
});
fs.writeFileSync(outputPath, bundle);
示例8: rdSync
return;
}
symLinks[lstat.dev][lstat.ino] = true;
}
const fstat = fs.statSync(fpath);
if (fstat.isDirectory()) {
const child = tree[file] = {}
rdSync(fpath, child, file)
} else {
tree[file] = null
}
} catch (e) {
// Ignore and move on.
}
});
return tree
}
const fsListing = JSON.stringify(rdSync(process.cwd(), {}, '/'));
if (process.argv.length === 3) {
const fname = process.argv[2];
let parent = path.dirname(fname);
while (!fs.existsSync(parent)) {
fs.mkdirSync(parent);
parent = path.dirname(parent);
}
fs.writeFileSync(fname, fsListing, { encoding: 'utf8' });
} else {
console.log(fsListing);
}
示例9: before
before(() => {
fs.writeFileSync(inputPath, fileContent);
testFunc = () => new SourceCodeReader({
exclude: [`**/${tmpFileName}`]
}).readSourceCode(inputPath);
});
示例10: createRandomFile
export async function createRandomFile(contents: string, fileExtension: string): Promise<string> {
const tmpFile = join(os.tmpdir(), rndName() + fileExtension);
fs.writeFileSync(tmpFile, contents);
return tmpFile;
}