1 | #!/usr/bin/env node
|
2 | const fs = require('fs');
|
3 | const util = require('util');
|
4 |
|
5 | const supportedExtensions = require('./src/extensions.js');
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | global.getDefault = global.getDefault || (m => (m.default ? m.default : m));
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | global.pawExistsSync = global.pawExistsSync || ((filePath, fileSystem = fs) => {
|
23 | if (fileSystem.existsSync(filePath)) return filePath;
|
24 | let resolvedFilePath = '';
|
25 | supportedExtensions.javascript.forEach((jsExt) => {
|
26 | if (resolvedFilePath) {
|
27 | return;
|
28 | }
|
29 | if (fileSystem.existsSync(filePath + jsExt)) {
|
30 | resolvedFilePath = filePath + jsExt;
|
31 | }
|
32 | });
|
33 | return resolvedFilePath;
|
34 | });
|
35 |
|
36 |
|
37 |
|
38 | global.pawDebug = global.pawDebug || ((data, options = {}) => {
|
39 |
|
40 | console.log(util.inspect(data, { depth: 10, ...options }));
|
41 | });
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 | let cacheEnabled = true;
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 | Array.from(process.argv).forEach((arg) => {
|
55 |
|
56 | const lArg = arg.toLowerCase();
|
57 | if (
|
58 | lArg.indexOf('-nc') !== false
|
59 | || lArg.indexOf('--no-cache') !== false
|
60 | ) {
|
61 | process.env.BABEL_DISABLE_CACHE = 1;
|
62 | cacheEnabled = false;
|
63 | }
|
64 | });
|
65 |
|
66 |
|
67 | const babelServerOptions = getDefault(require('./src/babel/node.js'))({
|
68 | cacheDirectory: cacheEnabled,
|
69 | hot: false,
|
70 | noChunk: true,
|
71 | cache: cacheEnabled,
|
72 | }).use.options;
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 | require('@babel/register')({
|
81 | presets: babelServerOptions.presets,
|
82 | plugins: babelServerOptions.plugins,
|
83 | cache: cacheEnabled,
|
84 | ignore: [
|
85 |
|
86 | /node_modules\/(?!(@pawjs|pawjs-)).*/,
|
87 | ],
|
88 | extensions: supportedExtensions.resolveExtensions,
|
89 | });
|
90 |
|
91 |
|
92 |
|
93 |
|
94 | const CliHandler = getDefault(require('./src/scripts/cli.ts'));
|
95 |
|
96 | const handler = new CliHandler();
|
97 | handler.run();
|
98 |
|
99 | module.exports = handler;
|