Skip to content

Commit bb77031

Browse files
committed
feat (scripts): add TOC generation and test script
1 parent d292e91 commit bb77031

File tree

5 files changed

+114
-72
lines changed

5 files changed

+114
-72
lines changed

README.md

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,32 @@ Transparent reactivity without special syntax and with a **100% language observa
66

77
[React Easy State](https://github.com/solkimicreb/react-easy-state) is a React state management solution - based on this library. This library is part of the [NX framework](https://nx-framework.com).
88

9-
## Table of contents
10-
11-
- [Installation](#installation)
12-
- [Usage](#usage)
13-
- [Features](#key-features)
14-
- [Platfrom Support](#platform-support)
15-
- [API](#api)
16-
- [Examples](#examples)
17-
- [Contributing](#contributing)
9+
<details>
10+
<summary><strong>Table of Contents</strong></summary>
11+
<!-- Do not edit the Table of Contents, instead regenerate with `npm run build-toc` -->
12+
13+
<!-- toc -->
14+
15+
* [Installation](#installation)
16+
* [Usage](#usage)
17+
* [Key features](#key-features)
18+
* [Platform support](#platform-support)
19+
* [API](#api)
20+
+ [const object = observable(object)](#const-object--observableobject)
21+
+ [const boolean = isObservable(object)](#const-boolean--isobservableobject)
22+
+ [const function = observe(function)](#const-function--observefunction)
23+
+ [unobserve(function)](#unobservefunction)
24+
+ [unqueue(function)](#unqueuefunction)
25+
+ [exec(function)](#execfunction)
26+
+ [const promise = nextTick(function)](#const-promise--nexttickfunction)
27+
+ [observable.$raw](#observableraw)
28+
* [Examples](#examples)
29+
* [Alternative builds](#alternative-builds)
30+
* [Contributing](#contributing)
31+
32+
<!-- tocstop -->
33+
34+
</details>
1835

1936
## Installation
2037

@@ -332,6 +349,17 @@ setTimeout(() => user.job = 'stylist')
332349
setTimeout(() => delete user.name)
333350
```
334351

352+
## Alternative builds
353+
354+
This library detects if you use ES6 or commonJS modules and serve the right format to you. The exposed bundles are transpiled to ES5 to support common tools - like UglifyJS minifying. If you would like a finer control over the provided build, you can specify them in your imports.
355+
356+
- `@nx-js/observer-util/dist/es.es6.js` exposes an ES6 build with ES6 modules.
357+
- `@nx-js/observer-util/dist/es.es5.js` exposes an ES5 build with ES6 modules.
358+
- `@nx-js/observer-util/dist/cjs.es6.js` exposes an ES6 build with commonJS modules.
359+
- `@nx-js/observer-util/dist/cjs.es5.js` exposes an ES5 build with commonJS modules.
360+
361+
If you use a bundler, set up an alias for `@nx-js/observer-util` to point to your desired build. You can learn how to do it with webpack [here](https://webpack.js.org/configuration/resolve/#resolve-alias) and with rollup [here](https://github.com/rollup/rollup-plugin-alias#usage).
362+
335363
## Contributing
336364

337365
Contributions are always welcomed! Just send a PR for fixes and doc updates and open issues for new features beforehand. Make sure that the tests and the linter pass and that

karma.conf.js

Lines changed: 0 additions & 60 deletions
This file was deleted.

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88
"dist"
99
],
1010
"scripts": {
11-
"test": "karma start karma.conf.js",
11+
"test": "node ./scripts/test.js",
1212
"test-builds": "node ./scripts/testBuilds.js",
1313
"lint": "standard",
14-
"lint-fix": "prettier --ignore-path '.gitignore' --write '**/*.js' && standard --fix",
14+
"lint-fix": "prettier --ignore-path '.gitignore' --write '**/!(bundle).js' && standard --fix",
1515
"coveralls": "cat ./coverage/lcov.info | ./node_modules/.bin/coveralls",
16-
"build": "node ./scripts/build.js"
16+
"build": "node ./scripts/build.js",
17+
"build-toc": "node ./scripts/buildToc.js"
1718
},
1819
"author": {
1920
"name": "Miklos Bertalan",
@@ -55,6 +56,7 @@
5556
"karma-mocha": "^1.3.0",
5657
"karma-rollup-preprocessor": "^5.0.1",
5758
"karma-source-map-support": "^1.2.0",
59+
"markdown-toc": "^1.1.0",
5860
"mocha": "^3.5.0",
5961
"nyc": "11.1.0",
6062
"pre-push": "^0.1.1",

scripts/buildToc.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const fs = require('fs')
2+
const path = require('path')
3+
const toc = require('markdown-toc')
4+
5+
const readmePath = path.resolve('README.md')
6+
const oldReadme = fs.readFileSync(readmePath, 'utf8')
7+
const newReadme = toc.insert(oldReadme, { maxdepth: 3, bullets: ['*', '+'] })
8+
9+
fs.writeFileSync(readmePath, newReadme)

scripts/test.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
const path = require('path')
2+
const resolve = require('rollup-plugin-node-resolve')
3+
const commonjs = require('rollup-plugin-commonjs')
4+
const babel = require('rollup-plugin-babel')
5+
const coverage = require('rollup-plugin-coverage')
6+
const alias = require('rollup-plugin-alias')
7+
const TestServer = require('karma').Server
8+
9+
const bundleType = process.env.BUNDLE_TYPE
10+
const bundlePath = bundleType ? `dist/${bundleType}.js` : 'src/index.js'
11+
12+
const config = {
13+
frameworks: ['mocha', 'chai', 'source-map-support'],
14+
reporters: ['progress', 'coverage'],
15+
files: ['tests/**/*.test.js'],
16+
preprocessors: {
17+
'tests/**/*.test.js': ['rollup']
18+
},
19+
rollupPreprocessor: {
20+
plugins: [
21+
resolve(),
22+
commonjs({
23+
namedExports: {
24+
'node_modules/chai/index.js': ['expect']
25+
}
26+
}),
27+
alias({
28+
'@nx-js/observer-util': path.resolve(bundlePath)
29+
}),
30+
coverage({
31+
include: ['src/**/*.js']
32+
}),
33+
babel({
34+
exclude: 'node_modules/**'
35+
})
36+
],
37+
format: 'iife',
38+
name: 'observer',
39+
sourcemap: 'inline'
40+
},
41+
coverageReporter: {
42+
dir: 'coverage',
43+
reporters: [{ type: 'lcov', subdir: '.' }, { type: 'text-summary' }]
44+
},
45+
port: 9876,
46+
colors: true,
47+
autoWatch: false,
48+
concurrency: Infinity,
49+
singleRun: true,
50+
browsers: ['ChromeHeadlessNoSandbox'],
51+
customLaunchers: {
52+
ChromeHeadlessNoSandbox: {
53+
base: 'ChromeHeadless',
54+
flags: ['--no-sandbox']
55+
}
56+
}
57+
}
58+
59+
const testServer = new TestServer(config, exitCode => {
60+
console.log(`Karma has exited with ${exitCode}`)
61+
process.exit(exitCode)
62+
})
63+
testServer.start()

0 commit comments

Comments
 (0)