Skip to content

Commit 449d28f

Browse files
committed
Setup repo
1 parent 2a4598d commit 449d28f

24 files changed

+5299
-0
lines changed

.circleci/config.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# https://circleci.com/docs/2.0/language-javascript/
2+
version: 2
3+
jobs:
4+
'node-10':
5+
docker:
6+
- image: circleci/node:10
7+
working_directory: ~/typescript-starter
8+
steps:
9+
- checkout
10+
# Download and cache dependencies
11+
- restore_cache:
12+
keys:
13+
- v1-dependencies-{{ checksum "package.json" }}
14+
# fallback to using the latest cache if no exact match is found
15+
- v1-dependencies-
16+
- run: npm install
17+
- save_cache:
18+
paths:
19+
- node_modules
20+
key: v1-dependencies-{{ checksum "package.json" }}
21+
- run: npm test
22+
- run: npx nyc report --reporter=lcov | npx codecov
23+
- run: npm run cov:check
24+
'node-latest':
25+
docker:
26+
- image: circleci/node:latest
27+
working_directory: ~/typescript-starter
28+
steps:
29+
- checkout
30+
- restore_cache:
31+
keys:
32+
- v1-dependencies-{{ checksum "package.json" }}
33+
- v1-dependencies-
34+
- run: npm install
35+
- save_cache:
36+
paths:
37+
- node_modules
38+
key: v1-dependencies-{{ checksum "package.json" }}
39+
- run: npm test
40+
- run: npx nyc report --reporter=lcov | npx codecov
41+
- run: npm run cov:check
42+
43+
workflows:
44+
version: 2
45+
build:
46+
jobs:
47+
- 'node-10'
48+
- 'node-latest'

.editorconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# http://editorconfig.org
2+
root = true
3+
4+
[*]
5+
charset = utf-8
6+
end_of_line = lf
7+
indent_size = 2
8+
indent_style = space
9+
insert_final_newline = true
10+
max_line_length = 80
11+
trim_trailing_whitespace = true
12+
13+
[*.md]
14+
max_line_length = 0
15+
trim_trailing_whitespace = false

.github/CONTRIBUTING.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Example Contributing Guidelines
2+
3+
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.

.github/ISSUE_TEMPLATE.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
* **I'm submitting a ...**
2+
[ ] bug report
3+
[ ] feature request
4+
[ ] question about the decisions made in the repository
5+
[ ] question about how to use this project
6+
7+
* **Summary**
8+
9+
10+
11+
* **Other information** (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. StackOverflow, personal fork, etc.)

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
* **What kind of change does this PR introduce?** (Bug fix, feature, docs update, ...)
2+
3+
4+
5+
* **What is the current behavior?** (You can also link to an open issue here)
6+
7+
8+
9+
* **What is the new behavior (if this is a feature change)?**
10+
11+
12+
13+
* **Other information**:

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
node_modules
2+
build
3+
test
4+
src/**.js
5+
.idea/*
6+
7+
coverage
8+
.nyc_output
9+
*.log
10+
11+
package-lock.json

.npmignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
src
2+
test
3+
tsconfig.json
4+
tsconfig.module.json
5+
tslint.json
6+
.travis.yml
7+
.github
8+
.prettierignore
9+
.vscode
10+
build/docs
11+
**/*.spec.*
12+
coverage
13+
.nyc_output
14+
*.log

.prettierignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# package.json is formatted by package managers, so we ignore it here
2+
package.json

.vscode/debug-ts.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
'use strict';
2+
const meow = require('meow');
3+
const path = require('path');
4+
5+
const tsFile = getTSFile();
6+
const jsFile = TS2JS(tsFile);
7+
8+
replaceCLIArg(tsFile, jsFile);
9+
10+
// Ava debugger
11+
require('ava/profile');
12+
13+
/**
14+
* get ts file path from CLI args
15+
*
16+
* @return string path
17+
*/
18+
function getTSFile() {
19+
const cli = meow();
20+
return cli.input[0];
21+
}
22+
23+
/**
24+
* get associated compiled js file path
25+
*
26+
* @param tsFile path
27+
* @return string path
28+
*/
29+
function TS2JS(tsFile) {
30+
const srcFolder = path.join(__dirname, '..', 'src');
31+
const distFolder = path.join(__dirname, '..', 'build', 'main');
32+
33+
const tsPathObj = path.parse(tsFile);
34+
35+
return path.format({
36+
dir: tsPathObj.dir.replace(srcFolder, distFolder),
37+
ext: '.js',
38+
name: tsPathObj.name,
39+
root: tsPathObj.root
40+
});
41+
}
42+
43+
/**
44+
* replace a value in CLI args
45+
*
46+
* @param search value to search
47+
* @param replace value to replace
48+
* @return void
49+
*/
50+
function replaceCLIArg(search, replace) {
51+
process.argv[process.argv.indexOf(search)] = replace;
52+
}

.vscode/launch.json

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [{
4+
"type": "node",
5+
"request": "launch",
6+
"name": "Debug Project",
7+
// we test in `build` to make cleanup fast and easy
8+
"cwd": "${workspaceFolder}/build",
9+
// Replace this with your project root. If there are multiple, you can
10+
// automatically run the currently visible file with: "program": ${file}"
11+
"program": "${workspaceFolder}/src/cli/cli.ts",
12+
// "args": ["--no-install"],
13+
"outFiles": ["${workspaceFolder}/build/main/**/*.js"],
14+
"skipFiles": [
15+
"<node_internals>/**/*.js",
16+
"${workspaceFolder}/node_modules/**/*.js"
17+
],
18+
"preLaunchTask": "npm: build",
19+
"stopOnEntry": true,
20+
"smartStep": true,
21+
"runtimeArgs": ["--nolazy"],
22+
"env": {
23+
"TYPESCRIPT_STARTER_REPO_URL": "${workspaceFolder}"
24+
},
25+
"console": "externalTerminal"
26+
},
27+
{
28+
"type": "node",
29+
"request": "launch",
30+
"name": "Debug Spec",
31+
"program": "${workspaceRoot}/.vscode/debug-ts.js",
32+
"args": ["${file}"],
33+
"skipFiles": ["<node_internals>/**/*.js"],
34+
// Consider using `npm run watch` or `yarn watch` for faster debugging
35+
// "preLaunchTask": "npm: build",
36+
// "smartStep": true,
37+
"runtimeArgs": ["--nolazy"]
38+
}]
39+
}

.vscode/settings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"typescript.tsdk": "node_modules/typescript/lib"
3+
// "typescript.implementationsCodeLens.enabled": true
4+
// "typescript.referencesCodeLens.enabled": true
5+
}

package.json

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
{
2+
"name": "cql.js",
3+
"version": "0.0.1",
4+
"description": "general purpose library for CovenantSQL blockchain",
5+
"main": "build/main/index.js",
6+
"typings": "build/main/index.d.ts",
7+
"module": "build/module/index.js",
8+
"repository": "https://github.com/foreseaz/test",
9+
"license": "MIT",
10+
"keywords": [],
11+
"scripts": {
12+
"describe": "npm-scripts-info",
13+
"build": "run-s clean && run-p build:*",
14+
"build:main": "tsc -p tsconfig.json",
15+
"build:module": "tsc -p tsconfig.module.json",
16+
"fix": "run-s fix:*",
17+
"fix:prettier": "prettier \"src/**/*.ts\" --write",
18+
"fix:tslint": "tslint --fix --project .",
19+
"test": "run-s build test:*",
20+
"test:lint": "tslint --project . && prettier \"src/**/*.ts\" --list-different",
21+
"test:unit": "nyc --silent ava",
22+
"watch": "run-s clean build:main && run-p \"build:main -- -w\" \"test:unit -- --watch\"",
23+
"cov": "run-s build test:unit cov:html && opn coverage/index.html",
24+
"cov:html": "nyc report --reporter=html",
25+
"cov:send": "nyc report --reporter=lcov > coverage.lcov && codecov",
26+
"cov:check": "nyc report && nyc check-coverage --lines 100 --functions 100 --branches 100",
27+
"doc": "run-s doc:html && opn build/docs/index.html",
28+
"doc:html": "typedoc src/ --exclude **/*.spec.ts --target ES6 --mode file --out build/docs",
29+
"doc:json": "typedoc src/ --exclude **/*.spec.ts --target ES6 --mode file --json build/docs/typedoc.json",
30+
"doc:publish": "gh-pages -m \"[ci skip] Updates\" -d build/docs",
31+
"version": "standard-version",
32+
"reset": "git clean -dfx && git reset --hard && npm i",
33+
"clean": "trash build test",
34+
"all": "run-s reset test cov:check doc:html",
35+
"prepare-release": "run-s all version doc:publish",
36+
"preinstall": "node -e \"if(process.env.npm_execpath.indexOf('yarn') === -1) throw new Error('test must be installed with Yarn: https://yarnpkg.com/')\""
37+
},
38+
"scripts-info": {
39+
"info": "Display information about the package scripts",
40+
"build": "Clean and rebuild the project",
41+
"fix": "Try to automatically fix any linting problems",
42+
"test": "Lint and unit test the project",
43+
"watch": "Watch and rebuild the project on save, then rerun relevant tests",
44+
"cov": "Rebuild, run tests, then create and open the coverage report",
45+
"doc": "Generate HTML API documentation and open it in a browser",
46+
"doc:json": "Generate API documentation in typedoc JSON format",
47+
"version": "Bump package.json version, update CHANGELOG.md, tag release",
48+
"reset": "Delete all untracked files and reset the repo to the last commit",
49+
"prepare-release": "One-step: clean, build, test, publish docs, and prep a release"
50+
},
51+
"engines": {
52+
"node": ">=8.9"
53+
},
54+
"dependencies": {
55+
"sha.js": "^2.4.11"
56+
},
57+
"devDependencies": {
58+
"ava": "1.0.0-beta.7",
59+
"codecov": "^3.1.0",
60+
"cz-conventional-changelog": "^2.1.0",
61+
"gh-pages": "^2.0.1",
62+
"npm-run-all": "^4.1.5",
63+
"nyc": "^13.1.0",
64+
"opn-cli": "^4.0.0",
65+
"prettier": "^1.15.2",
66+
"standard-version": "^4.4.0",
67+
"trash-cli": "^1.4.0",
68+
"tslint": "^5.11.0",
69+
"tslint-config-prettier": "^1.17.0",
70+
"tslint-immutable": "^5.0.0",
71+
"typedoc": "^0.13.0",
72+
"typescript": "^3.1.6"
73+
},
74+
"ava": {
75+
"failFast": true,
76+
"files": [
77+
"build/main/**/*.spec.js"
78+
],
79+
"sources": [
80+
"build/main/**/*.js"
81+
]
82+
},
83+
"config": {
84+
"commitizen": {
85+
"path": "cz-conventional-changelog"
86+
}
87+
},
88+
"prettier": {
89+
"singleQuote": true,
90+
"semi": false
91+
},
92+
"nyc": {
93+
"exclude": [
94+
"**/*.spec.js"
95+
]
96+
}
97+
}

src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export * from './lib/async'
2+
export * from './lib/hash'
3+
export * from './lib/number'

src/lib/async.spec.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// tslint:disable:no-expression-statement
2+
import test from 'ava'
3+
import { asyncABC } from './async'
4+
5+
test('getABC', async t => {
6+
t.deepEqual(await asyncABC(), ['a', 'b', 'c'])
7+
})

src/lib/async.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* A sample async function (to demo Typescript's es7 async/await downleveling).
3+
*
4+
* ### Example (es imports)
5+
* ```js
6+
* import { asyncABC } from 'typescript-starter'
7+
* console.log(await asyncABC())
8+
* // => ['a','b','c']
9+
* ```
10+
*
11+
* ### Example (commonjs)
12+
* ```js
13+
* var double = require('typescript-starter').asyncABC;
14+
* asyncABC().then(console.log);
15+
* // => ['a','b','c']
16+
* ```
17+
*
18+
* @returns a Promise which should contain `['a','b','c']`
19+
*/
20+
export async function asyncABC(): Promise<ReadonlyArray<string>> {
21+
function somethingSlow(index: 0 | 1 | 2): Promise<string> {
22+
const storage = 'abc'.charAt(index)
23+
return new Promise<string>(resolve =>
24+
// later...
25+
resolve(storage)
26+
)
27+
}
28+
const a = await somethingSlow(0)
29+
const b = await somethingSlow(1)
30+
const c = await somethingSlow(2)
31+
return [a, b, c]
32+
}

src/lib/hash.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// tslint:disable:no-expression-statement no-object-mutation
2+
import test, { Macro } from 'ava'
3+
import { sha256, sha256Native } from './hash'
4+
5+
const hash: Macro = (t, input: string, expected: string) => {
6+
t.is(sha256(input), expected)
7+
t.is(sha256Native(input), expected)
8+
}
9+
10+
hash.title = (providedTitle: string, input: string, expected: string) =>
11+
`${providedTitle}: ${input} => ${expected}`
12+
13+
test(
14+
'sha256',
15+
hash,
16+
'test',
17+
'9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08'
18+
)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy