Skip to content

Commit 465d7d2

Browse files
committed
chore: add opt-in quality of life improvements and general fixes
* add opt-in quality of life improvements for development, details follow. * add `.editorconfig`. * move prettier config to `package.json`. * fix precommit script to run on WSL. * add ignore patterns to unused vars/args * preliminary work on getting eslint working (though I'm replacing it with us going full tslint instead). * replace shx commands with rimraf in `package.json`. * specify min node and yarn versions. * Since upgrade to TS was also done on a different branch this specifies a version range instead. About improvements: This is opt-in behavior, meaning it's not enabled by default, as to not hinder the team and new contributors. However, I strongly recommend everyone to do opt in. Here's how: Create a file called `.opt-in` at the root of the repository, with the options you wish to enable (one per line). - `pre-commit`: * Source code files are formatted with Prettier automatically. * Source code files are checked with TSLint and ESLint automatically. - `commit-msg`: * Commit messages are validated to follow a convention. See <https://www.conventionalcommits.org/en/v1.0.0-beta.2/> for details. Please note, if you do opt-in, that since these are new practices, not enforced before, there's a good chance you might want a workaround if you're getting warnings from unrelated areas of your current task. While we encourage you to fix as many as you can, you can always opt-out in an case by case basis by running `git commit -n`. About node versions: Make sure that developers are running a supported and tested version of Node. When Node 12 comes up, we would explicitly update this field after testing. This is better than unexpected issues resulting from people running an early release or a GA release that hasn't been tested.
1 parent 7961e47 commit 465d7d2

12 files changed

+1791
-517
lines changed

.commitlint-patterns.json

Whitespace-only changes.

.commitlintrc.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
extends: ['@commitlint/config-conventional']
3+
};

.editorconfig

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

.eslintrc

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,41 @@
11
{
2-
"extends": "airbnb",
2+
"extends": ["airbnb", "prettier"],
33
"parser": "babel-eslint",
4+
"parserOptions": {
5+
"ecmaFeatures": {
6+
"legacyDecorators": true
7+
}
8+
},
49
"plugins": [
510
"vue"
611
],
712
"env": {
813
"browser": true,
914
"node": true
1015
},
16+
"globals": {
17+
"Electron": false,
18+
},
19+
"settings": {
20+
"import/resolver": "webpack"
21+
},
1122
"rules": {
1223
"class-methods-use-this": "off",
1324
"no-prototype-builtins": "off",
1425
"arrow-parens": "off",
1526
"comma-dangle": "off",
1627
"prefer-rest-params": "off",
28+
"import/prefer-default": "off",
1729
"import/no-extraneous-dependencies": [
1830
"error",
1931
{
2032
"devDependencies": true
2133
}
2234
],
23-
"spaced-comment": "off"
35+
"spaced-comment": "off",
36+
"no-unused-vars": [ "error", {
37+
"varsIgnorePattern": "^_",
38+
"argsIgnorePattern": "^_"
39+
} ]
2440
}
2541
}

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ electron.sln
1616
electron.VC.db
1717
.vs/
1818
plugins/
19-
yarn-error.log
19+
yarn-error.log
20+
.opt-in

.prettierrc

Lines changed: 0 additions & 3 deletions
This file was deleted.

app/services/selection/selection-api.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ import {
44
ISceneItem,
55
TSceneNodeApi,
66
ISceneItemNode,
7-
ISceneItemFolderApi, TSceneNodeModel
7+
ISceneItemFolderApi,
8+
TSceneNodeModel,
89
} from 'services/scenes';
910
import { ISourceApi } from 'services/sources';
1011

1112
/**
1213
* Represents active items and folders for current scene
1314
*/
14-
export interface ISelectionServiceApi extends ISelection {
15-
}
15+
export interface ISelectionServiceApi extends ISelection {}
1616

1717
/**
1818
* Allows call bulk actions with scene items and folders.
@@ -142,7 +142,6 @@ export interface ISelection extends ISceneItemActions {
142142
*/
143143
setParent(folderId: string): void;
144144

145-
146145
/**
147146
* Returns a minimal representation of selection
148147
* for selection list like this:

package.json

Lines changed: 57 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,52 @@
55
"license": "GPL-3.0",
66
"version": "0.11.7",
77
"main": "main.js",
8+
"engines": {
9+
"node": ">= 8 < 12",
10+
"yarn": ">= 1.5.2"
11+
},
812
"scripts": {
913
"compile": "yarn clear && webpack-cli --progress --mode development",
1014
"compile:ci": "yarn clear && webpack-cli --mode development",
1115
"compile:production": "yarn clear && webpack-cli --progress --mode production",
1216
"watch": "yarn clear && webpack-cli --watch --progress --mode development",
1317
"start": "electron .",
14-
"clear-plugins": "shx rm -rf plugins",
15-
"package": "shx rm -rf dist && build -w --x64 --config.extraMetadata.env=production",
16-
"package:preview": "shx rm -rf dist && build -w --x64 --config.extraMetadata.env=production --config.extraMetadata.name=\"slobs-client-preview\" --config.productName=\"Streamlabs OBS Preview\" --config.appId=\"com.streamlabs.slobspreview\"",
17-
"package:ipc": "shx rm -rf dist && build -w --x64 --config.extraMetadata.env=production --config.extraMetadata.name=\"slobs-client-ipc\" --config.productName=\"Streamlabs OBS IPC\" --config.appId=\"com.streamlabs.slobsipc\"",
18+
"clear-plugins": "rimraf plugins",
19+
"package": "rimraf dist && build -w --x64 --config.extraMetadata.env=production",
20+
"package:preview": "rimraf dist && build -w --x64 --config.extraMetadata.env=production --config.extraMetadata.name=\"slobs-client-preview\" --config.productName=\"Streamlabs OBS Preview\" --config.appId=\"com.streamlabs.slobspreview\"",
21+
"package:ipc": "rimraf dist && build -w --x64 --config.extraMetadata.env=production --config.extraMetadata.name=\"slobs-client-ipc\" --config.productName=\"Streamlabs OBS IPC\" --config.appId=\"com.streamlabs.slobsipc\"",
1822
"release": "yarn install --cwd bin && node bin/release.js",
1923
"test": "tsc -p test && ava -v",
2024
"test-flaky": "node ./test/helpers/runner.js",
21-
"clear": "shx rm -rf bundles/media",
25+
"clear": "rimraf bundles/media",
2226
"typedoc": "typedoc --out docs/dist ./app/services --mode modules --theme ./docs/theme --readme ./docs/README.md --ignoreCompilerErrors --excludePrivate --excludeExternals --hideGenerator",
2327
"compile-tests": "tsc -p test",
24-
"screentest": "node test/screentest/runner.js"
28+
"screentest": "node test/screentest/runner.js",
29+
"commit": "commit"
30+
},
31+
"prettier": {
32+
"singleQuote": true,
33+
"printWidth": 100,
34+
"endOfLine": "lf",
35+
"trailingComma": "all"
36+
},
37+
"husky": {
38+
"hooks": {
39+
"pre-commit": "node scripts/precommit.js",
40+
"commit-msg": "node scripts/commit-msg.js"
41+
}
42+
},
43+
"lint-staged": {
44+
"*.ts": [
45+
"prettier --write",
46+
"tslint --fix",
47+
"git add"
48+
]
49+
},
50+
"config": {
51+
"commitizen": {
52+
"path": "@commitlint/prompt"
53+
}
2554
},
2655
"build": {
2756
"appId": "com.streamlabs.slobs",
@@ -89,6 +118,10 @@
89118
"@babel/core": "^7.1.6",
90119
"@babel/plugin-proposal-decorators": "^7.1.6",
91120
"@babel/preset-env": "^7.1.6",
121+
"@commitlint/cli": "^7.2.1",
122+
"@commitlint/config-conventional": "^7.1.2",
123+
"@commitlint/prompt": "^7.2.1",
124+
"@commitlint/prompt-cli": "^7.2.1",
92125
"@sentry/browser": "^4.4.1",
93126
"@types/archiver": "2.1.2",
94127
"@types/lodash": "4.14.115",
@@ -99,40 +132,47 @@
99132
"@types/webdriverio": "^4.13.0",
100133
"@xkeshi/vue-qrcode": "0.3.0",
101134
"ava": "v1.0.0-rc.2",
102-
"babel-eslint": "8.2.6",
135+
"babel-eslint": "10.0.1",
103136
"babel-loader": "^8.0.4",
104137
"babel-plugin-transform-class-properties": "6.24.1",
105138
"babel-plugin-transform-decorators-legacy": "1.3.5",
106139
"circular-dependency-plugin": "3.0.0",
140+
"commitizen": "^3.0.4",
141+
"cross-spawn": "^6.0.5",
107142
"css-element-queries": "^1.0.2",
108143
"css-loader": "0.28.11",
109144
"devtron": "1.4.0",
110145
"electron": "2.0.14",
111146
"electron-builder": "20.22.0",
112147
"electron-devtools-installer": "2.2.4",
113148
"emojione": "3.1.7",
114-
"eslint": "3.19.0",
115-
"eslint-config-airbnb": "14.1.0",
116-
"eslint-plugin-import": "2.13.0",
117-
"eslint-plugin-jsx-a11y": "4.0.0",
118-
"eslint-plugin-react": "6.10.3",
149+
"eslint": "^4.12.1",
150+
"eslint-config-airbnb": "^17.1.0",
151+
"eslint-config-prettier": "^3.3.0",
152+
"eslint-import-resolver-webpack": "^0.10.1",
153+
"eslint-plugin-import": "^2.14.0",
154+
"eslint-plugin-jsx-a11y": "^6.1.1",
155+
"eslint-plugin-react": "^7.11.0",
119156
"eslint-plugin-vue": "2.1.0",
120157
"file-loader": "1.1.11",
121158
"fuse.js": "3.2.1",
159+
"husky": "^1.2.0",
122160
"js-yaml": "3.12.0",
123161
"less": "2.7.3",
124162
"less-loader": "4.1.0",
163+
"lint-staged": "^8.1.0",
125164
"lodash": "4.17.10",
126165
"lodash-decorators": "4.3.1",
127166
"moment": "2.22.2",
128167
"node-win32-np": "1.0.6",
129168
"pixelmatch": "4.0.2",
130169
"pngjs": "3.3.3",
170+
"prettier": "^1.15.2",
131171
"progress": "2.0.0",
172+
"read-pkg-up": "^4.0.0",
132173
"recursive-readdir": "^2.2.2",
133174
"reflect-metadata": "0.1.12",
134175
"rxjs": "6.3.3",
135-
"shx": "^0.3.2",
136176
"sl-vue-tree": "https://github.com/stream-labs/sl-vue-tree.git",
137177
"sockjs": "0.3.19",
138178
"sockjs-client": "1.1.5",
@@ -145,7 +185,7 @@
145185
"tslint-config-prettier": "1.14.0",
146186
"tslint-loader": "3.6.0",
147187
"typedoc": "0.11.1",
148-
"typescript": "3.2.1",
188+
"typescript": "^3.2.1",
149189
"unzip-stream": "0.3.0",
150190
"urijs": "1.19.1",
151191
"v-tooltip": "2.0.0-rc.31",
@@ -167,9 +207,10 @@
167207
"vuex": "3.0.1",
168208
"webdriverio": "^4.14.1",
169209
"webpack": "4.26.1",
170-
"webpack-cli": "3.1.2"
210+
"webpack-cli": "3.1.2",
211+
"which": "^1.3.1"
171212
},
172213
"resolutions": {
173214
"uglify-es": "3.3.9"
174215
}
175-
}
216+
}

scripts/commit-msg.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const spawn = require('cross-spawn');
2+
const { isOptedIn, resolveBin } = require('./utils');
3+
4+
if (!isOptedIn('commit-msg')) {
5+
process.exit(0);
6+
}
7+
8+
const result = spawn.sync(resolveBin('commitlint'), ['-E', 'HUSKY_GIT_PARAMS'], {
9+
stdio: 'inherit',
10+
});
11+
12+
process.stdout.write('\n');
13+
if (result.status !== 0) {
14+
process.exit(result.status);
15+
}

scripts/precommit.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const spawn = require('cross-spawn');
2+
const { isOptedIn, resolveBin } = require('./utils');
3+
4+
const args = process.argv.slice(2);
5+
6+
const config = [];
7+
8+
if (!isOptedIn('pre-commit')) {
9+
process.exit(0);
10+
}
11+
12+
const lintStagedResult = spawn.sync(resolveBin('lint-staged'), [], {
13+
env: process.env,
14+
stdio: 'inherit',
15+
});
16+
17+
if (lintStagedResult.status !== 0) {
18+
process.exit(lintStagedResult.status);
19+
}

scripts/utils.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/* eslint-disable import/no-dynamic-require,global-require */
2+
const fs = require('fs');
3+
const which = require('which');
4+
const path = require('path');
5+
const readPkgUp = require('read-pkg-up')
6+
7+
function resolveBin(modName, { executable = modName, cwd = process.cwd() } = {}) {
8+
let pathFromWhich;
9+
try {
10+
pathFromWhich = fs.realpathSync(which.sync(executable));
11+
} catch (_error) {
12+
// ignore _error
13+
}
14+
try {
15+
const modPkgPath = require.resolve(`${modName}/package.json`);
16+
const modPkgDir = path.dirname(modPkgPath);
17+
const { bin } = require(modPkgPath);
18+
const binPath = typeof bin === 'string' ? bin : bin[executable];
19+
const fullPathToBin = path.join(modPkgDir, binPath);
20+
if (fullPathToBin === pathFromWhich) {
21+
return executable;
22+
}
23+
return fullPathToBin.replace(cwd, '.');
24+
} catch (error) {
25+
if (pathFromWhich) {
26+
return executable;
27+
}
28+
throw error;
29+
}
30+
}
31+
const { pkg, path: pkgPath } = readPkgUp.sync({
32+
cwd: fs.realpathSync(process.cwd()),
33+
});
34+
const appDirectory = path.dirname(pkgPath);
35+
const fromRoot = (...p) => path.join(appDirectory, ...p);
36+
37+
function isOptedIn(key, t = true, f = false) {
38+
if (!fs.existsSync(fromRoot('.opt-in'))) {
39+
return f;
40+
}
41+
const contents = fs.readFileSync(fromRoot('.opt-in'), 'utf-8');
42+
return contents.includes(key) ? t : f;
43+
}
44+
45+
module.exports = {
46+
resolveBin,
47+
isOptedIn,
48+
};

0 commit comments

Comments
 (0)