Skip to content

Commit 3612b5a

Browse files
committedApr 1, 2019
🔥 it works
0 parents  commit 3612b5a

17 files changed

+4386
-0
lines changed
 

‎.circleci/config.yml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
version: 2
2+
jobs:
3+
build:
4+
docker:
5+
- image: circleci/node:10.13.0
6+
working_directory: /home/circleci/app
7+
steps:
8+
- checkout
9+
10+
- restore_cache:
11+
key: v1-dep-{{ checksum "yarn.lock" }}
12+
13+
- run:
14+
name: Install deps
15+
command: yarn install --frozen-lockfile
16+
17+
- save_cache:
18+
paths:
19+
- ./node_modules
20+
- ~/.cache
21+
key: v1-dep-{{ checksum "yarn.lock" }}
22+
23+
- run:
24+
name: Run tests
25+
command: yarn test

‎.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
lib

‎.prettierignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
.vscode
3+
package.json
4+
lib

‎.prettierrc

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"printWidth": 100,
3+
"tabWidth": 2,
4+
"semi": true,
5+
"singleQuote": false,
6+
"trailingComma": "all",
7+
"proseWrap": "always"
8+
}

‎CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Changelog

‎CONTRIBUTING.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Contributing
2+
3+
All contributions are welcomed.
4+
5+
Do you have an idea for improving this check? Please, first submit a github issue and describe your
6+
proposal.
7+
8+
When you're done with your changes use `yarn test:fix` to run `prettier` to reformat code, `tslint`
9+
in fix mode, `tsc` to make sure that there are no compilation errors, and unit tests.
10+
11+
Thanks! 🙏🏻

‎LICENSE

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
MIT License
2+
3+
Copyright (c) Chris Kaczor <chris@codechecks.io> (codechecks.com)
4+
5+
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:
6+
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
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.

‎README.md

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<p align="center">
2+
<img src="./meta/check.png" width="700" alt="codechecks.io">
3+
<h3 align="center">Commit Deployment</h3>
4+
<p align="center">Ship every code change that you make</p>
5+
6+
<p align="center">
7+
<a href="https://circleci.com/gh/codechecks/commit-deployment"><img alt="Build Status" src="https://circleci.com/gh/codechecks/commit-deployment/tree/master.svg?style=svg"></a>
8+
<a href="/package.json"><img alt="Software License" src="https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square"></a>
9+
</p>
10+
</p>
11+
12+
## Install
13+
14+
```sh
15+
npm add --save-dev @codechecks/commit-deployment
16+
```
17+
18+
or
19+
20+
```sh
21+
yarn add --dev @codechecks/commit-deployment
22+
```
23+
24+
## Usage
25+
26+
Add to your `codechecks.json` file:
27+
28+
<!-- prettier-ignore -->
29+
```json5
30+
{
31+
"checks": [
32+
{
33+
"name": "commit-deployment",
34+
"options": {
35+
"buildPath": "./dist"
36+
}
37+
}
38+
39+
// ...
40+
]
41+
}
42+
```
43+
44+
With each pull request you will get a link do current deployment of your frontend app.
45+
46+
## API
47+
48+
### commitDeployment(options: Options): Promise\<void>
49+
50+
#### Options
51+
52+
```typescript
53+
interface Options {
54+
buildPath: string;
55+
rootFile?: string;
56+
}
57+
```
58+
59+
##### buildPath
60+
61+
`string`<br>\
62+
Relative (to current codechecks file) path to build that is supposed to be deployed.
63+
64+
##### rootFile
65+
66+
optional `string`<br>\
67+
Default: `index.html`<br>\
68+
File considered as root in your build. Attached link will point directly to it.
69+
70+
## Contributing
71+
72+
All contributions are welcomed. Read more in [CONTRIBUTING.md](./CONTRIBUTING.md)
73+
74+
## Licence
75+
76+
MIT @ [codechecks.io](https://codechecks.io)

‎jest.config.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
roots: ["<rootDir>/src"],
3+
transform: {
4+
"^.+\\.tsx?$": "ts-jest",
5+
},
6+
testRegex: "(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$",
7+
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
8+
};

‎meta/check.png

98.1 KB
Loading

‎package.json

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
{
2+
"name": "@codechecks/commit-deployment",
3+
"description": "Ship every code change that you make",
4+
"keywords": [
5+
"commit-deploy",
6+
"deployment",
7+
"continuous deployment",
8+
"codechecks"
9+
],
10+
"repository": "codechecks/commit-deployment",
11+
"author": "Chris Kaczor <chris@kaczor.io>",
12+
"version": "0.0.1",
13+
"main": "lib/index.js",
14+
"types": "lib/index.d.ts",
15+
"license": "MIT",
16+
"scripts": {
17+
"start": "ts-node ./src/index.ts",
18+
"build": "rm -rf ./lib && tsc",
19+
"format": "prettier --list-different '**/*.{ts,json,md, gql}'",
20+
"format:fix": "prettier --write '**/*.{ts,json,md,gql}'",
21+
"tslint": "tslint -p ./tsconfig.json -e 'node_modules/**/*' 'src/**/*.ts'",
22+
"tslint:fix": "tslint --fix --format stylish -p ./tsconfig.json -e 'node_modules/**/*' '**/*.ts'",
23+
"tsc": "tsc --noEmit",
24+
"lint": "yarn format && yarn tslint && yarn tsc",
25+
"lint:fix": "yarn format:fix && yarn tslint:fix && yarn tsc",
26+
"test:unit": "jest",
27+
"test:watch": "jest --watch",
28+
"test": "yarn lint && yarn test:unit",
29+
"test:fix": "yarn lint:fix && yarn test:unit",
30+
"prepublishOnly": "yarn test && yarn build"
31+
},
32+
"files": [
33+
"lib/**/*"
34+
],
35+
"devDependencies": {
36+
"@codechecks/client": "^0.0.52",
37+
"@types/bluebird": "^3.5.25",
38+
"@types/bytes": "^3.0.0",
39+
"@types/glob": "^7.1.1",
40+
"@types/gzip-size": "^4.1.0",
41+
"@types/jest": "^23.3.12",
42+
"@types/lodash": "^4.14.121",
43+
"@types/mock-fs": "^3.6.30",
44+
"@types/node": "^10.12.18",
45+
"@types/pretty-bytes": "^5.1.0",
46+
"bluebird": "^3.5.3",
47+
"jest": "^23.6.0",
48+
"mock-fs": "^4.8.0",
49+
"prettier": "^1.15.3",
50+
"ts-essentials": "^2.0.2",
51+
"ts-jest": "^23.10.5",
52+
"ts-node": "^7.0.1",
53+
"tslint": "^5.12.1",
54+
"tslint-language-service": "^0.9.9",
55+
"typescript": "^3.2.2",
56+
"typestrict": "^1.0.2"
57+
},
58+
"peerDependencies": {
59+
"@codechecks/client": "^0.0.48"
60+
},
61+
"dependencies": {
62+
"bytes": "^3.0.0",
63+
"get-folder-size": "^2.0.0",
64+
"glob": "^7.1.3",
65+
"gzip-size": "^5.0.0",
66+
"lodash": "^4.17.11"
67+
},
68+
"publishConfig": {
69+
"access": "public"
70+
},
71+
"engines": {
72+
"node": ">=6"
73+
}
74+
}

‎src/__mocks__/@codechecks/client.ts

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import * as CC from "@codechecks/client";
2+
import { join } from "path";
3+
4+
export const codechecks: Partial<typeof CC.codechecks> = {
5+
report: jest.fn(),
6+
getValue: jest.fn(),
7+
saveValue: jest.fn(),
8+
getCollection: jest.fn(),
9+
saveCollection: jest.fn(),
10+
isPr: jest.fn(),
11+
context: {
12+
workspaceRoot: join(__dirname, "..", ".."),
13+
} as any,
14+
getArtifactLink: jest.fn(),
15+
getPageLink: jest.fn(),
16+
success: jest.fn(),
17+
failure: jest.fn(),
18+
};

‎src/__tests__/index.spec.ts

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { commitDeployment } from "../index";
2+
import { codechecks } from "@codechecks/client";
3+
4+
type Mocked<T> = { [k in keyof T]: jest.Mock<T[k]> };
5+
6+
describe("commit-deployment", () => {
7+
const codeChecksMock = require("../__mocks__/@codechecks/client").codechecks as Mocked<
8+
typeof codechecks
9+
>;
10+
beforeEach(() => jest.resetAllMocks());
11+
12+
it("should work", async () => {
13+
codeChecksMock.isPr.mockReturnValue(false);
14+
15+
await commitDeployment({
16+
buildPath: "dist",
17+
});
18+
19+
expect(codechecks.getPageLink).toMatchInlineSnapshot(`
20+
[MockFunction] {
21+
"calls": Array [
22+
Array [
23+
"build",
24+
"index.html",
25+
],
26+
],
27+
"results": Array [
28+
Object {
29+
"isThrow": false,
30+
"value": undefined,
31+
},
32+
],
33+
}
34+
`);
35+
expect(codechecks.success).toMatchInlineSnapshot(`
36+
[MockFunction] {
37+
"calls": Array [
38+
Array [
39+
Object {
40+
"detailsUrl": undefined,
41+
"name": "Commit Deployment",
42+
"shortDescription": "Deployment ready",
43+
},
44+
],
45+
],
46+
"results": Array [
47+
Object {
48+
"isThrow": false,
49+
"value": undefined,
50+
},
51+
],
52+
}
53+
`);
54+
expect(codechecks.saveCollection).toMatchInlineSnapshot(`
55+
[MockFunction] {
56+
"calls": Array [
57+
Array [
58+
"@codechecks/commit-deployment",
59+
"/Users/krzkaczor/Workspace/codechecks/commit-deployment/src/dist",
60+
],
61+
],
62+
"results": Array [
63+
Object {
64+
"isThrow": false,
65+
"value": undefined,
66+
},
67+
],
68+
}
69+
`);
70+
});
71+
});

‎src/index.ts

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { codechecks } from "@codechecks/client";
2+
import { join } from "path";
3+
4+
const ARTIFACT_KEY = "@codechecks/commit-deployment";
5+
6+
export async function commitDeployment(_options: Options): Promise<void> {
7+
const options = normalizeOptions(_options);
8+
9+
await codechecks.saveCollection(ARTIFACT_KEY, options.buildPath);
10+
await codechecks.success({
11+
name: "Commit Deployment",
12+
shortDescription: "Deployment ready",
13+
detailsUrl: codechecks.getPageLink("build", options.rootFile),
14+
});
15+
}
16+
17+
export default commitDeployment;
18+
19+
export interface Options {
20+
buildPath: string;
21+
rootFile?: string;
22+
}
23+
24+
function normalizeOptions(options: Options): Required<Options> {
25+
return {
26+
buildPath: join(codechecks.context.workspaceRoot, options.buildPath),
27+
rootFile: options.rootFile || "index.html",
28+
};
29+
}

‎tsconfig.json

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es2017",
4+
"module": "commonjs",
5+
"strict": true,
6+
"experimentalDecorators": true,
7+
"emitDecoratorMetadata": true,
8+
"forceConsistentCasingInFileNames": true,
9+
"plugins": [
10+
{
11+
"name": "tslint-language-service",
12+
"configFile": "./node_modules/typestrict/tslint.js",
13+
"alwaysShowRuleFailuresAsWarnings": true
14+
}
15+
],
16+
"lib": ["es2015", "esnext.asynciterable"],
17+
"sourceMap": true,
18+
"declaration": true,
19+
"outDir": "lib"
20+
},
21+
"include": ["src/**/*.ts"],
22+
"exclude": ["node_modules"]
23+
}

‎tslint.json

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"extends": "typestrict",
3+
"rules": {
4+
"no-console": true,
5+
"no-debugger": true,
6+
"typedef": [true, "call-signature"],
7+
"mocha-avoid-only": true,
8+
"interface-name": [true, "never-prefix"],
9+
"no-commented-code": true,
10+
"no-use-before-declare": false,
11+
"restrict-plus-operands": false
12+
}
13+
}

‎yarn.lock

+4,014
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.