-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathproject-init.ts
71 lines (65 loc) · 2.23 KB
/
project-init.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
import { BuilderContext } from '../context';
import { BuildHandler, BuildResult } from '../types';
import { Logger } from '@nestjs/common';
import * as path from 'path';
import { buildProjectPath, copyProjectTemplate } from '../utils/files';
import { BuildNode } from '../hanlder-manager';
@BuildNode()
export class ProjectInitHandler implements BuildHandler {
readonly id = 'op:PROJECT::STATE:SETUP';
private readonly logger = new Logger('ProjectInitHandler');
async run(context: BuilderContext): Promise<BuildResult> {
this.logger.log('Setting up project...');
// setup project workspaces
const uuid = context.getGlobalContext('projectUUID');
// FIXME: default convention of frontend and backend folders
copyProjectTemplate(
path.join(__dirname, '..', '..', '..', 'template', 'react-ts'),
uuid,
'frontend',
);
copyProjectTemplate(
path.join(__dirname, '..', '..', '..', 'template', 'template-backend'),
uuid,
'backend',
);
context.setGlobalContext(
'frontendPath',
buildProjectPath(uuid, 'frontend'),
);
context.setGlobalContext('backendPath', buildProjectPath(uuid, 'backend'));
// TODO: setup allInOne, frontend-backend, etc
context.setGlobalContext('projectStructure', 'frontend-backend');
// TODO: setup project path
/*
if (projectStructure === 'frontend-backend') {
// setup frontend and backend folders
copyProjectTemplate('../../../template/react-ts', uuid, 'frontend');
copyProjectTemplate('../../../template/template-backend', uuid, 'backend');
context.setGlobalContext(
'frontendPath',
path.join(getProjectsDir(), uuid, 'frontend'),
);
context.setGlobalContext(
'backendPath',
path.join(getProjectsDir(), uuid, 'backend'),
);
} else if (projectStructure === 'allInOne') {
// setup all in one folder
copyProjectTemplate('../../../template/allInOne', uuid);
context.setGlobalContext(
'frontendPath',
path.join(getProjectsDir(), uuid),
);
context.setGlobalContext(
'backendPath',
path.join(getProjectsDir(), uuid),
);
}
*/
return {
success: true,
data: 'Project setup completed successfully',
};
}
}