-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathindex.js
More file actions
executable file
·82 lines (70 loc) · 1.91 KB
/
index.js
File metadata and controls
executable file
·82 lines (70 loc) · 1.91 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
82
#!/usr/bin/env node
/* eslint-disable no-console */
import { getEnv } from './utils/env.js';
import { printSeparator } from './utils/log.js';
import { getPresetApi } from './utils/preset.js';
const command = process.argv[2];
const options = process.argv.slice(3);
if (command === '--help' || command === '-h' || command === 'help') {
console.log(`Please use one of the following commands:
* start
* build
`);
process.exit(0);
}
console.log(`Running command: ${command}`, `With options: ${options}`);
function getMode() {
if (options.includes('--dev')) {
return 'development';
} else if (options.includes('--prod')) {
return 'production';
}
return command === 'start' ? 'development' : 'production';
}
async function runScript() {
printSeparator('CONFIGURATION');
const restOptions = options.filter(
opt => opt !== '--dev' && opt !== '--prod' && !opt.startsWith('--config='),
);
// current env vars and talend scripts configuration in <project-folder>/talend-scripts.(js/json)
const env = getEnv(options);
env.TALEND_MODE = getMode(command, options);
console.log(`Talend scripts mode : ${env.TALEND_MODE}`);
if (env.TALEND_SCRIPTS_CONFIG) {
console.log('Talend scripts configuration file found and loaded');
}
// object passed to preset
const presetApi = getPresetApi(env);
printSeparator('RUN');
const commandFileName = command.replace(/:/g, '-');
const script = await import(`./scripts/${commandFileName}.js`);
let result = {
status: 'no status',
};
try {
result = script.default(env, presetApi, restOptions);
} catch (e) {
console.error(e);
}
if (result?.then) {
result
.then(() => {
process.exit(0);
})
.catch(e => {
console.error(e);
process.exit(1);
});
} else {
process.exit(result.status);
}
}
switch (command) {
case 'build':
case 'start':
runScript(command, options);
break;
default:
console.log(`Command ${command} not found.`);
process.exit(-1);
}