-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.ts
103 lines (92 loc) · 3.11 KB
/
app.ts
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import path from 'path';
import chalk from 'chalk';
import fs from 'fs';
import { isWriteable } from './utils/writeable';
import { AppType, Language } from './types';
import { installTemplate } from './templates/installTemplate';
interface Config {
appPath: string;
port: number;
language?: string;
appType?: 'host' | 'remote';
publicPath?: string;
}
export const createApp = async (config: Config) => {
const {
appPath, language, appType, publicPath, port
} = config;
let template = 'js-remote';
if (language === Language.TypeScript) {
if (appType === AppType.Remote) {
template = 'ts-remote';
} else {
template = 'ts-host';
}
}
if (language === Language.JavaScript) {
if (appType === AppType.Remote) {
template = 'js-remote';
} else {
template = 'js-host';
}
}
const root = path.resolve(appPath);
if (!(await isWriteable(path.dirname(root)))) {
console.error(
chalk.redBright(
'The application path is not writable, please check folder permissions and try again.'
)
);
console.error(
chalk.yellowBright(
'It is likely you do not have write permissions for this folder.'
)
);
process.exit(1);
}
console.log(`${chalk.green(`Creating a new MFE application in ${chalk.green.bold(root)}.`)}\n`);
fs.mkdirSync(root, { recursive: true });
process.chdir(root);
await installTemplate({
root,
template,
language: language || Language.JavaScript,
appName: path.basename(root),
publicPath: publicPath || '/',
appType: appType || AppType.Remote,
port: port || 3000
}).then(() => {
const displayedCommand = 'npm';
console.log();
console.log(`Success! Created ${root} at ${appPath}`);
console.log('Inside that directory, you can run several commands:');
console.log();
console.log(chalk.cyan(` ${displayedCommand} start`));
console.log(' Starts the development server.');
console.log();
console.log(
chalk.cyan(` ${displayedCommand} run build`)
);
console.log(' Bundles the app into static files for production.');
console.log();
console.log(chalk.cyan(` ${displayedCommand} test`));
console.log(' Starts the test runner.');
console.log();
console.log(
chalk.cyan(` ${displayedCommand} run eject`)
);
console.log(
' Removes this tool and copies build dependencies, configuration files'
);
console.log(
' and scripts into the app directory. If you do this, you can’t go back!'
);
console.log();
console.log('We suggest that you begin by typing:');
console.log();
console.log(chalk.cyan(' cd'), path.basename(root));
console.log(` ${chalk.cyan(`${displayedCommand} start`)}`);
console.log();
console.log('Happy hacking!!');
});
};