oraksoft-node-tools 0.1.6 → 0.1.30

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/lib/deploy-ftp.js CHANGED
@@ -1,100 +1,178 @@
1
1
  import { Client } from "basic-ftp";
2
- import path from "path";
2
+ import path, { parse } from "path";
3
3
  import fs from 'fs';
4
4
  import { fileURLToPath } from 'url';
5
+ import { parseArgs } from './args-parser.js';
6
+ import { addVersionToFilename, appendRandomToFilename, parseEnvContent } from "./osf-node-utils.js";
5
7
 
8
+ // @ts-ignore
6
9
  const __filename = fileURLToPath(import.meta.url);
7
10
  const __dirname = path.dirname(__filename);
8
11
 
9
12
  export async function deployFtp() {
10
- // Argüman kontrolü ve yardım mesajı
11
- if (process.argv.includes('--help') || process.argv.includes('-h')) {
12
- // package.json'dan versiyon al
13
- const packageJsonPath = path.join(__dirname, '..', 'package.json');
14
- const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
15
-
16
- console.log(`orak-deploy-ftp version ${packageJson.version}`);
17
- console.log('Kullanım: orak-deploy-ftp');
18
- console.log('Dist klasöründeki dosyaları FTP sunucusuna yükler.');
19
- console.log('Konfigürasyon: .env dosyasında FTP bilgileri gerekli.');
20
- process.exit(0);
21
- }
13
+ const args = parseArgs();
14
+
15
+ // Argüman kontrolü ve yardım mesajı
16
+ if (args.help || args.h) {
17
+ // package.json'dan versiyon al
18
+ const pathPackageJsonLib = path.join(__dirname, '..', 'package.json');
19
+ const objPackageJsonLib = JSON.parse(fs.readFileSync(pathPackageJsonLib, 'utf-8'));
20
+ console.log(`orak-deploy-ftp version ${objPackageJsonLib.version}`);
21
+ console.log('Kullanım: orak-deploy-ftp');
22
+ console.log('Dist klasöründeki dosyaları FTP sunucusuna yükler.');
23
+ console.log('Konfigürasyon: .env dosyasında FTP bilgileri gerekli.');
24
+ process.exit(0);
25
+ }
26
+
27
+ console.log("🚀 FTP Deploy Başlatılıyor...");
22
28
 
23
- const projectRoot = process.cwd();
29
+ const projectRoot = process.cwd();
24
30
 
25
- // .env dosyasını oku
26
- const envPath = path.join(projectRoot, '.env');
27
-
28
- if (!fs.existsSync(envPath)) {
29
- console.error(`
30
- ❌ .env dosyası bulunamadı!
31
+ // .env.orakconfig dosyasını oku
32
+ const envPath = path.join(projectRoot, '.env.orakconfig');
31
33
 
32
- .env dosyası oluşturun ve şu bilgileri ekleyin:
34
+ if (!fs.existsSync(envPath)) {
35
+ console.error(`
36
+ ❌ .env.orakconfig dosyası bulunamadı!
37
+
38
+ .env.orakconfig dosyası oluşturun ve şu bilgileri ekleyin:
33
39
  osf_ftp_host=ftp.example.com
34
40
  osf_ftp_user=username
35
41
  osf_ftp_password=password
36
42
  osf_ftp_secure=false
37
- osf_local_file=deploy.tar.gz
38
- osf_remote_path=/public_html
39
- `);
40
- process.exit(1);
41
- }
43
+ `);
44
+ process.exit(1);
45
+ }
42
46
 
43
- // .env dosyasını parse et
44
- const envContent = fs.readFileSync(envPath, 'utf-8');
45
- const envVars = {};
46
-
47
- envContent.split('\n').forEach(line => {
48
- const trimmedLine = line.trim();
49
- if (trimmedLine && !trimmedLine.startsWith('#')) {
50
- const [key, ...valueParts] = trimmedLine.split('=');
51
- if (key && valueParts.length > 0) {
52
- envVars[key.trim()] = valueParts.join('=').trim();
53
- }
54
- }
55
- });
47
+ // .env.xx dosyasını parse et
48
+ const envContent = fs.readFileSync(envPath, 'utf-8');
49
+ const envVars = parseEnvContent(envContent);
56
50
 
57
- const ftpHost = envVars.osf_ftp_host;
58
- const ftpUser = envVars.osf_ftp_user;
59
- const ftpPassword = envVars.osf_ftp_password;
60
- const ftpSecure = envVars.osf_ftp_secure === 'true';
61
- const localFileName = envVars.osf_local_file || 'deploy.tar.gz';
62
- const remotePath = envVars.osf_remote_path || '/';
51
+ let ftpHost = envVars.osf_ftp_host;
52
+ const ftpUser = envVars.osf_ftp_user;
53
+ const ftpPassword = envVars.osf_ftp_password;
54
+ const ftpSecure = envVars.osf_ftp_secure === 'true';
63
55
 
64
- let localFilePath1 = path.join(projectRoot, "dist", localFileName);
65
- let remoteFilePath1 = path.posix.join(remotePath, localFileName);
56
+ // osf_ftp_local_file support with profile suffix (osf_ftp_local_file_{profile})
57
+ let localFileKey = 'osf_ftp_local_file';
58
+ let remotePathKey = 'osf_ftp_remote_path';
66
59
 
67
- if (!ftpHost || !ftpUser || !ftpPassword) {
68
- console.error("Error: FTP bilgileri eksik. .env.oraksoft dosyasında osf_ftp_host, osf_ftp_user ve osf_ftp_password alanlarını kontrol edin.");
69
- process.exit(1);
70
- }
60
+ if (args.profile || args.p) {
61
+ args.profile = args.profile || args.p;
62
+ console.log(`🔖 Profil kullanılıyor: ${args.profile}`);
63
+ localFileKey = localFileKey + '_' + args.profile;
64
+ remotePathKey = remotePathKey + '_' + args.profile;
65
+ }
66
+
67
+ //let localFileName = envVars[localFileKey]; // ?? envVars.osf_ftp_local_file;
68
+ //let remotePath = envVars[remotePathKey]; // || '/';
69
+
70
+ const pathOrakConfigJson = path.join(projectRoot, 'orak-config.json');
71
+
72
+ if (!fs.existsSync(pathOrakConfigJson)) {
73
+ console.error(`
74
+ ❌ orak-config.json dosyası bulunamadı!
75
+
76
+ .orak-config.json dosyası oluşturun ve şu bilgileri ekleyin:
77
+ ${localFileKey}=<local_file>
78
+ ${remotePathKey}=<remote_path>
79
+ `);
80
+ process.exit(1);
81
+ }
82
+
83
+ const objOrakConfig = JSON.parse(fs.readFileSync(pathOrakConfigJson, 'utf-8'));
84
+
85
+ //orak-config.json dosyasını oku
86
+ let localFileName = objOrakConfig[localFileKey];
87
+ let remotePath = objOrakConfig[remotePathKey];
88
+
89
+ const pathPackageJsonCurrProj = path.join(projectRoot, 'package.json');
90
+ const objPackageJsonCurrProj = JSON.parse(fs.readFileSync(pathPackageJsonCurrProj, 'utf-8'));
91
+
92
+ // Eğer --v verilmişse filename uzantısının öncesine versiyon ekle (örn: test-1_2_3.txt veya deploy-1_2_3.tar.gz)
93
+ if (args.v && localFileName) {
94
+
95
+ const txVersion = objPackageJsonCurrProj.version; //.replace(/\./g, '_');
96
+ localFileName = addVersionToFilename(localFileName, txVersion);
97
+
98
+ console.log(`📦 Versiyon eklendi: ${txVersion}`);
99
+ console.log(`📄 Güncel dosya adı: ${localFileName}`);
100
+ }
101
+
102
+ let localFilePath = path.join(projectRoot, localFileName); //"dist"
103
+ // Dosya adının sonuna rastgele karakter ekle (güvenlik için)
104
+ let remoteFilePath = path.posix.join(remotePath, appendRandomToFilename(path.basename(localFileName)));
105
+
106
+ console.log(`Yerel dosya: ${localFilePath}`);
107
+ console.log(`Remote adres: ${remoteFilePath}`);
71
108
 
72
- const client = new Client();
73
- client.ftp.verbose = true;
74
-
75
- try {
76
- await client.access({
77
- host: ftpHost,
78
- user: ftpUser,
79
- password: ftpPassword,
80
- secure: ftpSecure
81
- });
82
-
83
- const localFilePath = localFilePath1;
84
- const remoteFilePath = remoteFilePath1;
85
-
86
- if (!fs.existsSync(localFilePath)) {
87
- console.error(`Error: Yerel dosya bulunamadı: ${localFilePath}`);
88
- process.exit(1);
89
- }
90
-
91
- console.log(`Yükleniyor: ${localFilePath} -> ${remoteFilePath}`);
92
- await client.uploadFrom(localFilePath, remoteFilePath);
93
- console.log("✅ FTP yükleme tamamlandı!");
109
+ if (!ftpHost || !ftpUser || !ftpPassword) {
110
+ console.error("Error: FTP bilgileri eksik. .env.orakconfig dosyasında osf_ftp_host, osf_ftp_user ve osf_ftp_password alanlarını kontrol edin.");
111
+ process.exit(1);
112
+ }
113
+
114
+ if (!remoteFilePath) {
115
+ console.error("Error: orak-config.json dosyasında osf_ftp_remote_path alanını kontrol edin.");
116
+ process.exit(1);
117
+ }
118
+
119
+ if (!localFilePath) {
120
+ console.error("Error: orak-config.json dosyasında osf_ftp_local_file alanını kontrol edin.");
121
+ process.exit(1);
122
+ }
123
+
124
+ const client = new Client();
125
+ client.ftp.verbose = true;
126
+
127
+ try {
128
+ await client.access({
129
+ host: ftpHost,
130
+ user: ftpUser,
131
+ password: ftpPassword,
132
+ secure: ftpSecure
133
+ });
134
+
135
+ if (!fs.existsSync(localFilePath)) {
136
+ console.error(`Error: Yerel dosya bulunamadı: ${localFilePath}`);
137
+ process.exit(1);
94
138
  }
95
- catch(err) {
96
- console.error("❌ FTP Hatası:", err);
97
- process.exit(1);
139
+
140
+ console.log(`Yükleniyor: ${localFilePath} -> ${remoteFilePath}`);
141
+ await client.uploadFrom(localFilePath, remoteFilePath);
142
+ console.log("✅ FTP yükleme tamamlandı!");
143
+ console.log(`✅ Lokal: ${localFilePath}`);
144
+ console.log(`✅ Remote: ${remoteFilePath}`);
145
+
146
+ // --meta argümanı verilirse yükleme bilgilerini içeren bir JSON dosyası oluştur ve FTP'ye yükler
147
+ if (args.meta) {
148
+ let objFileInfo = {
149
+ "oa1TxVersion": objPackageJsonCurrProj.version,
150
+ "oa1TxUrl": 'https://' + remoteFilePath,
151
+ };
152
+
153
+ let metaFileName = 'app-deploy-info.jsn';
154
+ // objFileInfo bilgi uploadInfo olarak kaydet
155
+ const pathMetaFile = path.join(projectRoot, '.orak-dist', metaFileName);
156
+ fs.writeFileSync(pathMetaFile, JSON.stringify(objFileInfo, null, 2), 'utf-8');
157
+ //console.log(`📁 FTP yükleme bilgisi kaydedildi: ${uploadInfoPath}`);
158
+
159
+ // app-deploy-info.json dosyası da upload edilir
160
+ await client.uploadFrom(pathMetaFile, path.posix.join(remotePath, metaFileName));
161
+ console.log(`📁 FTP'ye ${metaFileName} dosyası yüklendi: ${path.posix.join(remotePath, metaFileName)}`);
162
+
98
163
  }
99
- client.close();
164
+
165
+
166
+ }
167
+ catch (err) {
168
+ console.error("❌ FTP Hatası:", err);
169
+ process.exit(1);
170
+ }
171
+ client.close();
172
+
173
+
174
+
175
+
176
+
177
+
100
178
  }
package/lib/env-change.js CHANGED
@@ -1,68 +1,71 @@
1
1
  import fs from 'fs';
2
2
  import path from 'path';
3
3
  import { fileURLToPath } from 'url';
4
+ import { parseArgs } from './args-parser.js';
4
5
 
5
6
  const __filename = fileURLToPath(import.meta.url);
6
7
  const __dirname = path.dirname(__filename);
7
8
 
8
9
  export function envChange() {
10
+ const args = parseArgs();
9
11
 
10
- // Komut satırından argüman alma
11
- // process.argv[0] = node executable
12
- // process.argv[1] = script dosyası
13
- // process.argv[2] = ilk argüman
14
- const envArgument = process.argv[2];
12
+ // Komut satırından argüman alma (named ve positional)
13
+ // Named: --env dev veya --environment prod
14
+ // Positional: orak-env-change dev (args._[0])
15
+ const envArgument = args.env || args.environment || args._?.[0];
16
+ //console.log(args);
15
17
 
16
- // Argüman kontrolü ve yardım mesajı
17
- if (process.argv.includes('--help') || process.argv.includes('-h')) {
18
- // package.json'dan versiyon al
19
- const packageJsonPath = path.join(__dirname, '..', 'package.json');
20
- const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
21
-
22
- console.log(`orak-env-change version ${packageJson.version}`);
23
- console.log('Kullanım: orak-env-change [ortam_adı]');
24
- console.log('Örnek: orak-env-change dev');
25
- console.log('Argüman verilmezse orak-config.json\'daki fiEnvChangeStatus değeri kullanılır.');
26
- process.exit(0);
27
- }
18
+ // Argüman kontrolü ve yardım mesajı
19
+ if (args.help || args.h) {
20
+ // oraksoft-node-tools package.json'dan versiyon al
21
+ const packageJsonPath = path.join(__dirname, '..', 'package.json');
22
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
28
23
 
29
- // Çalışma dizinini tespit et (komutun çalıştırıldığı yer)
30
- const projectRoot = process.cwd();
24
+ console.log(`orak-env-change version ${packageJson.version}`);
25
+ console.log('Kullanım: orak-env-change [ortam_adı]');
26
+ console.log('Örnek: orak-env-change dev');
27
+ //console.log('Argüman verilmezse orak-config.json\'daki fiEnvChangeStatus değeri kullanılır.');
28
+ process.exit(0);
29
+ }
31
30
 
32
- // orak-config.json dosyasını oku
33
- const configPath = path.join(projectRoot, 'orak-config.json');
34
-
35
- let config = {};
36
- if (fs.existsSync(configPath)) {
37
- config = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
38
- }
31
+ // Çalışma dizinini tespit et (komutun çalıştırıldığı yer)
32
+ const projectRoot = process.cwd();
33
+
34
+ // orak-config.json dosyasını okuma
35
+ const configPath = path.join(projectRoot, 'orak-config.json');
36
+
37
+ let jsoOrakConfig = {};
38
+ // exists - Path olup olmadığına bakar
39
+ if (fs.existsSync(configPath)) {
40
+ jsoOrakConfig = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
41
+ }
39
42
 
40
- let txEnv = envArgument || config.fiEnvChangeStatus;
43
+ let txEnv = envArgument; // || jsoOrakConfig.fiEnvChangeStatus;
41
44
 
42
- if (!txEnv) {
43
- console.error('❌ Ortam adı belirtilmedi ve orak-config.json\'da fiEnvChangeStatus bulunamadı.');
44
- console.log('Kullanım: orak-env-change [ortam_adı]');
45
- console.log('Alternatif: orak-config.json dosyasında "fiEnvChangeStatus" değeri tanımlayın.');
46
- process.exit(1);
47
- }
45
+ if (!txEnv) {
46
+ console.error('❌ Ortam adı belirtilmedi '); //ve orak-config.json\'da fiEnvChangeStatus bulunamadı.
47
+ console.log('Kullanım: orak-env-change [ortam_adı]');
48
+ console.log('Alternatif: orak-config.json dosyasında "fiEnvChangeStatus" değeri tanımlayın.');
49
+ process.exit(1);
50
+ }
48
51
 
49
- try {
50
- // .env dosyasının içeriğini .env.{txEnv} içeriğine eşitle
51
- const envPath = path.join(projectRoot, '.env.' + txEnv);
52
-
53
- if (!fs.existsSync(envPath)) {
54
- console.error(`❌ Ortam dosyası bulunamadı: ${envPath}`);
55
- process.exit(1);
56
- }
57
-
58
- const envContent = fs.readFileSync(envPath, 'utf-8');
59
- fs.writeFileSync(path.join(projectRoot, '.env'), envContent);
60
-
61
- // Başarı mesajı
62
- console.log(`✅ Ortam dosyası başarıyla değiştirildi: .env.${txEnv} -> .env`);
63
- console.log(`📁 Dosya yolu: ${path.join(projectRoot, '.env')}`);
64
- } catch (error) {
65
- console.error('❌ Ortam dosyası değiştirme hatası:', error.message);
66
- process.exit(1);
52
+ try {
53
+ // .env dosyasının içeriğini .env.{txEnv} içeriğine eşitle
54
+ const envPath = path.join(projectRoot, '.env.' + txEnv);
55
+
56
+ if (!fs.existsSync(envPath)) {
57
+ console.error(`❌ Ortam dosyası bulunamadı: ${envPath}`);
58
+ process.exit(1);
67
59
  }
60
+
61
+ const envContent = fs.readFileSync(envPath, 'utf-8');
62
+ fs.writeFileSync(path.join(projectRoot, '.env'), envContent);
63
+
64
+ // Başarı mesajı
65
+ console.log(`✅ Ortam dosyası başarıyla değiştirildi: .env.${txEnv} -> .env`);
66
+ console.log(`📁 Dosya yolu: ${path.join(projectRoot, '.env')}`);
67
+ } catch (error) {
68
+ console.error('❌ Ortam dosyası değiştirme hatası:', error.message);
69
+ process.exit(1);
70
+ }
68
71
  }
@@ -1,68 +1,70 @@
1
1
  import fs from 'fs';
2
2
  import path from 'path';
3
3
  import { fileURLToPath } from 'url';
4
+ import { parseArgs } from './args-parser.js';
4
5
 
5
6
  const __filename = fileURLToPath(import.meta.url);
6
7
  const __dirname = path.dirname(__filename);
7
8
 
8
9
  export function envDevChange() {
10
+ const args = parseArgs();
9
11
 
10
- // Komut satırından argüman alma
11
- // process.argv[0] = node executable
12
- // process.argv[1] = script dosyası
13
- // process.argv[2] = ilk argüman
14
- const envArgument = process.argv[2];
12
+ // Komut satırından argüman alma (named ve positional)
13
+ // Named: --env dev veya --environment prod
14
+ // Positional: orak-env-dev-change dev (args._[0])
15
+ const envArgument = args.env || args.environment || args._?.[0];
16
+ //console.log(args);
15
17
 
16
- // Argüman kontrolü ve yardım mesajı
17
- if (process.argv.includes('--help') || process.argv.includes('-h')) {
18
- // package.json'dan versiyon al
19
- const packageJsonPath = path.join(__dirname, '..', 'package.json');
20
- const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
21
-
22
- console.log(`orak-env-dev-change version ${packageJson.version}`);
23
- console.log('Kullanım: orak-env-dev-change [ortam_adı]');
24
- console.log('Örnek: orak-env-dev-change dev');
25
- console.log('Argüman verilmezse orak-config.json\'daki fiEnvChangeStatus değeri kullanılır.');
26
- process.exit(0);
27
- }
18
+ // Argüman kontrolü ve yardım mesajı
19
+ if (args.help || args.h) {
20
+ // oraksoft-node-tools package.json'dan versiyon al
21
+ const packageJsonPath = path.join(__dirname, '..', 'package.json');
22
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
28
23
 
29
- // Çalışma dizinini tespit et (komutun çalıştırıldığı yer)
30
- const projectRoot = process.cwd();
24
+ console.log(`orak-env-dev-change version ${packageJson.version}`);
25
+ console.log('Kullanım: orak-env-dev-change [ortam_adı]');
26
+ console.log('Örnek: orak-env-dev-change dev');
27
+ process.exit(0);
28
+ }
31
29
 
32
- // orak-config.json dosyasını oku
33
- const configPath = path.join(projectRoot, 'orak-config.json');
34
-
35
- let config = {};
36
- if (fs.existsSync(configPath)) {
37
- config = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
38
- }
30
+ // Çalışma dizinini tespit et (komutun çalıştırıldığı yer)
31
+ const projectRoot = process.cwd();
32
+
33
+ // orak-config.json dosyasını okuma
34
+ // const configPath = path.join(projectRoot, 'orak-config.json');
35
+
36
+ // let objOrakConfigJson = {};
37
+ // // exists - Path olup olmadığına bakar
38
+ // if (fs.existsSync(configPath)) {
39
+ // objOrakConfigJson = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
40
+ // }
39
41
 
40
- let txEnv = envArgument || config.fiEnvChangeStatus;
42
+ let txEnv = envArgument; // || objOrakConfigJson.fiEnvDevChangeStatus;
41
43
 
42
- if (!txEnv) {
43
- console.error('❌ Ortam adı belirtilmedi ve orak-config.json\'da fiEnvChangeStatus bulunamadı.');
44
- console.log('Kullanım: orak-env-change [ortam_adı]');
45
- console.log('Alternatif: orak-config.json dosyasında "fiEnvChangeStatus" değeri tanımlayın.');
46
- process.exit(1);
47
- }
44
+ if (!txEnv) {
45
+ console.error('❌ Ortam adı belirtilmedi ');
46
+ console.log('Kullanım: orak-env-dev-change [ortam_adı]');
47
+ //console.log('Alternatif: orak-config.json dosyasında "fiEnvDevChangeStatus" değeri tanımlayın.');
48
+ process.exit(1);
49
+ }
48
50
 
49
- try {
50
- // .env dosyasının içeriğini .env.{txEnv} içeriğine eşitle
51
- const envPath = path.join(projectRoot, '.env.' + txEnv);
52
-
53
- if (!fs.existsSync(envPath)) {
54
- console.error(`❌ Ortam dosyası bulunamadı: ${envPath}`);
55
- process.exit(1);
56
- }
57
-
58
- const envContent = fs.readFileSync(envPath, 'utf-8');
59
- fs.writeFileSync(path.join(projectRoot, '.env.development'), envContent);
60
-
61
- // Başarı mesajı
62
- console.log(`✅ Ortam dosyası başarıyla değiştirildi: .env.${txEnv} -> .env.development`);
63
- console.log(`📁 Dosya yolu: ${path.join(projectRoot, '.env.development')}`);
64
- } catch (error) {
65
- console.error('❌ Ortam dosyası değiştirme hatası:', error.message);
66
- process.exit(1);
51
+ try {
52
+ // .env dosyasının içeriğini .env.{txEnv} içeriğine eşitle
53
+ const envPath = path.join(projectRoot, '.env.' + txEnv);
54
+
55
+ if (!fs.existsSync(envPath)) {
56
+ console.error(`❌ Ortam dosyası bulunamadı: ${envPath}`);
57
+ process.exit(1);
67
58
  }
59
+
60
+ const envContent = fs.readFileSync(envPath, 'utf-8');
61
+ fs.writeFileSync(path.join(projectRoot, '.env.development'), envContent);
62
+
63
+ // Başarı mesajı
64
+ console.log(`✅ Ortam dosyası başarıyla değiştirildi: .env.${txEnv} -> .env.development`);
65
+ console.log(`📁 Dosya yolu: ${path.join(projectRoot, '.env.development')}`);
66
+ } catch (error) {
67
+ console.error('❌ Ortam dosyası değiştirme hatası:', error.message);
68
+ process.exit(1);
69
+ }
68
70
  }
package/lib/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export { copyDeps } from './copy-deps.js';
2
2
  export { deployFtp } from './deploy-ftp.js';
3
- export { deployZip } from './deploy-zip.js';
3
+ export { zipPackage } from './zip-package.js';
4
+ export { zipContent } from './zip-content.js';
4
5
  export { envChange } from './env-change.js';
5
- export { envDevChange } from './env-dev-change.js';
@@ -0,0 +1,104 @@
1
+ import path from "path";
2
+
3
+ /**
4
+ * Çoklu uzantı desteğiyle dosya adına versiyon ekler
5
+ * @param {string} pFileName
6
+ * @param {string} pVersion
7
+ * @returns {string}
8
+ */
9
+ export function addVersionToFilename(pFileName, pVersion) {
10
+ const txVersion = pVersion.replace(/\./g, '_');
11
+ //const path = require('path');
12
+ const parsed = path.parse(pFileName);
13
+ let parsedFile = parseFileNameAndExtension(pFileName);
14
+ // dosya uzantısı
15
+ let ext = parsedFile.ext;
16
+ let nameNoExt = parsedFile.name;
17
+ const seper = '_'; // nameNoExt.endsWith('-') || nameNoExt.endsWith('_') ? '' : '-';
18
+ const newBase = nameNoExt + seper + txVersion;
19
+ return parsed.dir ? path.join(parsed.dir, newBase + ext) : newBase + ext;
20
+ }
21
+
22
+ export function addVersionToFilename2(pFileName, pVersion) {
23
+ const txVersion = pVersion.replace(/\./g, '_');
24
+ //const path = require('path');
25
+ const parsed = path.parse(pFileName);
26
+ const base = parsed.base;
27
+ const multiExts = ['.tar.gz', '.tar.bz2', '.tar.xz', '.tar.lz', '.tar.Z', '.tgz'];
28
+ // dosya uzantısı
29
+ let ext = parsed.ext;
30
+ let nameNoExt = parsed.name;
31
+ for (const me of multiExts) {
32
+ if (base.toLowerCase().endsWith(me.toLowerCase())) {
33
+ ext = me;
34
+ // uzantısız dosya adı (örn. deploy.tar.gz -> deploy)
35
+ nameNoExt = base.slice(0, -me.length);
36
+ break;
37
+ }
38
+ }
39
+ const seper = '_'; // nameNoExt.endsWith('-') || nameNoExt.endsWith('_') ? '' : '-';
40
+ const newBase = nameNoExt + seper + txVersion;
41
+ return parsed.dir ? path.join(parsed.dir, newBase + ext) : newBase + ext;
42
+ }
43
+
44
+ // .env benzeri dosya içeriğini parse eden util fonksiyonu
45
+ export function parseEnvContent(envContent) {
46
+ const envVars = {};
47
+ envContent.split('\n').forEach(line => {
48
+ const trimmedLine = line.trim();
49
+ if (trimmedLine && !trimmedLine.startsWith('#')) {
50
+ const [key, ...valueParts] = trimmedLine.split('=');
51
+ if (key && valueParts.length > 0) {
52
+ envVars[key.trim()] = valueParts.join('=').trim();
53
+ }
54
+ }
55
+ });
56
+ return envVars;
57
+ }
58
+
59
+ export function appendRandomToFilename(filename) {
60
+ const parsed = path.parse(filename);
61
+ const randomStr = Math.random().toString(36).substring(2, 10); // 8 karakter
62
+
63
+ let parsedFile = parseFileNameAndExtension(filename);
64
+ let ext = parsedFile.ext;
65
+ let nameNoExt = parsedFile.name;
66
+ return nameNoExt + '_' + randomStr + ext;
67
+ }
68
+
69
+ export function appendRandomToFilename2(filename) {
70
+ const randomStr = Math.random().toString(36).substring(2, 10); // 8 karakter
71
+ const base = path.basename(filename);
72
+ const firstDotIdx = base.indexOf('.');
73
+ let nameNoExt = base;
74
+ let ext = '';
75
+ if (firstDotIdx !== -1) {
76
+ nameNoExt = base.slice(0, firstDotIdx);
77
+ ext = base.slice(firstDotIdx);
78
+ }
79
+ return nameNoExt + '_' + randomStr + ext;
80
+ }
81
+
82
+ /**
83
+ * Çoklu uzantı desteğiyle dosya adı ve uzantısını parse eder
84
+ *
85
+ * @param {*} filename
86
+ * @returns { {name: string, ext: string} } name: uzantısız dosya adı, ext: dosya uzantısı (çoklu uzantı destekli)
87
+ */
88
+ export function parseFileNameAndExtension(filename) {
89
+ const base = path.basename(filename);
90
+ const firstDotIdx = base.indexOf('.');
91
+ let nameNoExt = base;
92
+ let ext = '';
93
+ if (firstDotIdx !== -1) {
94
+ nameNoExt = base.slice(0, firstDotIdx);
95
+ ext = base.slice(firstDotIdx);
96
+ }
97
+ return { "name": nameNoExt, "ext": ext };
98
+ }
99
+
100
+ export class DeployConfig {
101
+ objOrakConfig = {};
102
+ pathProjectRoot = "";
103
+ objPackageJson = {};
104
+ }