Repository navigation
Expand file tree
/
Copy pathjetpack.js
More file actions
executable file
·81 lines (72 loc) · 2.08 KB
/
Copy pathjetpack.js
File metadata and controls
executable file
·81 lines (72 loc) · 2.08 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env node
import process from 'process';
import { fileURLToPath } from 'url';
import { checkAnalyticsEnabled } from '../helpers/analytics.js';
/**
* Async import with better error handling.
*
* @param {string} path - Path to import from.
* @return {*} - Return from `import()`.
*/
async function guardedImport( path ) {
try {
return await import( path );
} catch ( error ) {
const bold =
( await import( 'chalk' ).then(
m => m.default?.stderr?.bold,
() => null
) ) || ( v => v );
console.error( error );
console.error( '' );
if ( error.code === 'ERR_MODULE_NOT_FOUND' ) {
// if pnpm install hasn't been run, the import() will fail here.
console.error(
bold(
'*** Something is missing from your install. Please run `pnpm install` and try again. ***'
)
);
} else {
console.error( bold( '*** Something unexpected happened. See error above. ***' ) );
}
process.exit( 1 );
}
}
const { checkCliLocation, compareToolVersions } = await guardedImport(
'../helpers/checkEnvironment.js'
);
/**
* Checks for executing the CLI within a different monorepo checkout.
*/
try {
await checkCliLocation();
} catch ( error ) {
console.error( error );
console.error( 'Something unexpected happened. See error above.' );
process.exit( 1 );
}
/**
* Standardizes the cwd for the process. Allows `jetpack` cli to run correctly from any location in the repo.
*/
process.chdir( fileURLToPath( new URL( '../../..', import.meta.url ) ) );
/**
* Checks to make sure we're on the right version of various tools.
*/
try {
if ( ! ( await compareToolVersions() ) && ! process.env.JETPACK_CLI_NONFATAL_VERSION_CHECKS ) {
console.error(
'(Continue despite the above errors by setting JETPACK_CLI_NONFATAL_VERSION_CHECKS=1)'
);
process.exit( 1 );
}
} catch ( error ) {
console.error( error );
console.error( 'Something unexpected happened. See error above.' );
process.exit( 1 );
}
/**
* Check if the user has been asked to enable analytics tracking.
*/
await checkAnalyticsEnabled();
const cliRouter = await guardedImport( '../cliRouter.js' );
cliRouter.cli();