File size: 1,482 Bytes
e1ae2c6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const path = require('node:path');
const { spawnSync } = require('node:child_process');

const { createLogger, isVerbose, startTimer } = require('../src/generator/utils/logger');

const log = createLogger('check');

function runNode(scriptPath) {
  const result = spawnSync(process.execPath, [scriptPath], { stdio: 'inherit' });
  return result && Number.isFinite(result.status) ? result.status : 1;
}

async function main() {
  const elapsedMs = startTimer();
  log.info('开始', { version: process.env.npm_package_version });

  const repoRoot = path.resolve(__dirname, '..');

  const lintExit = runNode(path.join(repoRoot, 'scripts', 'lint.js'));
  if (lintExit !== 0) {
    log.error('lint 失败', { exit: lintExit });
    process.exitCode = lintExit;
    return;
  }

  const testExit = runNode(path.join(repoRoot, 'scripts', 'test.js'));
  if (testExit !== 0) {
    log.error('test 失败', { exit: testExit });
    process.exitCode = testExit;
    return;
  }

  const buildExit = runNode(path.join(repoRoot, 'scripts', 'build.js'));
  if (buildExit !== 0) {
    log.error('build 失败', { exit: buildExit });
    process.exitCode = buildExit;
    return;
  }

  log.ok('完成', { ms: elapsedMs() });
}

if (require.main === module) {
  main().catch((error) => {
    log.error('执行失败', { message: error && error.message ? error.message : String(error) });
    if (isVerbose() && error && error.stack) console.error(error.stack);
    process.exitCode = 1;
  });
}