當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript fs.appendFileSync函數代碼示例

本文整理匯總了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));
    }
}
開發者ID:HSAR,項目名稱:vso-agent-tasks,代碼行數:7,代碼來源:utilities.ts

示例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)}`);
}
開發者ID:forki,項目名稱:Fable,代碼行數:30,代碼來源:index.ts

示例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))
  }
}
開發者ID:jaredallard,項目名稱:nexe,代碼行數:34,代碼來源:docker.ts

示例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;
};
開發者ID:catb0t,項目名稱:mal,代碼行數:28,代碼來源:node_readline.ts

示例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"))
}
開發者ID:dotty-staging,項目名稱:dotty,代碼行數:7,代碼來源:extension.ts

示例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);
  }
}
開發者ID:hongyanh,項目名稱:atom-coderoad,代碼行數:8,代碼來源:concat-tests.ts

示例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'));
    }

}
開發者ID:gliviu,項目名稱:dir-compare,代碼行數:8,代碼來源:runTests.ts

示例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));
    }
}
開發者ID:7sharp9,項目名稱:Fable,代碼行數:8,代碼來源:lib.ts

示例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);
  }
}
開發者ID:mstawick,項目名稱:material2,代碼行數:57,代碼來源:build-release.ts

示例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));
	}
}
開發者ID:gliviu,項目名稱:dir-compare,代碼行數:11,代碼來源:runTests.ts


注:本文中的fs.appendFileSync函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。