当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript fs-extra.appendFile函数代码示例

本文整理汇总了TypeScript中fs-extra.appendFile函数的典型用法代码示例。如果您正苦于以下问题:TypeScript appendFile函数的具体用法?TypeScript appendFile怎么用?TypeScript appendFile使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了appendFile函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: generateJsCode

async function generateJsCode(fullPath: string, ast: Babel.types.Program,
                              options: FableSplitterOptions,
                              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, "/");
    }

    // Add ResolvePathPlugin
    babelOptions.plugins = (babelOptions.plugins || [])
        .concat(getResolvePathPlugin(jsDir, options));

    // transform and save
    const result = await generateJsCodeFromBabelAst(ast, code, babelOptions);
    if (result != null) {
        await fs.writeFile(jsPath, result.code);
        if (result.map) {
            await fs.appendFile(jsPath, "\n//# sourceMappingURL=" + Path.basename(jsPath) + ".map");
            await fs.writeFile(jsPath + ".map", JSON.stringify(result.map));
        }
        console.log(`fable: Compiled ${Path.relative(process.cwd(), fullPath)}`);
    }
}
开发者ID:rfrerebe,项目名称:Fable,代码行数:33,代码来源:index.ts

示例2: dataExport

async function dataExport() {
    await db.connect()

    console.log(`Exporting database structure and metadata to /tmp/owid_metadata.sql...`)

    // Dump all tables including schema but exclude the rows of data_values
    await exec(`mysqldump ${DB_NAME} --ignore-table=${DB_NAME}.sessions --ignore-table=${DB_NAME}.user_invitations --ignore-table=${DB_NAME}.data_values -r /tmp/owid_metadata.sql`)
    await exec(`mysqldump --no-data ${DB_NAME} sessions user_invitations data_values >> /tmp/owid_metadata.sql`)

    // Strip passwords
    await exec(`sed -i -e "s/bcrypt[^']*//g" /tmp/owid_metadata.sql`)

    // Add default admin user
    await fs.appendFile("/tmp/owid_metadata.sql", "INSERT INTO users (`password`, `isSuperuser`, `email`, `fullName`, `createdAt`, `updatedAt`, `isActive`) VALUES ('bcrypt$$2b$12$EXfM7cWsjlNchpinv.j6KuOwK92hihg5r3fNssty8tLCUpOubST9u', 1, 'admin@example.com', 'Admin User', '2016-01-01 00:00:00', '2016-01-01 00:00:00', 1);\n")

    await db.end()
}
开发者ID:OurWorldInData,项目名称:owid-grapher,代码行数:17,代码来源:exportMetadata.ts

示例3: appendRow

export async function appendRow(file: string, row: {[column: string]: string}) {
  const exists = await fs.pathExists(file);
  if (!exists) {
    // Easy: write the whole file.
    const header = Object.keys(row);
    const rows = [header, header.map(k => row[k])]
    return writeCsv(file, rows);
  }

  const lines = readRows(file);
  const headerRow = await lines.next();
  if (headerRow.done) {
    throw new Error(`CSV file ${file} was empty`);
  }
  const headers = headerRow.value;
  const headerToIndex: {[header: string]: number} = {};
  headers.forEach((header, i) => {
    headerToIndex[header] = i;
  })

  // Check if there are any new headers in the row.
  const newHeaders = [];
  for (const k in row) {
    if (!(k in headerToIndex)) {
      newHeaders.push(k);
    }
  }

  if (newHeaders.length) {
    const fullHeaders = headers.concat(newHeaders);
    const rows = [fullHeaders];
    const emptyCols = newHeaders.map(() => '');
    for await (const row of lines) {
      rows.push(row.concat(emptyCols));
    }
    rows.push(fullHeaders.map(k => row[k] || ''));
    await writeCsv(file, rows);
  } else {
    // write the new row
    const newRow = headers.map(k => row[k] || '');
    await lines.return();  // close the file for reading.
    await fs.appendFile(file, await stringify([newRow]));
  }
}
开发者ID:danvk,项目名称:localturk,代码行数:44,代码来源:csv.ts

示例4: Given

Given('my text-run configuration contains:', async function(text) {
  await fs.appendFile(path.join(this.rootDir, 'text-run.yml'), `\n${text}`)
})
开发者ID:Originate,项目名称:tutorial-runner,代码行数:3,代码来源:given-steps.ts

示例5:

import * as webdriver from 'selenium-webdriver';
import * as protractor from 'protractor';
import * as fse from 'fs-extra';

let c = new webdriver.Command("hello");
let we = new protractor.WebElement(null, null);

fse.appendFile("lala", "baba");
开发者ID:IgorMinar,项目名称:tsc-types-test,代码行数:8,代码来源:test.ts


注:本文中的fs-extra.appendFile函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。