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
package/src/core/ThemeManager.js
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
const path = require('path');
|
|
3
|
-
const { slugify } = require('./Utils');
|
|
4
|
-
const http = require('http');
|
|
5
|
-
const https = require('https');
|
|
6
|
-
|
|
7
|
-
class ThemeManager {
|
|
8
|
-
constructor(site) {
|
|
9
|
-
this.site = site;
|
|
10
|
-
this.cwd = process.cwd();
|
|
11
|
-
this.theme = null;
|
|
12
|
-
this.registered = false;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
async initializeTheme(theme, reInit = false) {
|
|
16
|
-
this.theme = theme;
|
|
17
|
-
const themePath = path.join(this.cwd, this.site, theme);
|
|
18
|
-
const themeEnvPath = path.join(themePath, `${theme}.env`);
|
|
19
|
-
|
|
20
|
-
if (reInit) {
|
|
21
|
-
// await fs.rm(themePath, {recursive: true, force: true}, (err, file) => {});
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
if (!fs.existsSync(path.join(this.cwd, this.site))) {
|
|
25
|
-
fs.mkdirSync(path.join(this.cwd, this.site));
|
|
26
|
-
}
|
|
27
|
-
if (!fs.existsSync(themePath)) {
|
|
28
|
-
fs.mkdirSync(themePath);
|
|
29
|
-
}
|
|
30
|
-
if (reInit || !fs.existsSync(themeEnvPath)) {
|
|
31
|
-
fs.writeFileSync(themeEnvPath, '');
|
|
32
|
-
this.registered = false;
|
|
33
|
-
} else {
|
|
34
|
-
const data = fs.readFileSync(themeEnvPath);
|
|
35
|
-
try {
|
|
36
|
-
const environment = JSON.parse(data.toString());
|
|
37
|
-
this.registered = Boolean(environment.bearer);
|
|
38
|
-
} catch (e) {
|
|
39
|
-
this.registered = false;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
try {
|
|
44
|
-
const isValid = await this.checkSiteValidity();
|
|
45
|
-
if (!isValid) {
|
|
46
|
-
console.error('Geçersiz site: Siteye ulaşılamıyor.');
|
|
47
|
-
return false;
|
|
48
|
-
}
|
|
49
|
-
} catch (error) {
|
|
50
|
-
console.error('Geçersiz site: Siteye ulaşılamıyor.', error.message);
|
|
51
|
-
return false;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return true;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
setTheme(theme) {
|
|
58
|
-
this.theme = slugify(theme);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
isRegistered() {
|
|
62
|
-
return this.registered;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
buildEnvironment(environment) {
|
|
66
|
-
const envPath = path.join(this.cwd, this.site, this.theme, `${this.theme}.env`);
|
|
67
|
-
fs.writeFileSync(envPath, JSON.stringify(environment));
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
getEnvironment(theme) {
|
|
71
|
-
const themeEnvPath = path.join(this.cwd, this.site, slugify(theme), `${slugify(theme)}.env`);
|
|
72
|
-
return JSON.parse(fs.readFileSync(themeEnvPath));
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
getThemeInfo(directoryName) {
|
|
76
|
-
const themePath = path.join(process.cwd(), this.site, slugify(directoryName), '.theme');
|
|
77
|
-
if (fs.existsSync(themePath)) {
|
|
78
|
-
const themeInfo = fs.readFileSync(themePath, 'utf-8');
|
|
79
|
-
try {
|
|
80
|
-
return JSON.parse(themeInfo);
|
|
81
|
-
} catch (error) {
|
|
82
|
-
console.error('.theme dosyasını ayrıştırma hatası:', error);
|
|
83
|
-
return null;
|
|
84
|
-
}
|
|
85
|
-
} else {
|
|
86
|
-
console.error('.theme dosyası bulunamadı:', themePath);
|
|
87
|
-
return null;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
checkSiteValidity() {
|
|
92
|
-
return new Promise((resolve, reject) => {
|
|
93
|
-
const url = new URL(`https://${this.site}/Y/R`);
|
|
94
|
-
const request = url.protocol === 'https:' ? https : http;
|
|
95
|
-
|
|
96
|
-
const req = request.get(url, (res) => {
|
|
97
|
-
if (res.statusCode === 200) {
|
|
98
|
-
resolve(true);
|
|
99
|
-
} else {
|
|
100
|
-
resolve(false);
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
req.on('error', (err) => {
|
|
105
|
-
reject(err);
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
req.end();
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
module.exports = ThemeManager;
|
package/src/core/Utils.js
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
const figlet = require("figlet");
|
|
2
|
-
const packageJson = require('../../package.json');
|
|
3
|
-
const fs = require("fs");
|
|
4
|
-
const unzipper = require("unzipper");
|
|
5
|
-
const path = require("path");
|
|
6
|
-
|
|
7
|
-
class Utils {
|
|
8
|
-
static slugify(text) {
|
|
9
|
-
return text.toString().toLowerCase()
|
|
10
|
-
.replace(/\s+/g, '-')
|
|
11
|
-
.replace(/[^\w\-]+/g, '')
|
|
12
|
-
.replace(/\-\-+/g, '-')
|
|
13
|
-
.replace(/^-+/, '')
|
|
14
|
-
.replace(/-+$/, '');
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
static get allowedExtensions() {
|
|
18
|
-
return ['theme', 'twig', 'css', 'js', 'md', 'json', 'svg', 'jpeg', 'jpg', 'png', 'gif', 'webp'];
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
static clearScreen() {
|
|
22
|
-
process.stdout.write('\x1B[2J\x1B[0f');
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
static displayAsciiArt() {
|
|
26
|
-
return new Promise((resolve, reject) => {
|
|
27
|
-
figlet('T-SOFT CLI', {
|
|
28
|
-
font: 'Standard',
|
|
29
|
-
}, (err, data) => {
|
|
30
|
-
if (err) {
|
|
31
|
-
console.log('Something went wrong...');
|
|
32
|
-
console.dir(err);
|
|
33
|
-
reject(err);
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
console.log(data);
|
|
37
|
-
resolve();
|
|
38
|
-
});
|
|
39
|
-
}).then(() => {
|
|
40
|
-
console.log('Versiyon: ' + packageJson.version);
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
static info(tsoft, theme) {
|
|
45
|
-
Utils.clearScreen()
|
|
46
|
-
|
|
47
|
-
console.log('\n' +
|
|
48
|
-
'********************************************************\n' +
|
|
49
|
-
'* *\n' +
|
|
50
|
-
'* Dosya izlemeyi sonlandırmak için "q" tuşuna basın, *\n' +
|
|
51
|
-
'* Temayı güncellemek için "u" tuşuna basın, *\n' +
|
|
52
|
-
'* Temayı kaydetmek için "s" tuşuna basın, *\n' +
|
|
53
|
-
'* .theme dosyasını düzenlemek için "e" tuşuna basın, *\n' +
|
|
54
|
-
'* Tema dizinini açmak için "o" tuşuna basın. *\n' +
|
|
55
|
-
'* URL\'yi tarayıcıda açmak için "p" tuşuna basın. *\n' +
|
|
56
|
-
'* *\n' +
|
|
57
|
-
'********************************************************\n'
|
|
58
|
-
);
|
|
59
|
-
const {clientId, clientSecret} = tsoft.themeManager.getEnvironment(theme);
|
|
60
|
-
|
|
61
|
-
const url = 'https://' + tsoft.site + '?tsoft-cli=' + clientId + '&tsoft-cli-secret=' + clientSecret;
|
|
62
|
-
console.log('İzlenen tema: ' + theme);
|
|
63
|
-
console.log('Önizleme: \n')
|
|
64
|
-
console.log(url+ '\n');
|
|
65
|
-
|
|
66
|
-
process.stdin.setRawMode(true);
|
|
67
|
-
process.stdin.resume();
|
|
68
|
-
process.stdin.on('data', async (key) => {
|
|
69
|
-
if (key.toString() === 'p') {
|
|
70
|
-
console.log('URL tarayıcıda açılıyor...');
|
|
71
|
-
const open = (await import('open')).default;
|
|
72
|
-
await open(url);
|
|
73
|
-
} else if (key.toString() === 'q') {
|
|
74
|
-
console.log('Programdan çıkılıyor. Hoşça kalın!');
|
|
75
|
-
process.exit(0);
|
|
76
|
-
}
|
|
77
|
-
// Other keypress handlers can go here
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
static unzipFile(zipFilePath, extractToDir) {
|
|
83
|
-
return new Promise((resolve, reject) => {
|
|
84
|
-
fs.createReadStream(zipFilePath)
|
|
85
|
-
.pipe(unzipper.Extract({ path: extractToDir }))
|
|
86
|
-
.on('close', resolve)
|
|
87
|
-
.on('error', reject);
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
static async getSites(opt = {}) {
|
|
92
|
-
const cwd = opt.cwd ?? process.cwd();
|
|
93
|
-
return fs.readdirSync(cwd).filter(file => {
|
|
94
|
-
const filePath = path.join(cwd, file);
|
|
95
|
-
return file.charAt(0) !== '.'
|
|
96
|
-
&& !['node_modules', 'build', 'dist'].includes(file)
|
|
97
|
-
&& fs.statSync(filePath).isDirectory()
|
|
98
|
-
&& fs.existsSync(path.join(filePath, '.tsoft'));
|
|
99
|
-
}).filter(file => fs.statSync(path.join(cwd, file)).isDirectory());
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
module.exports = Utils;
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
const path = require('path');
|
|
2
|
-
const mockFs = require('mock-fs');
|
|
3
|
-
const FileManager = require('../src/file-manager');
|
|
4
|
-
|
|
5
|
-
describe('FileManager', () => {
|
|
6
|
-
const site = 'testSite';
|
|
7
|
-
const fileManager = new FileManager(site);
|
|
8
|
-
|
|
9
|
-
beforeEach(() => {
|
|
10
|
-
mockFs({
|
|
11
|
-
'/testDir': {
|
|
12
|
-
'file1.js': 'console.log("file1");',
|
|
13
|
-
'file2.css': 'body { margin: 0; }',
|
|
14
|
-
'subdir': {
|
|
15
|
-
'file3.jpg': '',
|
|
16
|
-
'file4.png': ''
|
|
17
|
-
}
|
|
18
|
-
},
|
|
19
|
-
[`${process.cwd()}/${site}`]: {
|
|
20
|
-
'myTheme': {
|
|
21
|
-
'file.js': 'console.log("test");'
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
afterEach(() => {
|
|
28
|
-
mockFs.restore();
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
describe('listFilesRecursive', () => {
|
|
32
|
-
it('should list all files recursively', () => {
|
|
33
|
-
// Act
|
|
34
|
-
const result = fileManager.listFilesRecursive('/testDir');
|
|
35
|
-
|
|
36
|
-
// Assert
|
|
37
|
-
expect(result).toEqual([
|
|
38
|
-
'/testDir/file1.js',
|
|
39
|
-
'/testDir/file2.css',
|
|
40
|
-
'/testDir/subdir/file3.jpg',
|
|
41
|
-
'/testDir/subdir/file4.png'
|
|
42
|
-
]);
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
describe('getRelativePath', () => {
|
|
47
|
-
it('should get the relative path of a file', () => {
|
|
48
|
-
// Arrange
|
|
49
|
-
const theme = 'myTheme';
|
|
50
|
-
const file = path.join(process.cwd(), site, theme, 'file.js');
|
|
51
|
-
const expectedRelativePath = 'file.js';
|
|
52
|
-
|
|
53
|
-
// Act
|
|
54
|
-
const result = fileManager.getRelativePath(theme, file);
|
|
55
|
-
|
|
56
|
-
// Assert
|
|
57
|
-
expect(result).toBe(expectedRelativePath);
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
describe('readFile', () => {
|
|
62
|
-
it('should read the contents of a file', () => {
|
|
63
|
-
// Arrange
|
|
64
|
-
const file = '/testDir/file1.js';
|
|
65
|
-
const fileContents = 'console.log("file1");';
|
|
66
|
-
|
|
67
|
-
// Act
|
|
68
|
-
const result = fileManager.readFile(file);
|
|
69
|
-
|
|
70
|
-
// Assert
|
|
71
|
-
expect(result).toBe(fileContents);
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
describe('isAllowedExtension', () => {
|
|
76
|
-
it('should return true for allowed extensions', () => {
|
|
77
|
-
// Arrange
|
|
78
|
-
const allowedFile = 'file.js';
|
|
79
|
-
const notAllowedFile = 'file.exe';
|
|
80
|
-
|
|
81
|
-
// Act
|
|
82
|
-
const isAllowedFileResult = fileManager.isAllowedExtension(allowedFile);
|
|
83
|
-
const isNotAllowedFileResult = fileManager.isAllowedExtension(notAllowedFile);
|
|
84
|
-
|
|
85
|
-
// Assert
|
|
86
|
-
expect(isAllowedFileResult).toBe(true);
|
|
87
|
-
expect(isNotAllowedFileResult).toBe(false);
|
|
88
|
-
});
|
|
89
|
-
});
|
|
90
|
-
});
|