-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathplopfile.js
76 lines (63 loc) · 2.14 KB
/
plopfile.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
const { copySync, mkdirpSync, pathExistsSync } = require("fs-extra");
const path = require("path");
const servicesLocation = path.join(__dirname, "services/");
const serviceTemplateLocation = path.join(__dirname, "shared/service-template/");
module.exports = plop => {
plop.setActionType("createService", answers => {
const newServiceLocation = path.join(servicesLocation, answers.serviceName);
if (pathExistsSync(newServiceLocation)) {
throw Error(`A service with the name "${answers.serviceName}" already exists.`);
}
mkdirpSync(newServiceLocation);
copySync(`${serviceTemplateLocation}/static/`, newServiceLocation);
return "Success";
});
plop.setGenerator("rad-generator", {
description: "Create new service",
prompts: [serviceNamePrompt, serviceVersionPrompt, serviceDescriptionPrompt],
actions: [createService, createDockerEntrypoint, createDockerFileProd, createPackageJson, createIntegrationTest],
});
};
// Prompts
const serviceNamePrompt = {
type: "input",
name: "serviceName",
message: "Service name",
};
const serviceVersionPrompt = {
type: "input",
name: "serviceVersion",
message: "Version",
default: "1.0.0",
};
const serviceDescriptionPrompt = {
type: "input",
name: "serviceDescription",
message: "Description",
default: "",
};
// Actions
const createService = {
type: "createService",
answer: "{{serviceName}}",
};
const createDockerEntrypoint = {
type: "add",
path: "./services/{{serviceName}}/docker/prod/docker-entrypoint.sh",
templateFile: "./shared/service-template/plop-templates/docker-entrypoint.sh",
};
const createDockerFileProd = {
type: "add",
path: "./services/{{serviceName}}/docker/prod/Dockerfile",
templateFile: "./shared/service-template/plop-templates/dockerfile.prod",
};
const createPackageJson = {
type: "add",
path: "./services/{{serviceName}}/package.json",
templateFile: "./shared/service-template/plop-templates/package.json",
};
const createIntegrationTest = {
type: "add",
path: "./services/{{serviceName}}/src/integration-tests/{{serviceName}}.spec.ts",
templateFile: "./shared/service-template/plop-templates/service.spec.ts",
};