當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。