tsoft-cli 2.0.0 → 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/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 +45 -6
- package/.editorconfig +0 -11
- package/.github/workflows/node.js.yml +0 -25
- package/.nvmrc +0 -1
- package/.prettierrc.json +0 -8
- package/.vscode/extensions.json +0 -3
- package/.vscode/settings.json +0 -4
- package/CHANGELOG.md +0 -113
- package/packages/cli/README.md +0 -53
- package/packages/cli/bin/dev.js +0 -5
- package/packages/cli/bin/run.cmd +0 -3
- package/packages/cli/enums.ts +0 -4
- package/packages/cli/index.ts +0 -11
- package/packages/cli/package.json +0 -59
- package/packages/cli/tsconfig.json +0 -9
- package/packages/shared/index.ts +0 -6
- package/packages/shared/package.json +0 -45
- package/packages/shared/src/cli-progress.ts +0 -3
- package/packages/shared/src/commands/cli-all-commands.ts +0 -6
- package/packages/shared/src/commands/version-command.ts +0 -12
- package/packages/shared/src/consola.ts +0 -1
- package/packages/shared/src/open.ts +0 -3
- package/packages/shared/src/unzip.ts +0 -15
- package/packages/shared/tsconfig.json +0 -9
- package/packages/theme/bin/dev.js +0 -5
- package/packages/theme/bin/run.cmd +0 -3
- package/packages/theme/bin/run.js +0 -5
- package/packages/theme/index.ts +0 -21
- package/packages/theme/jest.config.ts +0 -3
- package/packages/theme/package.json +0 -66
- package/packages/theme/src/commands/theme/create.ts +0 -51
- package/packages/theme/src/commands/theme/delete-site.ts +0 -30
- package/packages/theme/src/commands/theme/delete-theme.ts +0 -39
- package/packages/theme/src/commands/theme/dev.ts +0 -47
- package/packages/theme/src/commands/theme/pull.ts +0 -26
- package/packages/theme/src/enums.ts +0 -55
- package/packages/theme/src/services/ClientCredentials.ts +0 -127
- package/packages/theme/src/services/Constants.ts +0 -19
- package/packages/theme/src/services/CreateTheme.ts +0 -88
- package/packages/theme/src/services/DeleteSite.ts +0 -30
- package/packages/theme/src/services/DeleteTheme.ts +0 -46
- package/packages/theme/src/services/FileManager.ts +0 -62
- package/packages/theme/src/services/Request.ts +0 -18
- package/packages/theme/src/services/StartTheme.ts +0 -363
- package/packages/theme/src/services/SyncTheme.ts +0 -108
- package/packages/theme/src/services/ThemeManager.ts +0 -118
- package/packages/theme/src/services/Tsoft.ts +0 -151
- package/packages/theme/src/services/types.ts +0 -90
- package/packages/theme/src/types.ts +0 -20
- package/packages/theme/src/utils/screen.ts +0 -28
- package/packages/theme/src/utils/utils.ts +0 -83
- package/packages/theme/tests/FileManager.test.js +0 -90
- package/packages/theme/tsconfig.json +0 -9
- package/pnpm-workspace.yaml +0 -2
- package/pull_request_template.md +0 -5
- package/scripts/prebuild.js +0 -45
- package/scripts/versions.js +0 -70
- package/tsconfig.build.json +0 -21
- /package/{packages/cli/bin → bin}/run.js +0 -0
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs'
|
|
2
|
-
import http from 'node:http'
|
|
3
|
-
import https from 'node:https'
|
|
4
|
-
import { consola } from '@tsoft-cli/shared'
|
|
5
|
-
import { getFolderFromCWD, slugify } from '../utils/utils.js'
|
|
6
|
-
import type { TClientCredentialsGetEnvironment, TThemeFile } from './types.js'
|
|
7
|
-
import type { TThemeEnviroments } from '../types.js'
|
|
8
|
-
import { themeFileNames } from '../enums.js'
|
|
9
|
-
|
|
10
|
-
export class ThemeManager {
|
|
11
|
-
public site: string
|
|
12
|
-
public theme: string
|
|
13
|
-
public registered: boolean
|
|
14
|
-
|
|
15
|
-
constructor(site: string) {
|
|
16
|
-
this.site = site
|
|
17
|
-
this.theme = null
|
|
18
|
-
this.registered = false
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
public async initializeTheme(theme: string, reInit = false) {
|
|
22
|
-
this.theme = theme
|
|
23
|
-
const themePath = getFolderFromCWD(this.site, theme)
|
|
24
|
-
const themeEnvPath = getFolderFromCWD(this.site, theme, `${theme}${themeFileNames.env}`)
|
|
25
|
-
|
|
26
|
-
if (reInit) {
|
|
27
|
-
// await fs.rm(themePath, {recursive: true, force: true}, (err, file) => {});
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (!fs.existsSync(getFolderFromCWD(this.site))) {
|
|
31
|
-
fs.mkdirSync(getFolderFromCWD(this.site))
|
|
32
|
-
}
|
|
33
|
-
if (!fs.existsSync(themePath)) {
|
|
34
|
-
fs.mkdirSync(themePath)
|
|
35
|
-
}
|
|
36
|
-
if (reInit || !fs.existsSync(themeEnvPath)) {
|
|
37
|
-
fs.writeFileSync(themeEnvPath, '')
|
|
38
|
-
this.registered = false
|
|
39
|
-
} else {
|
|
40
|
-
const data = fs.readFileSync(themeEnvPath)
|
|
41
|
-
try {
|
|
42
|
-
const environment = JSON.parse(data.toString()) as TThemeEnviroments
|
|
43
|
-
this.registered = Boolean(environment.bearer)
|
|
44
|
-
} catch (e) {
|
|
45
|
-
this.registered = false
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
try {
|
|
50
|
-
const isValid = await this.checkSiteValidity()
|
|
51
|
-
if (!isValid) {
|
|
52
|
-
consola.error('Geçersiz site: Siteye ulaşılamıyor.')
|
|
53
|
-
return false
|
|
54
|
-
}
|
|
55
|
-
} catch (error) {
|
|
56
|
-
consola.error('Geçersiz site: Siteye ulaşılamıyor.', error.message)
|
|
57
|
-
return false
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return true
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
public setTheme(theme: string) {
|
|
64
|
-
this.theme = slugify(theme)
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
public isRegistered() {
|
|
68
|
-
return this.registered
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
public buildEnvironment(environment: TClientCredentialsGetEnvironment) {
|
|
72
|
-
const envPath = getFolderFromCWD(this.site, this.theme, `${this.theme}${themeFileNames.env}`)
|
|
73
|
-
fs.writeFileSync(envPath, JSON.stringify(environment))
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
public getEnvironment(theme: string): TThemeEnviroments {
|
|
77
|
-
const themeEnvPath = getFolderFromCWD(this.site, slugify(theme), `${slugify(theme)}${themeFileNames.env}`)
|
|
78
|
-
return JSON.parse(fs.readFileSync(themeEnvPath).toString())
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
public getThemeInfo(directoryName: string): TThemeFile {
|
|
82
|
-
const themePath = getFolderFromCWD(this.site, slugify(directoryName), themeFileNames.themeTxt)
|
|
83
|
-
|
|
84
|
-
if (fs.existsSync(themePath)) {
|
|
85
|
-
const themeInfo = fs.readFileSync(themePath, 'utf-8')
|
|
86
|
-
try {
|
|
87
|
-
return JSON.parse(themeInfo)
|
|
88
|
-
} catch (error) {
|
|
89
|
-
consola.error(`${themeFileNames.themeTxt} dosyasını ayrıştırma hatası:`, error)
|
|
90
|
-
return null
|
|
91
|
-
}
|
|
92
|
-
} else {
|
|
93
|
-
consola.error(`${themeFileNames.themeTxt} dosyası bulunamadı:`, themePath)
|
|
94
|
-
return null
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
public checkSiteValidity(): Promise<boolean> {
|
|
99
|
-
return new Promise((resolve, reject) => {
|
|
100
|
-
const url = new URL(`https://${this.site}/Y/R`)
|
|
101
|
-
const request = url.protocol == 'https:' ? https : http
|
|
102
|
-
|
|
103
|
-
const req = request.get(url, (res) => {
|
|
104
|
-
if (res.statusCode === 200) {
|
|
105
|
-
return resolve(true)
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
return resolve(false)
|
|
109
|
-
})
|
|
110
|
-
|
|
111
|
-
req.on('error', (err) => {
|
|
112
|
-
return reject(err)
|
|
113
|
-
})
|
|
114
|
-
|
|
115
|
-
req.end()
|
|
116
|
-
})
|
|
117
|
-
}
|
|
118
|
-
}
|
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
import path from 'node:path'
|
|
2
|
-
import { consola } from '@tsoft-cli/shared'
|
|
3
|
-
import { ClientCredentials } from './ClientCredentials.js'
|
|
4
|
-
import { Constants } from './Constants.js'
|
|
5
|
-
import { FileManager } from './FileManager.js'
|
|
6
|
-
import { ThemeManager } from './ThemeManager.js'
|
|
7
|
-
import { Request } from './Request.js'
|
|
8
|
-
import type { TUpdateThemeResponse } from '../types.js'
|
|
9
|
-
import type { TClientCredentialsRecoveryData } from './types.js'
|
|
10
|
-
import { themeFileNames } from '../enums.js'
|
|
11
|
-
|
|
12
|
-
export class Tsoft {
|
|
13
|
-
public site: string
|
|
14
|
-
public themeManager: ThemeManager
|
|
15
|
-
public fileManager: FileManager
|
|
16
|
-
public clientCredentials: ClientCredentials
|
|
17
|
-
private TSOFT_CLI_UUID = '7583a318-8542-4ec8-980c-48ea67031be3'
|
|
18
|
-
private ONLINESTORE_SAVE_URI = 'api/v3/admin/online-store-2/theme/file-manager?q=save'
|
|
19
|
-
private ONLINESTORE_DELETE_URI = 'api/v3/admin/online-store-2/theme/file-manager?q=delete'
|
|
20
|
-
private UPDATE_THEME_URI = 'api/v3/admin/online-store-2/theme/update-theme'
|
|
21
|
-
|
|
22
|
-
constructor(site: string) {
|
|
23
|
-
this.site = site
|
|
24
|
-
this.themeManager = new ThemeManager(site)
|
|
25
|
-
this.fileManager = new FileManager(site)
|
|
26
|
-
this.clientCredentials = new ClientCredentials(site)
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
async initialize(theme: string, reInit: boolean = false) {
|
|
30
|
-
await this.themeManager.initializeTheme(theme, reInit)
|
|
31
|
-
if (!this.themeManager.isRegistered()) {
|
|
32
|
-
return this.register(this.TSOFT_CLI_UUID, this.themeManager.getThemeInfo(theme))
|
|
33
|
-
} else {
|
|
34
|
-
consola.warn('You are already registered')
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
buildEnvironment() {
|
|
39
|
-
this.themeManager.buildEnvironment(this.clientCredentials.getEnvironment())
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
async authorize() {
|
|
43
|
-
await this.clientCredentials.authorize()
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
async register(CLIENT_UUID: string, clientConfiguration = {}) {
|
|
47
|
-
const response = await this.clientCredentials.register(CLIENT_UUID, clientConfiguration)
|
|
48
|
-
return response === true ? Constants.APPROVAL : null
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
async saveOnlineStore(theme: string) {
|
|
52
|
-
const fileList = this.fileManager.listFilesRecursive(path.join(process.cwd(), this.site, theme))
|
|
53
|
-
|
|
54
|
-
await Promise.all(
|
|
55
|
-
fileList
|
|
56
|
-
.filter((file) => !file.includes(themeFileNames.env))
|
|
57
|
-
.map(async (file) => {
|
|
58
|
-
const fileName = this.fileManager.getRelativePath(theme, file)
|
|
59
|
-
const content = this.fileManager.readFile(file)
|
|
60
|
-
const env = this.themeManager.getEnvironment(theme)
|
|
61
|
-
|
|
62
|
-
await Request.request(this.site, this.ONLINESTORE_SAVE_URI, {
|
|
63
|
-
method: 'POST',
|
|
64
|
-
headers: {
|
|
65
|
-
Authorization: `Bearer ${env.bearer}`,
|
|
66
|
-
Accept: 'application/json',
|
|
67
|
-
'Content-Type': 'application/json',
|
|
68
|
-
},
|
|
69
|
-
data: {
|
|
70
|
-
theme: theme,
|
|
71
|
-
path: fileName,
|
|
72
|
-
content: content,
|
|
73
|
-
},
|
|
74
|
-
})
|
|
75
|
-
}),
|
|
76
|
-
)
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
async saveFile(theme: string, fileName: string, content: string, bearerToken: string) {
|
|
80
|
-
return Request.request(this.site, this.ONLINESTORE_SAVE_URI, {
|
|
81
|
-
method: 'POST',
|
|
82
|
-
headers: {
|
|
83
|
-
Authorization: `Bearer ${bearerToken}`,
|
|
84
|
-
Accept: 'application/json',
|
|
85
|
-
'Content-Type': 'application/json',
|
|
86
|
-
},
|
|
87
|
-
data: {
|
|
88
|
-
theme: theme,
|
|
89
|
-
path: fileName,
|
|
90
|
-
content: content,
|
|
91
|
-
},
|
|
92
|
-
})
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
async deleteFile(theme: string, fileName: string, bearerToken: string) {
|
|
96
|
-
return Request.request(this.site, this.ONLINESTORE_DELETE_URI, {
|
|
97
|
-
method: 'POST',
|
|
98
|
-
headers: {
|
|
99
|
-
Authorization: `Bearer ${bearerToken}`,
|
|
100
|
-
Accept: 'application/json',
|
|
101
|
-
'Content-Type': 'application/json',
|
|
102
|
-
},
|
|
103
|
-
data: {
|
|
104
|
-
theme: theme,
|
|
105
|
-
items: [{ type: 'file', path: fileName }],
|
|
106
|
-
},
|
|
107
|
-
})
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
async deleteDirectory(theme: string, folderName: string, bearerToken: string) {
|
|
111
|
-
return Request.request(this.site, this.ONLINESTORE_DELETE_URI, {
|
|
112
|
-
method: 'POST',
|
|
113
|
-
headers: {
|
|
114
|
-
Authorization: `Bearer ${bearerToken}`,
|
|
115
|
-
Accept: 'application/json',
|
|
116
|
-
'Content-Type': 'application/json',
|
|
117
|
-
},
|
|
118
|
-
data: {
|
|
119
|
-
theme: theme,
|
|
120
|
-
items: [{ type: 'dir', path: folderName }],
|
|
121
|
-
},
|
|
122
|
-
})
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
async isTokenValid(theme: string) {
|
|
126
|
-
const env = this.themeManager.getEnvironment(theme)
|
|
127
|
-
return this.clientCredentials.validateToken(env.bearer)
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
async updateTheme(directoryName: string) {
|
|
131
|
-
const env = this.themeManager.getEnvironment(directoryName)
|
|
132
|
-
const themeInfo = this.themeManager.getThemeInfo(directoryName) // .theme bilgisi alınıyor
|
|
133
|
-
|
|
134
|
-
return Request.request<TUpdateThemeResponse>(this.site, this.UPDATE_THEME_URI, {
|
|
135
|
-
method: 'POST',
|
|
136
|
-
headers: {
|
|
137
|
-
Authorization: `Bearer ${env.bearer}`,
|
|
138
|
-
Accept: 'application/json',
|
|
139
|
-
'Content-Type': 'application/json',
|
|
140
|
-
},
|
|
141
|
-
data: {
|
|
142
|
-
theme: directoryName,
|
|
143
|
-
themeInfo: themeInfo,
|
|
144
|
-
},
|
|
145
|
-
})
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
async startRecovery(token: string): Promise<TClientCredentialsRecoveryData> {
|
|
149
|
-
return this.clientCredentials.recovery(token)
|
|
150
|
-
}
|
|
151
|
-
}
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
export type TClientCredentialsGetEnvironment = {
|
|
2
|
-
site: string
|
|
3
|
-
clientId: string
|
|
4
|
-
clientSecret: string
|
|
5
|
-
bearer: string
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export type TThemeFile = {
|
|
9
|
-
site: string
|
|
10
|
-
name: string
|
|
11
|
-
author: string
|
|
12
|
-
version: string
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export type TAuthorizeResponse = {
|
|
16
|
-
status: boolean
|
|
17
|
-
message: string
|
|
18
|
-
data: {
|
|
19
|
-
token: {
|
|
20
|
-
accessToken: {
|
|
21
|
-
name: string
|
|
22
|
-
abilities: string[]
|
|
23
|
-
expires_at: null
|
|
24
|
-
tokenable_id: number
|
|
25
|
-
tokenable_type: string
|
|
26
|
-
ip_address: string
|
|
27
|
-
updated_at: string
|
|
28
|
-
created_at: string
|
|
29
|
-
id: number
|
|
30
|
-
}
|
|
31
|
-
plainTextToken: string
|
|
32
|
-
}
|
|
33
|
-
tokenable?: {
|
|
34
|
-
name: string
|
|
35
|
-
author: string
|
|
36
|
-
version: string
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
attributes: {
|
|
40
|
-
'system.status': {
|
|
41
|
-
event: string
|
|
42
|
-
message: string
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export type TAuthMeResponse = {
|
|
48
|
-
status: boolean
|
|
49
|
-
message: string
|
|
50
|
-
data: {
|
|
51
|
-
id: number
|
|
52
|
-
name: string
|
|
53
|
-
is_active: number
|
|
54
|
-
}
|
|
55
|
-
attributes: {
|
|
56
|
-
'system.status': {
|
|
57
|
-
event: string
|
|
58
|
-
message: string
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export type TAuthApplication = {
|
|
64
|
-
status: boolean
|
|
65
|
-
message: string
|
|
66
|
-
data: {
|
|
67
|
-
public_key: string
|
|
68
|
-
}
|
|
69
|
-
attributes: {
|
|
70
|
-
'system.status': {
|
|
71
|
-
event: string
|
|
72
|
-
message: string
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export type TClientCredentialsRecoveryResponse = {
|
|
78
|
-
status: boolean
|
|
79
|
-
data: {
|
|
80
|
-
secret: string
|
|
81
|
-
public_key: string
|
|
82
|
-
}
|
|
83
|
-
throttle?: {
|
|
84
|
-
limit: string
|
|
85
|
-
retryAfter: string
|
|
86
|
-
resetDate: string
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export type TClientCredentialsRecoveryData = Pick<TClientCredentialsRecoveryResponse['data'], 'public_key' | 'secret'>
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { allowedExtensions, menuSelections, themeTypes } from './enums.js'
|
|
2
|
-
|
|
3
|
-
export type ValueOf<T> = T[keyof T]
|
|
4
|
-
|
|
5
|
-
export type TMainMenuSelections = ValueOf<typeof menuSelections>
|
|
6
|
-
|
|
7
|
-
export type TUpdateThemeResponse = {
|
|
8
|
-
status: boolean
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export type TThemeEnviroments = {
|
|
12
|
-
site: string
|
|
13
|
-
clientId: string
|
|
14
|
-
clientSecret: string
|
|
15
|
-
bearer: string
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export type TThemeTypes = ValueOf<typeof themeTypes>
|
|
19
|
-
|
|
20
|
-
export type TAllowedExtensions = (typeof allowedExtensions)[number]
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import figlet from 'figlet'
|
|
2
|
-
import { consola } from '@tsoft-cli/shared'
|
|
3
|
-
import { packageJson } from '../enums.js'
|
|
4
|
-
|
|
5
|
-
export async function displayAsciiArt(): Promise<void> {
|
|
6
|
-
return new Promise<void>((resolve, reject) => {
|
|
7
|
-
figlet(
|
|
8
|
-
'T-SOFT CLI',
|
|
9
|
-
{
|
|
10
|
-
font: 'Standard',
|
|
11
|
-
},
|
|
12
|
-
(err, data) => {
|
|
13
|
-
if (err) {
|
|
14
|
-
consola.error(err)
|
|
15
|
-
return reject(err)
|
|
16
|
-
}
|
|
17
|
-
consola.log(data)
|
|
18
|
-
return resolve()
|
|
19
|
-
},
|
|
20
|
-
)
|
|
21
|
-
}).then(() => {
|
|
22
|
-
consola.info('Versiyon: ' + packageJson.version)
|
|
23
|
-
})
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export function clearScreen(): void {
|
|
27
|
-
process.stdout.write('\x1B[2J\x1B[0f')
|
|
28
|
-
}
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs'
|
|
2
|
-
import path from 'node:path'
|
|
3
|
-
import { themeFileNames } from '../enums.js'
|
|
4
|
-
import type { TThemeFile } from '../services/types.js'
|
|
5
|
-
|
|
6
|
-
export function getNonThemeFolders(): string[] {
|
|
7
|
-
return ['node_modules', 'build', 'dist']
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export function checkThemeSiteFolder(value: string): boolean {
|
|
11
|
-
return new RegExp(/\b\w+\.com(\.tr)?\b/g).test(value)
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export function getLocalSites(opt: { cwd?: string } = {}): string[] {
|
|
15
|
-
const cwd = opt.cwd ?? process.cwd()
|
|
16
|
-
|
|
17
|
-
return fs
|
|
18
|
-
.readdirSync(cwd)
|
|
19
|
-
.filter((file) => {
|
|
20
|
-
const filePath = path.join(cwd, file)
|
|
21
|
-
|
|
22
|
-
return (
|
|
23
|
-
checkThemeSiteFolder(file) &&
|
|
24
|
-
fs.statSync(filePath).isDirectory() &&
|
|
25
|
-
fs.existsSync(path.join(filePath, themeFileNames.tsoft))
|
|
26
|
-
)
|
|
27
|
-
})
|
|
28
|
-
.filter((file) => fs.statSync(path.join(cwd, file)).isDirectory())
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function slugify(text: string): string {
|
|
32
|
-
return text
|
|
33
|
-
.toString()
|
|
34
|
-
.toLowerCase()
|
|
35
|
-
.replace(/\s+/g, '-')
|
|
36
|
-
.replace(/[^\w\-]+/g, '')
|
|
37
|
-
.replace(/\-\-+/g, '-')
|
|
38
|
-
.replace(/^-+/, '')
|
|
39
|
-
.replace(/-+$/, '')
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export function getPlatform(): NodeJS.Platform {
|
|
43
|
-
return process.platform
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export function getFolderFromCWD(...paths: string[]): string {
|
|
47
|
-
return path.join(process.cwd(), ...paths)
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export function getDirectories(source: string): string[] {
|
|
51
|
-
return fs
|
|
52
|
-
.readdirSync(source)
|
|
53
|
-
.filter((file) => checkThemeSiteFolder(file))
|
|
54
|
-
.filter((file) => fs.statSync(path.join(source, file)).isDirectory())
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export function getThemesFromFolder(source: string): string[] {
|
|
58
|
-
return fs
|
|
59
|
-
.readdirSync(source)
|
|
60
|
-
.filter((file) => file.charAt(0) !== '.' && !getNonThemeFolders().includes(file))
|
|
61
|
-
.filter((file) => fs.statSync(path.join(source, file)).isDirectory())
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export function getOpenFilePlatformCode() {
|
|
65
|
-
return getPlatform() == 'win32' ? 'start' : getPlatform() == 'darwin' ? 'open' : 'xdg-open'
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* İşlemlerin düzgün çalışması için ters slash(\) yerine düz slash yapmamız lazım gerekiyor.
|
|
70
|
-
* @param {string} path
|
|
71
|
-
* @returns {string}
|
|
72
|
-
*/
|
|
73
|
-
export function setPathForWebhookOperations(path: string): string {
|
|
74
|
-
return path.replace(/\\/g, '/')
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export function saveThemeData(themePath: string, themeData: TThemeFile): void {
|
|
78
|
-
fs.writeFileSync(path.join(themePath, themeFileNames.theme), JSON.stringify(themeData, null, 2))
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export function saveThemeTxt(themePath: string, themeData: TThemeFile): void {
|
|
82
|
-
fs.writeFileSync(path.join(themePath, themeFileNames.themeTxt), JSON.stringify(themeData, null, 2))
|
|
83
|
-
}
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
const path = require('node: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
|
-
})
|
package/pnpm-workspace.yaml
DELETED
package/pull_request_template.md
DELETED
package/scripts/prebuild.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Her build alma işleminden önce paketlerin içindeki build klasörlerini siler.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import fs from 'node:fs'
|
|
6
|
-
import path from 'node:path'
|
|
7
|
-
|
|
8
|
-
const cwd = process.cwd()
|
|
9
|
-
const packages = 'packages'
|
|
10
|
-
const build = 'build'
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Packages içindeki klasör isimlerini alır.
|
|
14
|
-
* @param {string} source
|
|
15
|
-
* @returns {string[]} cli, shared, ...
|
|
16
|
-
*/
|
|
17
|
-
function getPackagesFolder(source) {
|
|
18
|
-
return fs.readdirSync(source).filter((file) => fs.statSync(path.join(source, file)).isDirectory())
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Packages klasörü içindeki paketlerin build dosyalarını siler.
|
|
23
|
-
* @param {string} pkgName
|
|
24
|
-
*/
|
|
25
|
-
function removeBuildFiles(pkgName) {
|
|
26
|
-
return new Promise((resolve, reject) => {
|
|
27
|
-
fs.rm(path.join(cwd, packages, pkgName, build), { recursive: true, force: true }, (err) => {
|
|
28
|
-
if (err) {
|
|
29
|
-
return reject(err)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return resolve()
|
|
33
|
-
})
|
|
34
|
-
})
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function start() {
|
|
38
|
-
const packagesFolderNames = getPackagesFolder(path.join(cwd, packages))
|
|
39
|
-
|
|
40
|
-
for (const pkgName of packagesFolderNames) {
|
|
41
|
-
removeBuildFiles(pkgName)
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
start()
|