Forked and edited from: https://github.com/bitjson/typescript-starter
is a simple example library written in TypeScript
scripts in package.json for common tasks
example modules using TypeScript library in various environments (node, typescript, browser)
can be reused to create TypeScript libraries
Prerequisites:
git clone https://github.com/solargis/typescript-starter.git
cd typescript-starter
npm install
npm run build
Install dependencies
Clone project
Build library
sudo npm link
Link local module into global modules (optional)
cd examples/node-commonjs
npm install
npm start
Explore examples
Optionally link local module of @solargis/typescript-starter
npm link @solargis/typescript-starter
Apply previous steps for each example:
node-commonjs -
classic ES5 node module
node-typescript -
node module written in TypeScript
browser-rollup -
simple webapp bundled with Rollup
browser-ng -
example app generated with Angular CLI
browser-webpack -
sample webapp bundled with Webpack
Install TypeScript compiler globally
sudo npm install -g typescriptCompile single file
tsc myfile.tsCompile in watch mode
tsc -w myfile.tsCompile TypeScript project
tsc -p tsconfig.json
The tsconfig.json file specifies the root files and the compiler options required to compile the project.
If tsc is run without arguments, compiler searches for tsconfig.json in current directory, and continues with parent directories up.
Example tsconfig.json with "files" property:
{
"compilerOptions": {
"module": "commonjs",
"noImplicitAny": true,
"removeComments": true,
"preserveConstEnums": true,
"sourceMap": true
},
"files": [
"core.ts",
"sys.ts",
"types.ts",
"scanner.ts",
"parser.ts",
"utilities.ts"
]
}
Example with "include" and "exclude" properties:
{
"compilerOptions": {
"module": "system",
"noImplicitAny": true,
"removeComments": true,
"preserveConstEnums": true,
"outFile": "build/tsc.js",
"sourceMap": true
},
"include": [
"src/**/*"
],
"exclude": [
"node_modules",
"**/*.spec.ts"
]
}
target
module
moduleResolution
outFile
outDir
lib
importHelpers
typeRoots
node_modules/@types as default
types
sourceMap
inlineSourceMap
declaration
experimentalDecorators
baseUrl
rootDir
strict
pretty
Install globally (typescript is peer dependency)
sudo npm install -g tslint typescriptInit project - generate basic configuration file
tslint --initUsage
tslint -c tslint.json 'src/**/*.ts'Global installation
sudo npm install -g typedocLocal installation
npm install --save-dev typedocUsage
typedoc src/index.ts --mode file --out build/docsDocumentation generator for TypeScript projects
Publish generated documentation to gh-pages Git branch to github, available online
Install locally
npm install gh-pages --save-dev
Usage (push build/docs dir to gh-pages branch):
# package.json
{
"scripts": {
"docs:html": "typedoc src/index.ts --mode file --out build/docs",
"docs:publish": "npm run docs:html && gh-pages -d build/docs",
}
}
npm run docs:publish