New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

ws-ts

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ws-ts

a cli-tool for build typescript cli-project.

  • 0.1.4
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-92.31%
Maintainers
1
Weekly downloads
 
Created
Source

安装

先确保你已经在全局环境下安装了 typescript

npm install -g ws-ts

ws-ts

ws-ts 是一个命令行工具,用于 typescript 项目的开发(ws-ts 自身就是使用 typescript 开发,并构建自己)。 更确切地说,在 tsconfig.json 中可以配置路径映射,比如

{
  "compilerOptions": {
    "paths": {
      "@src/*": [ "src/*" ],
      "@utils": [ "src/utils" ]
    }
  }
}

则在 typescript 项目中,可以直接使用类似 import _ from '@utils' 的语法来导入工程下 src/utils 模块,十分优雅。 但是只能通过 ts-node 来执行 *.ts 才能准确应用路径映射规则,使用 tsc 编译项目得到的文件中 require 语句仍然使用 @utils,并不会自动做路径映射,因此导致执行失败。 虽然,通过使用 tsconfig-paths 模块,就可以使用 node 来执行生成的 js 了; 但是,如果项目中存在资源文件(如 config.yml),它们是不会被自动拷贝到构建目录(tsc 输出的目录)中去的,这种情况下仍然会导致无法直接使用 node 执行。

构建

ws-ts build <path> [(-o|--out) <path>] [-c|--clean] [(-i|--ignore-pattern) <ignore pattern>] [--log-level=(debug|info|warn|error|fatal)] [--log-option=[no-](date|pretty|colorful)]

说明

  • path: typescript 的工程根目录,必须含有 tsconfig.json
  • --out <path>: 指定输出目录,默认值为 tsconfig.json 中的 compilerOptions.outDir 属性值;(可选)
  • --clean: 删除掉特定规则下的目录/文件,规则定义在 .wsts.partial.ymlclean-ignore-patterns
  • --ignore-pattern <ignore pattern>: 指定资源文件的忽略规则(.gitignore 的语法)
  • --log-*: 见 emm-logger

栗子

# .wsts.partial.yml
resource-ignore-patterns:
  - dist/
  - out/
  - tsconfig.json
  - package.json
  - .npmignore
  - README.md

clean-ignore-patterns:
  - test/

clean-ignore-patterns 指定需要清除的路径的匹配规则,当且仅当指定了 --clean(或 -c)参数时才生效。

ws-ts 使用 git 风格的子命令语法,git build 命令用于构建 typescript 项目,根据 tsconfig.json 中的路径映射规则来矫正生成的 js 中的require路径; 同时,git build 将会把工程目录中的所有的资源文件复制到构建目录中,保证其与原项目的结构一致; 为了定制需要复制的子源文件的规则,可以通过 --ignore-pattern <pattern>(或 -i <pattern>)来指定忽略规则,它使用 .gitignore 中的语法, 如果你需要指定多个规则,需要再每个规则前加 --ignore-pattern(或 -i)参数; 此外,你还可以在 typescript 项目的根目录下创建一个 .wsts.partial.yml 文件,如:

resource-ignore-patterns:
  - dist/
  - out/
  - tsconfig.json
  - package.json
  - .npmignore

resource-ignore-patterns 下的所有规则和命令行选项 --ignore-pattern 指定的是等价的。ws-ts 预置了一些匹配规则:

resource-ignore-patterns:
  - .git/
  - .idea/
  - .gitignore
  - .wsts.partial.yml
  - node_modules/
  - test/
  - '*.ts'

Keywords

FAQs

Package last updated on 15 Jan 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc