oraksoft-node-tools 0.1.18 → 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/.orak-dist/app-deploy-info.jsn +4 -0
- package/.orak-dist/app-deploy-info.json +4 -0
- package/.orak-dist/deploy-0_1_29.tar.gz +0 -0
- package/.orak-dist/deploy-test-0_1_25.tar.gz +0 -0
- package/.orak-dist/test1.txt +0 -0
- package/.orak-dist/test2.txt +0 -0
- package/README.md +11 -3
- package/bin/orak-deploy-ftp-files.js +5 -0
- package/jsconfig.json +18 -0
- package/lib/deploy-ftp-files.js +152 -0
- package/lib/deploy-ftp.js +77 -66
- package/lib/osf-node-utils.js +104 -0
- package/lib/zip-content.js +28 -42
- package/lib/zip-package.js +22 -27
- package/package.json +2 -1
- package/.orak-dist/deploy-0_1_17.tar.gz +0 -0
- package/.orak-dist/deploy-test-0_1_17.tar.gz +0 -0
- package/.orak-dist/deploy-test.tar.gz +0 -0
- package/.orak-dist/deploy.tar.gz +0 -0
- /package/.orak-dist/{test-0_1_17.txt → test-0_1_27.txt} +0 -0
|
Binary file
|
|
Binary file
|
|
File without changes
|
|
File without changes
|
package/README.md
CHANGED
|
@@ -93,14 +93,22 @@ orak-deploy-ftp [--profile <name>] [--v]
|
|
|
93
93
|
|
|
94
94
|
**Gerekli .env.orakconfig dosyası:**
|
|
95
95
|
|
|
96
|
-
```
|
|
96
|
+
```bash
|
|
97
97
|
osf_ftp_host=ftp.example.com
|
|
98
98
|
osf_ftp_user=username
|
|
99
99
|
osf_ftp_password=password
|
|
100
100
|
osf_ftp_secure=false
|
|
101
|
+
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
**Gerekli orak-config.json dosyası:**
|
|
105
|
+
|
|
106
|
+
```bash
|
|
101
107
|
osf_ftp_local_file=deploy.tar.gz
|
|
102
108
|
osf_ftp_remote_path=public_html
|
|
103
|
-
|
|
109
|
+
|
|
110
|
+
```
|
|
111
|
+
|
|
104
112
|
|
|
105
113
|
- `osf_ftp_host`: FTP sunucusunun adresi
|
|
106
114
|
- `osf_ftp_user`: FTP kullanıcı adı
|
|
@@ -112,7 +120,7 @@ osf_ftp_remote_path=public_html
|
|
|
112
120
|
|
|
113
121
|
Ek opsiyonlar:
|
|
114
122
|
|
|
115
|
-
- `--profile <
|
|
123
|
+
- `--profile <profil_name>`: Belirtilen profil için önce `osf_ftp_local_file_<profil_name>` (veya `orak-config.json` içinde aynı anahtar) aranır. Örnek: `--profile test` -> `osf_ftp_local_file_test`. Konsolda: `test profil uygulandı.`
|
|
116
124
|
|
|
117
125
|
- `--v`: Paket sürümünü (`package.json` içindeki `version`) dosya adına ekler. Noktalar `_` ile değiştirilecek (örn. `1.2.3` -> `1_2_3`) ve çok parçalı uzantılar korunacaktır (`deploy.tar.gz` -> `deploy-1_2_3.tar.gz`). Konsolda: `📦 Versiyon eklendi: 1_2_3` ve `📄 Güncel dosya adı: ...`
|
|
118
126
|
|
package/jsconfig.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "es2020",
|
|
4
|
+
"module": "commonjs",
|
|
5
|
+
"checkJs": true,
|
|
6
|
+
"allowJs": true,
|
|
7
|
+
"moduleResolution": "node",
|
|
8
|
+
"baseUrl": ".",
|
|
9
|
+
"paths": {
|
|
10
|
+
"*": ["node_modules/*", "lib/*"]
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"exclude": [
|
|
14
|
+
"node_modules",
|
|
15
|
+
"**/dist",
|
|
16
|
+
"**/build"
|
|
17
|
+
]
|
|
18
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { Client } from "basic-ftp";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
import { fileURLToPath } from 'url';
|
|
5
|
+
import { parseArgs } from './args-parser.js';
|
|
6
|
+
import { parseEnvContent, addVersionToFilename, DeployConfig } from './osf-node-utils.js';
|
|
7
|
+
|
|
8
|
+
// @ts-ignore
|
|
9
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
10
|
+
const __dirname = path.dirname(__filename);
|
|
11
|
+
|
|
12
|
+
//console.log("filename:" + __filename);
|
|
13
|
+
//console.log("dirname:" + __dirname);
|
|
14
|
+
|
|
15
|
+
export async function deployFtpFiles() {
|
|
16
|
+
const args = parseArgs();
|
|
17
|
+
|
|
18
|
+
let deployConfig = new DeployConfig();
|
|
19
|
+
|
|
20
|
+
const packageJsonPath = path.join(__dirname, '..', 'package.json');
|
|
21
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
|
|
22
|
+
deployConfig.objPackageJson = packageJson;
|
|
23
|
+
|
|
24
|
+
// Argüman kontrolü ve yardım mesajı
|
|
25
|
+
if (args.help || args.h) {
|
|
26
|
+
// package.json'dan versiyon al
|
|
27
|
+
console.log(`orak-deploy-ftp-files version ${packageJson.version}`);
|
|
28
|
+
console.log('Kullanım: orak-deploy-ftp-files');
|
|
29
|
+
console.log('');
|
|
30
|
+
console.log('Konfigürasyon: .env dosyasında FTP bilgileri gerekli.');
|
|
31
|
+
process.exit(0);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
console.log("🚀 FTP Deploy Files Başlatılıyor...");
|
|
35
|
+
|
|
36
|
+
const projectRoot = process.cwd();
|
|
37
|
+
deployConfig.pathProjectRoot = projectRoot;
|
|
38
|
+
|
|
39
|
+
//console.log("Project Root:"+ projectRoot);
|
|
40
|
+
//Project Root:Y:\devrepo-oraksoft-web\oraksoft-node-tools
|
|
41
|
+
|
|
42
|
+
// .env.orakconfig dosyasını oku
|
|
43
|
+
const pathEnvOrakConfig = path.join(projectRoot, '.env.orakconfig');
|
|
44
|
+
|
|
45
|
+
//console.log("envPath:" + pathEnvOrakConfig);
|
|
46
|
+
//envPath:Y:\devrepo-oraksoft-web\oraksoft-node-tools\.env.orakconfig
|
|
47
|
+
|
|
48
|
+
if (!fs.existsSync(pathEnvOrakConfig)) {
|
|
49
|
+
console.error(`
|
|
50
|
+
❌ .env.orakconfig dosyası bulunamadı!
|
|
51
|
+
|
|
52
|
+
.env.orakconfig dosyası oluşturun ve şu bilgileri ekleyin:
|
|
53
|
+
osf_ftp_host=ftp.example.com
|
|
54
|
+
osf_ftp_user=username
|
|
55
|
+
osf_ftp_password=password
|
|
56
|
+
osf_ftp_secure=false
|
|
57
|
+
`);
|
|
58
|
+
process.exit(1);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// .env.xx dosyasını parse et
|
|
62
|
+
const envContent = fs.readFileSync(pathEnvOrakConfig, 'utf-8');
|
|
63
|
+
const envVars = parseEnvContent(envContent);
|
|
64
|
+
|
|
65
|
+
// ftp güvenlik bilgileri
|
|
66
|
+
let ftpHost = envVars.osf_ftp_host;
|
|
67
|
+
const ftpUser = envVars.osf_ftp_user;
|
|
68
|
+
const ftpPassword = envVars.osf_ftp_password;
|
|
69
|
+
const ftpSecure = envVars.osf_ftp_secure === 'true';
|
|
70
|
+
|
|
71
|
+
// osf_ftp_local_file support with profile suffix (osf_ftp_local_file_{profile})
|
|
72
|
+
let remotePathKey = 'dff_remote_path';
|
|
73
|
+
|
|
74
|
+
if (args.profile || args.p) {
|
|
75
|
+
args.profile = args.profile || args.p;
|
|
76
|
+
console.log(`🔖 Profil kullanılıyor: ${args.profile}`);
|
|
77
|
+
remotePathKey = remotePathKey + '_' + args.profile;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
//let localFileName = envVars[localFileKey];
|
|
81
|
+
let remotePath = envVars[remotePathKey];
|
|
82
|
+
|
|
83
|
+
// if (!ftpHost || !remotePath) {
|
|
84
|
+
const pathOrakConfigJson = path.join(projectRoot, 'orak-config.json');
|
|
85
|
+
|
|
86
|
+
if (!fs.existsSync(pathOrakConfigJson)) {
|
|
87
|
+
console.error(`
|
|
88
|
+
❌ orak-config.json dosyası bulunamadı!
|
|
89
|
+
|
|
90
|
+
.orak-config.json dosyası oluşturun ve şu bilgileri ekleyin:
|
|
91
|
+
${remotePathKey}=<remote_path>
|
|
92
|
+
`);
|
|
93
|
+
process.exit(1);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
//orak-config.json dosyasını oku
|
|
97
|
+
const jsonOrakConfig = JSON.parse(fs.readFileSync(pathOrakConfigJson, 'utf-8'));
|
|
98
|
+
deployConfig.objOrakConfig = jsonOrakConfig;
|
|
99
|
+
|
|
100
|
+
//ftpHost = ftpHost ?? jsonOrakConfig.osf_ftp_host;
|
|
101
|
+
remotePath = deployConfig.objOrakConfig[remotePathKey] ?? ''; //remotePath ??
|
|
102
|
+
|
|
103
|
+
if (!ftpHost || !ftpUser || !ftpPassword) {
|
|
104
|
+
console.error("Error: FTP bilgileri eksik. .env.orakconfig dosyasında osf_ftp_host, osf_ftp_user ve osf_ftp_password alanlarını kontrol edin.");
|
|
105
|
+
process.exit(1);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const client = new Client();
|
|
109
|
+
client.ftp.verbose = true;
|
|
110
|
+
|
|
111
|
+
/* @type {string[]} */
|
|
112
|
+
const filesToArchive = deployConfig.objOrakConfig.dff_list || [];
|
|
113
|
+
|
|
114
|
+
// "dff_list": [
|
|
115
|
+
// {
|
|
116
|
+
// "local": ".orak-dist/test1.txt",
|
|
117
|
+
// "remote": "temp"
|
|
118
|
+
// }
|
|
119
|
+
// ]
|
|
120
|
+
|
|
121
|
+
try {
|
|
122
|
+
await client.access({
|
|
123
|
+
host: ftpHost,
|
|
124
|
+
user: ftpUser,
|
|
125
|
+
password: ftpPassword,
|
|
126
|
+
secure: ftpSecure
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
// dff_list içindeki dosyaları yükle
|
|
130
|
+
for (const objFile of filesToArchive) {
|
|
131
|
+
const localFilePath = path.join(projectRoot, objFile.local);
|
|
132
|
+
// remoteFilePath: remote klasör + dosya adı
|
|
133
|
+
const remoteFilePath = path.posix.join(remotePath, objFile.remote, path.basename(objFile.local));
|
|
134
|
+
if (!fs.existsSync(localFilePath)) {
|
|
135
|
+
console.error(`Error: Yerel dosya bulunamadı: ${localFilePath}`);
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
console.log(`Yükleniyor: ${localFilePath} -> ${remoteFilePath}`);
|
|
139
|
+
await client.uploadFrom(localFilePath, remoteFilePath);
|
|
140
|
+
console.log(`✅ Lokal: ${localFilePath}`);
|
|
141
|
+
console.log(`✅ Remote: ${remoteFilePath}`);
|
|
142
|
+
console.log('-----------------------------');
|
|
143
|
+
}
|
|
144
|
+
console.log("✅ FTP yükleme tamamlandı!");
|
|
145
|
+
}
|
|
146
|
+
catch (err) {
|
|
147
|
+
console.error("❌ FTP Hatası:", err);
|
|
148
|
+
process.exit(1);
|
|
149
|
+
}
|
|
150
|
+
client.close();
|
|
151
|
+
|
|
152
|
+
}
|
package/lib/deploy-ftp.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
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
5
|
import { parseArgs } from './args-parser.js';
|
|
6
|
+
import { addVersionToFilename, appendRandomToFilename, parseEnvContent } from "./osf-node-utils.js";
|
|
6
7
|
|
|
8
|
+
// @ts-ignore
|
|
7
9
|
const __filename = fileURLToPath(import.meta.url);
|
|
8
10
|
const __dirname = path.dirname(__filename);
|
|
9
11
|
|
|
@@ -13,10 +15,9 @@ export async function deployFtp() {
|
|
|
13
15
|
// Argüman kontrolü ve yardım mesajı
|
|
14
16
|
if (args.help || args.h) {
|
|
15
17
|
// package.json'dan versiyon al
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
console.log(`orak-deploy-ftp version ${packageJson.version}`);
|
|
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}`);
|
|
20
21
|
console.log('Kullanım: orak-deploy-ftp');
|
|
21
22
|
console.log('Dist klasöründeki dosyaları FTP sunucusuna yükler.');
|
|
22
23
|
console.log('Konfigürasyon: .env dosyasında FTP bilgileri gerekli.');
|
|
@@ -39,25 +40,13 @@ osf_ftp_host=ftp.example.com
|
|
|
39
40
|
osf_ftp_user=username
|
|
40
41
|
osf_ftp_password=password
|
|
41
42
|
osf_ftp_secure=false
|
|
42
|
-
osf_ftp_local_file=deploy.tar.gz
|
|
43
|
-
osf_ftp_remote_path=public_html
|
|
44
43
|
`);
|
|
45
44
|
process.exit(1);
|
|
46
45
|
}
|
|
47
46
|
|
|
48
47
|
// .env.xx dosyasını parse et
|
|
49
48
|
const envContent = fs.readFileSync(envPath, 'utf-8');
|
|
50
|
-
const envVars =
|
|
51
|
-
|
|
52
|
-
envContent.split('\n').forEach(line => {
|
|
53
|
-
const trimmedLine = line.trim();
|
|
54
|
-
if (trimmedLine && !trimmedLine.startsWith('#')) {
|
|
55
|
-
const [key, ...valueParts] = trimmedLine.split('=');
|
|
56
|
-
if (key && valueParts.length > 0) {
|
|
57
|
-
envVars[key.trim()] = valueParts.join('=').trim();
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
});
|
|
49
|
+
const envVars = parseEnvContent(envContent);
|
|
61
50
|
|
|
62
51
|
let ftpHost = envVars.osf_ftp_host;
|
|
63
52
|
const ftpUser = envVars.osf_ftp_user;
|
|
@@ -66,73 +55,69 @@ osf_ftp_remote_path=public_html
|
|
|
66
55
|
|
|
67
56
|
// osf_ftp_local_file support with profile suffix (osf_ftp_local_file_{profile})
|
|
68
57
|
let localFileKey = 'osf_ftp_local_file';
|
|
69
|
-
|
|
70
|
-
|
|
58
|
+
let remotePathKey = 'osf_ftp_remote_path';
|
|
59
|
+
|
|
60
|
+
if (args.profile || args.p) {
|
|
61
|
+
args.profile = args.profile || args.p;
|
|
62
|
+
console.log(`🔖 Profil kullanılıyor: ${args.profile}`);
|
|
71
63
|
localFileKey = localFileKey + '_' + args.profile;
|
|
64
|
+
remotePathKey = remotePathKey + '_' + args.profile;
|
|
72
65
|
}
|
|
73
|
-
|
|
74
|
-
let
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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);
|
|
86
81
|
}
|
|
87
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
|
+
|
|
88
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)
|
|
89
93
|
if (args.v && localFileName) {
|
|
90
|
-
const packageJsonPath = path.join(__dirname, '..', 'package.json');
|
|
91
|
-
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
|
|
92
|
-
const txVersion = packageJson.version.replace(/\./g, '_');
|
|
93
|
-
|
|
94
|
-
const parsed = path.parse(localFileName);
|
|
95
|
-
const base = parsed.base; // filename with possible multi-part ext
|
|
96
|
-
|
|
97
|
-
// Desteklenen çok parçalı uzantılar
|
|
98
|
-
const multiExts = ['.tar.gz', '.tar.bz2', '.tar.xz', '.tar.lz', '.tar.Z', '.tgz'];
|
|
99
|
-
let ext = parsed.ext;
|
|
100
|
-
let nameNoExt = parsed.name;
|
|
101
|
-
|
|
102
|
-
for (const me of multiExts) {
|
|
103
|
-
if (base.endsWith(me)) {
|
|
104
|
-
ext = me;
|
|
105
|
-
nameNoExt = base.slice(0, -me.length);
|
|
106
|
-
break;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
94
|
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
localFileName = parsed.dir ? path.join(parsed.dir, newBase + ext) : newBase + ext;
|
|
95
|
+
const txVersion = objPackageJsonCurrProj.version; //.replace(/\./g, '_');
|
|
96
|
+
localFileName = addVersionToFilename(localFileName, txVersion);
|
|
113
97
|
|
|
114
98
|
console.log(`📦 Versiyon eklendi: ${txVersion}`);
|
|
115
99
|
console.log(`📄 Güncel dosya adı: ${localFileName}`);
|
|
116
100
|
}
|
|
117
101
|
|
|
118
|
-
let
|
|
119
|
-
|
|
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)));
|
|
120
105
|
|
|
121
|
-
console.log(`Yerel dosya: ${
|
|
122
|
-
console.log(`Remote adres: ${
|
|
106
|
+
console.log(`Yerel dosya: ${localFilePath}`);
|
|
107
|
+
console.log(`Remote adres: ${remoteFilePath}`);
|
|
123
108
|
|
|
124
109
|
if (!ftpHost || !ftpUser || !ftpPassword) {
|
|
125
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.");
|
|
126
111
|
process.exit(1);
|
|
127
112
|
}
|
|
128
113
|
|
|
129
|
-
if (!
|
|
130
|
-
console.error("Error:
|
|
114
|
+
if (!remoteFilePath) {
|
|
115
|
+
console.error("Error: orak-config.json dosyasında osf_ftp_remote_path alanını kontrol edin.");
|
|
131
116
|
process.exit(1);
|
|
132
117
|
}
|
|
133
118
|
|
|
134
|
-
if (!
|
|
135
|
-
console.error("Error:
|
|
119
|
+
if (!localFilePath) {
|
|
120
|
+
console.error("Error: orak-config.json dosyasında osf_ftp_local_file alanını kontrol edin.");
|
|
136
121
|
process.exit(1);
|
|
137
122
|
}
|
|
138
123
|
|
|
@@ -147,9 +132,6 @@ osf_ftp_remote_path=public_html
|
|
|
147
132
|
secure: ftpSecure
|
|
148
133
|
});
|
|
149
134
|
|
|
150
|
-
const localFilePath = localFilePath1;
|
|
151
|
-
const remoteFilePath = remoteFilePath1;
|
|
152
|
-
|
|
153
135
|
if (!fs.existsSync(localFilePath)) {
|
|
154
136
|
console.error(`Error: Yerel dosya bulunamadı: ${localFilePath}`);
|
|
155
137
|
process.exit(1);
|
|
@@ -158,10 +140,39 @@ osf_ftp_remote_path=public_html
|
|
|
158
140
|
console.log(`Yükleniyor: ${localFilePath} -> ${remoteFilePath}`);
|
|
159
141
|
await client.uploadFrom(localFilePath, remoteFilePath);
|
|
160
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
|
+
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
|
|
161
166
|
}
|
|
162
167
|
catch (err) {
|
|
163
168
|
console.error("❌ FTP Hatası:", err);
|
|
164
169
|
process.exit(1);
|
|
165
170
|
}
|
|
166
171
|
client.close();
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
|
|
167
178
|
}
|
|
@@ -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
|
+
}
|
package/lib/zip-content.js
CHANGED
|
@@ -4,18 +4,18 @@ import * as tar from 'tar';
|
|
|
4
4
|
import { fileURLToPath } from 'url';
|
|
5
5
|
import { parseArgs } from './args-parser.js';
|
|
6
6
|
|
|
7
|
+
// @ts-ignore
|
|
7
8
|
const __filename = fileURLToPath(import.meta.url);
|
|
8
9
|
const __dirname = path.dirname(__filename);
|
|
9
10
|
|
|
10
11
|
export async function deployZipContent() {
|
|
11
12
|
const args = parseArgs();
|
|
12
13
|
|
|
13
|
-
// package.json'dan versiyon al
|
|
14
|
-
const packageJsonPath = path.join(__dirname, '..', 'package.json');
|
|
15
|
-
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
|
|
16
|
-
|
|
17
14
|
// Argüman kontrolü ve yardım mesajı
|
|
18
15
|
if (args.help || args.h) {
|
|
16
|
+
// package.json'dan versiyon al
|
|
17
|
+
const packageJsonPath = path.join(__dirname, '..', 'package.json');
|
|
18
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
|
|
19
19
|
console.log(`orak-zip-content version ${packageJson.version}`);
|
|
20
20
|
console.log('Kullanım: orak-zip-content');
|
|
21
21
|
console.log('Belirtilen dosya ve klasörleri tar.gz formatında arşivler.');
|
|
@@ -26,67 +26,53 @@ export async function deployZipContent() {
|
|
|
26
26
|
// Çalışma dizinini tespit et (komutun çalıştırıldığı yer)
|
|
27
27
|
const projectRoot = process.cwd();
|
|
28
28
|
|
|
29
|
-
// .env dosyasını oku
|
|
30
|
-
// const envPath = path.join(projectRoot, '.env');
|
|
31
|
-
|
|
32
|
-
// if (fs.existsSync(envPath)) {
|
|
33
|
-
// const envContent = fs.readFileSync(envPath, 'utf-8');
|
|
34
|
-
// const envVars = {};
|
|
35
|
-
|
|
36
|
-
// envContent.split('\n').forEach(line => {
|
|
37
|
-
// const trimmedLine = line.trim();
|
|
38
|
-
// if (trimmedLine && !trimmedLine.startsWith('#')) {
|
|
39
|
-
// const [key, ...valueParts] = trimmedLine.split('=');
|
|
40
|
-
// if (key && valueParts.length > 0) {
|
|
41
|
-
// envVars[key.trim()] = valueParts.join('=').trim();
|
|
42
|
-
// }
|
|
43
|
-
// }
|
|
44
|
-
// });
|
|
45
|
-
|
|
46
|
-
// }
|
|
47
|
-
|
|
48
29
|
// orak-config.json dosyasını oku
|
|
49
|
-
const
|
|
30
|
+
const pathOrakconfigJson = path.join(projectRoot, 'orak-config.json');
|
|
50
31
|
|
|
51
|
-
if (!fs.existsSync(
|
|
52
|
-
console.error("Error: orak-config.json dosyası bulunamadı.
|
|
32
|
+
if (!fs.existsSync(pathOrakconfigJson)) {
|
|
33
|
+
console.error("Error: orak-config.json dosyası bulunamadı. Lütfen ekleyiniz.");
|
|
53
34
|
process.exit(1);
|
|
54
35
|
}
|
|
55
36
|
|
|
56
|
-
const
|
|
37
|
+
const objOrakConfigJson = JSON.parse(fs.readFileSync(pathOrakconfigJson, 'utf-8'));
|
|
57
38
|
|
|
58
|
-
if (!
|
|
39
|
+
if (!objOrakConfigJson["zip_content"] || !Array.isArray(objOrakConfigJson["zip_content"])) {
|
|
59
40
|
console.error("Error: 'zip_content' alanı orak-config.json içinde bir dizi olarak tanımlanmalıdır.");
|
|
60
41
|
process.exit(1);
|
|
61
42
|
}
|
|
62
43
|
|
|
63
|
-
let
|
|
44
|
+
let outputFileKey = 'zip_content_out_file';
|
|
64
45
|
|
|
65
|
-
if(args.profile) {
|
|
66
|
-
|
|
67
|
-
|
|
46
|
+
if (args.profile || args.p) {
|
|
47
|
+
args.profile = args.profile || args.p;
|
|
48
|
+
console.log(`🔖 Profil kullanılıyor: ${args.profile}`);
|
|
49
|
+
outputFileKey = outputFileKey + "_" + args.profile;
|
|
68
50
|
}
|
|
69
51
|
|
|
70
|
-
|
|
52
|
+
|
|
53
|
+
let archiveName = objOrakConfigJson[outputFileKey];
|
|
71
54
|
|
|
72
55
|
if (!archiveName) {
|
|
73
|
-
console.error("Error: " + `${
|
|
56
|
+
console.error("Error: " + `${outputFileKey} alanı orak-config.json içinde tanımlanmalıdır.`);
|
|
74
57
|
process.exit(1);
|
|
75
58
|
}
|
|
59
|
+
|
|
60
|
+
const packageJsonPath = path.join(projectRoot, 'package.json');
|
|
61
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
|
|
76
62
|
|
|
77
63
|
let txVersionForFileName = packageJson.version.replace(/\./g, '_');
|
|
78
64
|
|
|
79
65
|
if (args.v) {
|
|
80
|
-
// Ayırıcı ekle (ör. deploy-1_2_3.tar.gz) okunaklı olsun
|
|
81
|
-
const
|
|
82
|
-
archiveName = archiveName +
|
|
66
|
+
// Kelime Ayırıcı ekle (_) (ör. deploy-1_2_3.tar.gz) okunaklı olsun
|
|
67
|
+
const txWordSeper = '-'; // archiveName.endsWith('-') || archiveName.endsWith('_') ? '' : '-';
|
|
68
|
+
archiveName = archiveName + txWordSeper + txVersionForFileName;
|
|
83
69
|
console.log(`📦 Versiyon eklendi: ${txVersionForFileName}`);
|
|
84
70
|
}
|
|
85
71
|
|
|
86
72
|
// Dosya adına .tar.gz uzantısını ekle
|
|
87
73
|
archiveName = archiveName + '.tar.gz';
|
|
88
74
|
|
|
89
|
-
const filesToArchive =
|
|
75
|
+
const filesToArchive = objOrakConfigJson["zip_content"];
|
|
90
76
|
|
|
91
77
|
if (!filesToArchive) {
|
|
92
78
|
console.error("Error: 'zip_content' alanı orak-config.json içinde tanımlanmalıdır.");
|
|
@@ -108,10 +94,10 @@ export async function deployZipContent() {
|
|
|
108
94
|
|
|
109
95
|
if (stat.isDirectory()) {
|
|
110
96
|
// Klasörün içindeki dosyaları ekle
|
|
111
|
-
const walkDir = (
|
|
112
|
-
const files = fs.readdirSync(
|
|
97
|
+
const walkDir = (prmDir) => {
|
|
98
|
+
const files = fs.readdirSync(prmDir);
|
|
113
99
|
for (const file of files) {
|
|
114
|
-
const filePath = path.join(
|
|
100
|
+
const filePath = path.join(prmDir, file);
|
|
115
101
|
const fileStat = fs.statSync(filePath);
|
|
116
102
|
|
|
117
103
|
if (fileStat.isDirectory()) {
|
|
@@ -148,7 +134,7 @@ export async function deployZipContent() {
|
|
|
148
134
|
// Arşiv oluştur
|
|
149
135
|
try {
|
|
150
136
|
// Geçici klasör oluştur
|
|
151
|
-
const tempDir = path.join(distDir, '.
|
|
137
|
+
const tempDir = path.join(distDir, '.tempZipContentFi');
|
|
152
138
|
if (fs.existsSync(tempDir)) {
|
|
153
139
|
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
154
140
|
}
|
package/lib/zip-package.js
CHANGED
|
@@ -3,7 +3,9 @@ import path from 'path';
|
|
|
3
3
|
import * as tar from 'tar';
|
|
4
4
|
import { fileURLToPath } from 'url';
|
|
5
5
|
import { parseArgs } from './args-parser.js';
|
|
6
|
+
import { parseEnvContent } from './osf-node-utils.js';
|
|
6
7
|
|
|
8
|
+
// @ts-ignore
|
|
7
9
|
const __filename = fileURLToPath(import.meta.url);
|
|
8
10
|
const __dirname = path.dirname(__filename);
|
|
9
11
|
|
|
@@ -15,7 +17,6 @@ export async function zipPackage() {
|
|
|
15
17
|
// package.json'dan versiyon al
|
|
16
18
|
const packageJsonPath = path.join(__dirname, '..', 'package.json');
|
|
17
19
|
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
|
|
18
|
-
|
|
19
20
|
console.log(`orak-zip-package version ${packageJson.version}`);
|
|
20
21
|
console.log('Kullanım: orak-zip-package');
|
|
21
22
|
console.log('Belirtilen dosya ve klasörleri tar.gz formatında arşivler.');
|
|
@@ -27,24 +28,14 @@ export async function zipPackage() {
|
|
|
27
28
|
const projectRoot = process.cwd();
|
|
28
29
|
|
|
29
30
|
// .env dosyasını oku
|
|
30
|
-
const envPath = path.join(projectRoot, '.env');
|
|
31
|
-
|
|
32
|
-
const envVars = {};
|
|
33
|
-
|
|
34
|
-
if (fs.existsSync(envPath)) {
|
|
35
|
-
const envContent = fs.readFileSync(envPath, 'utf-8');
|
|
31
|
+
// const envPath = path.join(projectRoot, '.env');
|
|
36
32
|
|
|
37
|
-
|
|
38
|
-
const trimmedLine = line.trim();
|
|
39
|
-
if (trimmedLine && !trimmedLine.startsWith('#')) {
|
|
40
|
-
const [key, ...valueParts] = trimmedLine.split('=');
|
|
41
|
-
if (key && valueParts.length > 0) {
|
|
42
|
-
envVars[key.trim()] = valueParts.join('=').trim();
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
});
|
|
33
|
+
// let envVars = {};
|
|
46
34
|
|
|
47
|
-
|
|
35
|
+
// if (fs.existsSync(envPath)) {
|
|
36
|
+
// const envContent = fs.readFileSync(envPath, 'utf-8');
|
|
37
|
+
// envVars = parseEnvContent(envContent);
|
|
38
|
+
// }
|
|
48
39
|
|
|
49
40
|
// orak-config.json dosyasını oku
|
|
50
41
|
const configPath = path.join(projectRoot, 'orak-config.json');
|
|
@@ -54,31 +45,35 @@ export async function zipPackage() {
|
|
|
54
45
|
process.exit(1);
|
|
55
46
|
}
|
|
56
47
|
|
|
57
|
-
const
|
|
48
|
+
const objOrakConfigJson = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
|
|
58
49
|
|
|
59
|
-
if (!
|
|
50
|
+
if (!objOrakConfigJson.zip_package || !Array.isArray(objOrakConfigJson.zip_package)) {
|
|
60
51
|
console.error("Error: 'zip_package' alanı orak-config.json içinde bir dizi olarak tanımlanmalıdır.");
|
|
61
52
|
process.exit(1);
|
|
62
53
|
}
|
|
63
54
|
|
|
64
|
-
const filesToArchive =
|
|
55
|
+
const filesToArchive = objOrakConfigJson.zip_package;
|
|
65
56
|
|
|
66
|
-
let
|
|
57
|
+
let outputFileKey = 'zip_package_out_file';
|
|
67
58
|
|
|
68
|
-
|
|
69
|
-
|
|
59
|
+
// --profile veya -p argümanı ile profil belirtme
|
|
60
|
+
if(args.profile || args.p) {
|
|
61
|
+
args.profile = args.profile || args.p;
|
|
62
|
+
console.log(`🔖 Profil kullanılıyor: ${args.profile}`);
|
|
63
|
+
outputFileKey = outputFileKey + "_" + args.profile;
|
|
70
64
|
}
|
|
71
65
|
|
|
72
|
-
if (!
|
|
73
|
-
console.error(
|
|
66
|
+
if (!objOrakConfigJson[outputFileKey]) {
|
|
67
|
+
console.error(`Error : ${outputFileKey} alanı orak-config.json içinde tanımlanmalıdır.`);
|
|
74
68
|
process.exit(1);
|
|
75
69
|
}
|
|
76
70
|
|
|
77
|
-
let archiveName =
|
|
71
|
+
let archiveName = objOrakConfigJson[outputFileKey];
|
|
78
72
|
|
|
79
73
|
// package.json'dan versiyon al (opsiyonel --v ile eklenecek)
|
|
80
|
-
const packageJsonPath = path.join(
|
|
74
|
+
const packageJsonPath = path.join(projectRoot, 'package.json');
|
|
81
75
|
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
|
|
76
|
+
|
|
82
77
|
let txVersionForFileName = packageJson.version.replace(/\./g, '_');
|
|
83
78
|
|
|
84
79
|
if (args.v) {
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "oraksoft-node-tools",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.30",
|
|
4
4
|
"description": "CLI araçları koleksiyonu - orak-copy-deps, orak-deploy-ftp, orak-deploy-zip, orak-env-change ve orak-env-dev-change komutları",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"bin": {
|
|
8
8
|
"orak-copy-deps": "./bin/orak-copy-deps.js",
|
|
9
9
|
"orak-deploy-ftp": "./bin/orak-deploy-ftp.js",
|
|
10
|
+
"orak-deploy-ftp-files": "./bin/orak-deploy-ftp-files.js",
|
|
10
11
|
"orak-env-change": "./bin/orak-env-change.js",
|
|
11
12
|
"orak-env-dev-change": "./bin/orak-env-dev-change.js",
|
|
12
13
|
"orak-zip-content": "./bin/orak-zip-content.js",
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/.orak-dist/deploy.tar.gz
DELETED
|
Binary file
|
|
File without changes
|