bfg-common 1.1.0 → 1.1.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.
@@ -9,15 +9,15 @@ import {
9
9
  updateCustomComponents,
10
10
  } from './utils/methods'
11
11
 
12
- const npmDev = (): void => {
13
- const contentPath = path.join(
14
- __dirname.replace('/node_modules/bfg-common/modules/fixContentBuild', ''),
15
- 'content',
16
- 'help'
17
- )
18
- // Заменяем кастомные тэги
19
- updateCustomComponents(contentPath)
20
- }
12
+ // const npmDev = (): void => {
13
+ // const contentPath = path.join(
14
+ // __dirname.replace('/node_modules/bfg-common/modules/fixContentBuild', ''),
15
+ // 'content',
16
+ // 'help'
17
+ // )
18
+ // // Заменяем кастомные тэги
19
+ // updateCustomComponents(contentPath)
20
+ // }
21
21
 
22
22
  const npmGenerate = (): void => {
23
23
  // Правим путь к файлу
@@ -74,7 +74,7 @@ export default defineNuxtModule({
74
74
  setup() {
75
75
  switch (process.env.npm_command) {
76
76
  case 'run-script':
77
- npmDev()
77
+ // npmDev()
78
78
  break
79
79
  case 'exec':
80
80
  npmGenerate()
@@ -1,118 +1,117 @@
1
- import path from 'path'
2
- import fs from 'fs'
3
-
4
- const isImage = (fileName: string) => {
5
- const imageExtensions = ['.png', '.jpeg', '.jpg']
6
- return imageExtensions.some(
7
- (ext) => path.extname(fileName).toLowerCase() === ext
8
- )
9
- }
10
- const isMdFile = (fileName: string) => {
11
- return path.extname(fileName).toLowerCase() === '.md'
12
- }
13
-
14
- export const removeNonImageFiles = (dirPath: string) => {
15
- fs.readdirSync(dirPath).forEach((file: string) => {
16
- const filePath = path.join(dirPath, file)
17
- const isDir = fs.lstatSync(filePath).isDirectory()
18
-
19
- if (isDir) {
20
- removeNonImageFiles(filePath)
21
- } else {
22
- if (!isImage(file)) {
23
- fs.unlinkSync(filePath)
24
- }
25
- }
26
- })
27
- }
28
-
29
- export const removeImagesFromContent = (dirPath: string) => {
30
- fs.readdirSync(dirPath).forEach((file: string) => {
31
- const filePath = path.join(dirPath, file)
32
- const isDir = fs.lstatSync(filePath).isDirectory()
33
-
34
- if (isDir) {
35
- removeImagesFromContent(filePath)
36
- } else {
37
- if (isImage(file)) {
38
- fs.unlinkSync(filePath)
39
- } else if (isMdFile(file) && filePath.includes('_index.md')) {
40
- // Удаляем префикс "_" у индексных файлов
41
- const filePathWidthOutPrefix = filePath.replace('_index.md', 'index.md')
42
- fs.rename(filePath, filePathWidthOutPrefix, (err: any) => {
43
- if (err) {
44
- console.error(`Error renaming file: ${err}`)
45
- }
46
- })
47
- }
48
- }
49
- })
50
- }
51
-
52
- export const updateImagesPath = (dirPath: string) => {
53
- fs.readdirSync(dirPath).forEach((file: string) => {
54
- const filePath = path.join(dirPath, file)
55
- const isDir = fs.lstatSync(filePath).isDirectory()
56
-
57
- if (isDir) {
58
- updateImagesPath(filePath)
59
- } else {
60
- if (isMdFile(file)) {
61
- // @ts-ignore
62
- const imagePath = filePath
63
- .replaceAll('\\', '/')
64
- .match(/\/content.+\//)[0]
65
- .replace('/content/help', '/help/images')
66
- replaceFileContent(
67
- filePath,
68
- /!\[(.*)\]\((.*?)\)/g,
69
- `![$1](${imagePath}$2)`
70
- )
71
- }
72
- }
73
- })
74
- }
75
-
76
- export const updateCustomComponents = (dirPath: string) => {
77
- fs.readdirSync(dirPath).forEach((file: string) => {
78
- const filePath = path.join(dirPath, file)
79
- const isDir = fs.lstatSync(filePath).isDirectory()
80
-
81
- if (isDir) {
82
- updateCustomComponents(filePath)
83
- } else {
84
- if (isMdFile(file)) {
85
- replaceFileContent(
86
- filePath,
87
- /{{ *< *hint *(info) *> *}}|{{ *< *\/hint *> *}}/g,
88
- (_match: any, hintInfo: string) => {
89
- return hintInfo ? '\n::hint\n' : '\n::\n'
90
- }
91
- )
92
- }
93
- }
94
- })
95
- }
96
-
97
- export const replaceFileContent = (
98
- filePath: string,
99
- searchString: string | RegExp,
100
- replacementString: any
101
- ) => {
102
- fs.readFile(filePath, 'utf8', (err: any, data: string) => {
103
- if (err) {
104
- return console.log(err)
105
- }
106
-
107
- if (typeof replacementString === 'string' && data.match(replacementString))
108
- return
109
-
110
- const updatedContent = data.replace(searchString, replacementString)
111
-
112
- fs.writeFile(filePath, updatedContent, 'utf8', (err: any) => {
113
- if (err) {
114
- return console.log(err)
115
- }
116
- })
117
- })
118
- }
1
+ import path from 'path'
2
+ import fs from 'fs'
3
+
4
+ const isImage = (fileName: string) => {
5
+ const imageExtensions = ['.png', '.jpeg', '.jpg']
6
+ return imageExtensions.some(
7
+ (ext) => path.extname(fileName).toLowerCase() === ext
8
+ )
9
+ }
10
+ const isMdFile = (fileName: string) => {
11
+ return path.extname(fileName).toLowerCase() === '.md'
12
+ }
13
+
14
+ export const removeNonImageFiles = (dirPath: string) => {
15
+ fs.readdirSync(dirPath).forEach((file: string) => {
16
+ const filePath = path.join(dirPath, file)
17
+ const isDir = fs.lstatSync(filePath).isDirectory()
18
+
19
+ if (isDir) {
20
+ removeNonImageFiles(filePath)
21
+ } else {
22
+ if (!isImage(file)) {
23
+ fs.unlinkSync(filePath)
24
+ }
25
+ }
26
+ })
27
+ }
28
+
29
+ export const removeImagesFromContent = (dirPath: string) => {
30
+ fs.readdirSync(dirPath).forEach((file: string) => {
31
+ const filePath = path.join(dirPath, file)
32
+ const isDir = fs.lstatSync(filePath).isDirectory()
33
+
34
+ if (isDir) {
35
+ removeImagesFromContent(filePath)
36
+ } else {
37
+ if (isImage(file)) {
38
+ fs.unlinkSync(filePath)
39
+ } else if (isMdFile(file) && filePath.includes('_index.md')) {
40
+ // Удаляем префикс "_" у индексных файлов
41
+ const filePathWidthOutPrefix = filePath.replace('_index.md', 'index.md')
42
+ fs.rename(filePath, filePathWidthOutPrefix, (err: any) => {
43
+ if (err) {
44
+ console.error(`Error renaming file: ${err}`)
45
+ }
46
+ })
47
+ }
48
+ }
49
+ })
50
+ }
51
+
52
+ export const updateImagesPath = (dirPath: string) => {
53
+ fs.readdirSync(dirPath).forEach((file: string) => {
54
+ const filePath = path.join(dirPath, file)
55
+ const isDir = fs.lstatSync(filePath).isDirectory()
56
+
57
+ if (isDir) {
58
+ updateImagesPath(filePath)
59
+ } else {
60
+ if (isMdFile(file)) {
61
+ // @ts-ignore
62
+ const imagePath = filePath
63
+ .replaceAll('\\', '/')
64
+ .match(/\/content.+\//)[0]
65
+ .replace('/content/help', '/help/images')
66
+ replaceFileContent(
67
+ filePath,
68
+ /!\[(.*)\]\((.*?)\)/g,
69
+ `![$1](${imagePath}$2)`
70
+ )
71
+ }
72
+ }
73
+ })
74
+ }
75
+
76
+ export const updateCustomComponents = (dirPath: string) => {
77
+ fs.readdirSync(dirPath).forEach((file: string) => {
78
+ const filePath = path.join(dirPath, file)
79
+ const isDir = fs.lstatSync(filePath).isDirectory()
80
+
81
+ if (isDir) {
82
+ updateCustomComponents(filePath)
83
+ } else {
84
+ if (isMdFile(file)) {
85
+ replaceFileContent(
86
+ filePath,
87
+ /\{\{ *< *hint *(info) *> *\}\}|\{\{ *< *\/hint *> *\}\}/g,
88
+ (_match: any, hintInfo: string) => {
89
+ return hintInfo ? '\n::hint\n' : '\n::\n'
90
+ }
91
+ )
92
+ }
93
+ }
94
+ })
95
+ }
96
+
97
+ export const replaceFileContent = (
98
+ filePath: string,
99
+ searchString: string | RegExp,
100
+ replacementString: any
101
+ ) => {
102
+ fs.readFile(filePath, 'utf8', (err: any, data: string) => {
103
+ if (err) {
104
+ return console.log(err)
105
+ }
106
+
107
+ if (data.match(replacementString)) return
108
+
109
+ const updatedContent = data.replace(searchString, replacementString)
110
+
111
+ fs.writeFile(filePath, updatedContent, 'utf8', (err: any) => {
112
+ if (err) {
113
+ return console.log(err)
114
+ }
115
+ })
116
+ })
117
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bfg-common",
3
3
  "private": false,
4
- "version": "1.1.0",
4
+ "version": "1.1.2",
5
5
  "scripts": {
6
6
  "build": "nuxt build",
7
7
  "dev": "nuxt dev --port=3002",