tsoft-cli 1.0.1 → 1.0.2
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/bin/tsoft-cli.js +101 -11
- package/package.json +8 -3
- package/src/common.js +117 -0
package/bin/tsoft-cli.js
CHANGED
|
@@ -1,17 +1,107 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
2
|
+
const Common = require('../src/common');
|
|
3
3
|
const { program } = require('commander');
|
|
4
|
-
const
|
|
4
|
+
const axios = require('axios');
|
|
5
|
+
const chokidar = require('chokidar');
|
|
6
|
+
const path = require('path');
|
|
7
|
+
const fs = require('fs');
|
|
8
|
+
const _ = require('lodash');
|
|
5
9
|
|
|
6
10
|
program
|
|
7
|
-
|
|
8
|
-
|
|
11
|
+
.command('init')
|
|
12
|
+
.description('Initialize the CLI')
|
|
13
|
+
.action(() => {
|
|
14
|
+
init();
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
program.parse(process.argv);
|
|
18
|
+
|
|
19
|
+
function init() {
|
|
20
|
+
(async () => {
|
|
21
|
+
const {default: inquirer} = await import('inquirer');
|
|
22
|
+
|
|
23
|
+
const tsoft = new Common();
|
|
24
|
+
|
|
25
|
+
if (Common.skip !== true) {
|
|
26
|
+
await tsoft.handleStep1(
|
|
27
|
+
(await inquirer.prompt(
|
|
28
|
+
[
|
|
29
|
+
{
|
|
30
|
+
type: 'input',
|
|
31
|
+
name: 'step1',
|
|
32
|
+
message: 'Site Adresi https://(tsoft.com.tr):'
|
|
33
|
+
},
|
|
34
|
+
]
|
|
35
|
+
))
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
await tsoft.handleStep2(
|
|
39
|
+
(await inquirer.prompt(
|
|
40
|
+
[
|
|
41
|
+
{
|
|
42
|
+
type: 'input',
|
|
43
|
+
name: 'step2',
|
|
44
|
+
message: 'Parola (Panelden Onaylayın):'
|
|
45
|
+
},
|
|
46
|
+
]
|
|
47
|
+
))
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
await tsoft.handleStep3(
|
|
51
|
+
(await inquirer.prompt(
|
|
52
|
+
[
|
|
53
|
+
{
|
|
54
|
+
type: 'input',
|
|
55
|
+
name: 'step3',
|
|
56
|
+
message: 'Tema Adı:'
|
|
57
|
+
},
|
|
58
|
+
]
|
|
59
|
+
))
|
|
60
|
+
)
|
|
61
|
+
} else {
|
|
62
|
+
|
|
63
|
+
const debouncedSendFileChange = _.debounce(async (data) => {
|
|
64
|
+
try {
|
|
65
|
+
const response = await axios.post('https://'+this.site+'/api', { data });
|
|
66
|
+
console.log('API response:', response.data);
|
|
67
|
+
} catch (error) {
|
|
68
|
+
console.error('Error sending API request:', error);
|
|
69
|
+
}
|
|
70
|
+
}, 1000);
|
|
71
|
+
|
|
72
|
+
const watchDirectory = path.join(__dirname, 'themes'); // İzlemek istediğiniz dizinin yolunu belirtin
|
|
73
|
+
const watcher = chokidar.watch(watchDirectory, {
|
|
74
|
+
persistent: true,
|
|
75
|
+
ignored: /(^|[\/\\])\../,
|
|
76
|
+
ignoreInitial: true,
|
|
77
|
+
followSymlinks: true,
|
|
78
|
+
depth: 99,
|
|
79
|
+
awaitWriteFinish: {
|
|
80
|
+
stabilityThreshold: 2000,
|
|
81
|
+
pollInterval: 100
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
watcher.on('all', (event, filePath) => {
|
|
86
|
+
if (event === 'change' || event === 'add' || event === 'unlink') {
|
|
87
|
+
console.log(`File ${filePath} has been ${event}`);
|
|
88
|
+
|
|
89
|
+
// Dosya değişikliğinde dosya içeriğini oku ve debounce edilmiş API'ye gönder
|
|
90
|
+
fs.readFile(filePath, 'utf8', (err, data) => {
|
|
91
|
+
if (err) {
|
|
92
|
+
console.error('Error reading file:', err);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
debouncedSendFileChange(data);
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
})();
|
|
104
|
+
}
|
|
105
|
+
|
|
9
106
|
|
|
10
|
-
program
|
|
11
|
-
.command('init')
|
|
12
|
-
.description('Initialize a new project')
|
|
13
|
-
.action(() => {
|
|
14
|
-
console.log('Project initialized.');
|
|
15
|
-
});
|
|
16
107
|
|
|
17
|
-
program.parse(process.argv);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tsoft-cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -13,7 +13,12 @@
|
|
|
13
13
|
"tsoft-cli": "./bin/tsoft-cli.js"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
+
"axios": "^1.7.2",
|
|
17
|
+
"chokidar": "^3.6.0",
|
|
16
18
|
"commander": "^12.1.0",
|
|
17
|
-
"
|
|
18
|
-
|
|
19
|
+
"fs": "^0.0.1-security",
|
|
20
|
+
"inquirer": "^9.2.23",
|
|
21
|
+
"lodash": "^4.17.21"
|
|
22
|
+
},
|
|
23
|
+
"type": "commonjs"
|
|
19
24
|
}
|
package/src/common.js
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
const path = require("path");
|
|
2
|
+
const fs = require("fs");
|
|
3
|
+
|
|
4
|
+
class Common {
|
|
5
|
+
static CLIENT_UUID = "7583a318-8542-4ec8-980c-48ea67031be3";
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
site = null;
|
|
9
|
+
public_key = null;
|
|
10
|
+
secret = null;
|
|
11
|
+
|
|
12
|
+
theme = null;
|
|
13
|
+
|
|
14
|
+
bearer = null;
|
|
15
|
+
|
|
16
|
+
static skip = false;
|
|
17
|
+
|
|
18
|
+
constructor() {
|
|
19
|
+
try {
|
|
20
|
+
const environment = JSON.parse(fs.readFileSync(path.join(__dirname, '.environment'), 'utf8'))
|
|
21
|
+
|
|
22
|
+
this.site = environment.site;
|
|
23
|
+
this.public_key = environment.public_key;
|
|
24
|
+
this.secret = environment.secret;
|
|
25
|
+
this.theme = environment.theme;
|
|
26
|
+
this.bearer = environment.bearer;
|
|
27
|
+
|
|
28
|
+
Common.skip = true;
|
|
29
|
+
} catch (error) {
|
|
30
|
+
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
handleEnv(envObject) {
|
|
35
|
+
const filePath = path.join(__dirname, '.environment');
|
|
36
|
+
|
|
37
|
+
fs.writeFile(filePath, envObject, (err) => {
|
|
38
|
+
if (err) {
|
|
39
|
+
console.error('Error writing file:', err);
|
|
40
|
+
} else {
|
|
41
|
+
console.log('File written successfully');
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async handleStep1(message) {
|
|
47
|
+
this.site = message.step1;
|
|
48
|
+
await this.authorizationRequest();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async handleStep2(message) {
|
|
52
|
+
this.secret = message.step2;
|
|
53
|
+
await this.login();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async handleStep3(message) {
|
|
57
|
+
this.theme = message.step3;
|
|
58
|
+
|
|
59
|
+
this.handleEnv(JSON.stringify({
|
|
60
|
+
site: this.site,
|
|
61
|
+
public_key: this.public_key,
|
|
62
|
+
secret: this.secret,
|
|
63
|
+
theme: this.theme,
|
|
64
|
+
bearer: this.bearer
|
|
65
|
+
}));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
async authorizationRequest() {
|
|
70
|
+
const myHeaders = new Headers();
|
|
71
|
+
myHeaders.append("Content-Type", "application/json");
|
|
72
|
+
myHeaders.append("Accept", "application/json");
|
|
73
|
+
|
|
74
|
+
const raw = JSON.stringify({
|
|
75
|
+
"uuid": Common.CLIENT_UUID,
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
const requestOptions = {
|
|
79
|
+
method: "POST",
|
|
80
|
+
headers: myHeaders,
|
|
81
|
+
body: raw,
|
|
82
|
+
redirect: "follow"
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
fetch("https://" + this.site + "/api/v3/admin/auth/auth-application", requestOptions)
|
|
86
|
+
.then((response) => response.json())
|
|
87
|
+
.then((result) => {
|
|
88
|
+
this.public_key = result.public_key
|
|
89
|
+
})
|
|
90
|
+
.catch((error) => console.error(error));
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async login() {
|
|
94
|
+
const myHeaders = new Headers();
|
|
95
|
+
const formdata = new FormData();
|
|
96
|
+
formdata.append("public_key", this.public_key);
|
|
97
|
+
formdata.append("secret", this.secret);
|
|
98
|
+
|
|
99
|
+
const requestOptions = {
|
|
100
|
+
method: "POST",
|
|
101
|
+
headers: myHeaders,
|
|
102
|
+
body: formdata,
|
|
103
|
+
redirect: "follow"
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
fetch("https://" + this.site + "/api/v3/admin/auth/auth-application/authorize", requestOptions)
|
|
107
|
+
.then((response) => response.json())
|
|
108
|
+
.then((result) => {
|
|
109
|
+
this.bearer = result?.token?.plainTextToken;
|
|
110
|
+
})
|
|
111
|
+
.catch((error) => console.error(error));
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
module.exports = Common;
|