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


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

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


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

示例1: add

async function add(egretProjectRoot: string) {
    console.log('正在將 protobuf 源碼拷貝至項目中...');
    await fs.copyAsync(path.join(root, 'dist'), path.join(egretProjectRoot, 'protobuf/library'));
    await fs.mkdirpSync(path.join(egretProjectRoot, 'protobuf/protofile'));
    await fs.mkdirpSync(path.join(egretProjectRoot, 'protobuf/bundles'));
    await fs.writeFileAsync((path.join(egretProjectRoot, 'protobuf/pbconfig.json')), pbconfigContent, 'utf-8');

    const egretPropertiesPath = path.join(egretProjectRoot, 'egretProperties.json');
    if (await fs.existsAsync(egretPropertiesPath)) {
        console.log('正在將 protobuf 添加到 egretProperties.json 中...');
        const egretProperties = await fs.readJSONAsync(egretPropertiesPath);
        egretProperties.modules.push({ name: 'protobuf-library', path: 'protobuf/library' });
        egretProperties.modules.push({ name: 'protobuf-bundles', path: 'protobuf/bundles' });
        await fs.writeFileAsync(path.join(egretProjectRoot, 'egretProperties.json'), JSON.stringify(egretProperties, null, '\t\t'));
        console.log('正在將 protobuf 添加到 tsconfig.json 中...');
        const tsconfig = await fs.readJSONAsync(path.join(egretProjectRoot, 'tsconfig.json'));
        tsconfig.include.push('protobuf/**/*.d.ts');
        await fs.writeFileAsync(path.join(egretProjectRoot, 'tsconfig.json'), JSON.stringify(tsconfig, null, '\t\t'));
    }
    else {
        console.log('輸入的文件夾不是白鷺引擎項目')
    }


}
開發者ID:bestdpf,項目名稱:protobuf-egret,代碼行數:25,代碼來源:index.ts

示例2: generate

async function generate(rootDir: string) {

    const pbconfigPath = path.join(rootDir, 'pbconfig.json');
    if (!(await fs.existsAsync(pbconfigPath))) {
        if (await fs.existsAsync(path.join(rootDir, 'protobuf'))) {
            const pbconfigPath = path.join(rootDir, 'protobuf', 'pbconfig.json')
            if (!await (fs.existsAsync(pbconfigPath))) {
                await fs.writeFileAsync(pbconfigPath, pbconfigContent, 'utf-8');
            }
            await generate(path.join(rootDir, 'protobuf'));
        }
        else {
            throw '請首先執行 pb-egret add 命令'
        }
        return;
    }
    const pbconfig: ProtobufConfig = await fs.readJSONAsync(path.join(rootDir, 'pbconfig.json'));
    const tempfile = path.join(os.tmpdir(), 'pbegret', 'temp.js');
    await fs.mkdirpAsync(path.dirname(tempfile));
    const output = path.join(rootDir, pbconfig.outputFile);
    const dirname = path.dirname(output);
    await fs.mkdirpAsync(dirname);
    const protoRoot = path.join(rootDir, pbconfig.sourceRoot);
    const fileList = await fs.readdirAsync(protoRoot);
    const protoList = fileList.filter(item => path.extname(item) === '.proto')
    if (protoList.length == 0) {
        throw ' protofile 文件夾中不存在 .proto 文件'
    }
    await Promise.all(protoList.map(async (protofile) => {
        const content = await fs.readFileAsync(path.join(protoRoot, protofile), 'utf-8')
        if (content.indexOf('package') == -1) {
            throw `${protofile} 中必須包含 package 字段`
        }
    }))




    const args = ['-t', 'static', '-p', protoRoot, protoList.join(" "), '-o', tempfile]
    if (pbconfig.options['no-create']) {
        args.unshift('--no-create');
    }
    if (pbconfig.options['no-verify']) {
        args.unshift('--no-verify');
    }
    await shell('pbjs', args);
    let pbjsResult = await fs.readFileAsync(tempfile, 'utf-8');
    pbjsResult = 'var $protobuf = window.protobuf;\n$protobuf.roots.default=window;\n' + pbjsResult;
    await fs.writeFileAsync(output, pbjsResult, 'utf-8');
    const minjs = UglifyJS.minify(pbjsResult);
    await fs.writeFileAsync(output.replace('.js', '.min.js'), minjs.code, 'utf-8');
    await shell('pbts', ['--main', output, '-o', tempfile]);
    let pbtsResult = await fs.readFileAsync(tempfile, 'utf-8');
    pbtsResult = pbtsResult.replace(/\$protobuf/gi, "protobuf").replace(/export namespace/gi, 'declare namespace');
    pbtsResult = 'type Long = protobuf.Long;\n' + pbtsResult;
    await fs.writeFileAsync(output.replace(".js", ".d.ts"), pbtsResult, 'utf-8');
    await fs.removeAsync(tempfile);

}
開發者ID:bestdpf,項目名稱:protobuf-egret,代碼行數:59,代碼來源:index.ts

示例3: updateREADME

async function updateREADME() {

  const README_PATH = jd('../../README.md')
  const README_BUFFER = await fsep.readFileAsync(README_PATH)
  const README_CONTENTS = README_BUFFER.toString()
  const SOURCE_TREE = await sourceFolderTree()

  const commentMarker = c => `[//]: # (${c})`
  const START_MARKER = commentMarker('START_FILE_STRUCTURE')
  const END_MARKER = commentMarker('END_FILE_STRUCTURE')

  const t = '```'
  const pre =
`${START_MARKER}

${t}plaintext
${SOURCE_TREE}${t}

${END_MARKER}`

  const newReadme = replaceBetween(START_MARKER, END_MARKER)(README_CONTENTS, pre)

  await fsep.writeFileAsync(README_PATH, newReadme)

  log('Wrote new README sucessfulyl')

}
開發者ID:Edward-Lombe,項目名稱:elm-electron,代碼行數:27,代碼來源:update-README.ts

示例4: resolve

    return new Promise<void>((resolve, reject) => {
        if (!operations.addLaunchJson) {
            return resolve();
        }
        
        let targetFramework = '<target-framework>';
        let executableName = '<project-name.dll>';

        let done = false;
        for (var project of info.Projects) {
            for (var configuration of project.Configurations) {
                if (configuration.Name === "Debug" && configuration.EmitEntryPoint === true) {                       
                    if (project.Frameworks.length > 0) {
                        targetFramework = project.Frameworks[0].ShortName;
                        executableName = path.basename(configuration.CompilationOutputAssemblyFile)
                    }
                    
                    done = true;
                    break;
                }
            }               
            
            if (done) {
                break;
            }
        }
        
        const launchJson = createLaunchJson(targetFramework, executableName);
        const launchJsonText = JSON.stringify(launchJson, null, '    ');
        
        return fs.writeFileAsync(paths.launchJsonPath, launchJsonText);
    });
開發者ID:Jeffiy,項目名稱:omnisharp-vscode,代碼行數:32,代碼來源:assets.ts

示例5: writeFileAsync

 stats.results.map(async result => {
   const wasFixed = result.output !== undefined;
   if (wasFixed) {
     fixedFiles.push(result.filePath);
     await writeFileAsync(result.filePath, result.output);
   }
 })
開發者ID:otbe,項目名稱:ws,代碼行數:7,代碼來源:eslint.ts

示例6: resolve

    return new Promise<void>((resolve, reject) => {
        if (!operations.addLaunchJson) {
            return resolve();
        }

        const isWebProject = hasWebServerDependency(projectData);
        const launchJson = createLaunchJson(projectData, isWebProject);
        const launchJsonText = JSON.stringify(launchJson, null, '    ');
        
        return fs.writeFileAsync(paths.launchJsonPath, launchJsonText);
    });
開發者ID:Firaenix,項目名稱:omnisharp-vscode,代碼行數:11,代碼來源:assets.ts

示例7: format

    filePaths.map(async (filePath, index) => {
      const content = contents[index];
      let formattedContent;

      try {
        formattedContent = format(content, options);
      } catch (err) {
        error(`Couldn't format ${red(filePath)}.`);
        throw err;
      }

      if (content !== formattedContent) {
        fixedFiles.push(filePath);
        await writeFileAsync(filePath, formattedContent);
      }
    })
開發者ID:otbe,項目名稱:ws,代碼行數:16,代碼來源:prettier.ts

示例8: writeTypescriptFile

async function writeTypescriptFile (filename: string, output: string) {
  const result = await processString('', output.trim(), {
    replace: false,
    verify: false,
    tsconfig: false,
    tslint: false,
    editorconfig: false,
    tsfmt: true,
    tsconfigFile: null,
    tslintFile: null,
    tsfmtFile: null,
    vscode: false,
    vscodeFile: null
  });

  await ensureDirAsync(dirname(filename));
  await writeFileAsync(filename, result.dest, { encoding: 'utf-8' });
}
開發者ID:chasidic,項目名稱:mysql,代碼行數:18,代碼來源:GenerateTypescript.ts

示例9: toMarkdownFile

export async function toMarkdownFile(typeDocJsonFile: string, outputFile: string = defaultOutputFile): Promise<any> {
  return await writeFileAsync(outputFile, toMarkdown(typeDocJsonFile));
}
開發者ID:Mercateo,項目名稱:typedocs,代碼行數:3,代碼來源:index.ts


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