2.2.0 • Published 5 years ago

ts-node-builder v2.2.0

Weekly downloads
209
License
MIT
Repository
github
Last release
5 years ago

Ts-node-builder

This is an angular cli builder tool compatible and made for the use in nx.dev tool.

It helps in building and developing typescript node apps using nodemon , tsc also , helps get away from webpack since it has many problems when used with node js.

npm version

Installation

npm i ts-node-builder

or using yarn

yarn add ts-node-builder

How to use

Since this is a builder I am assuming that you already have a nrwl workspace installed you can checkout their guide on how to make a fullstack app here if you don't have one already.

In your workspace.json file inside the architect property add a new property

lets call it build or you can call it whatever you want.

Example of as the json below

{
	"architect": {
		"build": {
			"builder": "ts-node-builder:build",
			"options": {
				"mainInOutput": "dist/out-tsc/apps/api/src/app.js",
				"tsconfig": "apps/api/tsconfig.app.json",
				"runAndBuild": false
			}
		}
	}
}

As you can see above first we needed specify the builder in this case it is

ts-node-builder:build

then we need to specify the builder options.

Now we will talk in details what are the available builders and their available options

ts-node-builder:dev

Description

This builder help in the development process by using nodemon and ts-node to

compile and run typescript and watch for change to recompile and restart the node server.

Builder name

ts-node-builder:dev

Builder options

namemandatorydatatypedefaultdescription
mainInOutputyesstringN/AThis is the main file to run in the output path ex: dist/src/app.js
tsconfigyesstringN/Athis is the tsconfig file path to use
watchnostring[]N/Aarray of folders to pass to nodemon by default nodemon watch the project based directory it's recommended to specify this value but, it's optional
debugnobooleanfalsethis is a flag to run the process in debug mode
debugPortnonumber9229this is the debug port if specified it's used also it's value was 0 then it will auto assign a free port each time it runs
NODE_ENVnostringdevelopmentnode environment variable you can put it with any value you want
delayBetweenRestartsnonumber or string1.5 secondsthis is the delay in seconds which is passed to nodemon it's measured in seconds or milliseconds when specified check nodemon docs here
copynoarrayN/Athis option is used to copy commands it's an array of objects [ {"from":"./from/path", "to": "./to/path" } ] it can copy files or directories

ts-node-builder:build

Description

This builder will help you to build the project by running the tsc command and use the tsconfig

that will provide and it optionally have the ability to run the server after the compilation, usually

this builder is used in deployments to build the project.

Builder name

ts-node-builder:build

Builder options

namemandatorydatatypedefaultdescription
mainInOutputyesstringN/AThis is the main file to run in the output path ex: dist/src/app.js
tsconfigyesstringN/Atsconfig.json path to be used in the build process
runAndBuildnobooleanfalsethis is an option that will run the node server after building if false it will only build
NODE_ENVnostringproductionif you want to set the node env it's production by default since usually it's assumed that this command will be used for the build process
copynoarrayN/Athis option is used to copy commands it's an array of objects [ {"from":"./from/path", "to": "./to/path" } ] it can copy files or directories
cleannostring []N/Athis options allow cleaning before build by giving it an array of paths to delete before the build happen "clean":["folder/to/delete"]

NICE NOTE usually the users of this builder are nx.dev users so , I have also made a nx helper cli to help run for example all the microservices with just one command based on a json file check it out here

Please raise any issues if there is any problem and don't forget to put a star :star: :wink: if you like this package.

Made with :heart: to my organization and to the opensource world.

Release Notes

1.0.0

This was the first version it included the two commands dev and build . dev was using the ts-node and nodemon. build was using tsc and node commands normally.

2.0.0

Changed the dev command and made it use tsc and nodemon instead of ts-node since sometimes ts-node make problems in typescript weird problems. also added new features like delayDelayBetweenRestarts flag to prevent nodemon from restarting multiple times unnecessary and NODE_ENV too so if we wanted to develop on a different env than the development but, it's development by default.

2.1.0

new feature adding a copy option to take an array of object from and to for things like assets and those stuff. it looks like that

[
	{
		"from":"./from/path",
		"to": "./to/path"
	}
]

2.2.0

new feature thanks to gibsonjoshua55 who implemented it which is to be able to clean up or delete folders before the build and it's used like that

{
    "clean": ["folder/to/delete","other/folder/to_delete"]
}