tsoft-cli 1.4.3 → 2.0.1
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/README.md +29 -94
- package/bin/run.js +5 -0
- package/build/enums.d.ts +1 -0
- package/build/enums.js +4 -0
- package/build/enums.js.map +1 -0
- package/build/index.d.ts +5 -0
- package/build/index.js +10 -0
- package/build/index.js.map +1 -0
- package/package.json +49 -21
- package/CHANGELOG.md +0 -88
- package/bin/index.js +0 -77
- package/jest.config.js +0 -3
- package/src/Tsoft.js +0 -137
- package/src/commands/CreateCommand.js +0 -102
- package/src/commands/StartCommand.js +0 -281
- package/src/commands/SyncCommand.js +0 -97
- package/src/core/ClientCredentials.js +0 -107
- package/src/core/Constants.js +0 -19
- package/src/core/FileManager.js +0 -53
- package/src/core/Request.js +0 -41
- package/src/core/ThemeManager.js +0 -113
- package/src/core/Utils.js +0 -104
- package/tests/FileManager.test.js +0 -90
|
@@ -1,281 +0,0 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
const path = require('path');
|
|
3
|
-
const chokidar = require('chokidar');
|
|
4
|
-
const readline = require('readline');
|
|
5
|
-
const { exec } = require('child_process');
|
|
6
|
-
const Tsoft = require('../Tsoft');
|
|
7
|
-
const Constants = require('../core/Constants');
|
|
8
|
-
const cliProgress = require('cli-progress');
|
|
9
|
-
const { Input } = require('enquirer');
|
|
10
|
-
const { displayAsciiArt, info, unzipFile } = require('../core/Utils');
|
|
11
|
-
|
|
12
|
-
class StartCommand {
|
|
13
|
-
static async showProgress(tsoft, theme) {
|
|
14
|
-
const themePath = path.join(process.cwd(), tsoft.site, theme);
|
|
15
|
-
const fileList = tsoft.fileManager.listFilesRecursive(themePath).filter(file => !file.includes('.env'));
|
|
16
|
-
fileList.push(path.join(themePath, '.theme'));
|
|
17
|
-
const totalFiles = fileList.length;
|
|
18
|
-
|
|
19
|
-
const progressBar = new cliProgress.SingleBar({
|
|
20
|
-
format: 'İlerleme |{bar}| {percentage}% || {value}/{total} Dosya Yüklendi',
|
|
21
|
-
barCompleteChar: '\u2588',
|
|
22
|
-
barIncompleteChar: '\u2591',
|
|
23
|
-
hideCursor: true,
|
|
24
|
-
clearOnComplete: true
|
|
25
|
-
});
|
|
26
|
-
progressBar.start(totalFiles, 0);
|
|
27
|
-
|
|
28
|
-
for (let i = 0; i < totalFiles; i++) {
|
|
29
|
-
const file = fileList[i];
|
|
30
|
-
const fileName = tsoft.fileManager.getRelativePath(theme, file);
|
|
31
|
-
const content = tsoft.fileManager.readFile(file);
|
|
32
|
-
const env = tsoft.themeManager.getEnvironment(theme);
|
|
33
|
-
|
|
34
|
-
try {
|
|
35
|
-
await tsoft.saveFile(theme, fileName, content, env.bearer);
|
|
36
|
-
} catch (error) {
|
|
37
|
-
console.error(`Dosya yükleme hatası ${fileName}:`, error);
|
|
38
|
-
}
|
|
39
|
-
progressBar.update(i + 1);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
progressBar.stop();
|
|
43
|
-
|
|
44
|
-
return 'Tüm dosyalar ilerleme ile başarıyla yüklendi';
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
static async initializeAndAuthorize(tsoft, themeName) {
|
|
48
|
-
await tsoft.initialize(themeName);
|
|
49
|
-
|
|
50
|
-
const approvalPrompt = new Input({
|
|
51
|
-
name: 'approval',
|
|
52
|
-
message: 'Lütfen onay kodunu sağlayın:'
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
const approval = await approvalPrompt.run();
|
|
56
|
-
|
|
57
|
-
if (approval) {
|
|
58
|
-
await Constants.APPROVAL.handler(tsoft.clientCredentials.setClientSecret(approval));
|
|
59
|
-
tsoft.buildEnvironment();
|
|
60
|
-
console.info('Ortam dosyası başarıyla oluşturuldu.');
|
|
61
|
-
return true;
|
|
62
|
-
} else {
|
|
63
|
-
console.error('Onay kodu gerekli.');
|
|
64
|
-
return false;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
static async handleExistingEnvironment(tsoft, themeName, themeEnvPath) {
|
|
69
|
-
let envData = {};
|
|
70
|
-
if (fs.existsSync(themeEnvPath)) {
|
|
71
|
-
try {
|
|
72
|
-
envData = JSON.parse(fs.readFileSync(themeEnvPath, 'utf-8'));
|
|
73
|
-
} catch (error) {
|
|
74
|
-
console.warn(`${themeEnvPath} dosyasında geçersiz JSON formatı. Bu dosya silinecek ve yeniden yetkilendirmeniz gerekecek.`);
|
|
75
|
-
fs.unlinkSync(themeEnvPath);
|
|
76
|
-
console.info('Geçersiz ortam dosyası silindi. Başlatma işlemine devam ediliyor...');
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
if (envData.bearer) {
|
|
80
|
-
const bearerTokenValid = await tsoft.isTokenValid(themeName);
|
|
81
|
-
|
|
82
|
-
if (bearerTokenValid) {
|
|
83
|
-
console.info('Geçerli bir taşıyıcı jetonuna sahip mevcut ortam dosyası bulundu. Mevcut yapılandırma ile devam ediliyor...');
|
|
84
|
-
return true;
|
|
85
|
-
} else {
|
|
86
|
-
console.warn('Mevcut taşıyıcı jetonu geçersiz. Yeniden yetkilendirmeniz gerekecek.');
|
|
87
|
-
fs.unlinkSync(themeEnvPath);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
return false;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
static async startWatching(themePath, tsoft, theme) {
|
|
95
|
-
const watcher = chokidar.watch(themePath, {
|
|
96
|
-
ignored: /(^|[\/\\])(\.theme|(.*?)\.env)$/, // .theme ve .env dosyaları yoksayılır
|
|
97
|
-
persistent: true
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
watcher.on('change', async (filePath) => {
|
|
101
|
-
console.log(`Dosya değiştirildi ${filePath}`);
|
|
102
|
-
await StartCommand.handleFileChange(filePath, tsoft, theme);
|
|
103
|
-
}).on('unlink', async (filePath) => {
|
|
104
|
-
console.log(`Dosya silindi ${filePath}`);
|
|
105
|
-
await StartCommand.handleFileDeletion(filePath, tsoft, theme);
|
|
106
|
-
}).on('unlinkDir', async (dirPath) => {
|
|
107
|
-
console.log(`Dizin silindi ${dirPath}`);
|
|
108
|
-
await StartCommand.handleDirectoryDeletion(dirPath, tsoft, theme);
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
console.log(`${themePath} dizinindeki dosya değişiklikleri izleniyor`);
|
|
112
|
-
|
|
113
|
-
const rl = readline.createInterface({
|
|
114
|
-
input: process.stdin,
|
|
115
|
-
output: process.stdout
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
info(tsoft, theme);
|
|
119
|
-
|
|
120
|
-
rl.on('line', async (input) => {
|
|
121
|
-
await StartCommand.handleUserInput(input, tsoft, theme, watcher, rl);
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
static async handleFileChange(filePath, tsoft, theme) {
|
|
126
|
-
const env = JSON.parse(fs.readFileSync(path.join(process.cwd(), tsoft.site, theme, `${theme}.env`), 'utf-8'));
|
|
127
|
-
const fileName = filePath.replace(`${path.join(process.cwd(), tsoft.site, theme)}/`, '');
|
|
128
|
-
const content = fs.readFileSync(filePath).toString();
|
|
129
|
-
|
|
130
|
-
try {
|
|
131
|
-
await tsoft.saveFile(theme, fileName, content, env.bearer);
|
|
132
|
-
console.log(`Dosya başarıyla yüklendi ${fileName}`);
|
|
133
|
-
} catch (error) {
|
|
134
|
-
console.error(`Dosya yükleme hatası ${fileName}:`, error);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
static async handleFileDeletion(filePath, tsoft, theme) {
|
|
139
|
-
const env = JSON.parse(fs.readFileSync(path.join(process.cwd(), tsoft.site, theme, `${theme}.env`), 'utf-8'));
|
|
140
|
-
const fileName = filePath.replace(`${path.join(process.cwd(), tsoft.site, theme)}/`, '');
|
|
141
|
-
|
|
142
|
-
try {
|
|
143
|
-
await tsoft.deleteFile(theme, fileName, env.bearer);
|
|
144
|
-
console.log(`Dosya başarıyla silindi ${fileName}`);
|
|
145
|
-
} catch (error) {
|
|
146
|
-
console.error(`Dosya silme hatası ${fileName}:`, error);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
static async handleDirectoryDeletion(dirPath, tsoft, theme) {
|
|
151
|
-
const env = JSON.parse(fs.readFileSync(path.join(process.cwd(), tsoft.site, theme, `${theme}.env`), 'utf-8'));
|
|
152
|
-
const dirName = dirPath.replace(`${path.join(process.cwd(), tsoft.site, theme)}/`, '');
|
|
153
|
-
|
|
154
|
-
try {
|
|
155
|
-
await tsoft.deleteDirectory(theme, dirName, env.bearer);
|
|
156
|
-
console.log(`Dizin başarıyla silindi ${dirName}`);
|
|
157
|
-
} catch (error) {
|
|
158
|
-
console.error(`Dizin silme hatası ${dirName}:`, error);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
static async handleUserInput(input, tsoft, theme, watcher, rl) {
|
|
163
|
-
info(tsoft, theme);
|
|
164
|
-
switch (input.trim()) {
|
|
165
|
-
case 'q':
|
|
166
|
-
console.log('Dosya izleme işlemi sonlandırılıyor...');
|
|
167
|
-
watcher.close();
|
|
168
|
-
rl.close();
|
|
169
|
-
process.exit(0);
|
|
170
|
-
break;
|
|
171
|
-
case 'u':
|
|
172
|
-
console.log('Tema güncelleniyor...');
|
|
173
|
-
try {
|
|
174
|
-
const result = await StartCommand.updateTheme(tsoft, theme);
|
|
175
|
-
console.log(result);
|
|
176
|
-
|
|
177
|
-
} catch (error) {
|
|
178
|
-
console.error(`Tema güncelleme hatası:`, error);
|
|
179
|
-
}
|
|
180
|
-
break;
|
|
181
|
-
case 's':
|
|
182
|
-
console.log('Tüm dosyalar ilerleme ile yüklenmeye başlanıyor...');
|
|
183
|
-
try {
|
|
184
|
-
const result = await StartCommand.showProgress(tsoft, theme);
|
|
185
|
-
console.log(result);
|
|
186
|
-
|
|
187
|
-
} catch (error) {
|
|
188
|
-
console.error(`İlerleme gösterim hatası:`, error);
|
|
189
|
-
}
|
|
190
|
-
break;
|
|
191
|
-
case 'e':
|
|
192
|
-
console.log('.theme dosyası düzenleniyor...');
|
|
193
|
-
try {
|
|
194
|
-
await StartCommand.editThemeFile(tsoft.themeManager, theme);
|
|
195
|
-
} catch (error) {
|
|
196
|
-
console.error(`.theme dosyası düzenleme hatası:`, error);
|
|
197
|
-
}
|
|
198
|
-
break;
|
|
199
|
-
case 'o':
|
|
200
|
-
console.log('Tema dizini açılıyor...');
|
|
201
|
-
const openCommand = process.platform === 'win32' ? 'start' :
|
|
202
|
-
process.platform === 'darwin' ? 'open' :
|
|
203
|
-
'xdg-open';
|
|
204
|
-
exec(`${openCommand} ${path.join(process.cwd(), tsoft.site, theme)}`, (err) => {
|
|
205
|
-
if (err) {
|
|
206
|
-
console.error('Tema dizini açılamadı:', err);
|
|
207
|
-
} else {
|
|
208
|
-
console.log('Tema dizini başarıyla açıldı.');
|
|
209
|
-
}
|
|
210
|
-
});
|
|
211
|
-
break;
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
static async start(siteName, themeName, recentlyCreated = false) {
|
|
216
|
-
await displayAsciiArt();
|
|
217
|
-
console.log('Geliştirme ortamı aşağıdaki ayrıntılarla başlatılıyor:');
|
|
218
|
-
console.log(`Site Adı: ${siteName}`);
|
|
219
|
-
console.log(`Tema Adı: ${themeName}`);
|
|
220
|
-
|
|
221
|
-
const tsoft = new Tsoft(siteName);
|
|
222
|
-
const themeEnvPath = path.join(process.cwd(), siteName, themeName, `${themeName}.env`);
|
|
223
|
-
|
|
224
|
-
const existingEnvValid = await StartCommand.handleExistingEnvironment(tsoft, themeName, themeEnvPath);
|
|
225
|
-
if (existingEnvValid) {
|
|
226
|
-
await StartCommand.startWatching(path.join(process.cwd(), siteName, themeName), tsoft, themeName);
|
|
227
|
-
return;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
const initializedAndAuthorized = await StartCommand.initializeAndAuthorize(tsoft, themeName);
|
|
231
|
-
if (initializedAndAuthorized) {
|
|
232
|
-
if(recentlyCreated) {
|
|
233
|
-
const defaultZipFile = path.join(process.cwd(), siteName, themeName, 'theme.zip');
|
|
234
|
-
console.log('Default tema dosyaları indirme işlemi başlatılıyor, lütfen bekleyin');
|
|
235
|
-
const themePath = path.join(process.cwd(), siteName, themeName);
|
|
236
|
-
await tsoft.fileManager.downloadAndSaveZip(
|
|
237
|
-
themePath, defaultZipFile,
|
|
238
|
-
tsoft.clientCredentials.bearer,
|
|
239
|
-
'default'
|
|
240
|
-
);
|
|
241
|
-
console.log('Default tema dosyaları indirildi. Çıkarma işlemi başlatılıyor');
|
|
242
|
-
await unzipFile(defaultZipFile, themePath);
|
|
243
|
-
console.log('Çıkarma işlemi tamamlandı.');
|
|
244
|
-
fs.unlinkSync(defaultZipFile);
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
await StartCommand.startWatching(path.join(process.cwd(), siteName, themeName), tsoft, themeName);
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
static async updateTheme(tsoft, theme) {
|
|
252
|
-
const directoryName = path.basename(path.join(process.cwd(), tsoft.site, theme));
|
|
253
|
-
const response = await tsoft.updateTheme(directoryName);
|
|
254
|
-
if (response.status === true) {
|
|
255
|
-
return 'Successfully updated';
|
|
256
|
-
} else {
|
|
257
|
-
throw new Error('Update failed');
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
static async editThemeFile(themeManager, directoryName) {
|
|
262
|
-
const themePath = path.join(process.cwd(), themeManager.site, directoryName, '.theme');
|
|
263
|
-
if (!fs.existsSync(themePath)) {
|
|
264
|
-
console.error('.theme file not found.');
|
|
265
|
-
return;
|
|
266
|
-
}
|
|
267
|
-
console.log(`Opening .theme file: ${themePath}`);
|
|
268
|
-
const openCommand = process.platform === 'win32' ? 'start' :
|
|
269
|
-
process.platform === 'darwin' ? 'open' :
|
|
270
|
-
'xdg-open';
|
|
271
|
-
exec(`${openCommand} ${themePath}`, (err) => {
|
|
272
|
-
if (err) {
|
|
273
|
-
console.error('Failed to open .theme file:', err);
|
|
274
|
-
} else {
|
|
275
|
-
console.log('.theme file opened successfully.');
|
|
276
|
-
}
|
|
277
|
-
});
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
module.exports = StartCommand;
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
const path = require('path');
|
|
3
|
-
const { Input } = require('enquirer');
|
|
4
|
-
const { clearScreen } = require('../core/Utils');
|
|
5
|
-
const { selectSite, createThemeDirectory } = require('./CreateCommand');
|
|
6
|
-
const StartCommand = require('./StartCommand');
|
|
7
|
-
const Tsoft = require("../Tsoft");
|
|
8
|
-
const { slugify, unzipFile } = require('../core/Utils');
|
|
9
|
-
|
|
10
|
-
class SyncCommand {
|
|
11
|
-
static async syncTheme() {
|
|
12
|
-
const cwd = process.cwd();
|
|
13
|
-
const sites = fs.readdirSync(cwd).filter(file => {
|
|
14
|
-
return file.charAt(0) !== '.' && !['node_modules', 'build', 'dist'].includes(file);
|
|
15
|
-
}).filter(file => fs.statSync(path.join(cwd, file)).isDirectory());
|
|
16
|
-
|
|
17
|
-
const selectedSite = await selectSite(sites);
|
|
18
|
-
|
|
19
|
-
const tsoft = new Tsoft(selectedSite);
|
|
20
|
-
|
|
21
|
-
let recoveryCode;
|
|
22
|
-
let recoveryData;
|
|
23
|
-
while (!recoveryData) {
|
|
24
|
-
const codePrompt = new Input({
|
|
25
|
-
name: 'code',
|
|
26
|
-
message: 'Lütfen kurtarma anahtarını girin:'
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
recoveryCode = await codePrompt.run();
|
|
30
|
-
|
|
31
|
-
try {
|
|
32
|
-
recoveryData = await tsoft.startRecovery(recoveryCode);
|
|
33
|
-
} catch (error) {
|
|
34
|
-
if (error.message.includes('Çok fazla deneme yapıldı')) {
|
|
35
|
-
console.error(`Hata: ${error.message}`);
|
|
36
|
-
return;
|
|
37
|
-
} else {
|
|
38
|
-
console.error(`Hata: ${error.message}`);
|
|
39
|
-
continue;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (!recoveryData) {
|
|
44
|
-
console.error('Kurtarma işlemi başarısız oldu. Lütfen geçerli bir kurtarma anahtarı girin.');
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const { secret, public_key } = recoveryData;
|
|
49
|
-
|
|
50
|
-
tsoft.clientCredentials.setClientSecret(secret).setClientId(public_key);
|
|
51
|
-
const authorizeResponse = await tsoft.clientCredentials.authorize(true);
|
|
52
|
-
const themeInformation = authorizeResponse.data.tokenable;
|
|
53
|
-
|
|
54
|
-
const themeName = themeInformation.name;
|
|
55
|
-
const themeNameSlug = slugify(themeName);
|
|
56
|
-
const themePath = await createThemeDirectory(selectedSite, themeNameSlug);
|
|
57
|
-
|
|
58
|
-
const themeData = {
|
|
59
|
-
site: selectedSite,
|
|
60
|
-
name: themeName,
|
|
61
|
-
author: themeInformation.author,
|
|
62
|
-
version: themeInformation.version
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
fs.writeFileSync(path.join(themePath, '.theme'), JSON.stringify(themeData, null, 2));
|
|
66
|
-
tsoft.themeManager.setTheme(themeNameSlug);
|
|
67
|
-
|
|
68
|
-
if (!fs.existsSync(themePath)) {
|
|
69
|
-
fs.mkdirSync(themePath, { recursive: true });
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
clearScreen();
|
|
73
|
-
|
|
74
|
-
const zipFilePath = path.join(themePath, 'theme.zip');
|
|
75
|
-
|
|
76
|
-
try {
|
|
77
|
-
console.log('Zip dosyası indiriliyor...');
|
|
78
|
-
await tsoft.fileManager.downloadAndSaveZip(themePath, zipFilePath, tsoft.clientCredentials.bearer);
|
|
79
|
-
console.log('İndirme tamamlandı.');
|
|
80
|
-
|
|
81
|
-
console.log('Dosyalar çıkarılıyor...');
|
|
82
|
-
await unzipFile(zipFilePath, themePath);
|
|
83
|
-
console.log('Çıkarma işlemi tamamlandı.');
|
|
84
|
-
fs.unlinkSync(zipFilePath);
|
|
85
|
-
} catch (error) {
|
|
86
|
-
console.error(`Zip dosyası ile ilgili bir hata oluştu: ${error.message}`);
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
tsoft.buildEnvironment();
|
|
91
|
-
|
|
92
|
-
// Geliştirme ortamını başlat
|
|
93
|
-
await StartCommand.start(selectedSite, themeNameSlug);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
module.exports = SyncCommand;
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
const {buildPostRequest} = require('./Request');
|
|
2
|
-
|
|
3
|
-
class ClientCredentials {
|
|
4
|
-
constructor(site) {
|
|
5
|
-
this.site = site;
|
|
6
|
-
this.clientId = null;
|
|
7
|
-
this.clientSecret = null;
|
|
8
|
-
this.bearer = null;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
setClientId(clientId) {
|
|
12
|
-
this.clientId = clientId;
|
|
13
|
-
return this;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
setClientSecret(clientSecret) {
|
|
17
|
-
this.clientSecret = clientSecret;
|
|
18
|
-
return this;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
getEnvironment() {
|
|
22
|
-
return {
|
|
23
|
-
site: this.site,
|
|
24
|
-
clientId: this.clientId,
|
|
25
|
-
clientSecret: this.clientSecret,
|
|
26
|
-
bearer: this.bearer
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
async register(CLIENT_UUID, clientConfiguration = {}) {
|
|
31
|
-
const uri = "api/v3/admin/auth/auth-application";
|
|
32
|
-
const result = await buildPostRequest(this.site, uri, {
|
|
33
|
-
headers: {
|
|
34
|
-
'Content-Type': 'application/json',
|
|
35
|
-
'Accept': 'application/json'
|
|
36
|
-
},
|
|
37
|
-
body: JSON.stringify({
|
|
38
|
-
uuid: CLIENT_UUID,
|
|
39
|
-
configuration: {
|
|
40
|
-
name: clientConfiguration.name,
|
|
41
|
-
author: clientConfiguration.author,
|
|
42
|
-
version: clientConfiguration.version
|
|
43
|
-
}
|
|
44
|
-
})
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
if (result.status === true) {
|
|
48
|
-
this.clientId = result.data.public_key;
|
|
49
|
-
return true;
|
|
50
|
-
} else {
|
|
51
|
-
return false;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
async authorize() {
|
|
56
|
-
const uri = "api/v3/admin/auth/auth-application/authorize";
|
|
57
|
-
return await buildPostRequest(this.site, uri, {
|
|
58
|
-
headers: {
|
|
59
|
-
'Content-Type': 'application/json',
|
|
60
|
-
'Accept': 'application/json'
|
|
61
|
-
},
|
|
62
|
-
body: JSON.stringify({
|
|
63
|
-
public_key: this.clientId,
|
|
64
|
-
secret: this.clientSecret
|
|
65
|
-
})
|
|
66
|
-
}).then((result) => {
|
|
67
|
-
if (result.status === true) {
|
|
68
|
-
this.bearer = result.data.token.plainTextToken;
|
|
69
|
-
return result;
|
|
70
|
-
}
|
|
71
|
-
return false;
|
|
72
|
-
}).catch((error) => {
|
|
73
|
-
console.error('Hata:', error.message);
|
|
74
|
-
return false;
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
async validateToken(token) {
|
|
79
|
-
const uri = 'api/v3/admin/auth/me';
|
|
80
|
-
const response = await buildPostRequest(this.site, uri, {
|
|
81
|
-
headers: {
|
|
82
|
-
Authorization: `Bearer ${token}`
|
|
83
|
-
},
|
|
84
|
-
body: JSON.stringify({
|
|
85
|
-
_method: 'GET'
|
|
86
|
-
})
|
|
87
|
-
});
|
|
88
|
-
return response.message === 'ok';
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
async recovery(token) {
|
|
92
|
-
const uri = `api/v3/admin/auth/auth-application/recovery/${token}`;
|
|
93
|
-
const response = await buildPostRequest(this.site, uri);
|
|
94
|
-
if (response.status) {
|
|
95
|
-
return {
|
|
96
|
-
secret: response.data.secret,
|
|
97
|
-
public_key: response.data.public_key
|
|
98
|
-
};
|
|
99
|
-
} else if (response?.throttle) {
|
|
100
|
-
const {limit, retryAfter, resetDate} = response.throttle;
|
|
101
|
-
throw new Error(`Çok fazla deneme yapıldı. Lütfen ${retryAfter} saniye sonra tekrar deneyin. Limit: ${limit}, Reset Zamanı: ${resetDate}`);
|
|
102
|
-
}
|
|
103
|
-
return null;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
module.exports = ClientCredentials;
|
package/src/core/Constants.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
const handleAuthorization = async (credentialHandler) => {
|
|
2
|
-
await credentialHandler.authorize();
|
|
3
|
-
};
|
|
4
|
-
|
|
5
|
-
const Constants = Object.freeze({
|
|
6
|
-
INITIALIZE: {
|
|
7
|
-
type: 'input',
|
|
8
|
-
name: 'site',
|
|
9
|
-
message: 'Lütfen site adresini giriniz (örnek: https://tsoft.com.tr):'
|
|
10
|
-
},
|
|
11
|
-
APPROVAL: {
|
|
12
|
-
type: 'input',
|
|
13
|
-
name: 'approval',
|
|
14
|
-
message: 'Parolanızı giriniz (Lütfen panelden onaylayınız):',
|
|
15
|
-
handler: handleAuthorization
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
module.exports = Constants;
|
package/src/core/FileManager.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
const path = require('path');
|
|
3
|
-
const Utils = require('./Utils');
|
|
4
|
-
const { buildDownloadZipRequest } = require('./Request');
|
|
5
|
-
|
|
6
|
-
class FileManager {
|
|
7
|
-
constructor(site) {
|
|
8
|
-
this.site = site;
|
|
9
|
-
this.cwd = process.cwd();
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
listFilesRecursive(directory, fileList = []) {
|
|
13
|
-
const files = fs.readdirSync(directory);
|
|
14
|
-
files.forEach(file => {
|
|
15
|
-
const fullPath = path.join(directory, file);
|
|
16
|
-
if (fs.statSync(fullPath).isDirectory()) {
|
|
17
|
-
this.listFilesRecursive(fullPath, fileList);
|
|
18
|
-
} else {
|
|
19
|
-
this.isAllowedExtension(fullPath) && fileList.push(fullPath);
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
return fileList;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
getRelativePath(theme, file) {
|
|
26
|
-
const themePath = path.join(this.cwd, this.site, theme);
|
|
27
|
-
return file.replace(`${themePath}/`, '');
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
readFile(file) {
|
|
31
|
-
return fs.readFileSync(file).toString();
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
isAllowedExtension(file) {
|
|
35
|
-
const ext = path.extname(file).substring(1);
|
|
36
|
-
return Utils.allowedExtensions.includes(ext);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
async downloadAndSaveZip(saveToDir, zipFilePath, bearerToken, type = 'none') {
|
|
40
|
-
const response = await buildDownloadZipRequest(this.site, `api/v3/admin/online-store-2/theme/download-theme?type=${type}`, {
|
|
41
|
-
headers: {
|
|
42
|
-
'Content-Type': 'application/zip',
|
|
43
|
-
'Accept': 'application/zip',
|
|
44
|
-
'Authorization': `Bearer ${bearerToken}`
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
fs.writeFileSync(zipFilePath, Buffer.from(response));
|
|
49
|
-
console.log(`Zip dosyası ${zipFilePath} konumuna kaydedildi.`);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
module.exports = FileManager;
|
package/src/core/Request.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
class Request {
|
|
2
|
-
static async buildPostRequest(site, uri, options = {}) {
|
|
3
|
-
const fetch = (await import('node-fetch')).default;
|
|
4
|
-
try {
|
|
5
|
-
const response = await fetch(`https://${site}/${uri}`, {
|
|
6
|
-
method: 'POST',
|
|
7
|
-
headers: {
|
|
8
|
-
'Content-Type': 'application/json',
|
|
9
|
-
'Accept': 'application/json',
|
|
10
|
-
...options.headers
|
|
11
|
-
},
|
|
12
|
-
body: options.body
|
|
13
|
-
});
|
|
14
|
-
return await response.json();
|
|
15
|
-
} catch (error) {
|
|
16
|
-
console.error(error);
|
|
17
|
-
throw new Error('Request failed');
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
static async buildDownloadZipRequest(site, uri, options = {}) {
|
|
22
|
-
const fetch = (await import('node-fetch')).default;
|
|
23
|
-
try {
|
|
24
|
-
const response = await fetch(`https://${site}/${uri}`, {
|
|
25
|
-
method: 'POST',
|
|
26
|
-
headers: {
|
|
27
|
-
'Content-Type': 'application/zip',
|
|
28
|
-
'Accept': 'application/zip',
|
|
29
|
-
...options.headers
|
|
30
|
-
},
|
|
31
|
-
body: options.body
|
|
32
|
-
});
|
|
33
|
-
return await response.arrayBuffer();
|
|
34
|
-
} catch (error) {
|
|
35
|
-
console.error(error);
|
|
36
|
-
throw new Error('Request failed');
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
module.exports = Request;
|