commit f46ce77f57c08866873b5c80acd052e0ddba8bc9 Author: Franck Royer Date: Fri Mar 5 09:34:01 2021 +1100 Initial commit Created with bitjson/typescript-starter@586cdb3029ab2c52e2f0893adafbbb017059e1c9 diff --git a/.cspell.json b/.cspell.json new file mode 100644 index 0000000000..59c785dd42 --- /dev/null +++ b/.cspell.json @@ -0,0 +1,34 @@ +{ + "version": "0.1", + "$schema": "https://raw.githubusercontent.com/streetsidesoftware/cspell/master/cspell.schema.json", + "language": "en", + "words": [ + "bitjson", + "bitauth", + "cimg", + "circleci", + "codecov", + "commitlint", + "dependabot", + "editorconfig", + "esnext", + "execa", + "exponentiate", + "globby", + "libauth", + "mkdir", + "prettierignore", + "sandboxed", + "transpiled", + "typedoc", + "untracked" + ], + "flagWords": [], + "ignorePaths": [ + "package.json", + "package-lock.json", + "yarn.lock", + "tsconfig.json", + "node_modules/**" + ] +} diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000000..63187fe16f --- /dev/null +++ b/.editorconfig @@ -0,0 +1,15 @@ +# http://editorconfig.org +root = true + +[*] +charset = utf-8 +end_of_line = lf +indent_size = 2 +indent_style = space +insert_final_newline = true +max_line_length = 80 +trim_trailing_whitespace = true + +[*.md] +max_line_length = 0 +trim_trailing_whitespace = false diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000000..e3f05aaa2d --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,34 @@ +{ + "root": true, + "parser": "@typescript-eslint/parser", + "parserOptions": { "project": "./tsconfig.json" }, + "env": { "es6": true }, + "ignorePatterns": ["node_modules", "build", "coverage"], + "plugins": ["import", "eslint-comments", "functional"], + "extends": [ + "eslint:recommended", + "plugin:eslint-comments/recommended", + "plugin:@typescript-eslint/recommended", + "plugin:import/typescript", + "plugin:functional/lite", + "prettier", + "prettier/@typescript-eslint" + ], + "globals": { "BigInt": true, "console": true, "WebAssembly": true }, + "rules": { + "@typescript-eslint/explicit-module-boundary-types": "off", + "eslint-comments/disable-enable-pair": [ + "error", + { "allowWholeFile": true } + ], + "eslint-comments/no-unused-disable": "error", + "import/order": [ + "error", + { "newlines-between": "always", "alphabetize": { "order": "asc" } } + ], + "sort-imports": [ + "error", + { "ignoreDeclarationSort": true, "ignoreCase": true } + ] + } +} diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md new file mode 100644 index 0000000000..5ac541a7c7 --- /dev/null +++ b/.github/CONTRIBUTING.md @@ -0,0 +1,3 @@ +# Example Contributing Guidelines + +This is an example of GitHub's contributing guidelines file. Check out GitHub's [CONTRIBUTING.md help center article](https://help.github.com/articles/setting-guidelines-for-repository-contributors/) for more information. diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md new file mode 100644 index 0000000000..5863654bdc --- /dev/null +++ b/.github/ISSUE_TEMPLATE.md @@ -0,0 +1,9 @@ +- **I'm submitting a ...** + [ ] bug report + [ ] feature request + [ ] question about the decisions made in the repository + [ ] question about how to use this project + +- **Summary** + +- **Other information** (e.g. detailed explanation, stack traces, related issues, suggestions how to fix, links for us to have context, eg. StackOverflow, personal fork, etc.) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000000..e04147782f --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,7 @@ +- **What kind of change does this PR introduce?** (Bug fix, feature, docs update, ...) + +- **What is the current behavior?** (You can also link to an open issue here) + +- **What is the new behavior (if this is a feature change)?** + +- **Other information**: diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000..c9c3cfdefd --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +.idea/* +.nyc_output +build +node_modules +test +src/**.js +coverage +*.log +yarn.lock diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000000..0e80a3c867 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,2 @@ +# package.json is formatted by package managers, so we ignore it here +package.json \ No newline at end of file diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000000..439ccd5b5f --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,8 @@ +{ + "recommendations": [ + "dbaeumer.vscode-eslint", + "esbenp.prettier-vscode", + "eamodio.gitlens", + "streetsidesoftware.code-spell-checker", + ] +} diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000000..171e54aae2 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,29 @@ +{ + "version": "0.2.0", + "configurations": [ + // To debug, make sure a *.spec.ts file is active in the editor, then run a configuration + { + "type": "node", + "request": "launch", + "name": "Debug Active Spec", + "runtimeExecutable": "${workspaceFolder}/node_modules/.bin/ava", + "runtimeArgs": ["debug", "--break", "--serial", "${file}"], + "port": 9229, + "outputCapture": "std", + "skipFiles": ["/**/*.js"], + "preLaunchTask": "npm: build" + // "smartStep": true + }, + { + // Use this one if you're already running `yarn watch` + "type": "node", + "request": "launch", + "name": "Debug Active Spec (no build)", + "runtimeExecutable": "${workspaceFolder}/node_modules/.bin/ava", + "runtimeArgs": ["debug", "--break", "--serial", "${file}"], + "port": 9229, + "outputCapture": "std", + "skipFiles": ["/**/*.js"] + // "smartStep": true + }] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000000..9d5230ab2e --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "cSpell.userWords": [], // only use words from .cspell.json + "cSpell.enabled": true, + "editor.formatOnSave": true, + "typescript.tsdk": "node_modules/typescript/lib", + "typescript.enablePromptUseWorkspaceTsdk": true +} diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000000..8718e1bd65 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 Franck Royer + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000000..5e932d054d --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# waku-js-chat + +A chat application running on node and waku diff --git a/package.json b/package.json new file mode 100644 index 0000000000..ac58d18dd6 --- /dev/null +++ b/package.json @@ -0,0 +1,106 @@ +{ + "name": "waku-js-chat", + "version": "1.0.0", + "description": "A chat application running on node and waku", + "main": "build/main/index.js", + "typings": "build/main/index.d.ts", + "module": "build/module/index.js", + "repository": "https://github.com/D4nte/waku-js-chat", + "license": "MIT", + "keywords": [], + "scripts": { + "build": "run-p build:*", + "build:main": "tsc -p tsconfig.json", + "build:module": "tsc -p tsconfig.module.json", + "fix": "run-s fix:*", + "fix:prettier": "prettier \"src/**/*.ts\" --write", + "fix:lint": "eslint src --ext .ts --fix", + "test": "run-s build test:*", + "test:lint": "eslint src --ext .ts", + "test:prettier": "prettier \"src/**/*.ts\" --list-different", + "test:spelling": "cspell \"{README.md,.github/*.md,src/**/*.ts}\"", + "test:unit": "nyc --silent ava", + "check-cli": "run-s test diff-integration-tests check-integration-tests", + "check-integration-tests": "run-s check-integration-test:*", + "diff-integration-tests": "mkdir -p diff && rm -rf diff/test && cp -r test diff/test && rm -rf diff/test/test-*/.git && cd diff && git init --quiet && git add -A && git commit --quiet --no-verify --allow-empty -m 'WIP' && echo '\\n\\nCommitted most recent integration test output in the \"diff\" directory. Review the changes with \"cd diff && git diff HEAD\" or your preferred git diff viewer.'", + "watch:build": "tsc -p tsconfig.json -w", + "watch:test": "nyc --silent ava --watch", + "cov": "run-s build test:unit cov:html cov:lcov && open-cli coverage/index.html", + "cov:html": "nyc report --reporter=html", + "cov:lcov": "nyc report --reporter=lcov", + "cov:send": "run-s cov:lcov && codecov", + "cov:check": "nyc report && nyc check-coverage --lines 100 --functions 100 --branches 100", + "doc": "run-s doc:html && open-cli build/docs/index.html", + "doc:html": "typedoc src/ --exclude **/*.spec.ts --target ES6 --mode file --out build/docs", + "doc:json": "typedoc src/ --exclude **/*.spec.ts --target ES6 --mode file --json build/docs/typedoc.json", + "doc:publish": "gh-pages -m \"[ci skip] Updates\" -d build/docs", + "version": "standard-version", + "reset-hard": "git clean -dfx && git reset --hard && npm i", + "prepare-release": "run-s reset-hard test cov:check doc:html version doc:publish" + }, + "engines": { + "node": ">=10" + }, + "dependencies": { + "@bitauth/libauth": "^1.17.1" + }, + "devDependencies": { + "@ava/typescript": "^1.1.1", + "@istanbuljs/nyc-config-typescript": "^1.0.1", + "@typescript-eslint/eslint-plugin": "^4.0.1", + "@typescript-eslint/parser": "^4.0.1", + "ava": "^3.12.1", + "codecov": "^3.5.0", + "cspell": "^4.1.0", + "cz-conventional-changelog": "^3.3.0", + "eslint": "^7.8.0", + "eslint-config-prettier": "^6.11.0", + "eslint-plugin-eslint-comments": "^3.2.0", + "eslint-plugin-functional": "^3.0.2", + "eslint-plugin-import": "^2.22.0", + "gh-pages": "^3.1.0", + "npm-run-all": "^4.1.5", + "nyc": "^15.1.0", + "open-cli": "^6.0.1", + "prettier": "^2.1.1", + "standard-version": "^9.0.0", + "ts-node": "^9.0.0", + "typedoc": "^0.19.0", + "typescript": "^4.0.2" + }, + "files": [ + "build/main", + "build/module", + "!**/*.spec.*", + "!**/*.json", + "CHANGELOG.md", + "LICENSE", + "README.md" + ], + "ava": { + "failFast": true, + "timeout": "60s", + "typescript": { + "rewritePaths": { + "src/": "build/main/" + } + }, + "files": [ + "!build/module/**" + ] + }, + "config": { + "commitizen": { + "path": "cz-conventional-changelog" + } + }, + "prettier": { + "singleQuote": true + }, + "nyc": { + "extends": "@istanbuljs/nyc-config-typescript", + "exclude": [ + "**/*.spec.js" + ] + } +} diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000000..25b867cc93 --- /dev/null +++ b/src/index.ts @@ -0,0 +1,2 @@ +export * from './lib/async'; +export * from './lib/number'; diff --git a/src/lib/async.spec.ts b/src/lib/async.spec.ts new file mode 100644 index 0000000000..31bd17d5ba --- /dev/null +++ b/src/lib/async.spec.ts @@ -0,0 +1,7 @@ +import test from 'ava'; + +import { asyncABC } from './async'; + +test('getABC', async (t) => { + t.deepEqual(await asyncABC(), ['a', 'b', 'c']); +}); diff --git a/src/lib/async.ts b/src/lib/async.ts new file mode 100644 index 0000000000..6a387275c1 --- /dev/null +++ b/src/lib/async.ts @@ -0,0 +1,32 @@ +/** + * A sample async function (to demo Typescript's es7 async/await down-leveling). + * + * ### Example (es imports) + * ```js + * import { asyncABC } from 'typescript-starter' + * console.log(await asyncABC()) + * // => ['a','b','c'] + * ``` + * + * ### Example (commonjs) + * ```js + * var double = require('typescript-starter').asyncABC; + * asyncABC().then(console.log); + * // => ['a','b','c'] + * ``` + * + * @returns a Promise which should contain `['a','b','c']` + */ +export const asyncABC = async () => { + const somethingSlow = (index: 0 | 1 | 2) => { + const storage = 'abc'.charAt(index); + return new Promise((resolve) => + // later... + resolve(storage) + ); + }; + const a = await somethingSlow(0); + const b = await somethingSlow(1); + const c = await somethingSlow(2); + return [a, b, c]; +}; diff --git a/src/lib/number.spec.ts b/src/lib/number.spec.ts new file mode 100644 index 0000000000..4b2e8dd5be --- /dev/null +++ b/src/lib/number.spec.ts @@ -0,0 +1,11 @@ +import test from 'ava'; + +import { double, power } from './number'; + +test('double', (t) => { + t.is(double(2), 4); +}); + +test('power', (t) => { + t.is(power(2, 4), 16); +}); diff --git a/src/lib/number.ts b/src/lib/number.ts new file mode 100644 index 0000000000..d28ddcc751 --- /dev/null +++ b/src/lib/number.ts @@ -0,0 +1,51 @@ +/** + * Multiplies a value by 2. (Also a full example of TypeDoc's functionality.) + * + * ### Example (es module) + * ```js + * import { double } from 'typescript-starter' + * console.log(double(4)) + * // => 8 + * ``` + * + * ### Example (commonjs) + * ```js + * var double = require('typescript-starter').double; + * console.log(double(4)) + * // => 8 + * ``` + * + * @param value - Comment describing the `value` parameter. + * @returns Comment describing the return type. + * @anotherNote Some other value. + */ +export const double = (value: number) => { + return value * 2; +}; + +/** + * Raise the value of the first parameter to the power of the second using the + * es7 exponentiation operator (`**`). + * + * ### Example (es module) + * ```js + * import { power } from 'typescript-starter' + * console.log(power(2,3)) + * // => 8 + * ``` + * + * ### Example (commonjs) + * ```js + * var power = require('typescript-starter').power; + * console.log(power(2,3)) + * // => 8 + * ``` + * @param base - the base to exponentiate + * @param exponent - the power to which to raise the base + */ +export const power = (base: number, exponent: number) => { + /** + * This es7 exponentiation operator is transpiled by TypeScript + */ + return base ** exponent; +}; diff --git a/src/types/example.d.ts b/src/types/example.d.ts new file mode 100644 index 0000000000..67a843ab91 --- /dev/null +++ b/src/types/example.d.ts @@ -0,0 +1,24 @@ +/** + * If you import a dependency which does not include its own type definitions, + * TypeScript will try to find a definition for it by following the `typeRoots` + * compiler option in tsconfig.json. For this project, we've configured it to + * fall back to this folder if nothing is found in node_modules/@types. + * + * Often, you can install the DefinitelyTyped + * (https://github.com/DefinitelyTyped/DefinitelyTyped) type definition for the + * dependency in question. However, if no one has yet contributed definitions + * for the package, you may want to declare your own. (If you're using the + * `noImplicitAny` compiler options, you'll be required to declare it.) + * + * This is an example type definition which allows import from `module-name`, + * e.g.: + * ```ts + * import something from 'module-name'; + * something(); + * ``` + */ +declare module 'module-name' { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const whatever: any; + export = whatever; +} diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000000..b91523b900 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,47 @@ +{ + "compilerOptions": { + "incremental": true, + "target": "es2017", + "outDir": "build/main", + "rootDir": "src", + "moduleResolution": "node", + "module": "commonjs", + "declaration": true, + "inlineSourceMap": true, + "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */, + "resolveJsonModule": true /* Include modules imported with .json extension. */, + + "strict": true /* Enable all strict type-checking options. */, + + /* Strict Type-Checking Options */ + // "noImplicitAny": true /* Raise error on expressions and declarations with an implied 'any' type. */, + // "strictNullChecks": true /* Enable strict null checks. */, + // "strictFunctionTypes": true /* Enable strict checking of function types. */, + // "strictPropertyInitialization": true /* Enable strict checking of property initialization in classes. */, + // "noImplicitThis": true /* Raise error on 'this' expressions with an implied 'any' type. */, + // "alwaysStrict": true /* Parse in strict mode and emit "use strict" for each source file. */, + + /* Additional Checks */ + "noUnusedLocals": true /* Report errors on unused locals. */, + "noUnusedParameters": true /* Report errors on unused parameters. */, + "noImplicitReturns": true /* Report error when not all code paths in function return a value. */, + "noFallthroughCasesInSwitch": true /* Report errors for fallthrough cases in switch statement. */, + + /* Debugging Options */ + "traceResolution": false /* Report module resolution log messages. */, + "listEmittedFiles": false /* Print names of generated files part of the compilation. */, + "listFiles": false /* Print names of files part of the compilation. */, + "pretty": true /* Stylize errors and messages using color and context. */, + + /* Experimental Options */ + // "experimentalDecorators": true /* Enables experimental support for ES7 decorators. */, + // "emitDecoratorMetadata": true /* Enables experimental support for emitting type metadata for decorators. */, + + "lib": ["es2017"], + "types": ["node"], + "typeRoots": ["node_modules/@types", "src/types"] + }, + "include": ["src/**/*.ts"], + "exclude": ["node_modules/**"], + "compileOnSave": false +} diff --git a/tsconfig.module.json b/tsconfig.module.json new file mode 100644 index 0000000000..dfb74fa3a3 --- /dev/null +++ b/tsconfig.module.json @@ -0,0 +1,11 @@ +{ + "extends": "./tsconfig", + "compilerOptions": { + "target": "esnext", + "outDir": "build/module", + "module": "esnext" + }, + "exclude": [ + "node_modules/**" + ] +}