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


TypeScript fs-extra-promise.outputFileAsync函數代碼示例

本文整理匯總了TypeScript中fs-extra-promise.outputFileAsync函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript outputFileAsync函數的具體用法?TypeScript outputFileAsync怎麽用?TypeScript outputFileAsync使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了outputFileAsync函數的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: writeTranslation

function writeTranslation(translation: ParsedTranslation) {
  const filename = join(project.ws.srcDir, project.ws.i18n.dir, `${translation.locale}.js`);
  const data = `${GENERATED_WARNING}
module.exports.asts = ${JSON.stringify(translation.asts, null, '  ')};`;

  return outputFileAsync(filename, data);
}
開發者ID:Mercateo,項目名稱:typedocs,代碼行數:7,代碼來源:i18n-compile.ts

示例2: resolve

 res.on('end', () => {
   if (IGNORED_CONTENTS.some((content) => body === content)) {
     resolve();
   } else {
     outputFileAsync(outputPath, body).then(() => resolve()).catch(reject);
   }
 });
開發者ID:Mercateo,項目名稱:typedocs,代碼行數:7,代碼來源:i18n-import.ts

示例3: write_file

export async function write_file(file_path: string, data: string): Promise<void>{
	await lock.acquire();
	try{
		await fs.outputFileAsync(file_path, data);
	}
	finally{
		lock.release();
	}
}
開發者ID:BelaPlatform,項目名稱:Bela,代碼行數:9,代碼來源:FileManager.ts

示例4: writeTranslation

async function writeTranslation(
  defaultTranslation: ParsedTranslation,
  translation: ParsedTranslation
) {
  const filename = join(project.ws.i18n!.distDir, `${translation.locale}.js`);
  const keys = Object.keys(defaultTranslation.data);
  const intlLocale = await toIntlLocale(translation.locale);

  const data = `${GENERATED_WARNING}
var IntlMessageFormat = require('intl-messageformat');
// use intl polyfill for IE 10 and Safari 9
require('intl');
require('intl/locale-data/jsonp/${intlLocale}');

module.exports.LOCALE = '${translation.locale}';
module.exports.INTL_LOCALE = '${intlLocale}';
module.exports.LANGUAGE_CODE = '${translation.locale.split('_')[0]}';
module.exports.COUNTRY_CODE = '${translation.locale.split('_')[1]}';

var cachedMessages = {};
${keys
  .map(
    (key) => `
module.exports['${key}'] = function(${
      hasArguments(translation.asts[key]) ? 'data' : ''
    }) {${
      translation.asts[key]
        ? `
  if (!cachedMessages['${key}']) {
    var ast = ${indent(
      '    ',
      stringifyObject(translation.asts[key], stringifyObjectOptions)
    )};
    cachedMessages['${key}'] = new IntlMessageFormat(ast, '${intlLocale}');
  }

  return cachedMessages['${key}'].format(${
            hasArguments(translation.asts[key]) ? 'data' : ''
          });`
        : `return 'Missing key "${key}".';`
    }
};
`
  )
  .join('')}
`;

  return outputFileAsync(filename, data);
}
開發者ID:Mercateo,項目名稱:ws,代碼行數:49,代碼來源:compile.ts

示例5: writeDeclaration

function writeDeclaration(translations: ParsedTranslation[]) {
  const filename = join(project.ws.i18n!.distDir, 'index.d.ts');
  const defaultTranslation = translations[0];
  const keys = Object.keys(defaultTranslation.data);

  const data = `${GENERATED_WARNING}
declare interface I18N {
  /**
   * Your locale in the format \`de_DE\`, \`en_US\`, etc.
   */
  LOCALE: string;

  /**
   * Your locale in the format \`de-DE\`, \`en-US\`, etc.
   */
  INTL_LOCALE: string;

  /**
   * Your language code in the format \`de\`, \`en\`, etc.
   */
  LANGUAGE_CODE: string;

  /**
   * Your country code in the format \`DE\`, \`US\`, etc.
   */
  COUNTRY_CODE: string;${keys
    .map(
      (key) =>
        `
${getDocumentation(translations, key)}
  ${key}: (${
          hasArguments(defaultTranslation.asts[key])
            ? `data: ${getArgumentTypes(defaultTranslation.asts[key])}`
            : ''
        }) => string,`
    )
    .join('\n')}
}
`;

  return outputFileAsync(filename, data);
}
開發者ID:Mercateo,項目名稱:ws,代碼行數:42,代碼來源:compile.ts

示例6: writeIndexTranslation

function writeIndexTranslation(translations: ParsedTranslation[]) {
  const filename = join(project.ws.srcDir, project.ws.i18n.dir, `index.${project.ws.entryExtension}`);
  const hasTypes = project.ws.entryExtension !== 'js';

  const data =
`${GENERATED_WARNING}
const INTL_LOCALE = process.env.LOCALE.replace('_', '-');
const asts = require(\`./\${process.env.LOCALE}\`).asts;
const IntlMessageFormat = require('intl-messageformat');

const lazyMessages = {};${Object.keys(translations[0].data).map(key => `
${getDocumentation(translations, key)}
export const ${key} = (${hasArguments(translations[0].asts[key]) ? `data${hasTypes ? `: ${getArguments(translations[0].asts[key])}` : ''}` : ''})${hasTypes ? ': string' : ''} => {
  if (!lazyMessages['${key}']) {
    lazyMessages['${key}'] = new IntlMessageFormat(asts['${key}'], INTL_LOCALE);
  }
  return lazyMessages['${key}'].format(${hasArguments(translations[0].asts[key]) ? 'data' : ''});
};`
).join('')}
`;

  return outputFileAsync(filename, data);
}
開發者ID:Mercateo,項目名稱:typedocs,代碼行數:23,代碼來源:i18n-compile.ts


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