Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

generator-ts-np

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

generator-ts-np

Yeoman Generator For Building Node Packages With Typescript

  • 2.0.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4
increased by100%
Maintainers
1
Weekly downloads
 
Created
Source

generator-ts-np

Yeoman Generator For Building Node Packages :package: With Typescript.

npm Build Status npm

TS-NP generator

What

This package helps you to scaffold a directory skeleton required to start writing an npm package in Typescript, which is fully configured and ready to contain your module logic. And finally, ready to publish.

Here you write your logic in Typescript and publish the compiled version of it - easily.

Why

  • Inspired from Typescript's own guide for node.
  • Lint rules inspired from Google APIs Node.js Client Repo which means higher code quality.
  • (Optional) Travis CI integration and Continuous Deployment to NPM when you push a tag.
  • Compiles down your code to es6. (You can change this)
  • No global dependencies.
  • No own dependencies other than dev-dependencies.
  • Pre-publish hook to lint and build - so that you never miss that stuff.
  • Vscode integration.
  • Integrated, fully configured Jest testing environment.
  • Write tests in typescript itself.
  • Scaffolds readme with all essential badges and stuffs.
  • Familiar directory structure.
  • Yarn/npm. Your choice.

You don't have to write any type definitions here. It will be packaged within your package automatically.

Prerequisites

  • Yeoman should be installed globally.
  • [Recommended] Node version 8 or later.

Install

npm install -g generator-ts-np

Usage

yo ts-np

Have a peek (Linux/Windows/Mac)

Handy commands

To know really what happens under the hood, refer scripts section in package.json at your package root.

ScriptWhat is it
npm test or npm run testFeatured Command :star:. This is a right combination of all other commands. (builds and runs your tests in tests/ directory)
npm run buildcompiles content of src/ into dist/ folder with some additional tasks like copying non-ts files cleaning dir, linting, prettifying etc.
npm run lintlints and styles your code with prettier and tslint and fixes fixable issues.
npm run lint-noFixinvokes npm lint without fix option => means if any issues found, it just notifies with out fixing it.

Travis CI/CD

ci/cd

CI/CD (Continuous Integration/ Continuous Deployment) helps you to automate the npm publish task.

This is disabled by default. Following are the things you would normally do while publishing your module(with out CI/CD).

  • increment package version in your package.json
  • run tests
  • test your package against few stable versions
  • build
  • create a git tag for that version
  • push tags
  • npm publish

With CI/CD enabled, all you have to do is:

  • increment package version in your package.json
  • create git tag (git tag v<version>)
  • push tags (git push --tags)

:warning: However, for the first time you have to manually publish it using npm publish. Rest of the updates can be handled via travis.

Travis will do all other things for you, including publishing your package to npm.

How To Enable Travis CI/CD

Open .travis.ym file in your scaffolded directory structure and follow instructions over there.

How To Publish Your Package

After hand checking everything is correct,

  • increment package version in your package.json
  • $ git tag vX.X.X (example: git tag v1.5.3)
  • $ git push --tags
  • Head to travis page and see it is being deployed

Directory structure

TL;DR

Here is what you get:

.
|   .editorconfig
|   .gitignore
|   .prettierignore
|   .prettierrc
|   .travis.yml
|   .yo-rc.json
|   ci-jest.config.json
|   gulpfile.js
|   package.json
|   README.md
|   tree.txt
|   tsconfig.json
|   tslint.json
|
+---.roughs
|       README.md
|
+---.vscode
|       launch.json
|
+---media
|       .gitkeep
|
+---src
|       index.ts
|
+---tests
|       add.spec.ts
|
\---typings
        typings.d.ts
  • Additionally when you npm run build or npm test, a dist folder will also be created with all your compiled code. dist/src is the directory which is going to be published to Npm.
  • media/: All your gallery.
  • src/: All your source code.
  • typings/: All your custom type definitions
  • tests/: All your tests. Jest Test Runner looks at this directory.
Special Notes
  • If you've any credentials/secrets, make a directory credentials/ or private/ at the root of your package, which will be ignored by both git and npm.
  • When you npm publish, mainly the content of dist/src/ will be published. To know what folders/files will be ignored, take a look at files section in package.json.
  • The media/ folder is .npmignored by default. So if you need to use some images inside your package, handle files section in package.json file accordingly. The idea here is that you should not publish any unnecessary stuffs to npm registry.

:warning: Important: Before publishing your package, hand check each file and verify everything is perfect. ts-np only helps you to get started quickly and step back it self leaving the rest to you.

Sponsor

Issues?

If you found any issues, kindly report at github issues.

Licence

MIT © Vajahath Ahmed

Keywords

FAQs

Package last updated on 25 Aug 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