tsoft-cli 1.4.3 → 2.0.0

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.
Files changed (72) hide show
  1. package/.editorconfig +11 -0
  2. package/.github/workflows/node.js.yml +25 -0
  3. package/.nvmrc +1 -0
  4. package/.prettierrc.json +8 -0
  5. package/.vscode/extensions.json +3 -0
  6. package/.vscode/settings.json +4 -0
  7. package/CHANGELOG.md +29 -4
  8. package/package.json +14 -25
  9. package/packages/cli/README.md +53 -0
  10. package/packages/cli/bin/dev.js +5 -0
  11. package/packages/cli/bin/run.cmd +3 -0
  12. package/packages/cli/bin/run.js +5 -0
  13. package/packages/cli/enums.ts +4 -0
  14. package/packages/cli/index.ts +11 -0
  15. package/packages/cli/package.json +59 -0
  16. package/packages/cli/tsconfig.json +9 -0
  17. package/packages/shared/index.ts +6 -0
  18. package/packages/shared/package.json +45 -0
  19. package/packages/shared/src/cli-progress.ts +3 -0
  20. package/packages/shared/src/commands/cli-all-commands.ts +6 -0
  21. package/packages/shared/src/commands/version-command.ts +12 -0
  22. package/packages/shared/src/consola.ts +1 -0
  23. package/packages/shared/src/open.ts +3 -0
  24. package/packages/shared/src/unzip.ts +15 -0
  25. package/packages/shared/tsconfig.json +9 -0
  26. package/packages/theme/bin/dev.js +5 -0
  27. package/packages/theme/bin/run.cmd +3 -0
  28. package/packages/theme/bin/run.js +5 -0
  29. package/packages/theme/index.ts +21 -0
  30. package/packages/theme/jest.config.ts +3 -0
  31. package/packages/theme/package.json +66 -0
  32. package/packages/theme/src/commands/theme/create.ts +51 -0
  33. package/packages/theme/src/commands/theme/delete-site.ts +30 -0
  34. package/packages/theme/src/commands/theme/delete-theme.ts +39 -0
  35. package/packages/theme/src/commands/theme/dev.ts +47 -0
  36. package/packages/theme/src/commands/theme/pull.ts +26 -0
  37. package/packages/theme/src/enums.ts +55 -0
  38. package/packages/theme/src/services/ClientCredentials.ts +127 -0
  39. package/packages/theme/src/services/Constants.ts +19 -0
  40. package/packages/theme/src/services/CreateTheme.ts +88 -0
  41. package/packages/theme/src/services/DeleteSite.ts +30 -0
  42. package/packages/theme/src/services/DeleteTheme.ts +46 -0
  43. package/packages/theme/src/services/FileManager.ts +62 -0
  44. package/packages/theme/src/services/Request.ts +18 -0
  45. package/packages/theme/src/services/StartTheme.ts +363 -0
  46. package/packages/theme/src/services/SyncTheme.ts +108 -0
  47. package/packages/theme/src/services/ThemeManager.ts +118 -0
  48. package/packages/theme/src/services/Tsoft.ts +151 -0
  49. package/packages/theme/src/services/types.ts +90 -0
  50. package/packages/theme/src/types.ts +20 -0
  51. package/packages/theme/src/utils/screen.ts +28 -0
  52. package/packages/theme/src/utils/utils.ts +83 -0
  53. package/packages/theme/tests/FileManager.test.js +90 -0
  54. package/packages/theme/tsconfig.json +9 -0
  55. package/pnpm-workspace.yaml +2 -0
  56. package/pull_request_template.md +5 -0
  57. package/scripts/prebuild.js +45 -0
  58. package/scripts/versions.js +70 -0
  59. package/tsconfig.build.json +21 -0
  60. package/bin/index.js +0 -77
  61. package/jest.config.js +0 -3
  62. package/src/Tsoft.js +0 -137
  63. package/src/commands/CreateCommand.js +0 -102
  64. package/src/commands/StartCommand.js +0 -281
  65. package/src/commands/SyncCommand.js +0 -97
  66. package/src/core/ClientCredentials.js +0 -107
  67. package/src/core/Constants.js +0 -19
  68. package/src/core/FileManager.js +0 -53
  69. package/src/core/Request.js +0 -41
  70. package/src/core/ThemeManager.js +0 -113
  71. package/src/core/Utils.js +0 -104
  72. package/tests/FileManager.test.js +0 -90
package/jest.config.js DELETED
@@ -1,3 +0,0 @@
1
- module.exports = {
2
- testEnvironment: 'node',
3
- };
package/src/Tsoft.js DELETED
@@ -1,137 +0,0 @@
1
- const ClientCredentials = require('./core/ClientCredentials');
2
- const Constants = require('./core/Constants');
3
- const FileManager = require('./core/FileManager');
4
- const ThemeManager = require('./core/ThemeManager');
5
- const path = require("path");
6
- const { buildPostRequest } = require('./core/Request');
7
-
8
- class Tsoft {
9
- static TSOFT_CLI_UUID = '7583a318-8542-4ec8-980c-48ea67031be3';
10
- static ONLINESTORE_SAVE_URI = 'api/v3/admin/online-store-2/theme/file-manager?q=save';
11
- static ONLINESTORE_DELETE_URI = 'api/v3/admin/online-store-2/theme/file-manager?q=delete';
12
- static UPDATE_THEME_URI = 'api/v3/admin/online-store-2/theme/update-theme';
13
-
14
- constructor(site) {
15
- this.site = site;
16
- this.themeManager = new ThemeManager(site);
17
- this.fileManager = new FileManager(site);
18
- this.clientCredentials = new ClientCredentials(site);
19
- }
20
-
21
- async initialize(theme, reInit = false) {
22
- await this.themeManager.initializeTheme(theme, reInit);
23
- if (!this.themeManager.isRegistered()) {
24
- return await this.register(Tsoft.TSOFT_CLI_UUID, this.themeManager.getThemeInfo(theme));
25
- } else {
26
- console.warn('You are already registered');
27
- }
28
- }
29
-
30
- buildEnvironment() {
31
- this.themeManager.buildEnvironment(this.clientCredentials.getEnvironment());
32
- }
33
-
34
- async authorize() {
35
- await this.clientCredentials.authorize();
36
- }
37
-
38
- async register(CLIENT_UUID, clientConfiguration = {}) {
39
- const response = await this.clientCredentials.register(CLIENT_UUID, clientConfiguration);
40
- return response === true ? Constants.APPROVAL : null;
41
- }
42
-
43
- async saveOnlineStore(theme) {
44
- const fileList = this.fileManager.listFilesRecursive(
45
- path.join(process.cwd(), this.site, theme)
46
- );
47
- await Promise.all(fileList.filter(file => !file.includes('.env')).map(async file => {
48
- const fileName = this.fileManager.getRelativePath(theme, file);
49
- const content = this.fileManager.readFile(file);
50
- const env = this.themeManager.getEnvironment(theme);
51
- await buildPostRequest(this.site, Tsoft.ONLINESTORE_SAVE_URI, {
52
- headers: {
53
- Authorization: `Bearer ${env.bearer}`
54
- },
55
- body: JSON.stringify({
56
- theme: theme,
57
- path: fileName,
58
- content: content
59
- })
60
- });
61
- }));
62
- }
63
-
64
- async saveFile(theme, fileName, content, bearerToken) {
65
- return await buildPostRequest(this.site, Tsoft.ONLINESTORE_SAVE_URI, {
66
- headers: {
67
- Authorization: `Bearer ${bearerToken}`,
68
- Accept: 'application/json',
69
- 'Content-Type': 'application/json'
70
- },
71
- body: JSON.stringify({
72
- theme: theme,
73
- path: fileName,
74
- content: content
75
- })
76
- });
77
- }
78
-
79
- async deleteFile(theme, fileName, bearerToken) {
80
- return await buildPostRequest(this.site, Tsoft.ONLINESTORE_DELETE_URI, {
81
- headers: {
82
- Authorization: `Bearer ${bearerToken}`,
83
- 'Content-Type': 'application/json'
84
- },
85
- body: JSON.stringify({
86
- theme: theme,
87
- items: [
88
- { type: 'file', path: fileName }
89
- ]
90
- })
91
- });
92
- }
93
-
94
- async deleteDirectory(theme, folderName, bearerToken) {
95
- return await buildPostRequest(this.site, Tsoft.ONLINESTORE_DELETE_URI, {
96
- headers: {
97
- Authorization: `Bearer ${bearerToken}`,
98
- Accept: 'application/json',
99
- 'Content-Type': 'application/json'
100
- },
101
- body: JSON.stringify({
102
- theme: theme,
103
- items: [
104
- { type: 'dir', path: folderName }
105
- ]
106
- })
107
- });
108
- }
109
-
110
- async isTokenValid(theme) {
111
- const env = this.themeManager.getEnvironment(theme);
112
- return await this.clientCredentials.validateToken(env.bearer);
113
- }
114
-
115
- async updateTheme(directoryName) {
116
- const env = this.themeManager.getEnvironment(directoryName);
117
- const themeInfo = this.themeManager.getThemeInfo(directoryName); // .theme bilgisi alınıyor
118
-
119
- return await buildPostRequest(this.site, Tsoft.UPDATE_THEME_URI, {
120
- headers: {
121
- Authorization: `Bearer ${env.bearer}`,
122
- 'Accept': 'application/json',
123
- 'Content-Type': 'application/json'
124
- },
125
- body: JSON.stringify({
126
- theme: directoryName,
127
- themeInfo: themeInfo
128
- })
129
- });
130
- }
131
-
132
- async startRecovery(token) {
133
- return await this.clientCredentials.recovery(token);
134
- }
135
- }
136
-
137
- module.exports = Tsoft;
@@ -1,102 +0,0 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
- const {Select, Input} = require('enquirer');
4
- const {slugify, clearScreen, getSites} = require('../core/Utils');
5
- const ThemeManager = require('../core/ThemeManager');
6
- const {start} = require('./StartCommand');
7
-
8
- class CreateCommand {
9
- static async selectSite(sites) {
10
- const siteChoices = [...sites, 'Yeni bir site oluştur'];
11
- const sitePrompt = new Select({
12
- name: 'site',
13
- message: 'Çalışmak istediğiniz sitenin adı:',
14
- choices: siteChoices
15
- });
16
- const selectedSite = await sitePrompt.run();
17
- return selectedSite === 'Yeni bir site oluştur' ? await CreateCommand.createNewSite() : selectedSite;
18
- }
19
-
20
- static async createNewSite() {
21
- const newSitePrompt = new Input({
22
- name: 'newSite',
23
- message: 'Yeni site adı:'
24
- });
25
- const siteName = await newSitePrompt.run();
26
- const themeManager = new ThemeManager(siteName);
27
- const isValid = await this.validateSiteName(themeManager, siteName);
28
- return isValid ? siteName : null;
29
- }
30
-
31
- static async validateSiteName(themeManager, siteName) {
32
- try {
33
- const isValid = await themeManager.checkSiteValidity(siteName);
34
- if (!isValid) {
35
- console.error('Geçersiz site adı. Lütfen geçerli bir site adı girin.');
36
- return false;
37
- }
38
- return true;
39
- } catch (error) {
40
- console.error('Site doğrulaması sırasında hata oluştu:', error.message);
41
- return false;
42
- }
43
- }
44
-
45
- static async getThemeDetails() {
46
- const themeNamePrompt = new Input({
47
- name: 'themeName',
48
- message: 'Tema adı:'
49
- });
50
- const authorPrompt = new Input({
51
- name: 'author',
52
- message: 'Author (isteğe bağlı):'
53
- });
54
- const versionPrompt = new Input({
55
- name: 'version',
56
- message: 'Version (isteğe bağlı, varsayılan 1.0.0):',
57
- initial: '1.0.0'
58
- });
59
- const themeName = await themeNamePrompt.run();
60
- const author = await authorPrompt.run();
61
- const version = await versionPrompt.run();
62
- return {themeName, author, version};
63
- }
64
-
65
- static async createThemeDirectory(siteName, themeNameSlug) {
66
- const cwd = process.cwd();
67
- const themePath = path.join(cwd, siteName, themeNameSlug);
68
- if (!fs.existsSync(themePath)) {
69
- fs.mkdirSync(themePath, {recursive: true});
70
- }
71
-
72
- const sitePath = path.join(process.cwd(), siteName);
73
- const tsoftFilePath = path.join(sitePath, '.tsoft');
74
- if (!fs.existsSync(tsoftFilePath)) {
75
- fs.writeFileSync(tsoftFilePath, '');
76
- }
77
-
78
-
79
- return themePath;
80
- }
81
-
82
- static async saveThemeData(themePath, themeData) {
83
- fs.writeFileSync(path.join(themePath, '.theme'), JSON.stringify(themeData, null, 2));
84
- }
85
-
86
- static async createTheme() {
87
- const sites = await getSites();
88
- const siteName = await this.selectSite(sites);
89
- if (!siteName) return;
90
-
91
- const {themeName, author, version} = await this.getThemeDetails();
92
- const themeNameSlug = slugify(themeName);
93
- const themePath = await this.createThemeDirectory(siteName, themeNameSlug);
94
- const themeData = {site: siteName, name: themeName, author: author, version: version};
95
- await this.saveThemeData(themePath, themeData);
96
- clearScreen();
97
- console.log(`Tema "${themeName}" başarıyla oluşturuldu.`);
98
- await start(siteName, themeNameSlug, true);
99
- }
100
- }
101
-
102
- module.exports = CreateCommand;
@@ -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;