@robotical/learning-site-tools
TypeScript icon, indicating that this package has built-in type declarations

1.0.6 • Public • Published

Step 1

echo "node_modules
/lib" >> .gitignore 

Step 2

npm install --save-dev typescript

Step 3

echo '
{
    "compilerOptions": {
        "target": "es6",
        "module": "commonjs",
        "declaration": true,
        "outDir": "./lib",
        "strict": true
    },
    "include": ["src"],
    "exclude": ["node_modules", "**/__tests__/*"]
}' >> tsconfig.json

Step 4

mkdir src

Step 5

echo "export const Greeter = (name: string) =>'Hello ' + name;" >> src/index.ts

Step 6

Add a build command in the scripts of packages.json like so: "build" : "tsc"

Step 7

Add "files": ["lib/**/*"] in the first level of packages.json

Formatting and linting

Step 1

npm install --save-dev prettier tslint tslint-config-prettier

Step 2

echo '
{
   "extends": ["tslint:recommended", "tslint-config-prettier"]
}' >> tslint.json

Step 3

echo '
{
  "printWidth": 120,
  "trailingComma": "all",
  "singleQuote": true
}
' >> .prettierrc

Step 4

Add the lint- and format scripts to package.json like so:

    "format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"",
    "lint": "tslint -p tsconfig.json",

Testing

Step 1

npm install --save-dev jest ts-jest @types/jest

Step 2

echo '
{
  "transform": {
    "^.+.(t|j)sx?$": "ts-jest"
  },
  "testRegex": "(/__tests__/(.*test)).(jsx?|tsx?)$",
  "moduleFileExtensions": ["ts", "tsx", "js", "jsx", "json", "node"]
}
' >> jestconfig.json

Step 3

add "test": "jest --config jestconfig.json" in the scripts of packages.json

Step 4

mkdir src/__tests__

Step 5

echo '
import { Greeter } from "../index";
test("My Greeter", () => {
  expect(Greeter("Carl")).toBe("Hello Carl");
});
' >> src/__tests__/Greeter.test.ts

Step 6

Replase the scripts in packages.json with these:

    "format": "prettier --write 'src/**/*.ts'",
    "lint": "tslint -p tsconfig.json",
    "build": "tsc",
    "prepare" : "npm run build",
    "prepublishOnly" : "npm test && npm run lint",
    "preversion" : "npm run lint",
    "version" : "npm run format && git add -A src",
    "postversion" : "git push && git push --tags",
    "test": "jest --config jestconfig.json"

Step 7

Add in the first level of packages.json these:

    "main": "lib/index.js",
    "types": "lib/index.d.ts",

Publishing

Info -- you can skip

prepare will run both BEFORE the package is packed and published, and on local npm install. Perfect for running building the code in package.json: "prepare" : "npm run build"

prepublishOnly will run BEFORE prepare and ONLY on npm publish. Here we will run our test and lint to make sure we don’t publish bad code: in package.json: "prepublishOnly" : "npm test && npm run lint"

preversion will run before bumping a new package version. To be extra sure that we’re not bumping a version with bad code, why not run lint here as well? 😃 in package.json: "preversion" : "npm run lint"

version will run after a new version has been bumped. If your package has a git repository, like in our case, a commit and a new version-tag will be made every time you bump a new version. This command will run BEFORE the commit is made. One idea is to run the formatter here and so no ugly code will pass into the new version: in package.json: "version" : "npm run format && git add -A src"

postversion will run after the commit has been made. A perfect place for pushing the commit as well as the tag. in package.json: "postversion" : "git push && git push --tags"

Step 1

npm run prepare && npm run prepublishOnly && npm run preversion

Step 2

Bump version

Step 3

npm run version && npm run postversion && npm publish

Publishing all commands

npm run prepare && npm run prepublishOnly && npm run preversion && npm run version && npm run postversion && npm publish -access public

Readme

Keywords

none

Package Sidebar

Install

npm i @robotical/learning-site-tools

Weekly Downloads

1

Version

1.0.6

License

ISC

Unpacked Size

12.8 kB

Total Files

12

Last publish

Collaborators

  • robdobsn
  • nikthegeek
  • robotical-sandy