Skip to content

Commit

Permalink
chore: add opt-in quality of life improvements and general fixes
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
blackxored committed Dec 12, 2018
1 parent 7961e47 commit 465d7d2
Show file tree
Hide file tree
Showing 12 changed files with 1,791 additions and 517 deletions.
Empty file added .commitlint-patterns.json
Empty file.
3 changes: 3 additions & 0 deletions .commitlintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
extends: ['@commitlint/config-conventional']
};
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
max_line_length = 100

[*.md]
insert_final_newline = false
trim_trailing_whitespace = false
max_line_length = 0
20 changes: 18 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,25 +1,41 @@
{
"extends": "airbnb",
"extends": ["airbnb", "prettier"],
"parser": "babel-eslint",
"parserOptions": {
"ecmaFeatures": {
"legacyDecorators": true
}
},
"plugins": [
"vue"
],
"env": {
"browser": true,
"node": true
},
"globals": {
"Electron": false,
},
"settings": {
"import/resolver": "webpack"
},
"rules": {
"class-methods-use-this": "off",
"no-prototype-builtins": "off",
"arrow-parens": "off",
"comma-dangle": "off",
"prefer-rest-params": "off",
"import/prefer-default": "off",
"import/no-extraneous-dependencies": [
"error",
{
"devDependencies": true
}
],
"spaced-comment": "off"
"spaced-comment": "off",
"no-unused-vars": [ "error", {
"varsIgnorePattern": "^_",
"argsIgnorePattern": "^_"
} ]
}
}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ electron.sln
electron.VC.db
.vs/
plugins/
yarn-error.log
yarn-error.log
.opt-in
3 changes: 0 additions & 3 deletions .prettierrc

This file was deleted.

7 changes: 3 additions & 4 deletions app/services/selection/selection-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import {
ISceneItem,
TSceneNodeApi,
ISceneItemNode,
ISceneItemFolderApi, TSceneNodeModel
ISceneItemFolderApi,
TSceneNodeModel,
} from 'services/scenes';
import { ISourceApi } from 'services/sources';

/**
* Represents active items and folders for current scene
*/
export interface ISelectionServiceApi extends ISelection {
}
export interface ISelectionServiceApi extends ISelection {}

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


/**
* Returns a minimal representation of selection
* for selection list like this:
Expand Down
73 changes: 57 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,52 @@
"license": "GPL-3.0",
"version": "0.11.7",
"main": "main.js",
"engines": {
"node": ">= 8 < 12",
"yarn": ">= 1.5.2"
},
"scripts": {
"compile": "yarn clear && webpack-cli --progress --mode development",
"compile:ci": "yarn clear && webpack-cli --mode development",
"compile:production": "yarn clear && webpack-cli --progress --mode production",
"watch": "yarn clear && webpack-cli --watch --progress --mode development",
"start": "electron .",
"clear-plugins": "shx rm -rf plugins",
"package": "shx rm -rf dist && build -w --x64 --config.extraMetadata.env=production",
"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\"",
"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\"",
"clear-plugins": "rimraf plugins",
"package": "rimraf dist && build -w --x64 --config.extraMetadata.env=production",
"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\"",
"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\"",
"release": "yarn install --cwd bin && node bin/release.js",
"test": "tsc -p test && ava -v",
"test-flaky": "node ./test/helpers/runner.js",
"clear": "shx rm -rf bundles/media",
"clear": "rimraf bundles/media",
"typedoc": "typedoc --out docs/dist ./app/services --mode modules --theme ./docs/theme --readme ./docs/README.md --ignoreCompilerErrors --excludePrivate --excludeExternals --hideGenerator",
"compile-tests": "tsc -p test",
"screentest": "node test/screentest/runner.js"
"screentest": "node test/screentest/runner.js",
"commit": "commit"
},
"prettier": {
"singleQuote": true,
"printWidth": 100,
"endOfLine": "lf",
"trailingComma": "all"
},
"husky": {
"hooks": {
"pre-commit": "node scripts/precommit.js",
"commit-msg": "node scripts/commit-msg.js"
}
},
"lint-staged": {
"*.ts": [
"prettier --write",
"tslint --fix",
"git add"
]
},
"config": {
"commitizen": {
"path": "@commitlint/prompt"
}
},
"build": {
"appId": "com.streamlabs.slobs",
Expand Down Expand Up @@ -89,6 +118,10 @@
"@babel/core": "^7.1.6",
"@babel/plugin-proposal-decorators": "^7.1.6",
"@babel/preset-env": "^7.1.6",
"@commitlint/cli": "^7.2.1",
"@commitlint/config-conventional": "^7.1.2",
"@commitlint/prompt": "^7.2.1",
"@commitlint/prompt-cli": "^7.2.1",
"@sentry/browser": "^4.4.1",
"@types/archiver": "2.1.2",
"@types/lodash": "4.14.115",
Expand All @@ -99,40 +132,47 @@
"@types/webdriverio": "^4.13.0",
"@xkeshi/vue-qrcode": "0.3.0",
"ava": "v1.0.0-rc.2",
"babel-eslint": "8.2.6",
"babel-eslint": "10.0.1",
"babel-loader": "^8.0.4",
"babel-plugin-transform-class-properties": "6.24.1",
"babel-plugin-transform-decorators-legacy": "1.3.5",
"circular-dependency-plugin": "3.0.0",
"commitizen": "^3.0.4",
"cross-spawn": "^6.0.5",
"css-element-queries": "^1.0.2",
"css-loader": "0.28.11",
"devtron": "1.4.0",
"electron": "2.0.14",
"electron-builder": "20.22.0",
"electron-devtools-installer": "2.2.4",
"emojione": "3.1.7",
"eslint": "3.19.0",
"eslint-config-airbnb": "14.1.0",
"eslint-plugin-import": "2.13.0",
"eslint-plugin-jsx-a11y": "4.0.0",
"eslint-plugin-react": "6.10.3",
"eslint": "^4.12.1",
"eslint-config-airbnb": "^17.1.0",
"eslint-config-prettier": "^3.3.0",
"eslint-import-resolver-webpack": "^0.10.1",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-jsx-a11y": "^6.1.1",
"eslint-plugin-react": "^7.11.0",
"eslint-plugin-vue": "2.1.0",
"file-loader": "1.1.11",
"fuse.js": "3.2.1",
"husky": "^1.2.0",
"js-yaml": "3.12.0",
"less": "2.7.3",
"less-loader": "4.1.0",
"lint-staged": "^8.1.0",
"lodash": "4.17.10",
"lodash-decorators": "4.3.1",
"moment": "2.22.2",
"node-win32-np": "1.0.6",
"pixelmatch": "4.0.2",
"pngjs": "3.3.3",
"prettier": "^1.15.2",
"progress": "2.0.0",
"read-pkg-up": "^4.0.0",
"recursive-readdir": "^2.2.2",
"reflect-metadata": "0.1.12",
"rxjs": "6.3.3",
"shx": "^0.3.2",
"sl-vue-tree": "https://github.com/stream-labs/sl-vue-tree.git",
"sockjs": "0.3.19",
"sockjs-client": "1.1.5",
Expand All @@ -145,7 +185,7 @@
"tslint-config-prettier": "1.14.0",
"tslint-loader": "3.6.0",
"typedoc": "0.11.1",
"typescript": "3.2.1",
"typescript": "^3.2.1",
"unzip-stream": "0.3.0",
"urijs": "1.19.1",
"v-tooltip": "2.0.0-rc.31",
Expand All @@ -167,9 +207,10 @@
"vuex": "3.0.1",
"webdriverio": "^4.14.1",
"webpack": "4.26.1",
"webpack-cli": "3.1.2"
"webpack-cli": "3.1.2",
"which": "^1.3.1"
},
"resolutions": {
"uglify-es": "3.3.9"
}
}
}
15 changes: 15 additions & 0 deletions scripts/commit-msg.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const spawn = require('cross-spawn');
const { isOptedIn, resolveBin } = require('./utils');

if (!isOptedIn('commit-msg')) {
process.exit(0);
}

const result = spawn.sync(resolveBin('commitlint'), ['-E', 'HUSKY_GIT_PARAMS'], {
stdio: 'inherit',
});

process.stdout.write('\n');
if (result.status !== 0) {
process.exit(result.status);
}
19 changes: 19 additions & 0 deletions scripts/precommit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const spawn = require('cross-spawn');
const { isOptedIn, resolveBin } = require('./utils');

const args = process.argv.slice(2);

const config = [];

if (!isOptedIn('pre-commit')) {
process.exit(0);
}

const lintStagedResult = spawn.sync(resolveBin('lint-staged'), [], {
env: process.env,
stdio: 'inherit',
});

if (lintStagedResult.status !== 0) {
process.exit(lintStagedResult.status);
}
48 changes: 48 additions & 0 deletions scripts/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/* eslint-disable import/no-dynamic-require,global-require */
const fs = require('fs');
const which = require('which');
const path = require('path');
const readPkgUp = require('read-pkg-up')

function resolveBin(modName, { executable = modName, cwd = process.cwd() } = {}) {
let pathFromWhich;
try {
pathFromWhich = fs.realpathSync(which.sync(executable));
} catch (_error) {
// ignore _error
}
try {
const modPkgPath = require.resolve(`${modName}/package.json`);
const modPkgDir = path.dirname(modPkgPath);
const { bin } = require(modPkgPath);
const binPath = typeof bin === 'string' ? bin : bin[executable];
const fullPathToBin = path.join(modPkgDir, binPath);
if (fullPathToBin === pathFromWhich) {
return executable;
}
return fullPathToBin.replace(cwd, '.');
} catch (error) {
if (pathFromWhich) {
return executable;
}
throw error;
}
}
const { pkg, path: pkgPath } = readPkgUp.sync({
cwd: fs.realpathSync(process.cwd()),
});
const appDirectory = path.dirname(pkgPath);
const fromRoot = (...p) => path.join(appDirectory, ...p);

function isOptedIn(key, t = true, f = false) {
if (!fs.existsSync(fromRoot('.opt-in'))) {
return f;
}
const contents = fs.readFileSync(fromRoot('.opt-in'), 'utf-8');
return contents.includes(key) ? t : f;
}

module.exports = {
resolveBin,
isOptedIn,
};
Loading

0 comments on commit 465d7d2

Please sign in to comment.