@panoptic-it-solutions/coolify-setup 1.0.0 → 1.1.1
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/generator.js +44 -5
- package/dist/git.d.ts +11 -1
- package/dist/git.js +57 -14
- package/dist/index.js +32 -5
- package/package.json +1 -1
package/dist/generator.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, writeFileSync, readFileSync } from 'fs';
|
|
2
2
|
import { join, dirname } from 'path';
|
|
3
|
+
import { execSync } from 'child_process';
|
|
3
4
|
import { generateDockerfile, generateDockerCompose, generateDockerComposeBuild, generateWorkflow, generateEntrypoint, generateMigrateScript, generateClaudeRules, } from './templates/index.js';
|
|
4
5
|
function ensureDir(filePath) {
|
|
5
6
|
const dir = dirname(filePath);
|
|
@@ -12,7 +13,7 @@ function writeFile(relativePath, content) {
|
|
|
12
13
|
ensureDir(fullPath);
|
|
13
14
|
writeFileSync(fullPath, content, 'utf-8');
|
|
14
15
|
}
|
|
15
|
-
function addEsbuildToPackageJson() {
|
|
16
|
+
function addEsbuildToPackageJson(packageManager) {
|
|
16
17
|
const packageJsonPath = join(process.cwd(), 'package.json');
|
|
17
18
|
if (!existsSync(packageJsonPath)) {
|
|
18
19
|
console.log('Warning: package.json not found, skipping esbuild addition');
|
|
@@ -28,6 +29,14 @@ function addEsbuildToPackageJson() {
|
|
|
28
29
|
if (!packageJson.devDependencies.esbuild) {
|
|
29
30
|
packageJson.devDependencies.esbuild = '^0.25.0';
|
|
30
31
|
writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2) + '\n', 'utf-8');
|
|
32
|
+
// Update the lockfile so Docker build works with frozen-lockfile
|
|
33
|
+
const installCmd = packageManager === 'pnpm'
|
|
34
|
+
? 'pnpm install'
|
|
35
|
+
: packageManager === 'yarn'
|
|
36
|
+
? 'yarn install'
|
|
37
|
+
: 'npm install';
|
|
38
|
+
console.log(`Running ${installCmd} to update lockfile...`);
|
|
39
|
+
execSync(installCmd, { stdio: 'inherit', cwd: process.cwd() });
|
|
31
40
|
return true;
|
|
32
41
|
}
|
|
33
42
|
return false;
|
|
@@ -37,6 +46,31 @@ function addEsbuildToPackageJson() {
|
|
|
37
46
|
return false;
|
|
38
47
|
}
|
|
39
48
|
}
|
|
49
|
+
function excludeMigrateFromTsConfig(migratePath) {
|
|
50
|
+
const tsconfigPath = join(process.cwd(), 'tsconfig.json');
|
|
51
|
+
if (!existsSync(tsconfigPath)) {
|
|
52
|
+
console.log('Warning: tsconfig.json not found, skipping exclusion');
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
try {
|
|
56
|
+
const tsconfig = JSON.parse(readFileSync(tsconfigPath, 'utf-8'));
|
|
57
|
+
// Ensure exclude array exists
|
|
58
|
+
if (!tsconfig.exclude) {
|
|
59
|
+
tsconfig.exclude = ['node_modules'];
|
|
60
|
+
}
|
|
61
|
+
// Add migrate.ts to exclude if not already present
|
|
62
|
+
if (!tsconfig.exclude.includes(migratePath)) {
|
|
63
|
+
tsconfig.exclude.push(migratePath);
|
|
64
|
+
writeFileSync(tsconfigPath, JSON.stringify(tsconfig, null, 2) + '\n', 'utf-8');
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
console.log('Warning: Failed to update tsconfig.json:', error);
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
40
74
|
export async function generateFiles(options) {
|
|
41
75
|
const { projectName, projectType, packageManager, includePostgres, includeRedis, includeMinio, } = options;
|
|
42
76
|
// Generate Dockerfile
|
|
@@ -78,15 +112,20 @@ export async function generateFiles(options) {
|
|
|
78
112
|
const migrateScript = generateMigrateScript({ projectType });
|
|
79
113
|
// For Next.js standalone projects, we need esbuild to bundle the migration script
|
|
80
114
|
if (projectType === 'nextjs') {
|
|
81
|
-
const added = addEsbuildToPackageJson();
|
|
115
|
+
const added = addEsbuildToPackageJson(packageManager);
|
|
82
116
|
if (added) {
|
|
83
117
|
console.log('Added esbuild to devDependencies (required for migration bundling)');
|
|
84
|
-
console.log('Run your package manager install command to install it');
|
|
85
118
|
}
|
|
86
119
|
// Write migrate.ts to lib/db/ for Next.js projects (will be bundled at build time)
|
|
87
|
-
const
|
|
120
|
+
const migratePath = 'lib/db/migrate.ts';
|
|
121
|
+
const existingMigratePath = join(process.cwd(), migratePath);
|
|
88
122
|
if (!existsSync(existingMigratePath)) {
|
|
89
|
-
writeFile(
|
|
123
|
+
writeFile(migratePath, migrateScript);
|
|
124
|
+
}
|
|
125
|
+
// Exclude migrate.ts from TypeScript compilation (it's bundled separately by esbuild)
|
|
126
|
+
const excluded = excludeMigrateFromTsConfig(migratePath);
|
|
127
|
+
if (excluded) {
|
|
128
|
+
console.log('Added lib/db/migrate.ts to tsconfig.json exclude (bundled separately)');
|
|
90
129
|
}
|
|
91
130
|
}
|
|
92
131
|
else {
|
package/dist/git.d.ts
CHANGED
|
@@ -1 +1,11 @@
|
|
|
1
|
-
export
|
|
1
|
+
export interface GitHubSetupResult {
|
|
2
|
+
repoCreated: boolean;
|
|
3
|
+
repoPushed: boolean;
|
|
4
|
+
mainBranchPushed: boolean;
|
|
5
|
+
stagingBranchCreated: boolean;
|
|
6
|
+
developBranchCreated: boolean;
|
|
7
|
+
defaultBranchSet: boolean;
|
|
8
|
+
existingRemote: string | null;
|
|
9
|
+
warnings: string[];
|
|
10
|
+
}
|
|
11
|
+
export declare function setupGitHub(projectName: string): Promise<GitHubSetupResult>;
|
package/dist/git.js
CHANGED
|
@@ -9,13 +9,12 @@ async function runAsync(command) {
|
|
|
9
9
|
const { stdout } = await execAsync(command);
|
|
10
10
|
return stdout.trim();
|
|
11
11
|
}
|
|
12
|
-
function
|
|
12
|
+
function getGitRemoteUrl() {
|
|
13
13
|
try {
|
|
14
|
-
run('git remote get-url origin');
|
|
15
|
-
return true;
|
|
14
|
+
return run('git remote get-url origin');
|
|
16
15
|
}
|
|
17
16
|
catch {
|
|
18
|
-
return
|
|
17
|
+
return null;
|
|
19
18
|
}
|
|
20
19
|
}
|
|
21
20
|
function isGitRepo() {
|
|
@@ -27,7 +26,24 @@ function isGitRepo() {
|
|
|
27
26
|
return false;
|
|
28
27
|
}
|
|
29
28
|
}
|
|
29
|
+
function isCorrectRemote(remoteUrl, projectName) {
|
|
30
|
+
const expectedPatterns = [
|
|
31
|
+
`github.com/${ORG}/${projectName}`,
|
|
32
|
+
`github.com:${ORG}/${projectName}`,
|
|
33
|
+
];
|
|
34
|
+
return expectedPatterns.some(pattern => remoteUrl.includes(pattern));
|
|
35
|
+
}
|
|
30
36
|
export async function setupGitHub(projectName) {
|
|
37
|
+
const result = {
|
|
38
|
+
repoCreated: false,
|
|
39
|
+
repoPushed: false,
|
|
40
|
+
mainBranchPushed: false,
|
|
41
|
+
stagingBranchCreated: false,
|
|
42
|
+
developBranchCreated: false,
|
|
43
|
+
defaultBranchSet: false,
|
|
44
|
+
existingRemote: null,
|
|
45
|
+
warnings: [],
|
|
46
|
+
};
|
|
31
47
|
// Initialize git if not already a repo
|
|
32
48
|
if (!isGitRepo()) {
|
|
33
49
|
run('git init');
|
|
@@ -48,14 +64,36 @@ export async function setupGitHub(projectName) {
|
|
|
48
64
|
catch {
|
|
49
65
|
throw new Error('Not authenticated with GitHub CLI. Run: gh auth login');
|
|
50
66
|
}
|
|
51
|
-
//
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
67
|
+
// Check existing remote
|
|
68
|
+
const existingRemote = getGitRemoteUrl();
|
|
69
|
+
result.existingRemote = existingRemote;
|
|
70
|
+
if (existingRemote) {
|
|
71
|
+
// Validate remote points to the correct repo
|
|
72
|
+
if (!isCorrectRemote(existingRemote, projectName)) {
|
|
73
|
+
result.warnings.push(`Existing remote '${existingRemote}' does not match expected repo '${ORG}/${projectName}'. ` +
|
|
74
|
+
`Remove it with 'git remote remove origin' and re-run setup to create the correct repo.`);
|
|
75
|
+
// Don't proceed with operations that would push to the wrong repo
|
|
76
|
+
return result;
|
|
77
|
+
}
|
|
78
|
+
// Remote exists and is correct, just push
|
|
79
|
+
try {
|
|
80
|
+
run('git push origin HEAD');
|
|
81
|
+
result.repoPushed = true;
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
result.warnings.push(`Failed to push to existing remote: ${error}`);
|
|
85
|
+
}
|
|
55
86
|
}
|
|
56
87
|
else {
|
|
57
|
-
//
|
|
58
|
-
|
|
88
|
+
// Create the repository
|
|
89
|
+
try {
|
|
90
|
+
await runAsync(`gh repo create ${ORG}/${projectName} --private --source=. --push`);
|
|
91
|
+
result.repoCreated = true;
|
|
92
|
+
result.repoPushed = true;
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
throw new Error(`Failed to create repository: ${error}`);
|
|
96
|
+
}
|
|
59
97
|
}
|
|
60
98
|
// Ensure we're on main and push
|
|
61
99
|
const currentBranch = run('git branch --show-current');
|
|
@@ -65,30 +103,35 @@ export async function setupGitHub(projectName) {
|
|
|
65
103
|
// Push main
|
|
66
104
|
try {
|
|
67
105
|
run('git push origin main');
|
|
106
|
+
result.mainBranchPushed = true;
|
|
68
107
|
}
|
|
69
108
|
catch {
|
|
70
|
-
|
|
109
|
+
result.warnings.push('Failed to push main branch (may already exist)');
|
|
71
110
|
}
|
|
72
111
|
// Create staging branch from main
|
|
73
112
|
try {
|
|
74
113
|
run('git push origin main:staging');
|
|
114
|
+
result.stagingBranchCreated = true;
|
|
75
115
|
}
|
|
76
116
|
catch {
|
|
77
|
-
|
|
117
|
+
result.warnings.push('Failed to create staging branch (may already exist)');
|
|
78
118
|
}
|
|
79
119
|
// Create and checkout develop branch
|
|
80
120
|
try {
|
|
81
121
|
run('git checkout -b develop 2>/dev/null || git checkout develop');
|
|
82
122
|
run('git push origin develop -u');
|
|
123
|
+
result.developBranchCreated = true;
|
|
83
124
|
}
|
|
84
125
|
catch {
|
|
85
|
-
|
|
126
|
+
result.warnings.push('Failed to create develop branch (may already exist)');
|
|
86
127
|
}
|
|
87
128
|
// Set develop as default branch
|
|
88
129
|
try {
|
|
89
130
|
await runAsync(`gh repo edit ${ORG}/${projectName} --default-branch develop`);
|
|
131
|
+
result.defaultBranchSet = true;
|
|
90
132
|
}
|
|
91
133
|
catch {
|
|
92
|
-
|
|
134
|
+
result.warnings.push('Failed to set develop as default branch (may lack permissions or already set)');
|
|
93
135
|
}
|
|
136
|
+
return result;
|
|
94
137
|
}
|
package/dist/index.js
CHANGED
|
@@ -78,11 +78,38 @@ async function main() {
|
|
|
78
78
|
if (response.createRepo) {
|
|
79
79
|
console.log(chalk.bold('\nSetting up GitHub...'));
|
|
80
80
|
try {
|
|
81
|
-
await setupGitHub(response.projectName);
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
81
|
+
const result = await setupGitHub(response.projectName);
|
|
82
|
+
// Report what actually happened
|
|
83
|
+
if (result.repoCreated) {
|
|
84
|
+
console.log(chalk.green(` ✓ Created repo: Panoptic-IT-Solutions/${response.projectName}`));
|
|
85
|
+
}
|
|
86
|
+
else if (result.existingRemote) {
|
|
87
|
+
console.log(chalk.yellow(` ⚠ Using existing remote: ${result.existingRemote}`));
|
|
88
|
+
}
|
|
89
|
+
if (result.repoPushed) {
|
|
90
|
+
console.log(chalk.green(' ✓ Pushed to remote'));
|
|
91
|
+
}
|
|
92
|
+
if (result.mainBranchPushed) {
|
|
93
|
+
console.log(chalk.green(' ✓ Pushed main branch'));
|
|
94
|
+
}
|
|
95
|
+
if (result.stagingBranchCreated) {
|
|
96
|
+
console.log(chalk.green(' ✓ Created staging branch'));
|
|
97
|
+
}
|
|
98
|
+
if (result.developBranchCreated) {
|
|
99
|
+
console.log(chalk.green(' ✓ Created develop branch'));
|
|
100
|
+
}
|
|
101
|
+
if (result.defaultBranchSet) {
|
|
102
|
+
console.log(chalk.green(' ✓ Set develop as default branch'));
|
|
103
|
+
}
|
|
104
|
+
// Show warnings
|
|
105
|
+
for (const warning of result.warnings) {
|
|
106
|
+
console.log(chalk.yellow(` ⚠ ${warning}`));
|
|
107
|
+
}
|
|
108
|
+
// If nothing succeeded, show a failure message
|
|
109
|
+
if (!result.repoCreated && !result.repoPushed && result.warnings.length > 0) {
|
|
110
|
+
console.log(chalk.red('\n ✗ GitHub setup did not complete successfully'));
|
|
111
|
+
console.log(chalk.yellow(' You can manually run: gh repo create Panoptic-IT-Solutions/' + response.projectName));
|
|
112
|
+
}
|
|
86
113
|
}
|
|
87
114
|
catch (error) {
|
|
88
115
|
console.log(chalk.red(` ✗ GitHub setup failed: ${error}`));
|