oraksoft-node-tools 0.1.18 → 0.1.38
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-0_1_34.zip +0 -0
- package/.orak-dist/deploy-test-0_1_25.tar.gz +0 -0
- package/.orak-dist/deploy.tar.gz +0 -0
- package/.orak-dist/deploy.zip +0 -0
- package/.orak-dist/deploy_0_1_34.tar.gz +0 -0
- package/.orak-dist/deploy_0_1_34.zip +0 -0
- package/.orak-dist/deploy_0_1_37.tar.gz +0 -0
- package/.orak-dist/test1.txt +0 -0
- package/.orak-dist/test2.txt +0 -0
- package/README.md +52 -11
- package/bin/orak-deploy-ftp-files.js +5 -0
- package/bin/orak-zip-content.js +2 -2
- package/bin/orak-zip-package.js +2 -2
- package/jsconfig.json +18 -0
- package/lib/copy-deps.js +73 -67
- package/lib/deploy-ftp.js +85 -67
- package/lib/index.js +2 -2
- package/lib/osf-node-utils.js +104 -0
- package/lib/zip-content.js +86 -59
- package/lib/zip-package.js +165 -64
- package/package.json +5 -2
- package/test-archive.zip +0 -0
- 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/lib/deploy-ftp-secure.js +0 -79
- /package/.orak-dist/{test-0_1_17.txt → test-0_1_27.txt} +0 -0
|
@@ -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
|
@@ -1,92 +1,86 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import * as tar from 'tar';
|
|
4
|
+
import { ZipArchive } from 'archiver';
|
|
4
5
|
import { fileURLToPath } from 'url';
|
|
5
6
|
import { parseArgs } from './args-parser.js';
|
|
6
7
|
|
|
8
|
+
// @ts-ignore
|
|
7
9
|
const __filename = fileURLToPath(import.meta.url);
|
|
8
10
|
const __dirname = path.dirname(__filename);
|
|
9
11
|
|
|
10
|
-
export async function
|
|
12
|
+
export async function makeZipContent() {
|
|
11
13
|
const args = parseArgs();
|
|
12
14
|
|
|
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
15
|
// Argüman kontrolü ve yardım mesajı
|
|
18
16
|
if (args.help || args.h) {
|
|
17
|
+
// package.json'dan versiyon al
|
|
18
|
+
const packageJsonPath = path.join(__dirname, '..', 'package.json');
|
|
19
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
|
|
19
20
|
console.log(`orak-zip-content version ${packageJson.version}`);
|
|
20
|
-
console.log('Kullanım: orak-zip-content');
|
|
21
|
-
console.log('Belirtilen dosya ve klasörleri tar.gz formatında arşivler.');
|
|
21
|
+
console.log('Kullanım: orak-zip-content [seçenekler]');
|
|
22
|
+
console.log('Belirtilen dosya ve klasörleri tar.gz (veya --zip ile ZIP) formatında arşivler.');
|
|
22
23
|
console.log('Konfigürasyon: orak-config.json dosyasında "zip-content" (array) ayarı gerekli.');
|
|
24
|
+
console.log('');
|
|
25
|
+
console.log('Seçenekler:');
|
|
26
|
+
console.log(' -v, --version Dosya adına versiyon ekle');
|
|
27
|
+
console.log(' -z, --zip ZIP formatında arşiv oluştur (varsayılan: tar.gz)');
|
|
28
|
+
console.log(' -p, --profile Profil belirtme');
|
|
29
|
+
console.log(' -h, --help Bu yardım mesajını göster');
|
|
23
30
|
process.exit(0);
|
|
24
31
|
}
|
|
25
32
|
|
|
26
33
|
// Çalışma dizinini tespit et (komutun çalıştırıldığı yer)
|
|
27
34
|
const projectRoot = process.cwd();
|
|
28
35
|
|
|
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
36
|
// orak-config.json dosyasını oku
|
|
49
|
-
const
|
|
37
|
+
const pathOrakconfigJson = path.join(projectRoot, 'orak-config.json');
|
|
50
38
|
|
|
51
|
-
if (!fs.existsSync(
|
|
52
|
-
console.error("Error: orak-config.json dosyası bulunamadı.
|
|
39
|
+
if (!fs.existsSync(pathOrakconfigJson)) {
|
|
40
|
+
console.error("Error: orak-config.json dosyası bulunamadı. Lütfen ekleyiniz.");
|
|
53
41
|
process.exit(1);
|
|
54
42
|
}
|
|
55
43
|
|
|
56
|
-
const
|
|
44
|
+
const objOrakConfigJson = JSON.parse(fs.readFileSync(pathOrakconfigJson, 'utf-8'));
|
|
57
45
|
|
|
58
|
-
if (!
|
|
46
|
+
if (!objOrakConfigJson["zip_content"] || !Array.isArray(objOrakConfigJson["zip_content"])) {
|
|
59
47
|
console.error("Error: 'zip_content' alanı orak-config.json içinde bir dizi olarak tanımlanmalıdır.");
|
|
60
48
|
process.exit(1);
|
|
61
49
|
}
|
|
62
50
|
|
|
63
|
-
let
|
|
51
|
+
let outputFileKey = 'zip_content_out_file';
|
|
64
52
|
|
|
65
|
-
if(args.profile) {
|
|
66
|
-
|
|
67
|
-
|
|
53
|
+
if (args.profile || args.p) {
|
|
54
|
+
args.profile = args.profile || args.p;
|
|
55
|
+
console.log(`🔖 Profil kullanılıyor: ${args.profile}`);
|
|
56
|
+
outputFileKey = outputFileKey + "_" + args.profile;
|
|
68
57
|
}
|
|
69
58
|
|
|
70
|
-
|
|
59
|
+
|
|
60
|
+
let archiveName = objOrakConfigJson[outputFileKey];
|
|
71
61
|
|
|
72
62
|
if (!archiveName) {
|
|
73
|
-
console.error("Error: " + `${
|
|
63
|
+
console.error("Error: " + `${outputFileKey} alanı orak-config.json içinde tanımlanmalıdır.`);
|
|
74
64
|
process.exit(1);
|
|
75
65
|
}
|
|
66
|
+
|
|
67
|
+
const packageJsonPath = path.join(projectRoot, 'package.json');
|
|
68
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
|
|
76
69
|
|
|
77
70
|
let txVersionForFileName = packageJson.version.replace(/\./g, '_');
|
|
78
71
|
|
|
79
72
|
if (args.v) {
|
|
80
|
-
// Ayırıcı ekle (ör. deploy-1_2_3.tar.gz) okunaklı olsun
|
|
81
|
-
const
|
|
82
|
-
archiveName = archiveName +
|
|
73
|
+
// Kelime Ayırıcı ekle (_) (ör. deploy-1_2_3.tar.gz) okunaklı olsun
|
|
74
|
+
const txWordSeper = '-'; // archiveName.endsWith('-') || archiveName.endsWith('_') ? '' : '-';
|
|
75
|
+
archiveName = archiveName + txWordSeper + txVersionForFileName;
|
|
83
76
|
console.log(`📦 Versiyon eklendi: ${txVersionForFileName}`);
|
|
84
77
|
}
|
|
85
78
|
|
|
86
|
-
// Dosya adına
|
|
87
|
-
|
|
79
|
+
// Dosya adına uzantı ekle
|
|
80
|
+
const isZipFormat = args.zip || args.z;
|
|
81
|
+
archiveName = archiveName + (isZipFormat ? '.zip' : '.tar.gz');
|
|
88
82
|
|
|
89
|
-
const filesToArchive =
|
|
83
|
+
const filesToArchive = objOrakConfigJson["zip_content"];
|
|
90
84
|
|
|
91
85
|
if (!filesToArchive) {
|
|
92
86
|
console.error("Error: 'zip_content' alanı orak-config.json içinde tanımlanmalıdır.");
|
|
@@ -108,10 +102,10 @@ export async function deployZipContent() {
|
|
|
108
102
|
|
|
109
103
|
if (stat.isDirectory()) {
|
|
110
104
|
// Klasörün içindeki dosyaları ekle
|
|
111
|
-
const walkDir = (
|
|
112
|
-
const files = fs.readdirSync(
|
|
105
|
+
const walkDir = (prmDir) => {
|
|
106
|
+
const files = fs.readdirSync(prmDir);
|
|
113
107
|
for (const file of files) {
|
|
114
|
-
const filePath = path.join(
|
|
108
|
+
const filePath = path.join(prmDir, file);
|
|
115
109
|
const fileStat = fs.statSync(filePath);
|
|
116
110
|
|
|
117
111
|
if (fileStat.isDirectory()) {
|
|
@@ -148,7 +142,7 @@ export async function deployZipContent() {
|
|
|
148
142
|
// Arşiv oluştur
|
|
149
143
|
try {
|
|
150
144
|
// Geçici klasör oluştur
|
|
151
|
-
const tempDir = path.join(distDir, '.
|
|
145
|
+
const tempDir = path.join(distDir, '.tempZipContentFi');
|
|
152
146
|
if (fs.existsSync(tempDir)) {
|
|
153
147
|
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
154
148
|
}
|
|
@@ -166,23 +160,56 @@ export async function deployZipContent() {
|
|
|
166
160
|
fs.copyFileSync(file.src, destPath);
|
|
167
161
|
}
|
|
168
162
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
163
|
+
if (isZipFormat) {
|
|
164
|
+
// ZIP formatında arşiv oluştur
|
|
165
|
+
await createZipArchive(archivePath, tempDir, fs.readdirSync(tempDir));
|
|
166
|
+
console.log(`✅ ZIP arşivi oluşturuldu: ${archivePath}`);
|
|
167
|
+
} else {
|
|
168
|
+
// tar.gz formatında arşiv oluştur
|
|
169
|
+
await tar.c(
|
|
170
|
+
{
|
|
171
|
+
gzip: true,
|
|
172
|
+
file: archivePath,
|
|
173
|
+
cwd: tempDir,
|
|
174
|
+
follow: true,
|
|
175
|
+
},
|
|
176
|
+
fs.readdirSync(tempDir)
|
|
177
|
+
);
|
|
178
|
+
console.log(`✅ Arşiv oluşturuldu: ${archivePath}`);
|
|
179
|
+
}
|
|
179
180
|
|
|
180
181
|
// Geçici klasörü sil
|
|
181
182
|
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
182
|
-
|
|
183
|
-
console.log(`✅ Arşiv oluşturuldu: ${archivePath}`);
|
|
184
183
|
} catch (err) {
|
|
185
184
|
console.error('❌ Arşivleme hatası:', err);
|
|
186
185
|
process.exit(1);
|
|
187
186
|
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// ZIP arşivi oluşturma yardımcı fonksiyonu
|
|
190
|
+
async function createZipArchive(archivePath, sourceDir, files) {
|
|
191
|
+
return new Promise((resolve, reject) => {
|
|
192
|
+
const output = fs.createWriteStream(archivePath);
|
|
193
|
+
const archive = new ZipArchive({ zlib: { level: 9 } });
|
|
194
|
+
|
|
195
|
+
output.on('close', resolve);
|
|
196
|
+
archive.on('error', reject);
|
|
197
|
+
output.on('error', reject);
|
|
198
|
+
|
|
199
|
+
archive.pipe(output);
|
|
200
|
+
|
|
201
|
+
// Dosyaları arşive ekle
|
|
202
|
+
for (const item of files) {
|
|
203
|
+
const itemPath = path.join(sourceDir, item);
|
|
204
|
+
const stat = fs.statSync(itemPath);
|
|
205
|
+
|
|
206
|
+
if (stat.isDirectory()) {
|
|
207
|
+
archive.directory(itemPath, item);
|
|
208
|
+
} else {
|
|
209
|
+
archive.file(itemPath, { name: item });
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
archive.finalize();
|
|
214
|
+
});
|
|
188
215
|
}
|
package/lib/zip-package.js
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import * as tar from 'tar';
|
|
4
|
+
import { ZipArchive } from 'archiver';
|
|
4
5
|
import { fileURLToPath } from 'url';
|
|
5
6
|
import { parseArgs } from './args-parser.js';
|
|
7
|
+
import { addVersionToFilename, parseEnvContent } from './osf-node-utils.js';
|
|
6
8
|
|
|
9
|
+
// @ts-ignore
|
|
7
10
|
const __filename = fileURLToPath(import.meta.url);
|
|
8
11
|
const __dirname = path.dirname(__filename);
|
|
9
12
|
|
|
10
|
-
export async function
|
|
13
|
+
export async function makeZipPackage() {
|
|
11
14
|
const args = parseArgs();
|
|
12
15
|
|
|
13
16
|
// Argüman kontrolü ve yardım mesajı
|
|
@@ -15,11 +18,16 @@ export async function zipPackage() {
|
|
|
15
18
|
// package.json'dan versiyon al
|
|
16
19
|
const packageJsonPath = path.join(__dirname, '..', 'package.json');
|
|
17
20
|
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
|
|
18
|
-
|
|
19
21
|
console.log(`orak-zip-package version ${packageJson.version}`);
|
|
20
|
-
console.log('Kullanım: orak-zip-package');
|
|
21
|
-
console.log('Belirtilen dosya ve klasörleri tar.gz formatında arşivler.');
|
|
22
|
+
console.log('Kullanım: orak-zip-package [seçenekler]');
|
|
23
|
+
console.log('Belirtilen dosya ve klasörleri tar.gz (veya --zip ile ZIP) formatında arşivler.');
|
|
22
24
|
console.log('Konfigürasyon: orak-config.json dosyasında "zip_package" ayarı gerekli.');
|
|
25
|
+
console.log('');
|
|
26
|
+
console.log('Seçenekler:');
|
|
27
|
+
console.log(' -v, --version Dosya adına versiyon ekle');
|
|
28
|
+
console.log(' -z, --zip ZIP formatında paket oluştur (varsayılan: tar.gz)');
|
|
29
|
+
console.log(' -p, --profile Profil belirtme');
|
|
30
|
+
console.log(' -h, --help Bu yardım mesajını göster');
|
|
23
31
|
process.exit(0);
|
|
24
32
|
}
|
|
25
33
|
|
|
@@ -27,24 +35,14 @@ export async function zipPackage() {
|
|
|
27
35
|
const projectRoot = process.cwd();
|
|
28
36
|
|
|
29
37
|
// .env dosyasını oku
|
|
30
|
-
const envPath = path.join(projectRoot, '.env');
|
|
31
|
-
|
|
32
|
-
const envVars = {};
|
|
38
|
+
// const envPath = path.join(projectRoot, '.env');
|
|
33
39
|
|
|
34
|
-
|
|
35
|
-
const envContent = fs.readFileSync(envPath, 'utf-8');
|
|
40
|
+
// let envVars = {};
|
|
36
41
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
if (key && valueParts.length > 0) {
|
|
42
|
-
envVars[key.trim()] = valueParts.join('=').trim();
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
}
|
|
42
|
+
// if (fs.existsSync(envPath)) {
|
|
43
|
+
// const envContent = fs.readFileSync(envPath, 'utf-8');
|
|
44
|
+
// envVars = parseEnvContent(envContent);
|
|
45
|
+
// }
|
|
48
46
|
|
|
49
47
|
// orak-config.json dosyasını oku
|
|
50
48
|
const configPath = path.join(projectRoot, 'orak-config.json');
|
|
@@ -54,42 +52,46 @@ export async function zipPackage() {
|
|
|
54
52
|
process.exit(1);
|
|
55
53
|
}
|
|
56
54
|
|
|
57
|
-
const
|
|
55
|
+
const objOrakConfigJson = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
|
|
58
56
|
|
|
59
|
-
if (!
|
|
57
|
+
if (!objOrakConfigJson.zip_package || !Array.isArray(objOrakConfigJson.zip_package)) {
|
|
60
58
|
console.error("Error: 'zip_package' alanı orak-config.json içinde bir dizi olarak tanımlanmalıdır.");
|
|
61
59
|
process.exit(1);
|
|
62
60
|
}
|
|
63
61
|
|
|
64
|
-
const filesToArchive =
|
|
62
|
+
const filesToArchive = objOrakConfigJson.zip_package;
|
|
65
63
|
|
|
66
|
-
let
|
|
64
|
+
let outputFileKey = 'zip_package_out_file';
|
|
67
65
|
|
|
68
|
-
|
|
69
|
-
|
|
66
|
+
// --profile veya -p argümanı ile profil belirtme
|
|
67
|
+
if(args.profile || args.p) {
|
|
68
|
+
args.profile = args.profile || args.p;
|
|
69
|
+
console.log(`🔖 Profil kullanılıyor: ${args.profile}`);
|
|
70
|
+
outputFileKey = outputFileKey + "_" + args.profile;
|
|
70
71
|
}
|
|
71
72
|
|
|
72
|
-
if (!
|
|
73
|
-
console.error(
|
|
73
|
+
if (!objOrakConfigJson[outputFileKey]) {
|
|
74
|
+
console.error(`Error : ${outputFileKey} alanı orak-config.json içinde tanımlanmalıdır.`);
|
|
74
75
|
process.exit(1);
|
|
75
76
|
}
|
|
76
77
|
|
|
77
|
-
let archiveName =
|
|
78
|
+
let archiveName = objOrakConfigJson[outputFileKey];
|
|
78
79
|
|
|
79
80
|
// package.json'dan versiyon al (opsiyonel --v ile eklenecek)
|
|
80
|
-
const packageJsonPath = path.join(
|
|
81
|
+
const packageJsonPath = path.join(projectRoot, 'package.json');
|
|
81
82
|
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
|
|
83
|
+
|
|
82
84
|
let txVersionForFileName = packageJson.version.replace(/\./g, '_');
|
|
83
85
|
|
|
84
86
|
if (args.v) {
|
|
85
87
|
// Ayırıcı ekle (örn. deploy-1_2_3.tar.gz) okunaklı olsun
|
|
86
|
-
|
|
87
|
-
archiveName = archiveName + sep + txVersionForFileName;
|
|
88
|
+
archiveName = addVersionToFilename(archiveName, txVersionForFileName);
|
|
88
89
|
console.log(`📦 Versiyon eklendi: ${txVersionForFileName}`);
|
|
89
90
|
}
|
|
90
91
|
|
|
91
|
-
// Dosya adına
|
|
92
|
-
|
|
92
|
+
// Dosya adına uzantı ekle
|
|
93
|
+
const isZipFormat = args.zip || args.z;
|
|
94
|
+
archiveName = archiveName + (isZipFormat ? '.zip' : '.tar.gz');
|
|
93
95
|
|
|
94
96
|
// dist klasörü ve arşiv adı
|
|
95
97
|
const distDir = projectRoot; // path.resolve(projectRoot, 'dist');
|
|
@@ -102,39 +104,138 @@ export async function zipPackage() {
|
|
|
102
104
|
|
|
103
105
|
// Arşiv oluştur
|
|
104
106
|
try {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
107
|
+
if (isZipFormat) {
|
|
108
|
+
// ZIP formatında arşiv oluştur
|
|
109
|
+
await createZipArchive(archivePath, projectRoot, filesToArchive);
|
|
110
|
+
console.log(`✅ ZIP arşivi oluşturuldu: ${archivePath}`);
|
|
111
|
+
} else {
|
|
112
|
+
// tar.gz formatında arşiv oluştur
|
|
113
|
+
await tar.c(
|
|
114
|
+
{
|
|
115
|
+
gzip: true,
|
|
116
|
+
file: archivePath,
|
|
117
|
+
cwd: projectRoot,
|
|
118
|
+
follow: true, // symlink/junction'ları takip et
|
|
119
|
+
filter: (path, stat) => {
|
|
120
|
+
// .git klasörlerini ve test dosyalarını hariç tut
|
|
121
|
+
const normalizedPath = path.replace(/\\/g, '/');
|
|
122
|
+
if (normalizedPath.includes('/.git/')
|
|
123
|
+
|| normalizedPath.includes('/.git')
|
|
124
|
+
|| normalizedPath.includes('/tests/')
|
|
125
|
+
|| normalizedPath.includes('/tests')
|
|
126
|
+
|| normalizedPath.includes('/fi-logs/')
|
|
127
|
+
|| normalizedPath.includes('/fi-logs')
|
|
128
|
+
|| normalizedPath.includes('/.github/')
|
|
129
|
+
|| normalizedPath.includes('/.github')
|
|
130
|
+
|| normalizedPath.endsWith('.md')
|
|
131
|
+
|| normalizedPath.endsWith('phpunit.xml.dist')
|
|
132
|
+
|| normalizedPath.endsWith('.gitignore')
|
|
133
|
+
|| normalizedPath.endsWith('.gitattributes')
|
|
134
|
+
) {
|
|
135
|
+
console.log('Excluding:', path);
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
return true;
|
|
129
139
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
console.log(`✅ Arşiv oluşturuldu: ${archivePath}`);
|
|
140
|
+
},
|
|
141
|
+
filesToArchive
|
|
142
|
+
);
|
|
143
|
+
console.log(`✅ Arşiv oluşturuldu: ${archivePath}`);
|
|
144
|
+
}
|
|
136
145
|
} catch (err) {
|
|
137
146
|
console.error('❌ Arşivleme hatası:', err);
|
|
138
147
|
process.exit(1);
|
|
139
148
|
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// ZIP arşivi oluşturma yardımcı fonksiyonu
|
|
152
|
+
async function createZipArchive(archivePath, projectRoot, filesToArchive) {
|
|
153
|
+
return new Promise((resolve, reject) => {
|
|
154
|
+
const output = fs.createWriteStream(archivePath);
|
|
155
|
+
const archive = new ZipArchive({ zlib: { level: 9 } });
|
|
156
|
+
|
|
157
|
+
output.on('close', resolve);
|
|
158
|
+
archive.on('error', reject);
|
|
159
|
+
output.on('error', reject);
|
|
160
|
+
|
|
161
|
+
archive.pipe(output);
|
|
162
|
+
|
|
163
|
+
// Dosya ve klasörleri arşive ekle
|
|
164
|
+
for (const item of filesToArchive) {
|
|
165
|
+
const itemPath = path.join(projectRoot, item);
|
|
166
|
+
|
|
167
|
+
if (!fs.existsSync(itemPath)) {
|
|
168
|
+
console.warn(`⚠️ Uyarı: "${item}" bulunamadı, atlanıyor.`);
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// Symlink ise gerçek path'ini al
|
|
173
|
+
let realPath = itemPath;
|
|
174
|
+
const lstat = fs.lstatSync(itemPath);
|
|
175
|
+
|
|
176
|
+
if (lstat.isSymbolicLink()) {
|
|
177
|
+
realPath = fs.realpathSync(itemPath);
|
|
178
|
+
console.log(`🔗 Sembolik link takip ediliyor: ${item} -> ${realPath}`);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const stat = fs.statSync(realPath);
|
|
182
|
+
|
|
183
|
+
if (stat.isDirectory()) {
|
|
184
|
+
addDirectoryToArchive(archive, realPath, item);
|
|
185
|
+
} else {
|
|
186
|
+
archive.file(realPath, { name: item });
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
archive.finalize();
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// Yardımcı fonksiyon: Klasörü recursive olarak arşive ekle ve sembolik linkler takip et
|
|
195
|
+
function addDirectoryToArchive(archive, directoryPath, baseArchivePath) {
|
|
196
|
+
const entries = fs.readdirSync(directoryPath);
|
|
197
|
+
|
|
198
|
+
for (const entry of entries) {
|
|
199
|
+
const entryPath = path.join(directoryPath, entry);
|
|
200
|
+
const archiveEntryPath = path.join(baseArchivePath, entry);
|
|
201
|
+
const normalizedPath = archiveEntryPath.replace(/\\/g, '/');
|
|
202
|
+
|
|
203
|
+
// Filtrele - .git, tests, vb. klasörleri hariç tut
|
|
204
|
+
if (normalizedPath.includes('/.git/')
|
|
205
|
+
|| normalizedPath.includes('/.git')
|
|
206
|
+
|| normalizedPath.includes('/tests/')
|
|
207
|
+
|| normalizedPath.includes('/tests')
|
|
208
|
+
|| normalizedPath.includes('/fi-logs/')
|
|
209
|
+
|| normalizedPath.includes('/fi-logs')
|
|
210
|
+
|| normalizedPath.includes('/.github/')
|
|
211
|
+
|| normalizedPath.includes('/.github')
|
|
212
|
+
|| normalizedPath.endsWith('.md')
|
|
213
|
+
|| normalizedPath.endsWith('phpunit.xml.dist')
|
|
214
|
+
|| normalizedPath.endsWith('.gitignore')
|
|
215
|
+
|| normalizedPath.endsWith('.gitattributes')
|
|
216
|
+
) {
|
|
217
|
+
console.log('Excluding:', archiveEntryPath);
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
let realPath = entryPath;
|
|
222
|
+
const lstat = fs.lstatSync(entryPath);
|
|
223
|
+
|
|
224
|
+
// Symlink ise gerçek path'ini al
|
|
225
|
+
if (lstat.isSymbolicLink()) {
|
|
226
|
+
realPath = fs.realpathSync(entryPath);
|
|
227
|
+
console.log(`🔗 Sembolik link takip ediliyor: ${archiveEntryPath} -> ${realPath}`);
|
|
228
|
+
const stat = fs.statSync(realPath);
|
|
229
|
+
|
|
230
|
+
if (stat.isDirectory()) {
|
|
231
|
+
addDirectoryToArchive(archive, realPath, archiveEntryPath);
|
|
232
|
+
} else {
|
|
233
|
+
archive.file(realPath, { name: archiveEntryPath });
|
|
234
|
+
}
|
|
235
|
+
} else if (lstat.isDirectory()) {
|
|
236
|
+
addDirectoryToArchive(archive, realPath, archiveEntryPath);
|
|
237
|
+
} else {
|
|
238
|
+
archive.file(realPath, { name: archiveEntryPath });
|
|
239
|
+
}
|
|
240
|
+
}
|
|
140
241
|
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "oraksoft-node-tools",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.38",
|
|
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",
|
|
@@ -32,6 +33,7 @@
|
|
|
32
33
|
"author": "Oraksoft",
|
|
33
34
|
"license": "MIT",
|
|
34
35
|
"dependencies": {
|
|
36
|
+
"archiver": "^8.0.0",
|
|
35
37
|
"basic-ftp": "^5.0.5",
|
|
36
38
|
"minimist": "^1.2.8",
|
|
37
39
|
"tar": "^7.4.3"
|
|
@@ -49,10 +51,11 @@
|
|
|
49
51
|
},
|
|
50
52
|
"homepage": "https://github.com/oraksoftware/oraksoft-node-tools#readme",
|
|
51
53
|
"scripts": {
|
|
54
|
+
"pn-install": "pnpm install",
|
|
52
55
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
53
56
|
"build": "echo \"Build completed\"",
|
|
54
|
-
"pn-publish": "pnpm publish --access public",
|
|
55
57
|
"pn-global-update": "pnpm link --global",
|
|
58
|
+
"pn-publish": "pnpm publish --access public",
|
|
56
59
|
"orak-deploy-test": "orak-deploy-ftp"
|
|
57
60
|
}
|
|
58
61
|
}
|
package/test-archive.zip
ADDED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|