@panoptic-it-solutions/coolify-setup 1.1.13 → 1.1.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/detector.d.ts +1 -0
- package/dist/detector.js +2 -0
- package/dist/generator.js +26 -9
- package/dist/index.js +6 -3
- package/dist/templates/dockerfile.d.ts +1 -0
- package/dist/templates/dockerfile.js +6 -4
- package/dist/templates/entrypoint.d.ts +1 -0
- package/dist/templates/entrypoint.js +4 -2
- package/dist/templates/migrate.d.ts +1 -0
- package/dist/templates/migrate.js +3 -2
- package/package.json +1 -1
package/dist/detector.d.ts
CHANGED
package/dist/detector.js
CHANGED
|
@@ -19,6 +19,7 @@ export async function detectProject() {
|
|
|
19
19
|
const hasYarnLock = exists('yarn.lock');
|
|
20
20
|
const hasDockerfile = exists('Dockerfile');
|
|
21
21
|
const hasDockerCompose = exists('docker-compose.yml');
|
|
22
|
+
const hasSrcApp = exists('src/app'); // Detect src/ directory structure
|
|
22
23
|
let packageManager = 'npm';
|
|
23
24
|
if (hasPnpmLock)
|
|
24
25
|
packageManager = 'pnpm';
|
|
@@ -30,5 +31,6 @@ export async function detectProject() {
|
|
|
30
31
|
hasDockerfile,
|
|
31
32
|
hasDockerCompose,
|
|
32
33
|
name: hasPackageJson ? getProjectName() : 'my-project',
|
|
34
|
+
usesSrcDirectory: hasSrcApp,
|
|
33
35
|
};
|
|
34
36
|
}
|
package/dist/generator.js
CHANGED
|
@@ -13,6 +13,12 @@ function writeFile(relativePath, content) {
|
|
|
13
13
|
ensureDir(fullPath);
|
|
14
14
|
writeFileSync(fullPath, content, 'utf-8');
|
|
15
15
|
}
|
|
16
|
+
function detectSrcDirectory() {
|
|
17
|
+
// Check if project uses src/ directory structure
|
|
18
|
+
const srcPath = join(process.cwd(), 'src');
|
|
19
|
+
const srcAppPath = join(process.cwd(), 'src/app');
|
|
20
|
+
return existsSync(srcPath) && existsSync(srcAppPath);
|
|
21
|
+
}
|
|
16
22
|
function addEsbuildToPackageJson(packageManager) {
|
|
17
23
|
const packageJsonPath = join(process.cwd(), 'package.json');
|
|
18
24
|
if (!existsSync(packageJsonPath)) {
|
|
@@ -47,9 +53,11 @@ function addEsbuildToPackageJson(packageManager) {
|
|
|
47
53
|
return false;
|
|
48
54
|
}
|
|
49
55
|
}
|
|
50
|
-
function copyMigrationsToLibDb() {
|
|
56
|
+
function copyMigrationsToLibDb(usesSrcDirectory) {
|
|
51
57
|
const cwd = process.cwd();
|
|
52
|
-
|
|
58
|
+
// Use src/lib/db for projects with src/ directory, otherwise lib/db
|
|
59
|
+
const libDbPath = usesSrcDirectory ? 'src/lib/db' : 'lib/db';
|
|
60
|
+
const destPath = join(cwd, libDbPath, 'migrations');
|
|
53
61
|
// Skip if destination already exists
|
|
54
62
|
if (existsSync(destPath)) {
|
|
55
63
|
return false;
|
|
@@ -59,15 +67,18 @@ function copyMigrationsToLibDb() {
|
|
|
59
67
|
for (const sourceRoot of sourceRoots) {
|
|
60
68
|
const sourcePath = join(cwd, sourceRoot, 'migrations');
|
|
61
69
|
if (existsSync(sourcePath)) {
|
|
62
|
-
// Ensure
|
|
70
|
+
// Ensure destination directory exists
|
|
63
71
|
ensureDir(join(destPath, 'dummy'));
|
|
64
72
|
// Copy (not move) to preserve source imports
|
|
65
73
|
execSync(`cp -r "${sourcePath}/." "${destPath}"`, { stdio: 'pipe' });
|
|
66
|
-
console.log(`Copied ${sourceRoot}/migrations →
|
|
74
|
+
console.log(`Copied ${sourceRoot}/migrations → ${libDbPath}/migrations`);
|
|
67
75
|
return true;
|
|
68
76
|
}
|
|
69
77
|
}
|
|
70
|
-
|
|
78
|
+
// No migrations found - create empty folder so Docker build doesn't fail
|
|
79
|
+
ensureDir(join(destPath, 'dummy'));
|
|
80
|
+
console.log(`Created empty ${libDbPath}/migrations (no source migrations found)`);
|
|
81
|
+
return true;
|
|
71
82
|
}
|
|
72
83
|
function excludeMigrateFromTsConfig(migratePath) {
|
|
73
84
|
const tsconfigPath = join(process.cwd(), 'tsconfig.json');
|
|
@@ -96,11 +107,14 @@ function excludeMigrateFromTsConfig(migratePath) {
|
|
|
96
107
|
}
|
|
97
108
|
export async function generateFiles(options) {
|
|
98
109
|
const { projectName, projectType, packageManager, includePostgres, includeRedis, includeMinio, } = options;
|
|
110
|
+
// Detect if project uses src/ directory structure
|
|
111
|
+
const usesSrcDirectory = projectType === 'nextjs' && detectSrcDirectory();
|
|
99
112
|
// Generate Dockerfile
|
|
100
113
|
const dockerfile = generateDockerfile({
|
|
101
114
|
projectType,
|
|
102
115
|
packageManager,
|
|
103
116
|
includePostgres,
|
|
117
|
+
usesSrcDirectory,
|
|
104
118
|
});
|
|
105
119
|
writeFile('Dockerfile', dockerfile);
|
|
106
120
|
// Generate docker-compose.yml
|
|
@@ -125,6 +139,7 @@ export async function generateFiles(options) {
|
|
|
125
139
|
const entrypoint = generateEntrypoint({
|
|
126
140
|
projectType,
|
|
127
141
|
includePostgres,
|
|
142
|
+
usesSrcDirectory,
|
|
128
143
|
});
|
|
129
144
|
writeFile('entrypoint.sh', entrypoint);
|
|
130
145
|
// Generate Claude rules
|
|
@@ -132,17 +147,19 @@ export async function generateFiles(options) {
|
|
|
132
147
|
writeFile('.claude/rules/coolify.md', claudeRules);
|
|
133
148
|
// Generate migrate.ts if postgres is included
|
|
134
149
|
if (includePostgres) {
|
|
135
|
-
const migrateScript = generateMigrateScript({ projectType });
|
|
150
|
+
const migrateScript = generateMigrateScript({ projectType, usesSrcDirectory });
|
|
136
151
|
// For Next.js standalone projects, we need esbuild to bundle the migration script
|
|
137
152
|
if (projectType === 'nextjs') {
|
|
138
153
|
const added = addEsbuildToPackageJson(packageManager);
|
|
139
154
|
if (added) {
|
|
140
155
|
console.log('Added esbuild to devDependencies (required for migration bundling)');
|
|
141
156
|
}
|
|
157
|
+
// Use src/lib/db for projects with src/ directory, otherwise lib/db
|
|
158
|
+
const libDbPath = usesSrcDirectory ? 'src/lib/db' : 'lib/db';
|
|
142
159
|
// Copy migrations to lib/db/ for Docker build (don't move - preserve source imports)
|
|
143
|
-
copyMigrationsToLibDb();
|
|
160
|
+
copyMigrationsToLibDb(usesSrcDirectory);
|
|
144
161
|
// Write migrate.ts to lib/db/ for Next.js projects (will be bundled at build time)
|
|
145
|
-
const migratePath =
|
|
162
|
+
const migratePath = `${libDbPath}/migrate.ts`;
|
|
146
163
|
const existingMigratePath = join(process.cwd(), migratePath);
|
|
147
164
|
if (!existsSync(existingMigratePath)) {
|
|
148
165
|
writeFile(migratePath, migrateScript);
|
|
@@ -150,7 +167,7 @@ export async function generateFiles(options) {
|
|
|
150
167
|
// Exclude migrate.ts from TypeScript compilation (it's bundled separately by esbuild)
|
|
151
168
|
const excluded = excludeMigrateFromTsConfig(migratePath);
|
|
152
169
|
if (excluded) {
|
|
153
|
-
console.log(
|
|
170
|
+
console.log(`Added ${migratePath} to tsconfig.json exclude (bundled separately)`);
|
|
154
171
|
}
|
|
155
172
|
}
|
|
156
173
|
else {
|
package/dist/index.js
CHANGED
|
@@ -88,8 +88,10 @@ async function main() {
|
|
|
88
88
|
// Add migrate script and db folder if postgres included
|
|
89
89
|
if (response.includePostgres) {
|
|
90
90
|
if (project.type === 'nextjs') {
|
|
91
|
-
|
|
92
|
-
|
|
91
|
+
// Use src/lib/db for projects with src/ directory, otherwise lib/db
|
|
92
|
+
const libDbPath = project.usesSrcDirectory ? 'src/lib/db' : 'lib/db';
|
|
93
|
+
generatedFiles.push(`${libDbPath}/migrate.ts`);
|
|
94
|
+
generatedFiles.push(`${libDbPath}/migrations/`); // Include copied migrations folder
|
|
93
95
|
generatedFiles.push('tsconfig.json'); // May be modified with exclude
|
|
94
96
|
}
|
|
95
97
|
else {
|
|
@@ -104,7 +106,8 @@ async function main() {
|
|
|
104
106
|
console.log(chalk.green(' ✓ entrypoint.sh'));
|
|
105
107
|
if (response.includePostgres) {
|
|
106
108
|
if (project.type === 'nextjs') {
|
|
107
|
-
|
|
109
|
+
const libDbPath = project.usesSrcDirectory ? 'src/lib/db' : 'lib/db';
|
|
110
|
+
console.log(chalk.green(` ✓ ${libDbPath}/migrate.ts`));
|
|
108
111
|
}
|
|
109
112
|
else {
|
|
110
113
|
console.log(chalk.green(' ✓ scripts/migrate.ts'));
|
|
@@ -5,7 +5,9 @@ export function generateDockerfile(options) {
|
|
|
5
5
|
return generateNodeDockerfile(options);
|
|
6
6
|
}
|
|
7
7
|
function generateNextjsDockerfile(options) {
|
|
8
|
-
const { packageManager, includePostgres } = options;
|
|
8
|
+
const { packageManager, includePostgres, usesSrcDirectory } = options;
|
|
9
|
+
// Use src/lib/db for projects with src/ directory structure
|
|
10
|
+
const libDbPath = usesSrcDirectory ? 'src/lib/db' : 'lib/db';
|
|
9
11
|
const installCmd = packageManager === 'pnpm'
|
|
10
12
|
? 'pnpm install --frozen-lockfile'
|
|
11
13
|
: packageManager === 'yarn'
|
|
@@ -39,12 +41,12 @@ function generateNextjsDockerfile(options) {
|
|
|
39
41
|
# Build the migration bundle (single JS file with all deps baked in)
|
|
40
42
|
# This avoids module resolution issues in the standalone container
|
|
41
43
|
# postgres is externalized and copied separately due to pnpm symlink resolution issues
|
|
42
|
-
RUN ${esbuildCmd}
|
|
44
|
+
RUN ${esbuildCmd} ${libDbPath}/migrate.ts --bundle --platform=node --target=node22 --outfile=${libDbPath}/migrate.bundle.js --external:dotenv --external:postgres` : '';
|
|
43
45
|
const migrationCopy = includePostgres ? `
|
|
44
46
|
|
|
45
47
|
# Copy database migrations and bundled migration script
|
|
46
|
-
COPY --from=builder --chown=nextjs:nodejs /app/
|
|
47
|
-
COPY --from=builder --chown=nextjs:nodejs /app/
|
|
48
|
+
COPY --from=builder --chown=nextjs:nodejs /app/${libDbPath}/migrations ./${libDbPath}/migrations
|
|
49
|
+
COPY --from=builder --chown=nextjs:nodejs /app/${libDbPath}/migrate.bundle.js ./${libDbPath}/migrate.bundle.js
|
|
48
50
|
|
|
49
51
|
# Copy postgres module for migration script (externalized from bundle due to pnpm symlinks)
|
|
50
52
|
COPY --from=builder --chown=nextjs:nodejs /app/node_modules/.pnpm/postgres@*/node_modules/postgres ./node_modules/postgres` : '';
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export function generateEntrypoint(options) {
|
|
2
|
-
const { projectType, includePostgres } = options;
|
|
2
|
+
const { projectType, includePostgres, usesSrcDirectory } = options;
|
|
3
|
+
// Use src/lib/db for projects with src/ directory, otherwise lib/db
|
|
4
|
+
const libDbPath = usesSrcDirectory ? 'src/lib/db' : 'lib/db';
|
|
3
5
|
// For Next.js standalone, we run the bundled JS file (no tsx needed)
|
|
4
6
|
// For Node.js, we use tsx since full node_modules is available
|
|
5
7
|
const migrationStep = includePostgres
|
|
@@ -7,7 +9,7 @@ export function generateEntrypoint(options) {
|
|
|
7
9
|
? `
|
|
8
10
|
# Run database migrations (bundled JS with all deps baked in)
|
|
9
11
|
echo "⏳ Running database migrations..."
|
|
10
|
-
node
|
|
12
|
+
node ${libDbPath}/migrate.bundle.js
|
|
11
13
|
`
|
|
12
14
|
: `
|
|
13
15
|
# Run database migrations
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
export function generateMigrateScript(options) {
|
|
2
2
|
const projectType = options?.projectType ?? 'nextjs';
|
|
3
|
-
|
|
3
|
+
const usesSrcDirectory = options?.usesSrcDirectory ?? false;
|
|
4
|
+
// For Next.js, migrations are in lib/db/migrations (or src/lib/db/migrations for src/ projects)
|
|
4
5
|
// For Node.js, migrations are in scripts/migrations (run with tsx)
|
|
5
6
|
const migrationsFolder = projectType === 'nextjs'
|
|
6
|
-
? './lib/db/migrations'
|
|
7
|
+
? (usesSrcDirectory ? './src/lib/db/migrations' : './lib/db/migrations')
|
|
7
8
|
: './scripts/migrations';
|
|
8
9
|
return `import { drizzle } from 'drizzle-orm/postgres-js';
|
|
9
10
|
import { migrate } from 'drizzle-orm/postgres-js/migrator';
|