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