Skip to content

Commit b1593be

Browse files
committed
Merge branch 'upgrade-tools' into 'master'
Upgrade to latest dev tools and linting See merge request meat-n-potatoes/pi-camera-connect!1
2 parents fdd6145 + 66a6407 commit b1593be

14 files changed

+3312
-2462
lines changed

.editorconfig

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 2
6+
charset = utf-8
7+
trim_trailing_whitespace = true
8+
insert_final_newline = true
9+
end_of_line = lf
10+
max_line_length = null
11+
12+
[*.md]
13+
trim_trailing_whitespace = false
14+
15+
[*.rs]
16+
indent_size = 4
17+
18+
[Makefile]
19+
indent_style = tab
20+
trim_trailing_whitespace = false

.gitignore

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1-
dist/
21
node_modules/
3-
yarn-error.log
2+
3+
# config
4+
*.secrets.*
5+
6+
# common build sites
7+
dist/
8+
dist-types/
9+
10+
# build artifacts
11+
*.tsbuildinfo
12+
*.lcov
13+
coverage/
14+
.eslintcache
15+
16+
# logs and errors
17+
npm-debug.log*
18+
yarn-debug.log*
19+
yarn-error.log*
20+
lerna-debug.log*
21+
stats.json
22+
23+
# dev environments
24+
.vscode/*
25+
**/.DS_Store

.npmignore

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
1-
**
2-
!build/**
3-
!package.json
4-
!yarn.lock
1+
src/
2+
yarn.lock
3+
4+
tsconfig.json
5+
*.tsbuildinfo
6+
.editorconfig
7+
.app-config.*
8+
app-config.*
9+
10+
.DS_Store
11+
coverage/
12+
13+
npm-debug.log*
14+
yarn-debug.log*
15+
yarn-error.log*
16+
lerna-debug.log*

package.json

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,48 @@
22
"name": "pi-camera-connect",
33
"version": "0.2.0",
44
"description": "Library to capture and stream Raspberry Pi camera data directly to NodeJS",
5-
"main": "build/index.js",
6-
"types": "build/index.d.ts",
7-
"author": "Servall Development",
5+
"main": "dist/index.js",
6+
"types": "dist/index.d.ts",
7+
"author": {
8+
"name": "Launchcode",
9+
"email": "[email protected]",
10+
"url": "https://lc.dev"
11+
},
812
"license": "MIT",
913
"repository": {
1014
"type": "git",
1115
"url": "https://github.com/servall/pi-camera-connect"
1216
},
1317
"scripts": {
14-
"test": "jest --runInBand",
1518
"build": "tsc -b",
16-
"prepublish": "yarn build"
19+
"clean": "rm -rf dist *.tsbuildinfo",
20+
"lint": "eslint --ext .ts,.tsx src",
21+
"fix": "eslint --ext .ts,.tsx src --fix",
22+
"test": "jest --runInBand",
23+
"prepublishOnly": "yarn clean && yarn build"
1724
},
1825
"devDependencies": {
19-
"@types/jest": "22",
26+
"@lcdev/eslint-config": "0.2",
27+
"@lcdev/jest": "0.2",
28+
"@lcdev/prettier": "0.1",
29+
"@lcdev/tsconfig": "0.1",
30+
"@types/jest": "25",
2031
"@types/node": "*",
21-
"jest": "22",
32+
"eslint": "6",
33+
"jest": "25",
2234
"nodemon": "1",
23-
"ts-jest": "22",
24-
"ts-node": "5",
25-
"tslint": "5",
35+
"prettier": "1",
2636
"typescript": "3"
2737
},
2838
"jest": {
29-
"transform": {
30-
"^.+\\.ts$": "ts-jest"
31-
},
32-
"testRegex": "(/tests/.*|(\\.|/)(test|spec))\\.(js|ts)$",
33-
"moduleFileExtensions": [
34-
"ts",
35-
"js",
36-
"json",
37-
"node"
38-
]
39+
"preset": "@lcdev/jest"
40+
},
41+
"prettier": "@lcdev/prettier",
42+
"eslintConfig": {
43+
"extends": "@lcdev",
44+
"rules": {
45+
"no-constant-condition": 0,
46+
"no-shadow": 0
47+
}
3948
}
4049
}

src/index.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
export { default as StillCamera, StillOptions } from "./lib/still-camera";
2-
export { default as StreamCamera, StreamOptions, Codec, SensorMode } from "./lib/stream-camera";
1+
export { default as StillCamera, StillOptions } from './lib/still-camera';
2+
export { default as StreamCamera, StreamOptions, Codec, SensorMode } from './lib/stream-camera';
33

44
export enum Rotation {
5-
Rotate0 = 0,
6-
Rotate90 = 90,
7-
Rotate180 = 180,
8-
Rotate270 = 270
5+
Rotate0 = 0,
6+
Rotate90 = 90,
7+
Rotate180 = 180,
8+
Rotate270 = 270,
99
}
1010

1111
export enum Flip {
12-
None = "none",
13-
Horizontal = "horizontal",
14-
Vertical = "vertical",
15-
Both = "both"
12+
None = 'none',
13+
Horizontal = 'horizontal',
14+
Vertical = 'vertical',
15+
Both = 'both',
1616
}

src/lib/still-camera.test.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import StillCamera from "./still-camera";
1+
import StillCamera from './still-camera';
22

3-
test("takeImage() returns JPEG", async () => {
3+
test('takeImage() returns JPEG', async () => {
4+
const stillCamera = new StillCamera();
45

5-
const stillCamera = new StillCamera();
6+
const jpegImage = await stillCamera.takeImage();
67

7-
const jpegImage = await stillCamera.takeImage();
8-
9-
expect(jpegImage.indexOf(StillCamera.jpegSignature)).toBe(0);
8+
expect(jpegImage.indexOf(StillCamera.jpegSignature)).toBe(0);
109
});

src/lib/still-camera.ts

Lines changed: 93 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,99 @@
1-
import { spawnPromise } from "../util";
2-
import { Rotation, Flip } from "..";
1+
import { spawnPromise } from '../util';
2+
import { Rotation, Flip } from '..';
33

44
export interface StillOptions {
5-
width?: number;
6-
height?: number;
7-
rotation?: Rotation;
8-
flip?: Flip;
9-
delay?: number;
5+
width?: number;
6+
height?: number;
7+
rotation?: Rotation;
8+
flip?: Flip;
9+
delay?: number;
1010
}
1111

1212
export default class StillCamera {
13-
14-
static readonly jpegSignature = Buffer.from([0xFF, 0xD8, 0xFF, 0xE1, 0x64, 0x1A, 0x45, 0x78, 0x69, 0x66, 0x00]);
15-
16-
private options: StillOptions;
17-
18-
constructor(options: StillOptions = {}) {
19-
20-
this.options = {
21-
rotation: Rotation.Rotate0,
22-
flip: Flip.None,
23-
delay: 1,
24-
...options
25-
};
26-
}
27-
28-
async takeImage() {
29-
30-
try {
31-
32-
return await spawnPromise("raspistill", [
33-
34-
/**
35-
* Width
36-
*/
37-
...(this.options.width ? ["--width", this.options.width.toString()] : []),
38-
39-
/**
40-
* Height
41-
*/
42-
...(this.options.height ? ["--height", this.options.height.toString()] : []),
43-
44-
/**
45-
* Rotation
46-
*/
47-
...(this.options.rotation ? ["--rotation", this.options.rotation.toString()] : []),
48-
49-
/**
50-
* Horizontal flip
51-
*/
52-
...(this.options.flip && (this.options.flip === Flip.Horizontal || this.options.flip === Flip.Both) ?
53-
["--hflip"] : []),
54-
55-
/**
56-
* Vertical flip
57-
*/
58-
...(this.options.flip && (this.options.flip === Flip.Vertical || this.options.flip === Flip.Both) ?
59-
["--vflip"] : []),
60-
61-
/**
62-
* Capture delay (ms)
63-
*/
64-
"--timeout", this.options.delay!.toString(),
65-
66-
/**
67-
* Do not display preview overlay on screen
68-
*/
69-
"--nopreview",
70-
71-
/**
72-
* Output to stdout
73-
*/
74-
"--output", "-"
75-
]);
76-
}
77-
catch (err) {
78-
79-
if (err.code === "ENOENT") {
80-
throw new Error("Could not take image with StillCamera. Are you running on a Raspberry Pi with 'raspistill' installed?");
81-
}
82-
83-
throw err;
84-
}
85-
}
13+
static readonly jpegSignature = Buffer.from([
14+
0xff,
15+
0xd8,
16+
0xff,
17+
0xe1,
18+
0x64,
19+
0x1a,
20+
0x45,
21+
0x78,
22+
0x69,
23+
0x66,
24+
0x00,
25+
]);
26+
27+
private readonly options: StillOptions;
28+
29+
constructor(options: StillOptions = {}) {
30+
this.options = {
31+
rotation: Rotation.Rotate0,
32+
flip: Flip.None,
33+
delay: 1,
34+
...options,
35+
};
36+
}
37+
38+
async takeImage() {
39+
try {
40+
return await spawnPromise('raspistill', [
41+
/**
42+
* Width
43+
*/
44+
...(this.options.width ? ['--width', this.options.width.toString()] : []),
45+
46+
/**
47+
* Height
48+
*/
49+
...(this.options.height ? ['--height', this.options.height.toString()] : []),
50+
51+
/**
52+
* Rotation
53+
*/
54+
...(this.options.rotation ? ['--rotation', this.options.rotation.toString()] : []),
55+
56+
/**
57+
* Horizontal flip
58+
*/
59+
...(this.options.flip &&
60+
(this.options.flip === Flip.Horizontal || this.options.flip === Flip.Both)
61+
? ['--hflip']
62+
: []),
63+
64+
/**
65+
* Vertical flip
66+
*/
67+
...(this.options.flip &&
68+
(this.options.flip === Flip.Vertical || this.options.flip === Flip.Both)
69+
? ['--vflip']
70+
: []),
71+
72+
/**
73+
* Capture delay (ms)
74+
*/
75+
'--timeout',
76+
this.options.delay!.toString(),
77+
78+
/**
79+
* Do not display preview overlay on screen
80+
*/
81+
'--nopreview',
82+
83+
/**
84+
* Output to stdout
85+
*/
86+
'--output',
87+
'-',
88+
]);
89+
} catch (err) {
90+
if (err.code === 'ENOENT') {
91+
throw new Error(
92+
"Could not take image with StillCamera. Are you running on a Raspberry Pi with 'raspistill' installed?",
93+
);
94+
}
95+
96+
throw err;
97+
}
98+
}
8699
}

0 commit comments

Comments
 (0)