@panoptic-it-solutions/coolify-setup 1.0.0 → 1.1.0

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 CHANGED
@@ -37,6 +37,31 @@ function addEsbuildToPackageJson() {
37
37
  return false;
38
38
  }
39
39
  }
40
+ function excludeMigrateFromTsConfig(migratePath) {
41
+ const tsconfigPath = join(process.cwd(), 'tsconfig.json');
42
+ if (!existsSync(tsconfigPath)) {
43
+ console.log('Warning: tsconfig.json not found, skipping exclusion');
44
+ return false;
45
+ }
46
+ try {
47
+ const tsconfig = JSON.parse(readFileSync(tsconfigPath, 'utf-8'));
48
+ // Ensure exclude array exists
49
+ if (!tsconfig.exclude) {
50
+ tsconfig.exclude = ['node_modules'];
51
+ }
52
+ // Add migrate.ts to exclude if not already present
53
+ if (!tsconfig.exclude.includes(migratePath)) {
54
+ tsconfig.exclude.push(migratePath);
55
+ writeFileSync(tsconfigPath, JSON.stringify(tsconfig, null, 2) + '\n', 'utf-8');
56
+ return true;
57
+ }
58
+ return false;
59
+ }
60
+ catch (error) {
61
+ console.log('Warning: Failed to update tsconfig.json:', error);
62
+ return false;
63
+ }
64
+ }
40
65
  export async function generateFiles(options) {
41
66
  const { projectName, projectType, packageManager, includePostgres, includeRedis, includeMinio, } = options;
42
67
  // Generate Dockerfile
@@ -84,9 +109,15 @@ export async function generateFiles(options) {
84
109
  console.log('Run your package manager install command to install it');
85
110
  }
86
111
  // Write migrate.ts to lib/db/ for Next.js projects (will be bundled at build time)
87
- const existingMigratePath = join(process.cwd(), 'lib/db/migrate.ts');
112
+ const migratePath = 'lib/db/migrate.ts';
113
+ const existingMigratePath = join(process.cwd(), migratePath);
88
114
  if (!existsSync(existingMigratePath)) {
89
- writeFile('lib/db/migrate.ts', migrateScript);
115
+ writeFile(migratePath, migrateScript);
116
+ }
117
+ // Exclude migrate.ts from TypeScript compilation (it's bundled separately by esbuild)
118
+ const excluded = excludeMigrateFromTsConfig(migratePath);
119
+ if (excluded) {
120
+ console.log('Added lib/db/migrate.ts to tsconfig.json exclude (bundled separately)');
90
121
  }
91
122
  }
92
123
  else {
package/dist/git.d.ts CHANGED
@@ -1 +1,11 @@
1
- export declare function setupGitHub(projectName: string): Promise<void>;
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 hasGitRemote() {
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 false;
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
- // Create repo if no remote exists
52
- if (!hasGitRemote()) {
53
- // Create the repository
54
- await runAsync(`gh repo create ${ORG}/${projectName} --private --source=. --push`);
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
- // Remote exists, just push
58
- run('git push origin HEAD');
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
- // May already be pushed
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
- // May already exist
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
- // May already exist
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
- // May fail if not owner or already set
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
- console.log(chalk.green(` ✓ Created repo: Panoptic-IT-Solutions/${response.projectName}`));
83
- console.log(chalk.green(' ✓ Pushed main branch'));
84
- console.log(chalk.green(' ✓ Created staging branch'));
85
- console.log(chalk.green(' ✓ Created develop branch (default)'));
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}`));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@panoptic-it-solutions/coolify-setup",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "CLI tool for setting up Coolify deployment on Panoptic projects",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",