@jcoreio/toolchain 1.0.0-beta.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/.eslintrc.js +6 -0
- package/bin/commitizen +5 -0
- package/bin/commitlint +5 -0
- package/bin/cz +5 -0
- package/bin/eslint +5 -0
- package/bin/git-cz +5 -0
- package/bin/lint-fix.cjs +8 -0
- package/bin/lint-staged +5 -0
- package/bin/prettier +5 -0
- package/bin/resolveBin.cjs +8 -0
- package/bin/semantic-release +5 -0
- package/commitizen.cjs +1 -0
- package/commitlint.config.cjs +11 -0
- package/eslint.config.cjs +8 -0
- package/eslint.extends.cjs +54 -0
- package/githooks/applypatch-msg +3 -0
- package/githooks/commit-msg +3 -0
- package/githooks/post-applypatch +3 -0
- package/githooks/post-checkout +3 -0
- package/githooks/post-commit +3 -0
- package/githooks/post-merge +3 -0
- package/githooks/post-receive +3 -0
- package/githooks/post-rewrite +3 -0
- package/githooks/post-update +3 -0
- package/githooks/pre-applypatch +3 -0
- package/githooks/pre-auto-gc +3 -0
- package/githooks/pre-commit +3 -0
- package/githooks/pre-merge-commit +3 -0
- package/githooks/pre-push +3 -0
- package/githooks/pre-rebase +3 -0
- package/githooks/pre-receive +3 -0
- package/githooks/prepare-commit-msg +3 -0
- package/githooks/push-to-checkout +3 -0
- package/githooks/runHook.cjs +32 -0
- package/githooks.cjs +5 -0
- package/lint-staged.config.cjs +20 -0
- package/package.json +60 -0
- package/plugins/buildDistPackageJson.cjs +7 -0
- package/plugins/compile.cjs +21 -0
- package/plugins/formatExtensions.cjs +12 -0
- package/plugins/getConfigFiles.cjs +57 -0
- package/plugins/getEslintExtends.cjs +1 -0
- package/plugins/lintExtensions.cjs +1 -0
- package/plugins/sourceExtensions.cjs +1 -0
- package/prettier.config.cjs +5 -0
- package/release.config.cjs +16 -0
- package/scripts/bootstrap/bootstrapConfigFiles.cjs +18 -0
- package/scripts/bootstrap/bootstrapEslintConfigs.cjs +30 -0
- package/scripts/bootstrap/bootstrapGitignore.cjs +37 -0
- package/scripts/bootstrap/bootstrapMoveTypeDefs.cjs +14 -0
- package/scripts/bootstrap/bootstrapProjectPackageJson.cjs +76 -0
- package/scripts/bootstrap/bootstrapRemoveDevDeps.cjs +110 -0
- package/scripts/bootstrap/bootstrapRemoveFiles.cjs +50 -0
- package/scripts/bootstrap/installGitHooks.cjs +31 -0
- package/scripts/bootstrap.cjs +48 -0
- package/scripts/build.cjs +66 -0
- package/scripts/check.cjs +19 -0
- package/scripts/clean.cjs +6 -0
- package/scripts/coverage.cjs +12 -0
- package/scripts/format.cjs +4 -0
- package/scripts/init.cjs +55 -0
- package/scripts/lint-fix.cjs +4 -0
- package/scripts/lint.cjs +4 -0
- package/scripts/open-coverage.cjs +7 -0
- package/scripts/preinstall/preinstallRemoveDevDeps.cjs +65 -0
- package/scripts/preinstall/preinstallRemoveFiles.cjs +50 -0
- package/scripts/preinstall/preinstallUpdateProjectPackageJson.cjs +39 -0
- package/scripts/preinstall.cjs +35 -0
- package/scripts/prepublish.cjs +11 -0
- package/scripts/runEslint.cjs +34 -0
- package/scripts/runPrettier.cjs +27 -0
- package/scripts/test.cjs +12 -0
- package/scripts/toolchain.cjs +82 -0
- package/util/ChdirFs.cjs +50 -0
- package/util/execa.cjs +72 -0
- package/util/findUps.cjs +44 -0
- package/util/getPlugins.cjs +21 -0
- package/util/getPluginsArraySync.cjs +14 -0
- package/util/getPluginsAsyncFunction.cjs +12 -0
- package/util/getPluginsObject.cjs +12 -0
- package/util/glob.cjs +6 -0
- package/util/hasTSSourcesSync.cjs +7 -0
- package/util/ini.cjs +36 -0
- package/util/once.cjs +6 -0
- package/util/projectFs.cjs +4 -0
- package/util/sortDeps.cjs +21 -0
- package/util/sortPlugins.cjs +67 -0
package/.eslintrc.js
ADDED
package/bin/commitizen
ADDED
package/bin/commitlint
ADDED
package/bin/cz
ADDED
package/bin/eslint
ADDED
package/bin/git-cz
ADDED
package/bin/lint-fix.cjs
ADDED
package/bin/lint-staged
ADDED
package/bin/prettier
ADDED
package/commitizen.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('cz-conventional-changelog')
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
extends: ['eslint:recommended'],
|
|
3
|
+
rules: {
|
|
4
|
+
'arrow-spacing': 'error',
|
|
5
|
+
'comma-spacing': 'error',
|
|
6
|
+
'computed-property-spacing': ['error', 'never'],
|
|
7
|
+
'eol-last': 'error',
|
|
8
|
+
'jsx-quotes': 'error',
|
|
9
|
+
'keyword-spacing': 'error',
|
|
10
|
+
'key-spacing': [
|
|
11
|
+
'error',
|
|
12
|
+
{
|
|
13
|
+
mode: 'strict',
|
|
14
|
+
},
|
|
15
|
+
],
|
|
16
|
+
'linebreak-style': 'error',
|
|
17
|
+
'no-console': 'error',
|
|
18
|
+
'no-unused-vars': [
|
|
19
|
+
'error',
|
|
20
|
+
{
|
|
21
|
+
args: 'none',
|
|
22
|
+
varsIgnorePattern: 'React',
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
'no-extra-semi': 'error',
|
|
26
|
+
'no-multi-spaces': 'error',
|
|
27
|
+
'no-multiple-empty-lines': 'error',
|
|
28
|
+
'no-trailing-spaces': 'error',
|
|
29
|
+
'no-unexpected-multiline': 'error',
|
|
30
|
+
'no-unreachable': 'error',
|
|
31
|
+
'no-whitespace-before-property': 'error',
|
|
32
|
+
'object-shorthand': ['error', 'always'],
|
|
33
|
+
'padded-blocks': ['error', 'never'],
|
|
34
|
+
semi: ['error', 'never'],
|
|
35
|
+
'space-before-blocks': ['error', 'always'],
|
|
36
|
+
'space-before-function-paren': [
|
|
37
|
+
'error',
|
|
38
|
+
{
|
|
39
|
+
anonymous: 'always',
|
|
40
|
+
named: 'never',
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
'space-in-parens': ['error', 'never'],
|
|
44
|
+
'space-infix-ops': ['error', { int32Hint: false }],
|
|
45
|
+
'space-unary-ops': [
|
|
46
|
+
'error',
|
|
47
|
+
{
|
|
48
|
+
words: true,
|
|
49
|
+
nonwords: false,
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
'rest-spread-spacing': ['error', 'never'],
|
|
53
|
+
},
|
|
54
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
const Path = require('path')
|
|
2
|
+
const { findGitDir } = require('../util/findUps.cjs')
|
|
3
|
+
const execa = require('../util/execa.cjs')
|
|
4
|
+
|
|
5
|
+
module.exports = async function runHook(hook) {
|
|
6
|
+
try {
|
|
7
|
+
const gitDir = findGitDir()
|
|
8
|
+
if (!gitDir) {
|
|
9
|
+
throw new Error(`failed to find .git directory`)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const projDir = Path.dirname(gitDir)
|
|
13
|
+
let hooks
|
|
14
|
+
try {
|
|
15
|
+
hooks = require(Path.join(projDir, 'githooks.cjs'))
|
|
16
|
+
} catch (error) {
|
|
17
|
+
hooks = require('../githooks.cjs')
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (hooks[hook]) {
|
|
21
|
+
await execa(hooks[hook], {
|
|
22
|
+
cwd: projDir,
|
|
23
|
+
shell: true,
|
|
24
|
+
})
|
|
25
|
+
}
|
|
26
|
+
} catch (error) {
|
|
27
|
+
const { exitCode } = error
|
|
28
|
+
process.exit(exitCode != null ? exitCode : 1)
|
|
29
|
+
return
|
|
30
|
+
}
|
|
31
|
+
process.exit(0)
|
|
32
|
+
}
|
package/githooks.cjs
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const getPluginsArraySync = require('./util/getPluginsArraySync.cjs')
|
|
2
|
+
|
|
3
|
+
const lintExtList = getPluginsArraySync('lintExtensions')
|
|
4
|
+
|
|
5
|
+
const lintExts =
|
|
6
|
+
lintExtList.length === 1
|
|
7
|
+
? `*.${lintExtList[0]}`
|
|
8
|
+
: `*.{${lintExtList.join(',')}}`
|
|
9
|
+
|
|
10
|
+
const formatExtList = getPluginsArraySync('formatExtensions')
|
|
11
|
+
|
|
12
|
+
const formatExts =
|
|
13
|
+
formatExtList.length === 1
|
|
14
|
+
? `*.${formatExtList[0]}`
|
|
15
|
+
: `*.{${formatExtList.join(',')}}`
|
|
16
|
+
|
|
17
|
+
module.exports = {
|
|
18
|
+
[lintExts]: ['tc lint:fix'],
|
|
19
|
+
[formatExts]: ['tc format'],
|
|
20
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@jcoreio/toolchain",
|
|
3
|
+
"version": "1.0.0-beta.1",
|
|
4
|
+
"description": "base JS build toolchain",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/jcoreio/toolchains.git",
|
|
8
|
+
"directory": "packages/base"
|
|
9
|
+
},
|
|
10
|
+
"author": "Andy Edwards",
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/jcoreio/toolchains/issues"
|
|
14
|
+
},
|
|
15
|
+
"homepage": "https://github.com/jcoreio/toolchains/tree/beta/packages/base",
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@commitlint/cli": "^15.0.0",
|
|
18
|
+
"@commitlint/config-conventional": "^15.0.0",
|
|
19
|
+
"@semantic-release/commit-analyzer": "^9.0.2",
|
|
20
|
+
"@semantic-release/github": "^8.0.4",
|
|
21
|
+
"@semantic-release/npm": "^10.0.4",
|
|
22
|
+
"@semantic-release/release-notes-generator": "^10.0.3",
|
|
23
|
+
"chalk": "^4.0.0",
|
|
24
|
+
"commitizen": "^4.2.4",
|
|
25
|
+
"cz-conventional-changelog": "^3.3.0",
|
|
26
|
+
"dedent-js": "^1.0.1",
|
|
27
|
+
"eslint": "^8.5.0",
|
|
28
|
+
"eslint-config-prettier": "^8.3.0",
|
|
29
|
+
"execa": "^5.0.0",
|
|
30
|
+
"find-up": "^5.0.0",
|
|
31
|
+
"fs-extra": "^10.0.0",
|
|
32
|
+
"json5": "^2.2.1",
|
|
33
|
+
"lint-staged": "^12.1.4",
|
|
34
|
+
"lodash": "^4.17.21",
|
|
35
|
+
"open": "^8.4.0",
|
|
36
|
+
"prettier": "^2.5.1",
|
|
37
|
+
"resolve-bin": "^1.0.0",
|
|
38
|
+
"semantic-release": "^21.0.5",
|
|
39
|
+
"toposort": "^2.0.2"
|
|
40
|
+
},
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"eslint": "^8.0.0"
|
|
43
|
+
},
|
|
44
|
+
"bin": {
|
|
45
|
+
"commitizen": "./bin/commitizen",
|
|
46
|
+
"commitlint": "./bin/commitlint",
|
|
47
|
+
"cz": "./bin/cz",
|
|
48
|
+
"eslint": "./bin/eslint",
|
|
49
|
+
"git-cz": "./bin/git-cz",
|
|
50
|
+
"lint-staged": "./bin/lint-staged",
|
|
51
|
+
"prettier": "./bin/prettier",
|
|
52
|
+
"semantic-release": "./bin/semantic-release",
|
|
53
|
+
"tc": "./scripts/toolchain.cjs",
|
|
54
|
+
"toolchain": "./scripts/toolchain.cjs"
|
|
55
|
+
},
|
|
56
|
+
"scripts": {
|
|
57
|
+
"tc": "tc",
|
|
58
|
+
"toolchain": "toolchain"
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const Path = require('path')
|
|
2
|
+
const { projectDir } = require('../util/findUps.cjs')
|
|
3
|
+
const fs = require('../util/projectFs.cjs')
|
|
4
|
+
|
|
5
|
+
module.exports = [
|
|
6
|
+
async function compile(args = []) {
|
|
7
|
+
const ignoreEnoent = (err) => {
|
|
8
|
+
if (err.code !== 'ENOENT') throw err
|
|
9
|
+
}
|
|
10
|
+
const filter = (src, dest) => {
|
|
11
|
+
// eslint-disable-next-line no-console
|
|
12
|
+
console.error(
|
|
13
|
+
Path.relative(projectDir, src),
|
|
14
|
+
'->',
|
|
15
|
+
Path.relative(projectDir, dest)
|
|
16
|
+
)
|
|
17
|
+
return true
|
|
18
|
+
}
|
|
19
|
+
await fs.copy('src', 'dist', { filter }).catch(ignoreEnoent)
|
|
20
|
+
},
|
|
21
|
+
]
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
const { name } = require('../package.json')
|
|
2
|
+
const dedent = require('dedent-js')
|
|
3
|
+
const fs = require('../util/projectFs.cjs')
|
|
4
|
+
const JSON5 = require('json5')
|
|
5
|
+
|
|
6
|
+
async function getRootEslintConfig() {
|
|
7
|
+
if (await fs.pathExists('.eslintrc.json')) {
|
|
8
|
+
return JSON5.parse(await fs.readFile('.eslintrc.json', 'utf8'))
|
|
9
|
+
}
|
|
10
|
+
if (await fs.pathExists('.eslintrc')) {
|
|
11
|
+
return JSON5.parse(await fs.readFile('.eslintrc', 'utf8'))
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
module.exports = [
|
|
16
|
+
async function getConfigFiles() {
|
|
17
|
+
const { env, rules } = (await getRootEslintConfig()) || {}
|
|
18
|
+
const files = {
|
|
19
|
+
'.eslintrc.cjs': dedent`
|
|
20
|
+
/* eslint-env node, es2018 */
|
|
21
|
+
module.exports = {
|
|
22
|
+
extends: [require.resolve('${name}/eslint.config.cjs')],${
|
|
23
|
+
env
|
|
24
|
+
? `\nenv: ${JSON.stringify(env, null, 2).replace(/\n/gm, '\n ')},`
|
|
25
|
+
: ''
|
|
26
|
+
}${
|
|
27
|
+
rules
|
|
28
|
+
? `\nrules: ${JSON.stringify(rules, null, 2).replace(/\n/gm, '\n ')}`
|
|
29
|
+
: ''
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
`,
|
|
33
|
+
'release.config.js': dedent`
|
|
34
|
+
/* eslint-env node, es2018 */
|
|
35
|
+
module.exports = {
|
|
36
|
+
extends: [require.resolve('${name}/release.config.cjs')],
|
|
37
|
+
}
|
|
38
|
+
`,
|
|
39
|
+
}
|
|
40
|
+
for (const file of [
|
|
41
|
+
'commitlint.config.cjs',
|
|
42
|
+
'githooks.cjs',
|
|
43
|
+
'lint-staged.config.cjs',
|
|
44
|
+
'prettier.config.cjs',
|
|
45
|
+
]) {
|
|
46
|
+
files[file] = dedent`
|
|
47
|
+
/* eslint-env node, es2018 */
|
|
48
|
+
const base = require('${name}/${file}')
|
|
49
|
+
module.exports = {
|
|
50
|
+
...base,
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
`
|
|
54
|
+
}
|
|
55
|
+
return files
|
|
56
|
+
},
|
|
57
|
+
]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = [() => [require.resolve('../eslint.extends.cjs')]]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = [() => ['js', 'cjs', 'mjs']]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = [() => ['js', 'cjs', 'mjs']]
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const { projectDir } = require('./util/findUps.cjs')
|
|
2
|
+
const path = require('path')
|
|
3
|
+
|
|
4
|
+
module.exports = {
|
|
5
|
+
plugins: [
|
|
6
|
+
require.resolve('@semantic-release/commit-analyzer'),
|
|
7
|
+
require.resolve('@semantic-release/release-notes-generator'),
|
|
8
|
+
[
|
|
9
|
+
require.resolve('@semantic-release/npm'),
|
|
10
|
+
{
|
|
11
|
+
pkgRoot: path.join(projectDir, 'dist'),
|
|
12
|
+
},
|
|
13
|
+
],
|
|
14
|
+
require.resolve('@semantic-release/github'),
|
|
15
|
+
],
|
|
16
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const fs = require('../../util/projectFs.cjs')
|
|
2
|
+
const getPluginsObject = require('../../util/getPluginsObject.cjs')
|
|
3
|
+
|
|
4
|
+
async function bootstrapConfigFiles() {
|
|
5
|
+
const files = await getPluginsObject('getConfigFiles')
|
|
6
|
+
for (const file in files) {
|
|
7
|
+
const value = files[file]
|
|
8
|
+
const content = typeof value === 'string' ? value : value.content
|
|
9
|
+
const overwrite = typeof value === 'string' ? false : value.overwrite
|
|
10
|
+
if (overwrite || !(await fs.pathExists(file))) {
|
|
11
|
+
await fs.writeFile(file, content, 'utf8')
|
|
12
|
+
// eslint-disable-next-line no-console
|
|
13
|
+
console.error(`wrote ${file}`)
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
module.exports = bootstrapConfigFiles
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const glob = require('@jcoreio/toolchain/util/glob.cjs')
|
|
2
|
+
const Path = require('path')
|
|
3
|
+
const JSON5 = require('json5')
|
|
4
|
+
const fs = require('../../util/projectFs.cjs')
|
|
5
|
+
|
|
6
|
+
async function bootstrapEslintConfigs() {
|
|
7
|
+
for (const file of await glob(Path.join('**', '.eslintrc{,.json}'))) {
|
|
8
|
+
const content = JSON5.parse(await fs.readFile(file, 'utf8'))
|
|
9
|
+
if (content.extends) {
|
|
10
|
+
delete content.extends
|
|
11
|
+
await fs.writeFile(file, JSON5.stringify(content, null, 2), 'utf8')
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
for (const file of [
|
|
15
|
+
'.eslintrc.js',
|
|
16
|
+
'.eslintrc.json',
|
|
17
|
+
'.eslintrc.yaml',
|
|
18
|
+
'.eslintrc.yml',
|
|
19
|
+
'.eslintrc',
|
|
20
|
+
]) {
|
|
21
|
+
const exists = await fs.pathExists(file)
|
|
22
|
+
if (exists) {
|
|
23
|
+
await fs.remove(file)
|
|
24
|
+
// eslint-disable-next-line no-console
|
|
25
|
+
console.error('removed', file)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
module.exports = bootstrapEslintConfigs
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const execa = require('../../util/execa.cjs')
|
|
2
|
+
const fs = require('../../util/projectFs.cjs')
|
|
3
|
+
|
|
4
|
+
async function bootstrapGitignore() {
|
|
5
|
+
const paths = {
|
|
6
|
+
'/dist': 'dist',
|
|
7
|
+
'.nyc_output': '.nyc_output',
|
|
8
|
+
node_modules: 'node_modules',
|
|
9
|
+
'/coverage': 'coverage',
|
|
10
|
+
}
|
|
11
|
+
const { stdout } = await execa(
|
|
12
|
+
'git',
|
|
13
|
+
['check-ignore', ...Object.values(paths)],
|
|
14
|
+
{
|
|
15
|
+
stdio: 'pipe',
|
|
16
|
+
encoding: 'utf8',
|
|
17
|
+
}
|
|
18
|
+
).catch((e) => e)
|
|
19
|
+
const ignored = new Set((stdout || '').split(/\r\n?|\n/gm))
|
|
20
|
+
await fs.ensureFile('.gitignore')
|
|
21
|
+
if (ignored.size < Object.keys(paths).length) {
|
|
22
|
+
const content = await fs.readFile('.gitignore', 'utf8')
|
|
23
|
+
|
|
24
|
+
const added = []
|
|
25
|
+
for (const path in paths) {
|
|
26
|
+
if (!ignored.has(paths[path])) added.push(path)
|
|
27
|
+
}
|
|
28
|
+
await fs.writeFile(
|
|
29
|
+
'.gitignore',
|
|
30
|
+
content.replace(/\n+?$/m, '\n') + added.join('\n') + '\n',
|
|
31
|
+
'utf8'
|
|
32
|
+
)
|
|
33
|
+
// eslint-disable-next-line no-console
|
|
34
|
+
console.error('updated .gitignore')
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
module.exports = bootstrapGitignore
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const glob = require('@jcoreio/toolchain/util/glob.cjs')
|
|
2
|
+
const fs = require('@jcoreio/toolchain/util/projectFs.cjs')
|
|
3
|
+
const path = require('path')
|
|
4
|
+
|
|
5
|
+
async function bootstrapMoveTypeDefs() {
|
|
6
|
+
for (const src of await glob('*.{d.ts,js.flow}')) {
|
|
7
|
+
const dest = path.join('src', src)
|
|
8
|
+
await fs.move(src, dest)
|
|
9
|
+
// eslint-disable-next-line no-console
|
|
10
|
+
console.error(`moved ${src} -> ${dest}`)
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
module.exports = bootstrapMoveTypeDefs
|