npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node2bat

v0.0.4-rc2

Published

node2bat

Downloads

9

Readme

node2bat

简介

node2bat 是一个可以将 NodeJS 脚本编译为 Windows 批处理脚本的工具。编译后的批处理不再依赖 NodeJS,双击可直接运行。你可以使用 NodeJS 的 API 来编写 Windows 批处理脚本发布给其他人使用,而不需要安装 NodeJS 的环境。借助 js 强大的语法支持,你的批处理将异常强大。

原理

windows 中自带了 javascript 引擎支持 jscript,所以 node2bat 便是使用 jscript 封装了一层 nodejs 的 api,然后巧妙地将 js 包含在 bat 文件中。

安装

先安装 NodeJS,然后执行:

npm install node2bat -g

使用

node2bat <file>

<file> 为 node 脚本,只支持 utf-8 编码

运行示例

源码 demo 目录是一个演示例子,其中 includeHTML.js 是基于 NodeJS 编写的自动化脚本,它的用途是给页面制作人员批量更新局部模板的。

这个脚本里面用到了 NodeJS 的文件与路径处理,我们可以编译 includeHTML.js 为 bat 文件,这样用户拿到我们的 bat 文件就可以直接双击运行了,无需安装 NodeJS 与学习命令行。

切换到源码目录,运行:

node2bat demo/includeHTML/includeHTML.js

运行完毕后会立刻生成独立的 includeHTML.bat,你也可以双击打开它试用一下。

JS API

node2bat 支持 NodeJS API 的核心 API,并且支持大多数 ECMA5 的 API,这些足可以满足绝大多数任务。

全局变量

内置模块

拖拽支持

如果拖拽文件到 bat 图标上运行,使用process.argv.slice(2) 可以获取这些文件的列表。

测试用例

node2bat test/test.js
start test/test.bat

更新日志

v0.0.3

  • 修复fs.writeFileSync()写入utf-8文件会插入 bom 的问题
  • 修复this指向为global对象的问题
  • require()方法支持载入 json 文件
  • fs.statSync()支持sizeatimemtimectime
  • require(id)支持读取外部 json 文件
  • 完善console模块
  • 完善process.env模块,完全与 NodeJS 保持一致
  • 鉴于使用场景为批处理,所以取消异步方法的支持
  • 提供测试用例

v0.0.2

  • 修正process.argv的 BUG
  • console.log方法可以友好的显示Object数据结构

v0.0.1

  • 支持 NodeJS 文件与路径操作等基础 API

License

MIT