-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathindex.mjs
executable file
·145 lines (132 loc) · 4.35 KB
/
index.mjs
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/usr/bin/env node
// _ __ ___ ___ __| |_ _ ___ __ _ ___| |_ __ _ ___| | __
// | '_ ` _ \ / _ \/ _` | | | / __|/ _` | / __| __/ _` |/ __| |/ /
// | | | | | | __/ (_| | |_| \__ \ (_| | \__ \ || (_| | (__| <
// |_| |_| |_|\___|\__,_|\__,_|___/\__,_| |___/\__\__,_|\___|_|\_\
// _ _ _ _ ____ ___
// __| | ___ ___| | _____ _ __(_)_______ __| | |___ \ / _ \
// / _` |/ _ \ / __| |/ / _ \ '__| |_ / _ \/ _` | __) || | | |
// | (_| | (_) | (__| < __/ | | |/ / __/ (_| | / __/ | |_| |
// \__,_|\___/ \___|_|\_\___|_| |_/___\___|\__,_| |_____(_)___/
import chalk from "chalk";
import inquirer from "inquirer";
import chalkAnimation from "chalk-animation";
import slugify from "slugify";
import { createSpinner } from "nanospinner";
import { heading } from "./src/lib/utils.mjs";
import { sleep } from "./src/lib/utils.mjs";
import { createFiles } from "./src/lib/builder.mjs";
import { askDbSetup } from "./src/prompts/dbSetup.mjs";
import { medusaConfig } from "./src/constants.mjs";
import {
askProjectSetup,
askSeedDemoData,
} from "./src/prompts/projectSetup.mjs";
import { askRedisSetup } from "./src/prompts/redisSetup.mjs";
import { askMinioSetup } from "./src/prompts/minioSetup.mjs";
import { askMeilisearchSetup } from "./src/prompts/meilisearchSetup.mjs";
import { askModulesSetup } from "./src/prompts/modulesSetup.mjs";
async function welcome() {
const rainbowTitle = chalkAnimation.rainbow(`
ハ____ハ 。゚゚・。・゚゚。
꒰ ⬩ ω ⬩ ꒱ ˚。 。˚
| つ ~ Welcome to medusa-stack-dockerized v2.0 ゚ ・。・゚
`);
await sleep(2000);
rainbowTitle.stop();
}
async function confirmProccess() {
const questions = [
{
type: "confirm",
name: "confirm",
message: "Proceed with these settings?",
default: true,
},
];
try {
const answers = await inquirer.prompt(questions);
if (!answers.confirm) {
console.log("Aborting...");
process.exit(0);
}
} catch (err) {
if (err.isTtyError) {
console.error("Prompt couldn't be rendered in the current environment.");
} else {
console.log(`
*。*.。*∧,,,∧
ヾ(⌒(_=•ω•)_ bye!
`);
}
process.exit(0);
}
// use loader to show the spinner
console.log("");
const loader = new createSpinner("Creating docker files ...");
loader.start();
await sleep();
loader.stop();
console.log("");
await createFiles(medusaConfig);
}
function finished() {
console.log("");
console.log(
`\n${chalk.blueBright(
"🎉 Process finished! Please check your files in the 'output' folder."
)}`
);
heading(" Next steps ");
const slugifiedName = slugify(medusaConfig.projectName, { lower: true });
const outputDir = `output/${slugifiedName}`;
console.log(`
👉 0. Go to your project directory: ${chalk.blueBright(`cd ${outputDir}`)}
👉 1. Start the backend with: ${chalk.blueBright(
"docker compose up postgres redis medusa_server medusa_worker -d"
)}
👉 2. Create your admin user with ${chalk.blueBright(
"docker compose exec -it medusa_server " + medusaConfig.postStartCommand
)}
👉 3. Generate a publishable api key for the storefront: ${chalk.blueBright(
"http://localhost:9000/app/settings/publishable-api-keys"
)}
👉 4. Fill the other enviroment variables for the storefront in the generated: ${chalk.blueBright(
".env file"
)}
👉 5. Start the storefront: ${chalk.blueBright(
"docker compose up storefront -d"
)}
🎉 Visit you brand new storefront at ${chalk.blueBright(
"http://localhost:8000"
)}
`);
}
// Run it with top-level await
console.clear();
await welcome();
heading(" Project Setup ");
await askProjectSetup();
if (medusaConfig.useDefaultSettings) {
console.log(chalk.green("\n\n"));
console.log(chalk.green("🌈 Going with default settings ..."));
console.log(chalk.green("\n\n"));
} else {
heading(" Database Setup ");
await askDbSetup();
heading(" Redis Setup ");
await askRedisSetup();
heading(" Minio Setup ");
await askMinioSetup();
heading(" Meilisearch Setup ");
await askMeilisearchSetup();
heading(" Modules Setup ");
await askModulesSetup();
}
heading(" Summary ");
console.log(chalk.green("\n\n"));
console.log(medusaConfig);
console.log(chalk.green("\n\n"));
await askSeedDemoData();
await confirmProccess();
finished();