@jcoreio/toolchain 3.2.2 → 3.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jcoreio/toolchain",
3
- "version": "3.2.2",
3
+ "version": "3.3.1",
4
4
  "description": "base JS build toolchain",
5
5
  "repository": {
6
6
  "type": "git",
package/scripts/build.cjs CHANGED
@@ -2,11 +2,11 @@ const getPluginsAsyncFunction = require('../util/getPluginsAsyncFunction.cjs')
2
2
  const Path = require('path')
3
3
  const { projectDir } = require('../util/findUps.cjs')
4
4
  const fs = require('../util/projectFs.cjs')
5
- const clean = require('./clean.cjs')
5
+ const execa = require('../util/execa.cjs')
6
6
  const glob = require('../util/glob.cjs')
7
7
 
8
8
  exports.run = async function build(args = []) {
9
- await clean.run()
9
+ await execa('tc', ['clean'])
10
10
  await fs.mkdirs('dist')
11
11
 
12
12
  const ignoreEnoent = (err) => {
package/scripts/init.cjs CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  const { packageJson } = require('../util/findUps.cjs')
4
4
  const fs = require('../util/projectFs.cjs')
5
- const preinstall = require('./preinstall.cjs')
6
5
  const execa = require('../util/execa.cjs')
7
6
  const hasTSFiles = require('../util/hasTSFiles.cjs')
8
7
  const { name, version } = require('../package.json')
@@ -58,7 +57,7 @@ async function init(args = []) {
58
57
 
59
58
  const isTest = Boolean(process.env.JCOREIO_TOOLCHAIN_TEST)
60
59
 
61
- await preinstall.run()
60
+ await execa('tc', ['preinstall'])
62
61
  await execa('pnpm', [
63
62
  'add',
64
63
  '-D',
@@ -1,11 +1,10 @@
1
- const check = require('./check.cjs')
2
- const build = require('./build.cjs')
1
+ const execa = require('../util/execa.cjs')
3
2
 
4
3
  exports.run = async function (args = []) {
5
- await check.run()
6
4
  const { scripts } = require('./toolchain.cjs')
7
- if (scripts.coverage) await scripts.coverage.run()
8
- await build.run()
5
+ await execa('tc', ['check'])
6
+ if (scripts.coverage) await execa('tc', ['coverage'])
7
+ await execa('tc', ['build'])
9
8
  }
10
9
 
11
10
  exports.description = 'run check, coverage, and build'
@@ -3,6 +3,8 @@
3
3
  const { name, version } = require('../package.json')
4
4
  const chalk = require('chalk')
5
5
  const getPluginsObjectSync = require('../util/getPluginsObjectSync.cjs')
6
+ const { toolchainConfig } = require('../util/findUps.cjs')
7
+ const execa = require('../util/execa.cjs')
6
8
 
7
9
  const scripts = {
8
10
  migrate: require('./migrate.cjs'),
@@ -26,6 +28,17 @@ const scripts = {
26
28
  },
27
29
  'install-git-hooks': require('./install-git-hooks.cjs'),
28
30
  ...getPluginsObjectSync('scripts'),
31
+ ...Object.fromEntries(
32
+ Object.entries(toolchainConfig.scripts || {}).map(([name, script]) => [
33
+ name,
34
+ typeof script === 'string'
35
+ ? {
36
+ run: () => execa(script, { shell: true }),
37
+ description: script,
38
+ }
39
+ : script,
40
+ ])
41
+ ),
29
42
  }
30
43
 
31
44
  exports.scripts = scripts
@@ -49,12 +62,18 @@ async function toolchain(command, args) {
49
62
  process.exit(1)
50
63
  }
51
64
 
52
- if (script !== scripts.version) {
65
+ if (require.main === module && script !== scripts.version) {
53
66
  console.error(chalk`{bold ${name}@${version}}`) // eslint-disable-line no-console
54
67
  }
55
68
 
56
69
  try {
70
+ if (!command.startsWith('pre' && scripts[`pre${command}`])) {
71
+ await (scripts[`pre${command}`] && scripts[`pre${command}`].run(args))
72
+ }
57
73
  await script.run(args)
74
+ if (!command.startsWith('post')) {
75
+ await (scripts[`post${command}`] && scripts[`post${command}`].run(args))
76
+ }
58
77
  } catch (error) {
59
78
  const { exitCode } = error
60
79
  if (typeof exitCode === 'number' && exitCode !== 0) {
@@ -5,4 +5,12 @@ module.exports = z.object({
5
5
  esmBabelEnv: z.record(z.unknown()).optional(),
6
6
  esWrapper: z.boolean().optional(),
7
7
  outputEsm: z.boolean().optional(),
8
+ scripts: z
9
+ .record(
10
+ z.union([
11
+ z.string(),
12
+ z.object({ run: z.function(), description: z.string() }),
13
+ ])
14
+ )
15
+ .optional(),
8
16
  })