diff --git a/README.md b/README.md index 1a80cf6..f6be6d0 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ silly. These are `npm --global` dependencies: -* [Lerna 2.0.0](https://lernajs.io/) +- [Lerna 2.0.0](https://lernajs.io/) # Installation diff --git a/bin/pre-commit.sh b/bin/pre-commit.sh new file mode 100644 index 0000000..79f46b5 --- /dev/null +++ b/bin/pre-commit.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +nodejs node_modules/lerna/bin/lerna.js run pre-commit\ +&& npm run check_code_format \ No newline at end of file diff --git a/bin/runTests.js b/bin/runTests.js index 8c93aad..06a9a7b 100755 --- a/bin/runTests.js +++ b/bin/runTests.js @@ -12,7 +12,8 @@ const CDP = require('chrome-remote-interface'); const SPEC_DIR = 'spec'; const TEST_FILENAME = '.spec_runner.html'; const HOST = '127.0.0.1'; -const PORT = 10080; +// Randomize the port so we can just run again if there's a stuck process. +const PORT = Math.floor(Math.random() * 40000) + 1025; const DEBUG = typeof process.env['DEBUG'] === 'string' @@ -150,7 +151,9 @@ async function runTestsInChrome() { Network.requestWillBeSent(result => reqMap.set(result.requestId, result.request.url)); Network.loadingFailed(result => - consolePrint(`\x1b[31mNetwork Error: ${result.errorText} for ${reqMap.get(result.requestId)}`) + consolePrint( + `\x1b[31mNetwork Error: ${result.errorText} for ${reqMap.get(result.requestId)}` + ) ); Runtime.exceptionThrown(result => diff --git a/package.json b/package.json index 50f61bd..50e49c7 100644 --- a/package.json +++ b/package.json @@ -5,9 +5,13 @@ "husky": "1.0.0-rc.13", "lerna": "2.0.0-beta.32" }, + "scripts": { + "check_code_format": "nodejs node_modules/prettier/bin-prettier.js --config ./prettier.config.js --list-different \"{.,{packages,bin}/**/!(dist)}/*.{js,json,md}\"", + "format_code": "nodejs node_modules/prettier/bin-prettier.js --config ./prettier.config.js --write \"{.,{packages,bin}/**/!(dist)}/*.{js,json,md}\"" + }, "husky": { "hooks": { - "pre-commit": "lerna run pre-commit" + "pre-commit": "sh ./bin/pre-commit.sh" } } } diff --git a/packages/frptools/README.md b/packages/frptools/README.md index 97b0e41..94d549f 100644 --- a/packages/frptools/README.md +++ b/packages/frptools/README.md @@ -284,7 +284,7 @@ container. FRPTools is the result of years of learning from the following projects: -* [KnockoutJS](http://knockoutjs.com/) -* [Overture](https://github.com/fastmail/overture) -* [Redux](https://redux.js.org/) -* [Mithril](https://mithril.js.org/) +- [KnockoutJS](http://knockoutjs.com/) +- [Overture](https://github.com/fastmail/overture) +- [Redux](https://redux.js.org/) +- [Mithril](https://mithril.js.org/) diff --git a/packages/frptools/package.json b/packages/frptools/package.json index 4c1b8e4..6e7dac0 100644 --- a/packages/frptools/package.json +++ b/packages/frptools/package.json @@ -3,12 +3,16 @@ "version": "3.2.1", "description": "Observable Property and Computed data streams", "main": "src/index.js", - "files": ["src"], + "files": [ + "src" + ], "scripts": { "test": "node ../../bin/runTests.js ./", "pre-commit": "npm run test" }, - "keywords": ["reactive"], + "keywords": [ + "reactive" + ], "author": "Timothy Farrell (https://github.com/explorigin)", "license": "Apache-2.0" } diff --git a/packages/gallery/README.md b/packages/gallery/README.md index 0ab623b..d6ba38b 100644 --- a/packages/gallery/README.md +++ b/packages/gallery/README.md @@ -5,8 +5,8 @@ myself and to share with friends and family. Along the way it became a learning ## Features -* Upload and view images -* Save files to Backblaze B2 storage. +- Upload and view images +- Save files to Backblaze B2 storage. ## Development Philosophy @@ -19,9 +19,9 @@ photo gallery for anyone who wishes to escape the social media silos. However, i This would not be possible without the giants who have laid the foundation: -* [Webpack](http://webpack.js.org/) -* [DOMVM](http://leeoniya.github.io/domvm/) -* [PouchDB](https://pouchdb.com/) +- [Webpack](http://webpack.js.org/) +- [DOMVM](http://leeoniya.github.io/domvm/) +- [PouchDB](https://pouchdb.com/) There are many more dependencies. You can find them in the [package.json](./package.json) file. @@ -36,12 +36,12 @@ localhost certificate exception in order to operate properly. In the future, I plan to add: -* sharable links -* local file storage -* CSRF for interacting with server component -* albums -* client-side encryption -* video support -* Sandstorm support -* CORS-based storage: - s3 - remotestorage - Google Cloud? - Dropbox? -* tags +- sharable links +- local file storage +- CSRF for interacting with server component +- albums +- client-side encryption +- video support +- Sandstorm support +- CORS-based storage: - s3 - remotestorage - Google Cloud? - Dropbox? +- tags diff --git a/packages/gallery/package.json b/packages/gallery/package.json index 2e9b628..84ee163 100644 --- a/packages/gallery/package.json +++ b/packages/gallery/package.json @@ -2,7 +2,9 @@ "name": "Gallery", "version": "0.0.1", "description": "Personal photo gallery", - "keywords": ["javascript"], + "keywords": [ + "javascript" + ], "author": "Timothy Farrell (https://github.com/explorigin)", "license": "Apache-2.0", "scripts": { diff --git a/packages/gallery/src/interface/focus.js b/packages/gallery/src/interface/focus.js index 4532454..de12497 100644 --- a/packages/gallery/src/interface/focus.js +++ b/packages/gallery/src/interface/focus.js @@ -50,11 +50,11 @@ export function FocusView(vm, params) { if (windowRatio > imageRatio) { return { height: vw / windowRatio, - width: vw / windowRatio * imageRatio + width: (vw / windowRatio) * imageRatio }; } return { - height: vh * windowRatio / imageRatio, + height: (vh * windowRatio) / imageRatio, width: vh * windowRatio }; }, diff --git a/packages/gallery/src/interface/sectionView.js b/packages/gallery/src/interface/sectionView.js index 91b3ff6..aa44784 100644 --- a/packages/gallery/src/interface/sectionView.js +++ b/packages/gallery/src/interface/sectionView.js @@ -32,7 +32,7 @@ export function SectionView(vm, params, key) { const availableWidth = vw - CONTENT_MARGIN_WIDTH; const aspectRatios = pArr.map(aspectRatio); const totalImageRatio = sum(aspectRatios); - const rowCount = Math.ceil(totalImageRatio * OPTIMAL_IMAGE_HEIGHT / availableWidth); + const rowCount = Math.ceil((totalImageRatio * OPTIMAL_IMAGE_HEIGHT) / availableWidth); const rowRatios = partition(aspectRatios, rowCount); let index = 0; @@ -41,7 +41,7 @@ export function SectionView(vm, params, key) { const rowTotal = sum(row); const imageRatio = row[0]; const portion = imageRatio / rowTotal; - let rowHeight = availableWidth * portion / aspectRatio(pArr[index]); + let rowHeight = (availableWidth * portion) / aspectRatio(pArr[index]); if (rowHeight > OPTIMAL_IMAGE_HEIGHT * ROW_HEIGHT_CUTOFF_MODIFIER) { rowHeight = OPTIMAL_IMAGE_HEIGHT * ROW_HEIGHT_CUTOFF_MODIFIER; } diff --git a/packages/portal/package.json b/packages/portal/package.json index 129c8a7..353c479 100644 --- a/packages/portal/package.json +++ b/packages/portal/package.json @@ -3,12 +3,17 @@ "version": "0.9.0", "description": "Expose an API to a web worker and its parent", "main": "src/index.js", - "files": ["src"], + "files": [ + "src" + ], "scripts": { "test": "node ../../bin/runTests.js ./", "pre-commit": "npm run test" }, - "keywords": ["worker", "webworker"], + "keywords": [ + "worker", + "webworker" + ], "author": "Timothy Farrell (https://github.com/explorigin)", "license": "Apache-2.0" } diff --git a/packages/pouchtype/package.json b/packages/pouchtype/package.json index 60b1edf..2439f7e 100644 --- a/packages/pouchtype/package.json +++ b/packages/pouchtype/package.json @@ -3,7 +3,11 @@ "version": "1.0.1", "description": "Document Management Layer for PouchDB", "main": "src/index.js", - "files": ["dist", "lib", "src"], + "files": [ + "dist", + "lib", + "src" + ], "scripts": { "test": "node ../../bin/runTests.js ./", "pre-commit": "npm run test" diff --git a/packages/projector/package.json b/packages/projector/package.json index 6f66d78..fa870c6 100644 --- a/packages/projector/package.json +++ b/packages/projector/package.json @@ -3,9 +3,13 @@ "version": "2.1.0", "description": "A DOM-abstraction communicator", "main": "src/index.js", - "files": ["src"], + "files": [ + "src" + ], "scripts": {}, - "keywords": ["router"], + "keywords": [ + "router" + ], "author": "Timothy Farrell (https://github.com/explorigin)", "license": "Apache-2.0", "dependencies": { diff --git a/packages/router/README.md b/packages/router/README.md index cace371..7fba2ae 100644 --- a/packages/router/README.md +++ b/packages/router/README.md @@ -16,43 +16,43 @@ const router = Router(routeSpecArray, rootURL='#'): An array of objects with the following properties: -* `name` _string_ - an optional string that can be referred to in the `href` and `goto` instance +- `name` _string_ - an optional string that can be referred to in the `href` and `goto` instance methods. Duplicate names are not allowed. -* `path` _string_ - the path template for this route. Path templates are matched in the order of the +- `path` _string_ - the path template for this route. Path templates are matched in the order of the array. Example: `"/"` - for the root path `"/articles"` - another static path `"/article/:id"` - a path with a variable `"/:unknownRoute"` - the last route could catch erroneous routes. Unmatched urls will automatically route here. -* `vars` _object_ - an optional object mapping variable names in the path template to a regular +- `vars` _object_ - an optional object mapping variable names in the path template to a regular expression for validation -* `enter` _function_ - a function for when this route is entered. The `enter` function receives two +- `enter` _function_ - a function for when this route is entered. The `enter` function receives two parameters: - * _route instance object_ - this is a object that contains properties: + - _route instance object_ - this is a object that contains properties: - * `name` _string_ - the route name - * `vars` _object_ - an object holding any variables parsed from the path - * `path` _string_ - the path as received + - `name` _string_ - the route name + - `vars` _object_ - an object holding any variables parsed from the path + - `path` _string_ - the path as received - * _router instance object_ - (see below) + - _router instance object_ - (see below) The `enter` function may return a callback that will be called instead of the `enter` function for further navigate events that will be handled by this route (with different variables). This allows `enter` to establish a context for the route it handles. -* `exit` _function_ - an optional function that will be called before calling `enter` of the next +- `exit` _function_ - an optional function that will be called before calling `enter` of the next path. `exit` has the option to delay the call to `enter` by returning a promise. This is intended for handling transition animations. If the route's `enter` function returns a callback, `exit` will not be called if the same route receives navigation but with different variables. `exit` receives the parameters similarly to `enter`: - * _route instance object_ - for the route being exited - * _route instance object_ - for the route yet-to-be entered - * _router instance object_ - (see below) + - _route instance object_ - for the route being exited + - _route instance object_ - for the route yet-to-be entered + - _router instance object_ - (see below) ### rootURL (optional string) @@ -62,24 +62,24 @@ The url prefix of all paths. This should always be `#` unless you're nesting rou The returned instance provides these methods: -* `goto(url: string)` or `goto(pathName: string, vars: object)` +- `goto(url: string)` or `goto(pathName: string, vars: object)` Match to a route by relative url or pathName and a vars object. Navigate there. -* `href(pathName: string, vars: object)` +- `href(pathName: string, vars: object)` Build a relative url based on the name and supplied vars. -* `start(initialRoute: string)` +- `start(initialRoute: string)` Listen to `window.onhashchange` for route changes. The `initialRoute` will be passed to `goto()` if there is no current route in `window.location`. -* `stop()` +- `stop()` Cancel subscription to `window.onhashchange` -* `current()` +- `current()` Get the current _route instance object_ as was provided to the current routes `enter` function. diff --git a/packages/router/package.json b/packages/router/package.json index c3639c8..de63720 100644 --- a/packages/router/package.json +++ b/packages/router/package.json @@ -3,12 +3,16 @@ "version": "2.1.0", "description": "A slim and unopinionated router", "main": "src/index.js", - "files": ["src"], + "files": [ + "src" + ], "scripts": { "test": "node ../../bin/runTests.js ./", "pre-commit": "npm run test" }, - "keywords": ["router"], + "keywords": [ + "router" + ], "author": "Timothy Farrell (https://github.com/explorigin)", "license": "Apache-2.0", "dependencies": { diff --git a/packages/trimkit/README.md b/packages/trimkit/README.md index bc94500..7451827 100644 --- a/packages/trimkit/README.md +++ b/packages/trimkit/README.md @@ -37,16 +37,16 @@ pre-compression gains can result in post-compression losses. YMMV. # Abstractions -* `undefined` -* `requestAnimationFrame` -* `Array.isArray` -* `Array.from` -* `Object.keys` -* `document` -* `typeof obj === 'function'` -* `typeof obj === 'string'` -* `typeof obj === 'number'` -* `null` -* `obj === undefined` -* `obj === null` -* `fn.apply(context, params)` +- `undefined` +- `requestAnimationFrame` +- `Array.isArray` +- `Array.from` +- `Object.keys` +- `document` +- `typeof obj === 'function'` +- `typeof obj === 'string'` +- `typeof obj === 'number'` +- `null` +- `obj === undefined` +- `obj === null` +- `fn.apply(context, params)` diff --git a/packages/trimkit/package.json b/packages/trimkit/package.json index f1345cb..566b58d 100644 --- a/packages/trimkit/package.json +++ b/packages/trimkit/package.json @@ -3,8 +3,12 @@ "version": "1.1.0", "description": "Javascript and DOM abstractions for smaller minifiable code", "main": "src/index.js", - "files": ["src"], - "keywords": ["javascript"], + "files": [ + "src" + ], + "keywords": [ + "javascript" + ], "author": "Timothy Farrell (https://github.com/explorigin)", "license": "Apache-2.0" } diff --git a/prettier.config.js b/prettier.config.js new file mode 100644 index 0000000..384cd76 --- /dev/null +++ b/prettier.config.js @@ -0,0 +1,12 @@ +module.exports = { + printWidth: 100, + tabWidth: 1, + useTabs: true, + singleQuote: true, + trailingComma: 'none', + bracketSpacing: true, + semi: true, + requirePragma: false, + proseWrap: 'always', + arrowParens: 'avoid' +};