-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
82 lines (67 loc) · 2.34 KB
/
index.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
import { cpSync, existsSync, rmSync, readFile, writeFileSync } from "fs";
import readline from "readline-sync";
import { FILES_TO_REPLACE } from "./constants";
interface AppDetails {
name: string;
port: string;
fullName: string;
productKey: string;
currentsId: string;
}
if (existsSync("playwright-tests/node_modules")) {
rmSync("playwright-tests/node_modules", { recursive: true });
}
cpSync("playwright-tests", "playwright-tests-starter", {
recursive: true,
force: true,
});
const appDetails: Partial<AppDetails> = {};
appDetails.fullName = readline.question(
"Enter product name? (eg: neetoDesk, neetoRecord, neetoPlanner):"
);
if (!appDetails.fullName.startsWith("neeto")) {
throw new Error("Invalid product name");
}
appDetails.name = appDetails.fullName.replace("neeto", "");
appDetails.port = readline.question(
"Enter product port number? (eg: 9001, 9002):"
);
if (!parseInt(appDetails.port)) {
throw new Error("Invalid port number");
}
appDetails.productKey = readline.question(
`Create a new project for this product in neetoPlaydash.
Visit https://neeto-engineering.neetoplaydash.com to create a new project.
Enter the project key for the product:`
);
if (!appDetails.productKey) {
throw new Error("Invalid neetoPlaydash project key");
}
appDetails.currentsId = readline.question(
`Create a new project for this product in https://app.currents.dev.
Enter the project id for the product:`
);
Promise.all(
FILES_TO_REPLACE.map(async (path) =>
readFile(path, (error, data) => {
error && console.error(error);
writeFileSync(
path,
data
.toString()
.replaceAll("<PRODUCT_PORT>", appDetails.port)
.replaceAll("<PLAYDASH_PROJECT_KEY>", appDetails.productKey)
.replaceAll("<PRODUCT_FULL_NAME>", appDetails.fullName.toLowerCase())
.replaceAll("<PRODUCT_NAME>", appDetails.name.toLowerCase())
.replaceAll("<CURRENTS_PROJECT_ID>", appDetails.currentsId)
);
})
)
).then(
() => console.log("Completed generating files"),
(reason) => console.log(`Error generating files. ${reason}`)
);
console.log(`Next steps:
1. Copy the newly generated playwright-tests-starter on to the neeto product.
2. Rename the directory to playwright-tests.
3. Execute \`yarn install\` and \`yarn playwright install\` within the playwright-tests directory.`);