• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript tmp.fileSync函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: _setupServerOptions

 function _setupServerOptions() {
   _keyFile = tmp.fileSync();
   _certFile = tmp.fileSync();
   _serverOptions = {
     root,
     protocol: 'h2',
     keyPath: _keyFile.name,
     certPath: _certFile.name
   };
 }
开发者ID:tony19-contrib,项目名称:polyserve,代码行数:10,代码来源:start_server_test.ts


示例2: createDatabaseSuite

export function createDatabaseSuite(suiteName: string, suite: DatabaseTestSuite) {
  const sqlitePath = tmp.fileSync().name
  const sqlite = new Database(logger.T)
  const postgres = new Database(logger.T)

  describe(`DB[SQLite] ${suiteName}`, async () => {
    beforeAll(async () => {
      await sqlite.initialize({
        location: sqlitePath,
        type: 'sqlite'
      })

      await sqlite.bootstrap()
      await sqlite.seedForTests()
    })

    afterAll(async () => {
      await sqlite.teardownTables()
      await sqlite.knex.destroy()
    })

    afterEach(async () => {
      await sqlite.teardownTables()
      await sqlite.bootstrap()
      await sqlite.seedForTests()
    })

    await suite(sqlite)
  })

  describe(`DB[Postgres] ${suiteName}`, () => {
    beforeAll(async () => {
      await postgres.initialize({
        type: 'postgres',
        host: process.env.PG_HOST || 'localhost',
        port: Number(process.env.PG_PORT || 5432),
        database: process.env.PG_DB || TEST_DATABASE,
        user: process.env.PG_USER || 'postgres',
        password: process.env.PG_PASSWORD || ''
      })

      await postgres.bootstrap()
      await postgres.seedForTests()
    })

    afterAll(async () => {
      await postgres.teardownTables()
      await postgres.knex.destroy()
    })

    afterEach(async () => {
      await postgres.teardownTables()
      await postgres.bootstrap()
      await postgres.seedForTests()
    })

    suite(postgres)
  })
}
开发者ID:seffalabdelaziz,项目名称:botpress,代码行数:59,代码来源:index.tests.ts


示例3: it

  it("should connect securely", async () => {
    const attrs = [{ name: "commonName", value: "buttplugtest.com" }];
    const pems = selfsigned.generate(attrs, { days: 365 });
    const tmpcert = tmp.fileSync();
    const tmpprivate = tmp.fileSync();
    fs.writeFileSync(tmpcert.name, pems.cert);
    fs.writeFileSync(tmpprivate.name, pems.private);
    _server.StartSecureServer(tmpcert.name, tmpprivate.name, _port, "127.0.0.1");

    const bpc = new ButtplugClient("test");
    await bpc.Connect(_secureConnector);
    expect(bpc.Connected).toBe(true);
    await bpc.Disconnect();
    expect(bpc.Connected).toBe(false);
    tmpcert.removeCallback();
    tmpprivate.removeCallback();
  });
开发者ID:metafetish,项目名称:buttplug-js,代码行数:17,代码来源:test-websockets.ts


示例4: createArchive

async function createArchive(ref: string): Promise<any> {
  const tar = spawn('git', ['archive', '--format', 'tar.gz', ref])
  const file = tmp.fileSync({postfix: '.tar.gz'})
  const write = tar.stdout.pipe(fs.createWriteStream(file.name))

  return new Promise((resolve, reject) => {
    write.on('close', () => resolve(file.name))
    write.on('error', reject)
  })
}
开发者ID:jimmyurl,项目名称:cli,代码行数:10,代码来源:git.ts


示例5: makeArchive

function makeArchive(app: string, includeDotfiles: boolean) {
  // create a file to stream archive data to.
  const { name: tarPath } = tmp.fileSync({
    discardDescriptor: true,
    prefix: `${app}-deploy-`,
    postfix: '.tar.gz'
  });
  const output = fs.createWriteStream(tarPath);
  const archive = archiver('tar', {
    gzip: true
  });

  // listen for all archive data to be written
  output.on('close', () => {
    // print something?
  });

  // good practice to catch warnings (ie stat failures and other non-blocking errors)
  archive.on('warning', (err) => {
    if (err.code === 'ENOENT') {
      // log warning
    } else {
      // throw error
      throw err;
    }
  });

  // good practice to catch this error explicitly
  archive.on('error', (err) => {
    throw err;
  });

  // pipe archive data to the file
  archive.pipe(output);

  return globby('**', {
    dot: includeDotfiles,
    gitignore: true,
    gitignoreName: '.skyignore'
  })
    .then((paths: [string]) => {
      paths.forEach((path) => {
        archive.file(path, {
          name: path
        });
      });
      // finalize the archive (ie we are done appending files but streams have to finish yet)
      return archive.finalize();
    })
    .then(() => {
      return tarPath;
    });
}
开发者ID:SkygearIO,项目名称:skycli,代码行数:53,代码来源:deploy.ts


示例6: Promise

 return new Promise((resolve, reject) => {
   const tmpfile = tmp.fileSync();
   const req = request.get(remoteUrl);
   const writeStream = fs.createWriteStream(tmpfile.name);
   req.on("error", (err: any) => reject(err));
   req.on("response", (response) => {
     if (response.statusCode !== 200) {
       reject(new FirebaseError(`download failed, status ${response.statusCode}`, { exit: 1 }));
     }
   });
   writeStream.on("finish", () => {
     resolve(tmpfile.name);
   });
   req.pipe(writeStream);
 });
开发者ID:firebase,项目名称:firebase-tools,代码行数:15,代码来源:download.ts


示例7: initConcatJs

/**
 * Entry-point for the Karma plugin.
 */
function initConcatJs(logger, emitter, basePath) {
  const log = logger.create('framework.concat_js');

  // Create a tmp file for the concat bundle that is automatically cleaned up on
  // exit.
  const tmpFile = tmp.fileSync({keep: false, dir: process.env['TEST_TMPDIR']});

  emitter.on('file_list_modified', files => {
    const bundleFile = {
      path: '/concatjs_bundle.js',
      contentPath: tmpFile.name,
      isUrl: false,
      content: ''
    } as any;
    const included = [];

    files.included.forEach(file => {
      if (path.extname(file.originalPath) !== '.js') {
        // Preserve all non-JS that were there in the included list.
        included.push(file);
      } else {
        const relativePath =
            path.relative(basePath, file.originalPath).replace(/\\/g, '/');

        // Remove 'use strict'.
        let content = file.content.replace(/('use strict'|"use strict");?/,
                                           '');
        content = JSON.stringify(
            content + '\n//# sourceURL=http://concatjs/base/' +
            relativePath + '\n');
        content = `//${relativePath}\neval(${content});\n`;
        bundleFile.content += content;
      }
    });

    bundleFile.sha = sha1(new Buffer(bundleFile.content));
    bundleFile.mtime = new Date();
    included.unshift(bundleFile);

    files.included = included;
    files.served.push(bundleFile);

    log.debug('Writing concatjs bundle to tmp file %s',
        bundleFile.contentPath);
    fs.writeFileSync(bundleFile.contentPath, bundleFile.content);
  });
}
开发者ID:ramyothman,项目名称:testdashboard,代码行数:50,代码来源:index.ts


示例8: request

    store: (absoluteImagePath: string): Thenable<string> => {
        if (ImageCache.has(absoluteImagePath)) {
            return ImageCache.get(absoluteImagePath);
        } else {
            try {
                const absoluteImageUrl = url.parse(absoluteImagePath);
                const tempFile = tmp.fileSync({
                    postfix: absoluteImageUrl.pathname ? path.parse(absoluteImageUrl.pathname).ext : 'png'
                });
                const filePath = tempFile.name;
                const promise = new Promise<string>((resolve, reject) => {
                    if (absoluteImageUrl.protocol && absoluteImageUrl.protocol.startsWith('http')) {
                        var r = request(absoluteImagePath);
                        r.on('error', function(err) {
                            reject(err);
                        });
                        r.on('response', function(res) {
                            r.pipe(fs.createWriteStream(filePath)).on('close', () => {
                                resolve(filePath);
                            });
                        });
                    } else {
                        try {
                            const handle = fs.watch(absoluteImagePath, function fileChangeListener() {
                                handle.close();
                                fs.unlink(filePath, () => {});
                                ImageCache.delete(absoluteImagePath);
                            });
                        } catch (e) {}
                        copyFile(absoluteImagePath, filePath, err => {
                            if (!err) {
                                resolve(filePath);
                            }
                        });
                    }
                });
                ImageCache.set(absoluteImagePath, promise);

                return promise;
            } catch (error) {}
        }
    },
开发者ID:kisstkondoros,项目名称:gutter-preview,代码行数:42,代码来源:imagecache.ts


示例9: processFile

async function processFile(filename: string) {
    let tmpFile = tmp.fileSync();
    let destFileName = getDestFileName(filename);

    console.log(`Parsing file ${filename} to ${destFileName}`);

    try {
        let parsed = sass.renderSync({ file: filename, outFile: tmpFile.name });
        let css = (new Buffer(parsed.css)).toString();
        fs.writeFileSync(tmpFile.name, css);
        let cssToDtsConverter = new DtsCreator();
        let content = await cssToDtsConverter.create(tmpFile.name);
        let tokens = content.rawTokenList as string[];

        let typings = TsTypeInfo.createFile();
        let formatter = (token) => program['camelCase'] ? camelCase(token) : token;

        typings.addClasses({
            name: 'Styles',
            isExported: true,
            isDefaultExportOfFile: true,
            isAmbient: true,
            isNamedExportOfFile: true,
            hasDeclareKeyword: true,
            properties: tokens.map<TsTypeInfo.ClassPropertyStructure>(token => ({ name: `'${formatter(token)}'`, type: 'string' })),
            onAfterWrite: writer => {
                writer.writeLine(``);                                
                writer.writeLine(`declare var style: Styles`);
                writer.writeLine(`export = style;`);
            }
        });

        fs.writeFileSync(destFileName, typings.write());
    }
    catch (e) {
        console.error(e);
        throw e;
    }
    finally {
        tmpFile.removeCallback();
    }
}
开发者ID:Bolisov,项目名称:sass-css-modules-to-typings-converter,代码行数:42,代码来源:index.ts


示例10: convertToTsv

function convertToTsv(filename: string, options: IXLSXExtractOptions, cb: (err: Error | null, tsv?: string) => void) {
	const file = tmp.fileSync();
	fs.unlinkSync(file.name);
	let error: Error | null = null;
	new XLSX().convert(filename, file.name, options)
		.on('end', () => {
			const exists = fs.existsSync(file.name);
			assert.equal(exists, true, 'file not written');
			if (exists) {
				const tsv = fs.readFileSync(file.name).toString();
				file.removeCallback();
				cb(error, tsv);
			} else {
				cb(error);
			}

		})
		.on('error', err => {
			error = err;
		});
}
开发者ID:ffalt,项目名称:xlsx-extract,代码行数:21,代码来源:test.ts



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript tmp.tmpNameSync函数代码示例发布时间:2022-05-25
下一篇:
TypeScript tmp.file函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap