@companion-module/tools 1.2.1 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/README.md +2 -0
- package/eslint/fragments.cjs +51 -53
- package/eslint/index.cjs +96 -0
- package/eslint/main.cjs +5 -91
- package/package.json +12 -12
- package/scripts/build.js +40 -4
- package/scripts/check.js +0 -0
- package/scripts/generate-manifest.js +0 -0
- package/webpack.config.cjs +3 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [1.3.1](https://github.com/bitfocus/companion-module-tools/compare/v1.3.0...v1.3.1) (2023-06-08)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* update readme ([def7f19](https://github.com/bitfocus/companion-module-tools/commit/def7f19ff41412d1b85e13beee277b48247a2c6c))
|
|
9
|
+
|
|
10
|
+
## [1.3.0](https://github.com/bitfocus/companion-module-tools/compare/v1.2.1...v1.3.0) (2023-06-08)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Features
|
|
14
|
+
|
|
15
|
+
* add option to build with support for node-gyp-build ([#24](https://github.com/bitfocus/companion-module-tools/issues/24)) ([2a4e311](https://github.com/bitfocus/companion-module-tools/commit/2a4e3115ca26c695d409080d07ef8ad5e6dd840a))
|
|
16
|
+
* rework eslint config to be generated to allow further customisation ([e30ae2b](https://github.com/bitfocus/companion-module-tools/commit/e30ae2b23714e858eb333c9be9396d03f187dbee))
|
|
17
|
+
|
|
3
18
|
## [1.2.1](https://github.com/bitfocus/companion-module-tools/compare/v1.2.0...v1.2.1) (2023-05-12)
|
|
4
19
|
|
|
5
20
|
|
package/README.md
CHANGED
|
@@ -8,6 +8,8 @@ This is a collection of tools, used for developing and verifying Companion modul
|
|
|
8
8
|
|
|
9
9
|
When used, this will build a module ready for distibution
|
|
10
10
|
|
|
11
|
+
More information on this command is available [on the wiki](https://github.com/bitfocus/companion-module-base/wiki/Module-packaging)
|
|
12
|
+
|
|
11
13
|
### companion-generate-manifest
|
|
12
14
|
|
|
13
15
|
Generate the new format manifest from an old package.json
|
package/eslint/fragments.cjs
CHANGED
|
@@ -1,64 +1,62 @@
|
|
|
1
|
-
const enableJest = false // TODO
|
|
2
|
-
|
|
3
1
|
function compact(arr) {
|
|
4
2
|
return arr.filter((v) => v !== undefined && v !== null)
|
|
5
3
|
}
|
|
6
4
|
|
|
7
|
-
module.exports = {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
tsPlugins: compact(['@typescript-eslint', 'prettier', enableJest ? 'jest' : null]),
|
|
5
|
+
module.exports = function createFragments(enableJest) {
|
|
6
|
+
return {
|
|
7
|
+
commonPlugins: compact(['prettier', enableJest ? 'jest' : null]),
|
|
8
|
+
tsPlugins: compact(['@typescript-eslint', 'prettier', enableJest ? 'jest' : null]),
|
|
12
9
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
10
|
+
commonExtends: ['eslint:recommended', 'plugin:n/recommended', 'plugin:prettier/recommended'],
|
|
11
|
+
tsExtends: compact([
|
|
12
|
+
'eslint:recommended',
|
|
13
|
+
'plugin:@typescript-eslint/eslint-recommended',
|
|
14
|
+
'plugin:@typescript-eslint/recommended',
|
|
15
|
+
'plugin:@typescript-eslint/recommended-requiring-type-checking',
|
|
16
|
+
'plugin:n/recommended',
|
|
17
|
+
enableJest ? 'plugin:jest/recommended' : null,
|
|
18
|
+
'prettier',
|
|
19
|
+
'plugin:prettier/recommended',
|
|
20
|
+
]),
|
|
24
21
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
22
|
+
commonRules: {
|
|
23
|
+
'prettier/prettier': 'error',
|
|
24
|
+
'no-unused-vars': ['error', { argsIgnorePattern: '^_', varsIgnorePattern: '^_(.+)' }],
|
|
25
|
+
'no-extra-semi': 'off',
|
|
26
|
+
'n/no-unsupported-features/es-syntax': ['error', { ignores: ['modules'] }],
|
|
27
|
+
'no-use-before-define': 'off',
|
|
28
|
+
'no-warning-comments': ['error', { terms: ['nocommit', '@nocommit', '@no-commit'] }],
|
|
29
|
+
'jest/no-mocks-import': 'off',
|
|
30
|
+
},
|
|
31
|
+
tsRules: {
|
|
32
|
+
'no-unused-vars': 'off',
|
|
33
|
+
'@typescript-eslint/no-explicit-any': 'off',
|
|
34
|
+
'@typescript-eslint/interface-name-prefix': 'off',
|
|
35
|
+
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_', varsIgnorePattern: '^_(.+)' }],
|
|
36
|
+
'@typescript-eslint/no-floating-promises': 'error',
|
|
37
|
+
'@typescript-eslint/explicit-module-boundary-types': ['error'],
|
|
38
|
+
'@typescript-eslint/promise-function-async': 'error',
|
|
39
|
+
'@typescript-eslint/require-await': 'off', // conflicts with 'promise-function-async'
|
|
43
40
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
41
|
+
/** Disable some annoyingly strict rules from the 'recommended-requiring-type-checking' pack */
|
|
42
|
+
'@typescript-eslint/no-unsafe-assignment': 0,
|
|
43
|
+
'@typescript-eslint/no-unsafe-member-access': 0,
|
|
44
|
+
'@typescript-eslint/no-unsafe-argument': 0,
|
|
45
|
+
'@typescript-eslint/no-unsafe-return': 0,
|
|
46
|
+
'@typescript-eslint/no-unsafe-call': 0,
|
|
47
|
+
'@typescript-eslint/restrict-template-expressions': 0,
|
|
48
|
+
'@typescript-eslint/restrict-plus-operands': 0,
|
|
49
|
+
/** End 'recommended-requiring-type-checking' overrides */
|
|
50
|
+
},
|
|
54
51
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
52
|
+
tsParser: {
|
|
53
|
+
parser: '@typescript-eslint/parser',
|
|
54
|
+
parserOptions: { project: './tsconfig.json' },
|
|
55
|
+
settings: {
|
|
56
|
+
node: {
|
|
57
|
+
tryExtensions: ['.js', '.json', '.node', '.ts', '.d.ts'],
|
|
58
|
+
},
|
|
61
59
|
},
|
|
62
60
|
},
|
|
63
|
-
}
|
|
61
|
+
}
|
|
64
62
|
}
|
package/eslint/index.cjs
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
const createFragments = require('./fragments.cjs')
|
|
2
|
+
|
|
3
|
+
module.exports = function generateEslintConfig(options = {}) {
|
|
4
|
+
const { commonPlugins, tsPlugins, commonExtends, tsExtends, commonRules, tsRules, tsParser } = createFragments(
|
|
5
|
+
options.enableJest
|
|
6
|
+
)
|
|
7
|
+
|
|
8
|
+
const disableJest = options.enableJest
|
|
9
|
+
? {
|
|
10
|
+
'jest/globals': false, // Block jest from this
|
|
11
|
+
}
|
|
12
|
+
: {}
|
|
13
|
+
const allowJest = options.enableJest
|
|
14
|
+
? {
|
|
15
|
+
'jest/globals': true,
|
|
16
|
+
jest: true,
|
|
17
|
+
}
|
|
18
|
+
: {}
|
|
19
|
+
|
|
20
|
+
const result = {
|
|
21
|
+
extends: commonExtends,
|
|
22
|
+
plugins: commonPlugins,
|
|
23
|
+
rules: {
|
|
24
|
+
'prettier/prettier': 'error',
|
|
25
|
+
},
|
|
26
|
+
env: { es2017: true },
|
|
27
|
+
parserOptions: { sourceType: 'module', ecmaVersion: 2022 },
|
|
28
|
+
overrides: [
|
|
29
|
+
// Note: the overrides replace the values defined above, so make sure to extend them if they are needed
|
|
30
|
+
{
|
|
31
|
+
files: ['*.js', '*.cjs', '*.mjs'],
|
|
32
|
+
settings: {
|
|
33
|
+
node: {
|
|
34
|
+
tryExtensions: ['.js', '.json', '.node', '.ts'],
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
env: {
|
|
38
|
+
...disableJest,
|
|
39
|
+
},
|
|
40
|
+
rules: {
|
|
41
|
+
...commonRules,
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (options.enableTypescript) {
|
|
48
|
+
result.overrides.push(
|
|
49
|
+
{
|
|
50
|
+
files: ['*.ts'],
|
|
51
|
+
extends: tsExtends,
|
|
52
|
+
plugins: tsPlugins,
|
|
53
|
+
...tsParser,
|
|
54
|
+
env: {
|
|
55
|
+
...disableJest,
|
|
56
|
+
},
|
|
57
|
+
rules: {
|
|
58
|
+
...commonRules,
|
|
59
|
+
...tsRules,
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
files: ['src/**/__tests__/**/*.ts'],
|
|
64
|
+
extends: tsExtends,
|
|
65
|
+
plugins: tsPlugins,
|
|
66
|
+
...tsParser,
|
|
67
|
+
env: {
|
|
68
|
+
...allowJest,
|
|
69
|
+
},
|
|
70
|
+
rules: {
|
|
71
|
+
...commonRules,
|
|
72
|
+
...tsRules,
|
|
73
|
+
'@typescript-eslint/ban-ts-ignore': 'off',
|
|
74
|
+
'@typescript-eslint/ban-ts-comment': 'off',
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
files: ['examples/**/*.ts'],
|
|
79
|
+
extends: tsExtends,
|
|
80
|
+
plugins: tsPlugins,
|
|
81
|
+
...tsParser,
|
|
82
|
+
env: {
|
|
83
|
+
...disableJest,
|
|
84
|
+
},
|
|
85
|
+
rules: {
|
|
86
|
+
...commonRules,
|
|
87
|
+
...tsRules,
|
|
88
|
+
'no-process-exit': 'off',
|
|
89
|
+
'n/no-missing-import': 'off',
|
|
90
|
+
},
|
|
91
|
+
}
|
|
92
|
+
)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return result
|
|
96
|
+
}
|
package/eslint/main.cjs
CHANGED
|
@@ -1,92 +1,6 @@
|
|
|
1
|
-
const
|
|
2
|
-
commonPlugins,
|
|
3
|
-
tsPlugins,
|
|
4
|
-
commonExtends,
|
|
5
|
-
tsExtends,
|
|
6
|
-
commonRules,
|
|
7
|
-
tsRules,
|
|
8
|
-
tsParser,
|
|
9
|
-
enableJest,
|
|
10
|
-
} = require('./fragments.cjs')
|
|
1
|
+
const generateEslintConfig = require('./index.cjs')
|
|
11
2
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
: {}
|
|
17
|
-
const allowJest = enableJest
|
|
18
|
-
? {
|
|
19
|
-
'jest/globals': true,
|
|
20
|
-
jest: true,
|
|
21
|
-
}
|
|
22
|
-
: {}
|
|
23
|
-
|
|
24
|
-
module.exports = {
|
|
25
|
-
extends: commonExtends,
|
|
26
|
-
plugins: commonPlugins,
|
|
27
|
-
rules: {
|
|
28
|
-
'prettier/prettier': 'error',
|
|
29
|
-
},
|
|
30
|
-
env: { es2017: true },
|
|
31
|
-
parserOptions: { sourceType: 'module', ecmaVersion: 2018 },
|
|
32
|
-
overrides: [
|
|
33
|
-
// Note: these replace the values defined above, so make sure to extend them if they are needed
|
|
34
|
-
{
|
|
35
|
-
files: ['*.ts'],
|
|
36
|
-
extends: tsExtends,
|
|
37
|
-
plugins: tsPlugins,
|
|
38
|
-
...tsParser,
|
|
39
|
-
env: {
|
|
40
|
-
...disableJest,
|
|
41
|
-
},
|
|
42
|
-
rules: {
|
|
43
|
-
...commonRules,
|
|
44
|
-
...tsRules,
|
|
45
|
-
},
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
files: ['*.js'],
|
|
49
|
-
settings: {
|
|
50
|
-
node: {
|
|
51
|
-
tryExtensions: ['.js', '.json', '.node', '.ts'],
|
|
52
|
-
},
|
|
53
|
-
},
|
|
54
|
-
env: {
|
|
55
|
-
...disableJest,
|
|
56
|
-
},
|
|
57
|
-
rules: {
|
|
58
|
-
...commonRules,
|
|
59
|
-
},
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
files: ['src/**/__tests__/**/*.ts'],
|
|
63
|
-
extends: tsExtends,
|
|
64
|
-
plugins: tsPlugins,
|
|
65
|
-
...tsParser,
|
|
66
|
-
env: {
|
|
67
|
-
...allowJest,
|
|
68
|
-
},
|
|
69
|
-
rules: {
|
|
70
|
-
...commonRules,
|
|
71
|
-
...tsRules,
|
|
72
|
-
'@typescript-eslint/ban-ts-ignore': 'off',
|
|
73
|
-
'@typescript-eslint/ban-ts-comment': 'off',
|
|
74
|
-
},
|
|
75
|
-
},
|
|
76
|
-
{
|
|
77
|
-
files: ['examples/**/*.ts'],
|
|
78
|
-
extends: tsExtends,
|
|
79
|
-
plugins: tsPlugins,
|
|
80
|
-
...tsParser,
|
|
81
|
-
env: {
|
|
82
|
-
...disableJest,
|
|
83
|
-
},
|
|
84
|
-
rules: {
|
|
85
|
-
...commonRules,
|
|
86
|
-
...tsRules,
|
|
87
|
-
'no-process-exit': 'off',
|
|
88
|
-
'node/no-missing-import': 'off',
|
|
89
|
-
},
|
|
90
|
-
},
|
|
91
|
-
],
|
|
92
|
-
}
|
|
3
|
+
/**
|
|
4
|
+
* @deprecated use the line like below to generate your own config
|
|
5
|
+
*/
|
|
6
|
+
module.exports = generateEslintConfig({ enableTypescript: true })
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@companion-module/tools",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"license": "MIT",
|
|
@@ -23,21 +23,21 @@
|
|
|
23
23
|
"webpack.*"
|
|
24
24
|
],
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
27
|
-
"@typescript-eslint/parser": "^5.
|
|
28
|
-
"eslint": "^8.
|
|
29
|
-
"eslint-config-prettier": "^8.
|
|
30
|
-
"eslint-plugin-
|
|
26
|
+
"@typescript-eslint/eslint-plugin": "^5.59.9",
|
|
27
|
+
"@typescript-eslint/parser": "^5.59.9",
|
|
28
|
+
"eslint": "^8.42.0",
|
|
29
|
+
"eslint-config-prettier": "^8.8.0",
|
|
30
|
+
"eslint-plugin-n": "^16.0.0",
|
|
31
31
|
"eslint-plugin-prettier": "^4.2.1",
|
|
32
32
|
"find-up": "^6.3.0",
|
|
33
33
|
"parse-author": "^2.0.0",
|
|
34
|
-
"prettier": "^2.8.
|
|
35
|
-
"tar": "^6.1.
|
|
36
|
-
"webpack": "^5.
|
|
37
|
-
"webpack-cli": "^5.
|
|
38
|
-
"zx": "^7.
|
|
34
|
+
"prettier": "^2.8.8",
|
|
35
|
+
"tar": "^6.1.15",
|
|
36
|
+
"webpack": "^5.86.0",
|
|
37
|
+
"webpack-cli": "^5.1.4",
|
|
38
|
+
"zx": "^7.2.2"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
|
-
"@companion-module/base": "^1.
|
|
41
|
+
"@companion-module/base": "^1.4.1"
|
|
42
42
|
}
|
|
43
43
|
}
|
package/scripts/build.js
CHANGED
|
@@ -30,12 +30,17 @@ console.log(`Framework path: ${frameworkDir}`)
|
|
|
30
30
|
// clean old
|
|
31
31
|
await fs.remove('pkg')
|
|
32
32
|
|
|
33
|
-
const webpackArgs =
|
|
34
|
-
if (argv.dev) webpackArgs
|
|
33
|
+
const webpackArgs = {}
|
|
34
|
+
if (argv.dev || argv.debug) webpackArgs['env']= 'dev'
|
|
35
|
+
|
|
36
|
+
const webpackArgsArray = []
|
|
37
|
+
for (const [k, v] of Object.entries(webpackArgs)) {
|
|
38
|
+
webpackArgsArray.push(`--${k}`, v)
|
|
39
|
+
}
|
|
35
40
|
|
|
36
41
|
// build the code
|
|
37
42
|
const webpackConfig = path.join(toolsDir, 'webpack.config.cjs').replace(/\\/g, '/') // Fix slashes because windows is a pain
|
|
38
|
-
await $`yarn webpack -c ${webpackConfig} ${
|
|
43
|
+
await $`yarn webpack -c ${webpackConfig} ${webpackArgsArray}`
|
|
39
44
|
|
|
40
45
|
// copy in the metadata
|
|
41
46
|
await fs.copy('companion', 'pkg/companion')
|
|
@@ -84,7 +89,7 @@ if (fs.existsSync(webpackExtPath)) {
|
|
|
84
89
|
for (const external of Object.keys(extGroup)) {
|
|
85
90
|
const extPath = await findUp('package.json', { cwd: require.resolve(external) })
|
|
86
91
|
const extJson = JSON.parse(await fs.readFile(extPath))
|
|
87
|
-
packageJson.dependencies[
|
|
92
|
+
packageJson.dependencies[external] = extJson.version
|
|
88
93
|
}
|
|
89
94
|
}
|
|
90
95
|
}
|
|
@@ -114,6 +119,37 @@ if (fs.existsSync(webpackExtPath)) {
|
|
|
114
119
|
}
|
|
115
120
|
}
|
|
116
121
|
|
|
122
|
+
// Copy node-gyp-build prebulds
|
|
123
|
+
const webpackConfigJson = await require(webpackConfig)(webpackArgs)
|
|
124
|
+
if (webpackConfigJson.node?.__dirname === true) {
|
|
125
|
+
const copyNodeGypBuildPrebuilds = (thisPath) => {
|
|
126
|
+
const nodeModPath = path.join(thisPath, 'node_modules')
|
|
127
|
+
if (fs.existsSync(nodeModPath)) {
|
|
128
|
+
for (const dir of fs.readdirSync(nodeModPath)) {
|
|
129
|
+
const modDir = path.join(nodeModPath, dir)
|
|
130
|
+
copyNodeGypBuildPrebuilds(modDir)
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const pkgJsonPath = path.join(thisPath, 'package.json')
|
|
135
|
+
if (thisPath && fs.existsSync(pkgJsonPath)) {
|
|
136
|
+
const dirPkgJsonStr = fs.readFileSync(pkgJsonPath)
|
|
137
|
+
const dirPkgJson = JSON.parse(dirPkgJsonStr.toString())
|
|
138
|
+
|
|
139
|
+
const prebuildsDir = path.join(thisPath, 'prebuilds')
|
|
140
|
+
if (dirPkgJson.dependencies?.['node-gyp-build'] && fs.existsSync(prebuildsDir)) {
|
|
141
|
+
fs.mkdirpSync(path.join('pkg', thisPath))
|
|
142
|
+
fs.copySync(prebuildsDir, path.join('pkg', prebuildsDir))
|
|
143
|
+
|
|
144
|
+
console.log('copying node-gyp-build prebuilds from', thisPath)
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
copyNodeGypBuildPrebuilds('')
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
|
|
117
153
|
// Write the package.json
|
|
118
154
|
// packageJson.bundleDependencies = Object.keys(packageJson.dependencies)
|
|
119
155
|
await fs.writeFile('pkg/package.json', JSON.stringify(packageJson))
|
package/scripts/check.js
CHANGED
|
File without changes
|
|
File without changes
|
package/webpack.config.cjs
CHANGED
|
@@ -58,5 +58,8 @@ module.exports = async (env) => {
|
|
|
58
58
|
// Let modules define additional plugins. Hopefully this won't conflict with anything we add
|
|
59
59
|
...(webpackExt.plugins || []),
|
|
60
60
|
],
|
|
61
|
+
node: webpackExt.useOriginalStructureDirname ? {
|
|
62
|
+
__dirname: true
|
|
63
|
+
} : undefined,
|
|
61
64
|
}
|
|
62
65
|
}
|