Skip to content

Commit a1aff3b

Browse files
committed
WIP working with plugins
1 parent 1defa5c commit a1aff3b

File tree

10 files changed

+129
-174
lines changed

10 files changed

+129
-174
lines changed

src/generators.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ export async function generateDockerFiles(
1313
project: StrapiProject,
1414
config: DockerConfig
1515
): Promise<void> {
16-
console.log("🐳 Generating complete Docker setup...");
17-
1816
const liquid = new Liquid();
1917
const secrets = generateSecrets();
2018

@@ -132,13 +130,4 @@ export async function generateDockerFiles(
132130

133131
// Write all files with smart env handling
134132
await writeFilesWithEnv(files, envFile, project.path);
135-
136-
// Show next steps
137-
console.log("\n🎯 Next steps:");
138-
console.log("1. Review the generated files");
139-
console.log("2. Run: docker-compose up -d");
140-
console.log("3. Your Strapi app will be available at http://localhost:1337");
141-
console.log(
142-
"\n⚠️ Keep your .env file secure - it contains sensitive secrets!"
143-
);
144133
}

src/index.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import {
44
intro,
55
outro,
6+
note,
67
text,
78
select,
89
confirm,
@@ -55,23 +56,30 @@ async function main() {
5556
const project = await detectStrapiProject();
5657

5758
if (!project.isStrapi) {
58-
outro(
59-
"❌ This doesn't appear to be a Strapi project. Please run this command in a Strapi project directory."
60-
);
59+
outro("❌ This doesn't appear to be a Strapi project.");
6160
process.exit(1);
6261
}
6362

64-
console.log(`✅ Detected Strapi project: ${project.name}`);
65-
console.log(`📦 Package manager: ${project.packageManager}`);
66-
console.log(`🔧 Type: ${project.type}`);
63+
// Show project details in a nice note
64+
const projectInfo = [
65+
`📦 Project: ${project.name}`,
66+
`🚀 Strapi Version: ${project.version || "unknown"}`,
67+
`📋 Package Manager: ${project.packageManager.toUpperCase()}`,
68+
`🔧 Language: ${
69+
project.type === "typescript" ? "TypeScript" : "JavaScript"
70+
}`,
71+
];
6772

68-
if (project.version) {
69-
console.log(`📋 Strapi version: ${project.version}`);
70-
}
73+
note(projectInfo.join("\n"), "✅ Project detected");
7174

7275
await runDockerizeWizard(project);
7376

74-
outro("🎉 Docker configuration complete! Happy coding!");
77+
outro("🎉 Docker setup complete!");
78+
79+
note(
80+
"💙 Thanks for using Strapi Dockerize!\n\n⭐ If this tool helped you, please star it on GitHub:\n https://github.com/strapi-community/strapi-tool-dockerize\n\n🐛 Found an issue? Report it:\n https://github.com/strapi-community/strapi-tool-dockerize/issues",
81+
"Support the project"
82+
);
7583
}
7684

7785
async function testPluginsCommand() {

src/plugins/databases/mariadb/questions.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,24 @@ import { text, select, password } from "@clack/prompts";
22

33
export async function questions() {
44
const dbName = await text({
5-
message: "Database name:",
5+
message: "Database name (press Enter for default):",
66
placeholder: "strapi",
77
defaultValue: "strapi",
88
validate: (value) => {
9-
if (!value) return "Database name is required";
10-
if (!/^[a-zA-Z0-9_-]+$/.test(value)) {
9+
const val = value || "strapi";
10+
if (!/^[a-zA-Z0-9_-]+$/.test(val)) {
1111
return "Database name can only contain letters, numbers, underscores and hyphens";
1212
}
1313
},
1414
});
1515

1616
const dbUser = await text({
17-
message: "Database user:",
17+
message: "Database user (press Enter for default):",
1818
placeholder: "strapi",
1919
defaultValue: "strapi",
2020
validate: (value) => {
21-
if (!value) return "Database user is required";
22-
if (!/^[a-zA-Z0-9_-]+$/.test(value)) {
21+
const val = value || "strapi";
22+
if (!/^[a-zA-Z0-9_-]+$/.test(val)) {
2323
return "Username can only contain letters, numbers, underscores and hyphens";
2424
}
2525
},
@@ -53,22 +53,23 @@ export async function questions() {
5353
}
5454

5555
const dbPort = await text({
56-
message: "Database port:",
56+
message: "Database port (press Enter for default):",
5757
placeholder: "3306",
5858
defaultValue: "3306",
5959
validate: (value) => {
60-
const port = parseInt(value);
60+
const val = value || "3306";
61+
const port = parseInt(val);
6162
if (isNaN(port)) return "Port must be a number";
6263
if (port < 1024 || port > 65535)
6364
return "Port must be between 1024 and 65535";
6465
},
6566
});
6667

6768
return {
68-
name: dbName,
69-
user: dbUser,
69+
name: dbName || "strapi",
70+
user: dbUser || "strapi",
7071
password: dbPassword,
71-
port: parseInt(dbPort as string),
72+
port: parseInt((dbPort as string) || "3306"),
7273
host: "localhost",
7374
};
7475
}

src/plugins/databases/mysql/questions.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,24 @@ import { text, select, password } from "@clack/prompts";
22

33
export async function questions() {
44
const dbName = await text({
5-
message: "Database name:",
5+
message: "Database name (press Enter for default):",
66
placeholder: "strapi",
77
defaultValue: "strapi",
88
validate: (value) => {
9-
if (!value) return "Database name is required";
10-
if (!/^[a-zA-Z0-9_-]+$/.test(value)) {
9+
const val = value || "strapi";
10+
if (!/^[a-zA-Z0-9_-]+$/.test(val)) {
1111
return "Database name can only contain letters, numbers, underscores and hyphens";
1212
}
1313
},
1414
});
1515

1616
const dbUser = await text({
17-
message: "Database user:",
17+
message: "Database user (press Enter for default):",
1818
placeholder: "strapi",
1919
defaultValue: "strapi",
2020
validate: (value) => {
21-
if (!value) return "Database user is required";
22-
if (!/^[a-zA-Z0-9_-]+$/.test(value)) {
21+
const val = value || "strapi";
22+
if (!/^[a-zA-Z0-9_-]+$/.test(val)) {
2323
return "Username can only contain letters, numbers, underscores and hyphens";
2424
}
2525
},
@@ -53,22 +53,23 @@ export async function questions() {
5353
}
5454

5555
const dbPort = await text({
56-
message: "Database port:",
56+
message: "Database port (press Enter for default):",
5757
placeholder: "3306",
5858
defaultValue: "3306",
5959
validate: (value) => {
60-
const port = parseInt(value);
60+
const val = value || "3306";
61+
const port = parseInt(val);
6162
if (isNaN(port)) return "Port must be a number";
6263
if (port < 1024 || port > 65535)
6364
return "Port must be between 1024 and 65535";
6465
},
6566
});
6667

6768
return {
68-
name: dbName,
69-
user: dbUser,
69+
name: dbName || "strapi",
70+
user: dbUser || "strapi",
7071
password: dbPassword,
71-
port: parseInt(dbPort as string),
72+
port: parseInt((dbPort as string) || "3306"),
7273
host: "localhost",
7374
};
7475
}

src/plugins/databases/postgresql/questions.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,24 @@ import { text, select, password } from "@clack/prompts";
22

33
export async function questions() {
44
const dbName = await text({
5-
message: "Database name:",
5+
message: "Database name (press Enter for default):",
66
placeholder: "strapi",
77
defaultValue: "strapi",
88
validate: (value) => {
9-
if (!value) return "Database name is required";
10-
if (!/^[a-zA-Z0-9_-]+$/.test(value)) {
9+
const val = value || "strapi"; // Use default if empty
10+
if (!/^[a-zA-Z0-9_-]+$/.test(val)) {
1111
return "Database name can only contain letters, numbers, underscores and hyphens";
1212
}
1313
},
1414
});
1515

1616
const dbUser = await text({
17-
message: "Database user:",
17+
message: "Database user (press Enter for default):",
1818
placeholder: "strapi",
1919
defaultValue: "strapi",
2020
validate: (value) => {
21-
if (!value) return "Database user is required";
22-
if (!/^[a-zA-Z0-9_-]+$/.test(value)) {
21+
const val = value || "strapi"; // Use default if empty
22+
if (!/^[a-zA-Z0-9_-]+$/.test(val)) {
2323
return "Username can only contain letters, numbers, underscores and hyphens";
2424
}
2525
},
@@ -53,22 +53,23 @@ export async function questions() {
5353
}
5454

5555
const dbPort = await text({
56-
message: "Database port:",
56+
message: "Database port (press Enter for default):",
5757
placeholder: "5432",
5858
defaultValue: "5432",
5959
validate: (value) => {
60-
const port = parseInt(value);
60+
const val = value || "5432"; // Use default if empty
61+
const port = parseInt(val);
6162
if (isNaN(port)) return "Port must be a number";
6263
if (port < 1024 || port > 65535)
6364
return "Port must be between 1024 and 65535";
6465
},
6566
});
6667

6768
return {
68-
name: dbName,
69-
user: dbUser,
69+
name: dbName || "strapi",
70+
user: dbUser || "strapi",
7071
password: dbPassword,
71-
port: parseInt(dbPort as string),
72+
port: parseInt((dbPort as string) || "5432"),
7273
host: "localhost",
7374
};
7475
}

src/plugins/databases/sqlite-adapter.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ export const sqlitePlugin: DatabasePlugin = {
3636
},
3737

3838
async generateFiles(config: Record<string, any>): Promise<void> {
39-
console.log("🗄️ Generating SQLite Docker configuration...");
40-
4139
const liquid = new Liquid();
4240

4341
// For SQLite, we create a simple compose service that just uses file-based storage

src/plugins/databases/sqlite/questions.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@ import { text, confirm } from "@clack/prompts";
22

33
export async function questions() {
44
const dbPath = await text({
5-
message: "Database file path:",
5+
message: "Database file path (press Enter for default):",
66
placeholder: "./data/strapi.db",
77
defaultValue: "./data/strapi.db",
8-
validate: (value) => {
9-
if (!value) return "Database path is required";
10-
},
118
});
129

1310
const createBackup = await confirm({
@@ -16,7 +13,7 @@ export async function questions() {
1613
});
1714

1815
return {
19-
path: dbPath,
16+
path: dbPath || "./data/strapi.db", // Fallback to default
2017
createBackup,
2118
// SQLite doesn't need host/port/user/password
2219
host: "localhost",

src/utils/env-manager.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ export function debugEnvMerge(
55
existingEnvPath: string,
66
dockerSections: EnvSection[]
77
): void {
8+
// Only show debug info in development mode
9+
if (process.env.NODE_ENV !== "development") {
10+
return;
11+
}
12+
813
console.log("🔍 Debug: Analyzing .env file merge...");
914

1015
if (existsSync(existingEnvPath)) {

src/utils/file-writer.ts

Lines changed: 2 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -88,66 +88,14 @@ export async function writeFilesWithEnv(
8888
envFile: EnvFileToWrite | null,
8989
projectPath: string = process.cwd()
9090
): Promise<void> {
91-
console.log("\n📁 Files to be created:");
92-
93-
// Show regular files
94-
for (const file of files) {
95-
const fullPath = join(projectPath, file.path);
96-
const exists = existsSync(fullPath);
97-
98-
console.log(` ${exists ? "🔄" : "📄"} ${file.path} - ${file.description}`);
99-
if (exists) {
100-
console.log(` ⚠️ File already exists and will be overwritten`);
101-
}
102-
}
103-
104-
// Show env file with special handling
105-
if (envFile) {
106-
const fullPath = join(projectPath, envFile.path);
107-
const exists = existsSync(fullPath);
108-
109-
console.log(
110-
` ${exists ? "🔄" : "📄"} ${envFile.path} - ${envFile.description}`
111-
);
112-
113-
if (exists) {
114-
const content = readFileSync(fullPath, "utf8");
115-
const hasDockerSection = content.includes(
116-
"🐳 Docker Configuration (Generated by Strapi Dockerize)"
117-
);
118-
119-
if (hasDockerSection) {
120-
console.log(
121-
` 🔄 Will update existing Docker configuration section`
122-
);
123-
} else {
124-
console.log(
125-
` ➕ Will add Docker configuration, preserving existing variables`
126-
);
127-
}
128-
} else {
129-
console.log(` 📝 Will create new file with Docker configuration`);
130-
}
131-
}
132-
133-
const shouldProceed = await confirm({
134-
message: "Create these files?",
135-
initialValue: true,
136-
});
137-
138-
if (!shouldProceed) {
139-
console.log("❌ File creation cancelled");
140-
return;
141-
}
142-
143-
console.log("\n🚀 Creating files...");
91+
// Note: File preview is now shown in the wizard, so we skip the preview here
92+
// and go straight to creation since user already confirmed
14493

14594
// Write regular files
14695
for (const file of files) {
14796
try {
14897
const fullPath = join(projectPath, file.path);
14998
writeFileSync(fullPath, file.content, "utf8");
150-
console.log(`✅ Created ${file.path}`);
15199
} catch (error) {
152100
console.error(`❌ Failed to create ${file.path}:`, error);
153101
throw error;
@@ -159,27 +107,11 @@ export async function writeFilesWithEnv(
159107
try {
160108
const fullPath = join(projectPath, envFile.path);
161109
const dockerSections = createDockerEnvSections(envFile.templateVars);
162-
163-
// Debug the merge process
164-
debugEnvMerge(fullPath, dockerSections);
165-
166110
const mergedContent = mergeEnvVariables(fullPath, dockerSections);
167-
168111
writeFileSync(fullPath, mergedContent, "utf8");
169-
170-
const exists = existsSync(fullPath);
171-
if (exists) {
172-
console.log(
173-
`✅ Updated ${envFile.path} (replaced Docker section, preserved other variables)`
174-
);
175-
} else {
176-
console.log(`✅ Created ${envFile.path} with Docker configuration`);
177-
}
178112
} catch (error) {
179113
console.error(`❌ Failed to create ${envFile.path}:`, error);
180114
throw error;
181115
}
182116
}
183-
184-
console.log("\n🎉 All files created successfully!");
185117
}

0 commit comments

Comments
 (0)