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


TypeScript fs.writeFile函数代码示例

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


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

示例1: reject

            fs.readFile(fileName, { encoding }, (err, fileText) => {
                /* istanbul ignore if */
                if (err) {
                    reject(err);
                    return;
                }

                const result = replaceInText(fileName, fileText);

                if (result.replaced) {
                    fs.writeFile(fileName, result.fileText!, writeErr => {
                        /* istanbul ignore if */
                        if (writeErr) {
                            reject(writeErr);
                            return;
                        }

                        resolve();
                    });
                }
                else {
                    resolve();
                }
            });
开发者ID:dsherret,项目名称:ts-nameof,代码行数:24,代码来源:replaceInFiles.ts

示例2: LoginReceiver

function LoginReceiver(msg) {
    console.log(msg);
    $("#user").prop('disabled', true);
    $("#password").prop('disabled', true);
    //alert(JSON.stringify(msg));
    if (msg.type == connect.MessageType.RESPONSE) {
        if (msg.content.type == connect.MessageType.LOGIN) {
            if (msg.content.code == connect.ResponseCode.INVALID_LOGIN_INFO) {
                ipcRenderer.send('loadWindow', 2);
                alert("Los datos ingresados no son correctos!");
            }
            else if(msg.content.code == connect.ResponseCode.OK) {
                var rooms = {"rooms": msg.content.content};

                ipcRenderer.send('loadWindow', 3);
                fs.writeFile(__dirname + '/../../tmp/rooms.json', JSON.stringify(rooms, null, 4));
                //ipcRenderer.send('updateFile', {"data": msg.content.content, "type": "rooms"});
            }
         }

        console.log("Respuesta para:", connect.MessageType[msg.content.type]);
        console.log("Codigo de respuesta:", connect.ResponseCode[msg.content.code]);
    }
}
开发者ID:edoren,项目名称:ChatClient,代码行数:24,代码来源:login_controller.ts

示例3: adjacency_list_to_dot

export function adjacency_list_to_dot(adj_list, output_path) {
	var fs = require('fs');
	var path = require('path');
	var child_process = require('child_process'); // to call dotty

	var output = 'digraph G {\n'
	for (var vertex in adj_list) {
		output += '\t"' + vertex.replace(/"/g, "'") + '"';
		
		var parents = adj_list[vertex];
		for (var i=0; i<parents.length; ++i)
			output += ' -> "' + parents[i].replace(/"/g, "'") + '"';
		output += ';\n';
	}
	output += '}';
	
	var output_dir = path.dirname(output_path);
	var filename = path.basename(output_path);
	var extension = path.extname(output_path).replace(/\./g, "");
	var dot_file = path.join(output_dir, filename.replace(extension, 'dot'));
	fs.writeFile(dot_file, output, function (err) {
		if (err)  throw err;
	});

	var path_to_dot = '"C:\\Program Files (x86)\\Graphviz2.38\\bin\\dot.exe"'
	var cmd = path_to_dot + " -T" + extension + ' ' + dot_file + ' -o ' + output_path;
	child_process.exec(cmd, function(error, stdout, stderr) {
		//dbg('stdout', stdout);
		//dbg('stderr', stderr);
		if (stderr) {
			throw stderr;
		} else {
			info_msg(output_path + " successfully created !");
		}
	});
}
开发者ID:kljh,项目名称:grid,代码行数:36,代码来源:deps_graph.ts

示例4:

remote.getCurrentWindow().capturePage(buf => {
	fs.writeFile('/tmp/screenshot.png', buf, err => {
		console.log(err);
	});
});
开发者ID:longlho,项目名称:DefinitelyTyped,代码行数:5,代码来源:github-electron-renderer-tests.ts

示例5: writeFile

 call_back =>
     writeFile(path_join(...dir_file), 'exports.bar = function(){}', 'utf8', call_back)
开发者ID:SamuelMarks,项目名称:nodejs-utils,代码行数:2,代码来源:test_utils.ts

示例6: generateNamespace

import { generateNamespace } from "@gql2ts/from-schema";
import { genSchema } from '../utils/generateSchema';
import * as path from "path";
import * as fs from 'fs';

const typescriptTypes = generateNamespace('GQL', genSchema());
fs.writeFile(
    path.join(__dirname, '../types/schema.d.ts'), 
    typescriptTypes, 
    (err) => console.log(err)
);
开发者ID:itaygolan,项目名称:GraphQL-Typescript-Server,代码行数:11,代码来源:createTypes.ts

示例7: reject

 .then(() => fs.writeFile(file, data, /*encoding*/ "utf8", err => err ? reject(err) : resolve()))
开发者ID:rbuckton,项目名称:chai-baseline,代码行数:1,代码来源:index.ts

示例8: ls

          '<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n';

function ls(path) {
  const files: string[] = fs.readdirSync(path);
  const prefix: string = (path.length > 2 ? path + '/' : './');
  for (const file of files) {
    const fname: string = prefix + file;
    const stat: fs.Stats = fs.statSync(fname);
    if (stat.isFile()) {
      if (file.endsWith('.htm') ||
          file.endsWith('.html')) {
        const mtime: string = dateFormat('yyyy-MM-dd', stat.mtime);
        out += '<url><loc>' + domain + fname.substring(1) +
              '</loc><lastmod>' + mtime + '</lastmod></url>\n';
      }
    } else if (stat.isDirectory()) {
      ls(fname);
    }
  }
}

try {
  ls('./');
  out += '</urlset>';
  fs.writeFile('./sitemap.xml', out, (err: NodeJS.ErrnoException): void => {
    if (err) { throw err; }
  });
} catch (e) {
  console.error(e);
}
开发者ID:kittttttan,项目名称:ktn-js,代码行数:30,代码来源:sitemap.ts

示例9: saveGame

export function saveGame() {
    writeFile("game.sav", "0.1;" + configSaver(), (err) => {
        throw err;
    });
}
开发者ID:reverse-squared,项目名称:OldMaterialClicker,代码行数:5,代码来源:save.ts

示例10:

			res.on('end', () => {
				fs.writeFile(location, Buffer.concat(buffer), 'utf8', () => {
					console.log('Keybindings were successfully fetched.');
					resolve();
				});
			});
开发者ID:kieferrm,项目名称:vscode,代码行数:6,代码来源:main.ts


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