-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathpaw.js
executable file
·83 lines (74 loc) · 2.3 KB
/
paw.js
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
82
83
#!/usr/bin/env node
const fs = require('fs');
const path = require('path');
let useCustomEnvPath = false;
// Read configurations from the .env as soon as possible
if (process.env.ENV_CONFIG_PATH) {
let envFilePath = process.env.ENV_CONFIG_PATH;
if (!path.isAbsolute(process.env.ENV_CONFIG_PATH)) {
envFilePath = path.resolve(process.cwd(), envFilePath);
}
if (fs.existsSync(envFilePath)) {
useCustomEnvPath = true;
require('dotenv').config({
path: envFilePath,
});
}
}
if (!useCustomEnvPath) {
require('dotenv').config();
}
const { getDefault } = require('./src/globals');
const { resolveExtensions } = getDefault(require('./src/extensions'));
/**
* @desc Set cache to enabled by default,
* at this moment we need this cache to determine if we would like to use babel cache
* @type {boolean}
*/
let cacheEnabled = true;
/**
* Traverse through all the arguments and check if the user has
* indicated if he does not want to use cache!
*/
Array.from(process.argv).forEach((arg) => {
// Convert argument to lowercase
const lArg = arg.toLowerCase();
if (
lArg.indexOf('-nc') !== false
|| lArg.indexOf('--no-cache') !== false
) {
process.env.BABEL_DISABLE_CACHE = 1;
cacheEnabled = false;
}
});
// Get babel configuration for nodejs server
const babelServerOptions = getDefault(require('./src/babel/node.js'))({
cacheDirectory: cacheEnabled,
hot: false,
noChunk: true,
cache: cacheEnabled,
}).use.options;
/**
* Use babel register so that we can use latest EcmaScript & TypeScript version
* in included files. Also we need to make sure that any plugins for pawjs or pawjs core
* modules needs to be access with new code directly and there should be no need for
* compiled code even if it lies in node_modules
*/
require('@babel/register')({
presets: babelServerOptions.presets,
plugins: babelServerOptions.plugins,
cache: cacheEnabled,
ignore: [
// Allow @pawjs core & pawjs- plugins to be of es6 or TS format
/node_modules\/(?!(@pawjs|pawjs-)).*/,
],
extensions: resolveExtensions,
});
/**
* After registering babel we can include typescript (TS) files as well
*/
// eslint-disable-next-line import/extensions
const CliHandler = getDefault(require('./src/scripts/cli.ts'));
const handler = new CliHandler();
handler.run();
module.exports = handler;