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.
@@ -0,0 +1,174 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import * as tar from 'tar';
4
+ import { fileURLToPath } from 'url';
5
+ import { parseArgs } from './args-parser.js';
6
+
7
+ // @ts-ignore
8
+ const __filename = fileURLToPath(import.meta.url);
9
+ const __dirname = path.dirname(__filename);
10
+
11
+ export async function deployZipContent() {
12
+ const args = parseArgs();
13
+
14
+ // Argüman kontrolü ve yardım mesajı
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
+ 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.');
22
+ console.log('Konfigürasyon: orak-config.json dosyasında "zip-content" (array) ayarı gerekli.');
23
+ process.exit(0);
24
+ }
25
+
26
+ // Çalışma dizinini tespit et (komutun çalıştırıldığı yer)
27
+ const projectRoot = process.cwd();
28
+
29
+ // orak-config.json dosyasını oku
30
+ const pathOrakconfigJson = path.join(projectRoot, 'orak-config.json');
31
+
32
+ if (!fs.existsSync(pathOrakconfigJson)) {
33
+ console.error("Error: orak-config.json dosyası bulunamadı. Lütfen ekleyiniz.");
34
+ process.exit(1);
35
+ }
36
+
37
+ const objOrakConfigJson = JSON.parse(fs.readFileSync(pathOrakconfigJson, 'utf-8'));
38
+
39
+ if (!objOrakConfigJson["zip_content"] || !Array.isArray(objOrakConfigJson["zip_content"])) {
40
+ console.error("Error: 'zip_content' alanı orak-config.json içinde bir dizi olarak tanımlanmalıdır.");
41
+ process.exit(1);
42
+ }
43
+
44
+ let outputFileKey = 'zip_content_out_file';
45
+
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;
50
+ }
51
+
52
+
53
+ let archiveName = objOrakConfigJson[outputFileKey];
54
+
55
+ if (!archiveName) {
56
+ console.error("Error: " + `${outputFileKey} alanı orak-config.json içinde tanımlanmalıdır.`);
57
+ process.exit(1);
58
+ }
59
+
60
+ const packageJsonPath = path.join(projectRoot, 'package.json');
61
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
62
+
63
+ let txVersionForFileName = packageJson.version.replace(/\./g, '_');
64
+
65
+ if (args.v) {
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;
69
+ console.log(`📦 Versiyon eklendi: ${txVersionForFileName}`);
70
+ }
71
+
72
+ // Dosya adına .tar.gz uzantısını ekle
73
+ archiveName = archiveName + '.tar.gz';
74
+
75
+ const filesToArchive = objOrakConfigJson["zip_content"];
76
+
77
+ if (!filesToArchive) {
78
+ console.error("Error: 'zip_content' alanı orak-config.json içinde tanımlanmalıdır.");
79
+ process.exit(1);
80
+ }
81
+
82
+ // Her klasör için dosyaları topla
83
+ const allFilesToArchive = [];
84
+
85
+ for (const item of filesToArchive) {
86
+ const fullPath = path.join(projectRoot, item);
87
+
88
+ if (!fs.existsSync(fullPath)) {
89
+ console.warn(`⚠️ Bulunamadı: ${item}`);
90
+ continue;
91
+ }
92
+
93
+ const stat = fs.statSync(fullPath);
94
+
95
+ if (stat.isDirectory()) {
96
+ // Klasörün içindeki dosyaları ekle
97
+ const walkDir = (prmDir) => {
98
+ const files = fs.readdirSync(prmDir);
99
+ for (const file of files) {
100
+ const filePath = path.join(prmDir, file);
101
+ const fileStat = fs.statSync(filePath);
102
+
103
+ if (fileStat.isDirectory()) {
104
+ walkDir(filePath);
105
+ } else {
106
+ // Klasör root'undan relative path
107
+ const relPath = path.relative(fullPath, filePath).replace(/\\/g, '/');
108
+ allFilesToArchive.push({
109
+ src: filePath,
110
+ dest: relPath
111
+ });
112
+ }
113
+ }
114
+ };
115
+ walkDir(fullPath);
116
+ } else {
117
+ // Tek dosya
118
+ allFilesToArchive.push({
119
+ src: fullPath,
120
+ dest: path.basename(item)
121
+ });
122
+ }
123
+ }
124
+
125
+ // dist klasörü ve arşiv adı
126
+ const distDir = projectRoot; // path.resolve(projectRoot, '.orak-dist');
127
+ const archivePath = path.join(distDir, archiveName);
128
+
129
+ // dist klasörü yoksa oluştur
130
+ if (!fs.existsSync(distDir)) {
131
+ fs.mkdirSync(distDir, { recursive: true });
132
+ }
133
+
134
+ // Arşiv oluştur
135
+ try {
136
+ // Geçici klasör oluştur
137
+ const tempDir = path.join(distDir, '.tempZipContentFi');
138
+ if (fs.existsSync(tempDir)) {
139
+ fs.rmSync(tempDir, { recursive: true, force: true });
140
+ }
141
+ fs.mkdirSync(tempDir, { recursive: true });
142
+
143
+ // Dosyaları geçici klasöre kopyala
144
+ for (const file of allFilesToArchive) {
145
+ const destPath = path.join(tempDir, file.dest);
146
+ const destDir = path.dirname(destPath);
147
+
148
+ if (!fs.existsSync(destDir)) {
149
+ fs.mkdirSync(destDir, { recursive: true });
150
+ }
151
+
152
+ fs.copyFileSync(file.src, destPath);
153
+ }
154
+
155
+ // Geçici klasörden arşiv oluştur
156
+ await tar.c(
157
+ {
158
+ gzip: true,
159
+ file: archivePath,
160
+ cwd: tempDir,
161
+ follow: true,
162
+ },
163
+ fs.readdirSync(tempDir)
164
+ );
165
+
166
+ // Geçici klasörü sil
167
+ fs.rmSync(tempDir, { recursive: true, force: true });
168
+
169
+ console.log(`✅ Arşiv oluşturuldu: ${archivePath}`);
170
+ } catch (err) {
171
+ console.error('❌ Arşivleme hatası:', err);
172
+ process.exit(1);
173
+ }
174
+ }
@@ -2,21 +2,25 @@ import fs from 'fs';
2
2
  import path from 'path';
3
3
  import * as tar from 'tar';
4
4
  import { fileURLToPath } from 'url';
5
+ import { parseArgs } from './args-parser.js';
6
+ import { 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
- export async function deployZip() {
12
+ export async function zipPackage() {
13
+ const args = parseArgs();
14
+
10
15
  // Argüman kontrolü ve yardım mesajı
11
- if (process.argv.includes('--help') || process.argv.includes('-h')) {
16
+ if (args.help || args.h) {
12
17
  // package.json'dan versiyon al
13
18
  const packageJsonPath = path.join(__dirname, '..', 'package.json');
14
19
  const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
15
-
16
- console.log(`orak-deploy-zip version ${packageJson.version}`);
17
- console.log('Kullanım: orak-deploy-zip');
20
+ console.log(`orak-zip-package version ${packageJson.version}`);
21
+ console.log('Kullanım: orak-zip-package');
18
22
  console.log('Belirtilen dosya ve klasörleri tar.gz formatında arşivler.');
19
- console.log('Konfigürasyon: orak-config.json dosyasında "fiDeployZipContent" ayarı gerekli.');
23
+ console.log('Konfigürasyon: orak-config.json dosyasında "zip_package" ayarı gerekli.');
20
24
  process.exit(0);
21
25
  }
22
26
 
@@ -24,28 +28,15 @@ export async function deployZip() {
24
28
  const projectRoot = process.cwd();
25
29
 
26
30
  // .env dosyasını oku
27
- const envPath = path.join(projectRoot, '.env');
28
- let archiveName = 'deploy.tar.gz';
29
-
30
- if (fs.existsSync(envPath)) {
31
- const envContent = fs.readFileSync(envPath, 'utf-8');
32
- const envVars = {};
33
-
34
- envContent.split('\n').forEach(line => {
35
- const trimmedLine = line.trim();
36
- if (trimmedLine && !trimmedLine.startsWith('#')) {
37
- const [key, ...valueParts] = trimmedLine.split('=');
38
- if (key && valueParts.length > 0) {
39
- envVars[key.trim()] = valueParts.join('=').trim();
40
- }
41
- }
42
- });
43
-
44
- if (envVars.osf_local_file) {
45
- archiveName = envVars.osf_local_file;
46
- }
47
- }
31
+ // const envPath = path.join(projectRoot, '.env');
32
+
33
+ // let envVars = {};
48
34
 
35
+ // if (fs.existsSync(envPath)) {
36
+ // const envContent = fs.readFileSync(envPath, 'utf-8');
37
+ // envVars = parseEnvContent(envContent);
38
+ // }
39
+
49
40
  // orak-config.json dosyasını oku
50
41
  const configPath = path.join(projectRoot, 'orak-config.json');
51
42
 
@@ -54,17 +45,49 @@ export async function deployZip() {
54
45
  process.exit(1);
55
46
  }
56
47
 
57
- const config = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
48
+ const objOrakConfigJson = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
49
+
50
+ if (!objOrakConfigJson.zip_package || !Array.isArray(objOrakConfigJson.zip_package)) {
51
+ console.error("Error: 'zip_package' alanı orak-config.json içinde bir dizi olarak tanımlanmalıdır.");
52
+ process.exit(1);
53
+ }
54
+
55
+ const filesToArchive = objOrakConfigJson.zip_package;
56
+
57
+ let outputFileKey = 'zip_package_out_file';
58
58
 
59
- if (!config.fiDeployZipContent || !Array.isArray(config.fiDeployZipContent)) {
60
- console.error("Error: 'fiDeployZipContent' alanı orak-config.json içinde bir dizi olarak tanımlanmalıdır.");
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;
64
+ }
65
+
66
+ if (!objOrakConfigJson[outputFileKey]) {
67
+ console.error(`Error : ${outputFileKey} alanı orak-config.json içinde tanımlanmalıdır.`);
61
68
  process.exit(1);
62
69
  }
63
70
 
64
- const filesToArchive = config.fiDeployZipContent;
71
+ let archiveName = objOrakConfigJson[outputFileKey];
72
+
73
+ // package.json'dan versiyon al (opsiyonel --v ile eklenecek)
74
+ const packageJsonPath = path.join(projectRoot, 'package.json');
75
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
76
+
77
+ let txVersionForFileName = packageJson.version.replace(/\./g, '_');
78
+
79
+ if (args.v) {
80
+ // Ayırıcı ekle (örn. deploy-1_2_3.tar.gz) okunaklı olsun
81
+ const sep = archiveName.endsWith('-') || archiveName.endsWith('_') ? '' : '-';
82
+ archiveName = archiveName + sep + txVersionForFileName;
83
+ console.log(`📦 Versiyon eklendi: ${txVersionForFileName}`);
84
+ }
85
+
86
+ // Dosya adına .tar.gz uzantısını ekle
87
+ archiveName = archiveName + '.tar.gz';
65
88
 
66
89
  // dist klasörü ve arşiv adı
67
- const distDir = path.resolve(projectRoot, 'dist');
90
+ const distDir = projectRoot; // path.resolve(projectRoot, 'dist');
68
91
  const archivePath = path.join(distDir, archiveName);
69
92
 
70
93
  // dist klasörü yoksa oluştur
package/package.json CHANGED
@@ -1,15 +1,24 @@
1
1
  {
2
2
  "name": "oraksoft-node-tools",
3
- "version": "0.1.6",
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-zip": "./bin/orak-deploy-zip.js",
10
+ "orak-deploy-ftp-files": "./bin/orak-deploy-ftp-files.js",
11
11
  "orak-env-change": "./bin/orak-env-change.js",
12
- "orak-env-dev-change": "./bin/orak-env-dev-change.js"
12
+ "orak-env-dev-change": "./bin/orak-env-dev-change.js",
13
+ "orak-zip-content": "./bin/orak-zip-content.js",
14
+ "orak-zip-package": "./bin/orak-zip-package.js"
15
+ },
16
+ "scripts_comment": {
17
+ "test": "Test komutu henüz tanımlanmadı.",
18
+ "prepublishOnly": "Yayınlamadan önce çalıştırılacak komut.",
19
+ "build": "Proje derleme komutu.",
20
+ "pn-publish": "Paketin genel erişimle yayınlanması için komut.",
21
+ "pn-global-update": "Paketin global olarak güncellenmesi için komut."
13
22
  },
14
23
  "keywords": [
15
24
  "cli",
@@ -25,6 +34,7 @@
25
34
  "license": "MIT",
26
35
  "dependencies": {
27
36
  "basic-ftp": "^5.0.5",
37
+ "minimist": "^1.2.8",
28
38
  "tar": "^7.4.3"
29
39
  },
30
40
  "engines": {
@@ -42,6 +52,8 @@
42
52
  "scripts": {
43
53
  "test": "echo \"Error: no test specified\" && exit 1",
44
54
  "build": "echo \"Build completed\"",
45
- "pn-publish": "pnpm publish --access public"
55
+ "pn-publish": "pnpm publish --access public",
56
+ "pn-global-update": "pnpm link --global",
57
+ "orak-deploy-test": "orak-deploy-ftp"
46
58
  }
47
59
  }
package/.env DELETED
@@ -1,15 +0,0 @@
1
- # Development Ortamı
2
- NODE_ENV=development
3
- API_URL=http://localhost:3000
4
- DB_HOST=localhost
5
- DB_NAME=myapp_dev
6
- DEBUG=true
7
-
8
- # Oraksoft
9
-
10
- osf_ftp_host=ftp.example.com
11
- osf_ftp_user=username
12
- osf_ftp_password=password
13
- osf_ftp_secure=false
14
- osf_local_file=deployphp25.tar.gz
15
- osf_remote_path=/public_html
package/.env.dev DELETED
@@ -1,6 +0,0 @@
1
- # Development Ortamı
2
- NODE_ENV=development
3
- API_URL=http://localhost:3000
4
- DB_HOST=localhost
5
- DB_NAME=myapp_dev
6
- DEBUG=true
package/.env.prod DELETED
@@ -1,6 +0,0 @@
1
- # Production Ortamı
2
- NODE_ENV=production
3
- API_URL=https://api.myapp.com
4
- DB_HOST=prod-db-server
5
- DB_NAME=myapp_prod
6
- DEBUG=false
@@ -1,5 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import { deployZip } from '../lib/deploy-zip.js';
4
-
5
- deployZip();
package/orak-config.json DELETED
@@ -1,16 +0,0 @@
1
- {
2
- "copyDepsModulesToCopy": [
3
- {
4
- "name": "module-name",
5
- "file": "dist/module.js"
6
- }
7
- ],
8
- "copyDepsLibFolder": "lib",
9
- "copyDepsLibFolderEmpty": true,
10
- "fiDeployZipContent": [
11
- "src/",
12
- "public/",
13
- "package.json"
14
- ],
15
- "fiEnvChangeStatus": "dev"
16
- }
File without changes