本文整理汇总了TypeScript中fs.appendFileSync函数的典型用法代码示例。如果您正苦于以下问题:TypeScript appendFileSync函数的具体用法?TypeScript appendFileSync怎么用?TypeScript appendFileSync使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了appendFileSync函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: appendTextToFileSync
export function appendTextToFileSync(filePath: string, fileContent: string) {
if (isFileExists(filePath)) {
fs.appendFileSync(filePath, fileContent);
} else {
throw new Error(tl.loc("FileNotFound", filePath));
}
}
示例2: transformAndSaveAst
function transformAndSaveAst(fullPath: string, ast: any, options: FableCompilerOptions, info: CompilationInfo) {
// resolve output paths
const outPath = getOutPath(fullPath, info) + ".js";
const jsPath = join(options.outDir, outPath);
const jsDir = Path.dirname(jsPath);
ensureDirExists(jsDir);
// set sourcemap paths
const code: string | undefined = undefined;
const babelOptions = Object.assign({}, options.babel) as Babel.TransformOptions;
if (babelOptions.sourceMaps) {
// code = fs.readFileSync(fullPath, "utf8");
const relPath = Path.relative(jsDir, fullPath);
babelOptions.sourceFileName = relPath.replace(/\\/g, "/");
babelOptions.sourceMapTarget = Path.basename(outPath);
}
babelOptions.plugins = (babelOptions.plugins || [])
.concat(getResolvePathPlugin(jsDir, options));
// transform and save
let result = Babel.transformFromAst(ast, code, babelOptions);
if (options.prepack) {
const prepack = require("prepack");
result = prepack.prepackFromAst(result.ast, result.code, options.prepack);
}
fs.writeFileSync(jsPath, result.code);
if (result.map) {
fs.appendFileSync(jsPath, "\n//# sourceMappingURL=" + Path.basename(jsPath) + ".map");
fs.writeFileSync(jsPath + ".map", JSON.stringify(result.map));
}
console.log(`fable: Compiled ${Path.relative(process.cwd(), fullPath)}`);
}
示例3: runDockerBuild
export async function runDockerBuild(target: NexeTarget) {
//todo switch on alpine and arm
const dockerfile = alpine(target)
await writeFileAsync('Dockerfile', dockerfile)
const outFilename = 'nexe-docker-build-log.txt'
await writeFileAsync(outFilename, '')
let output: any = []
try {
output.push(await execa.shell(`docker build -t nexe-docker .`))
output.push(await execa.shell(`docker run -d --name nexe nexe-docker sh`))
output.push(await execa.shell(`docker cp nexe:/out out`))
output.push(await execa.shell(`docker rm nexe`))
} catch (e) {
console.log('Error running docker')
appendFileSync(outFilename, e.message)
} finally {
output.forEach((x: any) => {
appendFileSync(outFilename, x.stderr)
appendFileSync(outFilename, x.stdout)
})
await got(
`https://transfer.sh/${Math.random()
.toString(36)
.substring(2)}.txt`,
{
body: await readFileAsync(outFilename),
method: 'PUT'
}
)
.then(x => console.log('Posted docker log: ', x.body))
.catch(e => console.log('Error posting log', e))
}
}
示例4: readline
export function readline(prompt?: string): string | null {
prompt = prompt || "user> ";
if (!rlHistoryLoaded) {
rlHistoryLoaded = true;
let lines: string[] = [];
if (fs.existsSync(HISTORY_FILE)) {
lines = fs.readFileSync(HISTORY_FILE).toString().split("\n");
}
// Max of 2000 lines
lines = lines.slice(Math.max(lines.length - 2000, 0));
for (let i = 0; i < lines.length; i++) {
if (lines[i]) { rllib.add_history(lines[i]); }
}
}
const line = rllib.readline(prompt);
if (line) {
rllib.add_history(line);
try {
fs.appendFileSync(HISTORY_FILE, line + "\n");
} catch (exc) {
// ignored
}
}
return line;
};
示例5: bootstrapSbtProject
function bootstrapSbtProject(buildSbtFileSource: string,
dottyPluginSbtFileSource: string) {
fs.mkdirSync(sbtProjectDir)
fs.appendFileSync(sbtBuildPropertiesFile, `sbt.version=${sbtVersion}`)
fs.copyFileSync(buildSbtFileSource, sbtBuildSbtFile)
fs.copyFileSync(dottyPluginSbtFileSource, path.join(sbtProjectDir, "plugins.sbt"))
}
示例6: readAppend
function readAppend(targetFile: string, file: string): void {
try {
let data = fs.readFileSync(file, 'utf8');
fs.appendFileSync(targetFile, data, 'utf8');
} catch (e) {
console.log('Error reading test file', e);
}
}
示例7: report
function report(testName, testDescription, output, exitCode, result, saveReport){
if(saveReport && !result){
fs.appendFileSync(REPORT_FILE, util.format(
"\n%s %s failed - result: %s, exitCode: %s, output: %s\n", testName, testDescription, result,
exitCode?exitCode:'n/a', output?output:'n/a'));
}
}
示例8: writeFile
export function writeFile(fileName: string, code: string, map: any) {
ensureDirExists(path.dirname(fileName));
fs.writeFileSync(fileName, code);
if (map) {
fs.appendFileSync(fileName, "\n//# sourceMappingURL=" + path.basename(fileName) + ".map");
fs.writeFileSync(fileName + ".map", JSON.stringify(map));
}
}
示例9: composeRelease
export function composeRelease(buildPackage: BuildPackage) {
const {name, sourceDir} = buildPackage;
const packageOut = buildPackage.outputDir;
const releasePath = join(outputDir, 'releases', name);
const importAsName = `@angular/${name}`;
inlinePackageMetadataFiles(packageOut);
// Copy all d.ts and metadata files to the `typings/` directory
copyFiles(packageOut, '**/*.+(d.ts|metadata.json)', join(releasePath, 'typings'));
// Copy UMD bundles.
copyFiles(bundlesDir, `${name}?(-*).umd?(.min).js?(.map)`, join(releasePath, 'bundles'));
// Copy ES5 bundles.
copyFiles(bundlesDir, `${name}.es5.js?(.map)`, join(releasePath, 'esm5'));
copyFiles(join(bundlesDir, name), `*.es5.js?(.map)`, join(releasePath, 'esm5'));
// Copy ES2015 bundles
copyFiles(bundlesDir, `${name}.js?(.map)`, join(releasePath, 'esm2015'));
copyFiles(join(bundlesDir, name), `!(*.es5|*.umd).js?(.map)`, join(releasePath, 'esm2015'));
// Copy any additional files that belong in the package.
copyFiles(projectDir, 'LICENSE', releasePath);
copyFiles(packagesDir, 'README.md', releasePath);
copyFiles(sourceDir, 'package.json', releasePath);
replaceVersionPlaceholders(releasePath);
insertPackageJsonVersionStamp(join(releasePath, 'package.json'));
createTypingsReexportFile(releasePath, './typings/index', name);
createMetadataReexportFile(releasePath, './typings/index', name, importAsName);
if (buildPackage.secondaryEntryPoints.length) {
createFilesForSecondaryEntryPoint(buildPackage, releasePath);
}
if (buildPackage.copySecondaryEntryPointStylesToRoot) {
copySecondaryEntryPointStylesheets(buildPackage, releasePath);
}
if (buildPackage.exportsSecondaryEntryPointsAtRoot) {
// Add re-exports to the root d.ts file to prevent errors of the form
// "@angular/material/material has no exported member 'MATERIAL_SANITY_CHECKS."
const es2015Exports = buildPackage.secondaryEntryPoints
.map(p => `export * from './${p}';`).join('\n');
appendFileSync(join(releasePath, `${name}.d.ts`), es2015Exports, 'utf-8');
// When re-exporting secondary entry-points, we need to manually create a metadata file that
// re-exports everything.
createMetadataReexportFile(
releasePath,
buildPackage.secondaryEntryPoints.concat(['typings/index']).map(p => `./${p}`),
name,
importAsName);
}
}
示例10: initReport
function initReport(saveReport){
if(saveReport){
if(fs.existsSync(REPORT_FILE)){
fs.unlinkSync(REPORT_FILE);
}
var os = require('os');
var pjson = require('../package.json');
fs.appendFileSync(REPORT_FILE, util.format('Date: %s, Node version: %s. OS platform: %s, OS release: %s, dir-compare version: %s\n',
new Date(), process.version, os.platform(), os.release(), pjson.version));
}
}