Skip to content
This repository has been archived by the owner on Sep 27, 2020. It is now read-only.

如何打包成可执行文件

Srar edited this page Jul 18, 2019 · 4 revisions

1.配置node-gyp依赖环境

  1. 安装Visual C++构建环境
  1. 安装Python2

更多信息请参考https://github.com/nodejs/node-gyp#on-windows

2.clone项目并安装依赖

git clone https://github.com/Srar/node-tap.git
cd ./node-tap
npm install --unsafe

3.修改node_modules\logform\index.js

'use strict';

/*
 * @api public
 * @property {function} format
 * Both the construction method and set of exposed
 * formats.
 */
const format = exports.format = require('./format');

/*
 * @api public
 * @method {function} levels
 * Registers the specified levels with logform.
 */
exports.levels = require('./levels');

const formats = {
  align: require("./align.js"),
  errors: require("./errors.js"),
  cli: require("./cli.js"),
  combine: require("./combine.js"),
  colorize: require("./colorize.js"),
  json: require("./json.js"),
  label: require("./label.js"),
  logstash: require("./logstash.js"),
  metadata: require("./metadata.js"),
  ms: require("./ms.js"),
  padLevels: require("./pad-levels.js"),
  prettyPrint: require("./pretty-print.js"),
  printf: require("./printf.js"),
  simple: require("./simple.js"),
  splat: require("./splat.js"),
  timestamp: require("./timestamp.js"),
  uncolorize: require("./uncolorize.js")
};

/*
 * @api private
 * method {function} exposeFormat
 * Exposes a sub-format on the main format object
 * as a lazy-loaded getter.
 */
function exposeFormat(name, path) {
  path = path || name;
  Object.defineProperty(format, name, {
    get() {
      return formats[name];
    },
    configurable: true
  });
}

//
// Setup all transports as lazy-loaded getters.
//
exposeFormat('align');
exposeFormat('errors');
exposeFormat('cli');
exposeFormat('combine');
exposeFormat('colorize');
exposeFormat('json');
exposeFormat('label');
exposeFormat('logstash');
exposeFormat('metadata');
exposeFormat('ms');
exposeFormat('padLevels', 'pad-levels');
exposeFormat('prettyPrint', 'pretty-print');
exposeFormat('printf');
exposeFormat('simple');
exposeFormat('splat');
exposeFormat('timestamp');
exposeFormat('uncolorize');

4.编译与打包

# TypeScript转换为JavaScript
npm run build
# 编译native库
npm run compile
# 打包成可执行文件
npm run package

当执行完毕以上命令且没有错误时, 您应当会在目录下找到一个名为sstap.exe的可执行文件.

您还需要将以下文件或目录放置在sstap.exe同一个目录.

  • \node-tap\下的driver目录以及目录内文件.
  • \node-tap\build\Release\下的addon.node文件.
  • \node-tap\下的node_modules目录.
  • \node-tap\node_modules\下的cap目录以及目录内文件.
  • \node-tap\node_modules\下的raw-socket目录以及目录内文件.

结构

node-tap\
├── node_modules\
│   ├── cap\
│     └── ....
│   ├── raw-socket\
│     └── ....
│   ├── driver\
│     └── ....
├── sstap.exe
└── addon.node

此时不出意外的话您就已经完成了打包操作.