3d-engine-sdk 中文文档教程

发布于 4年前 浏览 40 项目主页 更新于 3年前

TypeScript library starter

更漂亮的样式Greenkeeper 徽章特拉维斯工作服开发依赖项捐赠

一个使创建 TypeScript 库变得极其容易的入门项目。

Usage

git clone https://github.com/alexjoverm/typescript-library-starter.git YOURFOLDERNAME
cd YOURFOLDERNAME

# Run npm install and write your library name when asked. That's all!
npm install

开始编码! package.json 和入口文件已经设置好为你准备,所以不用担心链接到你的主文件、打字等。只需让这些文件具有相同的名称即可。

Features

Importing library

您可以导入生成的包以使用此启动器生成的整个库:

import myLib from 'mylib'

此外,如果您有模块化库,则可以从 dist/lib 导入转译的模块:

import something from 'mylib/dist/lib/something'

NPM scripts

  • npm t: Run test suite
  • npm start: Run npm run build in watch mode
  • npm run test:watch: Run test suite in interactive watch mode
  • npm run test:prod: Run linting and generate coverage
  • npm run build: Generate bundles and typings, create docs
  • npm run lint: Lints code
  • npm run commit: Commit using conventional commit style (husky will tell you to use it if you haven't :wink:)

Excluding peerDependencies

在库开发中,人们可能想要设置一些对等依赖项,从而从最终包中删除它们。 您可以在 Rollup 文档 中查看如何执行此操作。

好消息:这里的设置是为您准备的,您必须只在 rollup.config.jsexternal 属性中包含依赖项名称。 例如,如果你想排除lodash,就在那里写external: ['lodash']

Automatic releases

先决条件:您需要创建/登录帐户并将您的项目添加到:

Windows 的先决条件:语义发布使用 node-gyp 所以你需要 安装 Microsoft 的 windows-build-tools 使用此命令:

npm install --global --production windows-build-tools

Setup steps

按照控制台说明安装语义发布并运行它(对“你想要一个带有语义发布设置的 .travis.yml 文件吗?”回答否)。

注意:确保您已经在 package.json 文件中设置了 repository.url

npm install -g semantic-release-cli
semantic-release-cli setup
# IMPORTANT!! Answer NO to "Do you want a `.travis.yml` file with semantic-release setup?" question. It is already prepared for you :P

从现在开始,您需要使用 npm run commit,这是创建常规提交的便捷方式。

得益于语义发布,自动发布成为可能,它会自动在 githubnpm,plus 会自动生成更新日志。 此设置受到 egghead.io 上的 Kent C. Dodds 课程的高度影响

Git Hooks

已经设置了一个 precommit 挂钩,用于使用 Prettier 格式化代码:nail_care:

默认情况下,有两个禁用的 git 挂钩。 它们是在您运行 npm run semantic-release-prepare 脚本时设置的。 他们确保:

自动发布 结合使用更有意义

FAQ

Array.prototype.from, Promise, Map… is undefined?

这与 code>let, async/await…),但不在功能特性上(Array.prototype.find, Set, <代码>承诺…), . 为此,您需要 Polyfill,例如 core-jsbabel-polyfill(扩展 core-js)。

对于库,core-js 非常好用,因为您可以只导入您需要的 polyfill:

import "core-js/fn/array/find"
import "core-js/fn/string/includes"
import "core-js/fn/promise"
...

What is npm install doing on first run?

它运行脚本 tools/init 为您设置一切。 简而言之,它:

  • Configures RollupJS for the build, which creates the bundles
  • Configures package.json (typings file, main file, etc)
  • Renames main src and test files

What if I don't want git-hooks, automatic releases or semantic-release?

然后你可能想要:

  • Remove commitmsg, postinstall scripts from package.json. That will not use those git hooks to make sure you make a conventional commit
  • Remove npm run semantic-release from .travis.yml

What if I don't want to use coveralls or report my coverage?

.travis.yml 中删除 npm run report-coverage

Resources

Projects using typescript-library-starter

下面是一些使用 typescript-library-starter 的项目

Credits

@alexjoverm 和所有这些出色的贡献者(emoji key):


Ciro

???? ????

Marius Schulz

????

Alexander Odell

????

Ryan Ham

????

Chi

???? ???? ????

Matt Mazzola

???? ????

Sergii Lischuk

????

Steve Lee

????

Flavio Corpa

????

Dom

????

Alex Coles

????

David Khourshid

????

Aarón García Hervás

????

Jonathan Hart

????

Sanjiv Lobo

????

Stefan Aleksovski

????

dev.peerapong

????

Aaron Groome

????

Aaron Reisman

????

kid-sk

????

Andrea Gottardi

????

Yogendra Sharma

????

Rayan Salhab

????

这个项目遵循all-contributors a> 规范。 欢迎任何形式的贡献!

TypeScript library starter

styled with prettierGreenkeeper badgeTravisCoverallsDev DependenciesDonate

A starter project that makes creating a TypeScript library extremely easy.

Usage

git clone https://github.com/alexjoverm/typescript-library-starter.git YOURFOLDERNAME
cd YOURFOLDERNAME

# Run npm install and write your library name when asked. That's all!
npm install

Start coding! package.json and entry files are already set up for you, so don't worry about linking to your main file, typings, etc. Just keep those files with the same name.

Features

Importing library

You can import the generated bundle to use the whole library generated by this starter:

import myLib from 'mylib'

Additionally, you can import the transpiled modules from dist/lib in case you have a modular library:

import something from 'mylib/dist/lib/something'

NPM scripts

  • npm t: Run test suite
  • npm start: Run npm run build in watch mode
  • npm run test:watch: Run test suite in interactive watch mode
  • npm run test:prod: Run linting and generate coverage
  • npm run build: Generate bundles and typings, create docs
  • npm run lint: Lints code
  • npm run commit: Commit using conventional commit style (husky will tell you to use it if you haven't :wink:)

Excluding peerDependencies

On library development, one might want to set some peer dependencies, and thus remove those from the final bundle. You can see in Rollup docs how to do that.

Good news: the setup is here for you, you must only include the dependency name in external property within rollup.config.js. For example, if you want to exclude lodash, just write there external: ['lodash'].

Automatic releases

Prerequisites: you need to create/login accounts and add your project to:

Prerequisite for Windows: Semantic-release uses node-gyp so you will need to install Microsoft's windows-build-tools using this command:

npm install --global --production windows-build-tools

Setup steps

Follow the console instructions to install semantic release and run it (answer NO to "Do you want a .travis.yml file with semantic-release setup?").

Note: make sure you've setup repository.url in your package.json file

npm install -g semantic-release-cli
semantic-release-cli setup
# IMPORTANT!! Answer NO to "Do you want a `.travis.yml` file with semantic-release setup?" question. It is already prepared for you :P

From now on, you'll need to use npm run commit, which is a convenient way to create conventional commits.

Automatic releases are possible thanks to semantic release, which publishes your code automatically on github and npm, plus generates automatically a changelog. This setup is highly influenced by Kent C. Dodds course on egghead.io

Git Hooks

There is already set a precommit hook for formatting your code with Prettier :nail_care:

By default, there are two disabled git hooks. They're set up when you run the npm run semantic-release-prepare script. They make sure:

This makes more sense in combination with automatic releases

FAQ

Array.prototype.from, Promise, Map… is undefined?

TypeScript or Babel only provides down-emits on syntactical features (class, let, async/await…), but not on functional features (Array.prototype.find, Set, Promise…), . For that, you need Polyfills, such as core-js or babel-polyfill (which extends core-js).

For a library, core-js plays very nicely, since you can import just the polyfills you need:

import "core-js/fn/array/find"
import "core-js/fn/string/includes"
import "core-js/fn/promise"
...

What is npm install doing on first run?

It runs the script tools/init which sets up everything for you. In short, it:

  • Configures RollupJS for the build, which creates the bundles
  • Configures package.json (typings file, main file, etc)
  • Renames main src and test files

What if I don't want git-hooks, automatic releases or semantic-release?

Then you may want to:

  • Remove commitmsg, postinstall scripts from package.json. That will not use those git hooks to make sure you make a conventional commit
  • Remove npm run semantic-release from .travis.yml

What if I don't want to use coveralls or report my coverage?

Remove npm run report-coverage from .travis.yml

Resources

Projects using typescript-library-starter

Here are some projects that use typescript-library-starter:

Credits

Made with :heart: by @alexjoverm and all these wonderful contributors (emoji key):


Ciro

???? ????

Marius Schulz

????

Alexander Odell

????

Ryan Ham

????

Chi

???? ???? ????

Matt Mazzola

???? ????

Sergii Lischuk

????

Steve Lee

????

Flavio Corpa

????

Dom

????

Alex Coles

????

David Khourshid

????

Aarón García Hervás

????

Jonathan Hart

????

Sanjiv Lobo

????

Stefan Aleksovski

????

dev.peerapong

????

Aaron Groome

????

Aaron Reisman

????

kid-sk

????

Andrea Gottardi

????

Yogendra Sharma

????

Rayan Salhab

????

This project follows the all-contributors specification. Contributions of any kind are welcome!

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文