This commit is contained in:
peli 2020-06-22 10:57:12 -07:00
Родитель 6b25689026
Коммит 300c1aa02c
12 изменённых файлов: 357 добавлений и 53 удалений

13
.editorconfig Normal file
Просмотреть файл

@ -0,0 +1,13 @@
#root = true
[*]
indent_style = space
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
max_line_length = 100
indent_size = 2
[*.md]
trim_trailing_whitespace = false

27
.gitignore поставляемый
Просмотреть файл

@ -1,15 +1,12 @@
built/
.vscode/
node_modules/
jacdac-core
tmp
package-lock.json
Makefile.user
built/
dist/
.vscode/
node_modules/
tmp
lib/
lib-esm/
_bundles/
node_modules
coverage
.nyc_output
.DS_Store
*.log
.vscode
.idea
dist
compiled
.awcache
.rpt2_cache
docs

20
.travis.yml Normal file
Просмотреть файл

@ -0,0 +1,20 @@
language: node_js
cache:
directories:
- ~/.npm
notifications:
email: false
node_js:
- '10'
- '11'
- '8'
- '6'
script:
- npm run test:prod && npm run build
after_success:
- npm run travis-deploy-once "npm run report-coverage"
- if [ "$TRAVIS_BRANCH" = "master" -a "$TRAVIS_PULL_REQUEST" = "false" ]; then npm run travis-deploy-once "npm run deploy-docs"; fi
- if [ "$TRAVIS_BRANCH" = "master" -a "$TRAVIS_PULL_REQUEST" = "false" ]; then npm run travis-deploy-once "npm run semantic-release"; fi
branches:
except:
- /^v\d+\.\d+\.\d+$/

Просмотреть файл

@ -1,3 +1,39 @@
# JACDAC TypeScript
### Features
- Zero-setup. After running `npm install` things will setup for you :wink:
- **[RollupJS](https://rollupjs.org/)** for multiple optimized bundles following the [standard convention](http://2ality.com/2017/04/setting-up-multi-platform-packages.html) and [Tree-shaking](https://alexjoverm.github.io/2017/03/06/Tree-shaking-with-Webpack-2-TypeScript-and-Babel/)
- Tests, coverage and interactive watch mode using **[Jest](http://facebook.github.io/jest/)**
- **[Prettier](https://github.com/prettier/prettier)** and **[TSLint](https://palantir.github.io/tslint/)** for code formatting and consistency
- **Docs automatic generation and deployment** to `gh-pages`, using **[TypeDoc](http://typedoc.org/)**
- Automatic types `(*.d.ts)` file generation
- **[Travis](https://travis-ci.org)** integration and **[Coveralls](https://coveralls.io/)** report
- (Optional) **Automatic releases and changelog**, using [Semantic release](https://github.com/semantic-release/semantic-release), [Commitizen](https://github.com/commitizen/cz-cli), [Conventional changelog](https://github.com/conventional-changelog/conventional-changelog) and [Husky](https://github.com/typicode/husky) (for the git hooks)
### Importing library
You can import the generated bundle to use the whole library generated by this starter:
```javascript
import myLib from 'mylib'
```
Additionally, you can import the transpiled modules from `dist/lib` in case you have a modular library:
```javascript
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](http://facebook.github.io/jest/docs/cli.html#watch)
- `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](https://github.com/typicode/husky) will tell you to use it if you haven't :wink:)
# Contributing

Просмотреть файл

@ -1,30 +1,120 @@
{
"name": "jacdac-ts",
"version": "0.0.0",
"description": "TypeScript/JavaScript library for JACDAC",
"types": "index.d.ts",
"scripts": {
"clean": "rm -rf dist lib",
"build": "tsc & webpack"
},
"repository": {
"type": "git",
"url": "git+https://github.com/microsoft/jacdac-ts.git"
},
"keywords": [
"JACDAC"
"description": "",
"keywords": [],
"main": "dist/jacdac-ts.umd.js",
"module": "dist/jacdac-ts.es5.js",
"typings": "dist/types/jacdac-ts.d.ts",
"files": [
"dist"
],
"author": "Microsoft Corporation",
"license": "MIT",
"bugs": {
"url": "https://github.com/microsoft/jacdac-ts/issues"
"repository": {
"type": "git",
"url": ""
},
"license": "MIT",
"engines": {
"node": ">=6.0.0"
},
"scripts": {
"lint": "tslint --project tsconfig.json -t codeFrame 'src/**/*.ts' 'test/**/*.ts'",
"prebuild": "rimraf dist",
"build": "tsc --module commonjs && rollup -c rollup.config.ts && typedoc --out docs --target es6 --theme minimal --mode file src",
"start": "rollup -c rollup.config.ts -w",
"test": "jest --coverage",
"test:watch": "jest --coverage --watch",
"test:prod": "npm run lint && npm run test -- --no-cache",
"deploy-docs": "ts-node tools/gh-pages-publish",
"report-coverage": "cat ./coverage/lcov.info | coveralls",
"commit": "git-cz",
"semantic-release": "semantic-release",
"semantic-release-prepare": "ts-node tools/semantic-release-prepare",
"precommit": "lint-staged",
"travis-deploy-once": "travis-deploy-once"
},
"lint-staged": {
"{src,test}/**/*.ts": [
"prettier --write",
"git add"
]
},
"config": {
"commitizen": {
"path": "node_modules/cz-conventional-changelog"
}
},
"jest": {
"transform": {
".(ts|tsx)": "ts-jest"
},
"testEnvironment": "node",
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
"moduleFileExtensions": [
"ts",
"tsx",
"js"
],
"coveragePathIgnorePatterns": [
"/node_modules/",
"/test/"
],
"coverageThreshold": {
"global": {
"branches": 90,
"functions": 95,
"lines": 95,
"statements": 95
}
},
"collectCoverageFrom": [
"src/*.{js,ts}"
]
},
"prettier": {
"semi": false,
"singleQuote": true
},
"commitlint": {
"extends": [
"@commitlint/config-conventional"
]
},
"homepage": "https://github.com/microsoft/jacdac-ts#readme",
"devDependencies": {
"ts-loader": "^7.0.5",
"tslint": "^6.1.2",
"typescript": "^3.9.5",
"webpack": "^4.43.0",
"webpack-cli": "^3.3.12"
"@commitlint/cli": "^7.1.2",
"@commitlint/config-conventional": "^7.1.2",
"@types/jest": "^23.3.2",
"@types/node": "^10.11.0",
"colors": "^1.3.2",
"commitizen": "^3.0.0",
"coveralls": "^3.0.2",
"cross-env": "^5.2.0",
"cz-conventional-changelog": "^2.1.0",
"husky": "^1.0.1",
"jest": "^23.6.0",
"jest-config": "^23.6.0",
"lint-staged": "^8.0.0",
"lodash.camelcase": "^4.3.0",
"prettier": "^1.14.3",
"prompt": "^1.0.0",
"replace-in-file": "^3.4.2",
"rimraf": "^2.6.2",
"rollup": "^0.67.0",
"rollup-plugin-commonjs": "^9.1.8",
"rollup-plugin-json": "^3.1.0",
"rollup-plugin-node-resolve": "^3.4.0",
"rollup-plugin-sourcemaps": "^0.4.2",
"rollup-plugin-typescript2": "^0.18.0",
"semantic-release": "^15.9.16",
"shelljs": "^0.8.3",
"travis-deploy-once": "^5.0.9",
"ts-jest": "^23.10.2",
"ts-node": "^7.0.1",
"tslint": "^5.11.0",
"tslint-config-prettier": "^1.15.0",
"tslint-config-standard": "^8.0.1",
"typedoc": "^0.12.0",
"typescript": "^3.0.3"
}
}
}

38
rollup.config.ts Normal file
Просмотреть файл

@ -0,0 +1,38 @@
import resolve from 'rollup-plugin-node-resolve'
import commonjs from 'rollup-plugin-commonjs'
import sourceMaps from 'rollup-plugin-sourcemaps'
import camelCase from 'lodash.camelcase'
import typescript from 'rollup-plugin-typescript2'
import json from 'rollup-plugin-json'
const pkg = require('./package.json')
const libraryName = 'jacdac-ts'
export default {
input: `src/${libraryName}.ts`,
output: [
{ file: pkg.main, name: camelCase(libraryName), format: 'umd', sourcemap: true },
{ file: pkg.module, format: 'es', sourcemap: true },
],
// Indicate here external modules you don't wanna include in your bundle (i.e.: 'lodash')
external: [],
watch: {
include: 'src/**',
},
plugins: [
// Allow json resolution
json(),
// Compile TypeScript files
typescript({ useTsconfigDeclarationDir: true }),
// Allow bundling cjs modules (unlike webpack, rollup doesn't understand cjs)
commonjs(),
// Allow node_modules resolution, so you can use 'external' to control
// which external modules to include in the bundle
// https://github.com/rollup/rollup-plugin-node-resolve#usage
resolve(),
// Resolve source maps to the original source
sourceMaps(),
],
}

3
src/jacdac-ts.ts Normal file
Просмотреть файл

@ -0,0 +1,3 @@
require("./pxtutils")
require("./jd")
require("./jdpretty")

14
test/jacdac-ts.test.ts Normal file
Просмотреть файл

@ -0,0 +1,14 @@
import DummyClass from "../src/jacdac-ts"
/**
* Dummy test
*/
describe("Dummy test", () => {
it("works if true is truthy", () => {
expect(true).toBeTruthy()
})
it("DummyClass is instantiable", () => {
expect(new DummyClass()).toBeInstanceOf(DummyClass)
})
})

31
tools/gh-pages-publish.ts Normal file
Просмотреть файл

@ -0,0 +1,31 @@
const { cd, exec, echo, touch } = require("shelljs")
const { readFileSync } = require("fs")
const url = require("url")
let repoUrl
let pkg = JSON.parse(readFileSync("package.json") as any)
if (typeof pkg.repository === "object") {
if (!pkg.repository.hasOwnProperty("url")) {
throw new Error("URL does not exist in repository section")
}
repoUrl = pkg.repository.url
} else {
repoUrl = pkg.repository
}
let parsedUrl = url.parse(repoUrl)
let repository = (parsedUrl.host || "") + (parsedUrl.path || "")
let ghToken = process.env.GH_TOKEN
echo("Deploying docs!!!")
cd("docs")
touch(".nojekyll")
exec("git init")
exec("git add .")
exec('git config user.name "peli"')
exec('git config user.email "pelikhan@users.noreply.github.com"')
exec('git commit -m "docs(docs): update gh-pages"')
exec(
`git push --force --quiet "https://${ghToken}@${repository}" master:gh-pages`
)
echo("Docs deployed!!")

Просмотреть файл

@ -0,0 +1,54 @@
const path = require("path")
const { fork } = require("child_process")
const colors = require("colors")
const { readFileSync, writeFileSync } = require("fs")
const pkg = JSON.parse(
readFileSync(path.resolve(__dirname, "..", "package.json"))
)
pkg.scripts.prepush = "npm run test:prod && npm run build"
pkg.scripts.commitmsg = "commitlint -E HUSKY_GIT_PARAMS"
writeFileSync(
path.resolve(__dirname, "..", "package.json"),
JSON.stringify(pkg, null, 2)
)
// Call husky to set up the hooks
fork(path.resolve(__dirname, "..", "node_modules", "husky", "lib", "installer", 'bin'), ['install'])
console.log()
console.log(colors.green("Done!!"))
console.log()
if (pkg.repository.url.trim()) {
console.log(colors.cyan("Now run:"))
console.log(colors.cyan(" npm install -g semantic-release-cli"))
console.log(colors.cyan(" semantic-release-cli setup"))
console.log()
console.log(
colors.cyan('Important! Answer NO to "Generate travis.yml" question')
)
console.log()
console.log(
colors.gray(
'Note: Make sure "repository.url" in your package.json is correct before'
)
)
} else {
console.log(
colors.red(
'First you need to set the "repository.url" property in package.json'
)
)
console.log(colors.cyan("Then run:"))
console.log(colors.cyan(" npm install -g semantic-release-cli"))
console.log(colors.cyan(" semantic-release-cli setup"))
console.log()
console.log(
colors.cyan('Important! Answer NO to "Generate travis.yml" question')
)
}
console.log()

Просмотреть файл

@ -1,20 +1,22 @@
{
"include": [
"src/**.ts"
],
"compilerOptions": {
"module": "commonjs",
"esModuleInterop": true,
"target": "es5",
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"moduleResolution": "node",
"preserveConstEnums": true,
"removeComments": false,
"declaration": true,
"target": "es5",
"module":"es2015",
"lib": ["es2015", "es2016", "es2017", "dom"],
"strict": true,
"sourceMap": true,
"newLine": "LF",
"outDir": "lib",
}
}
"declaration": true,
"allowSyntheticDefaultImports": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"declarationDir": "dist/types",
"outDir": "dist/lib",
"typeRoots": [
"node_modules/@types"
]
},
"include": [
"src"
]
}

6
tslint.json Normal file
Просмотреть файл

@ -0,0 +1,6 @@
{
"extends": [
"tslint-config-standard",
"tslint-config-prettier"
]
}