bfg-common 1.1.2 → 1.1.3

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.
@@ -5,8 +5,7 @@ import {
5
5
  replaceFileContent,
6
6
  removeNonImageFiles,
7
7
  removeImagesFromContent,
8
- updateImagesPath,
9
- updateCustomComponents,
8
+ updateImagesPathAndCustomComponents,
10
9
  } from './utils/methods'
11
10
 
12
11
  // const npmDev = (): void => {
@@ -56,14 +55,11 @@ const npmGenerate = (): void => {
56
55
 
57
56
  // Удаляем картинки из папки content
58
57
  removeImagesFromContent(contentPath)
58
+
59
+ // Правим путь к картинкам и заменяем кастомные тэги
60
+ updateImagesPathAndCustomComponents(contentPath)
59
61
  })
60
62
  // End block
61
-
62
- // Правим путь к картинкам
63
- updateImagesPath(contentPath)
64
-
65
- // Заменяем кастомные тэги
66
- updateCustomComponents(contentPath)
67
63
  }
68
64
 
69
65
  export default defineNuxtModule({
@@ -49,16 +49,17 @@ export const removeImagesFromContent = (dirPath: string) => {
49
49
  })
50
50
  }
51
51
 
52
- export const updateImagesPath = (dirPath: string) => {
52
+ export const updateImagesPathAndCustomComponents = (dirPath: string) => {
53
53
  fs.readdirSync(dirPath).forEach((file: string) => {
54
54
  const filePath = path.join(dirPath, file)
55
55
  const isDir = fs.lstatSync(filePath).isDirectory()
56
56
 
57
57
  if (isDir) {
58
- updateImagesPath(filePath)
58
+ updateImagesPathAndCustomComponents(filePath)
59
59
  } else {
60
60
  if (isMdFile(file)) {
61
61
  // @ts-ignore
62
+ // Правим путь к картинкам
62
63
  const imagePath = filePath
63
64
  .replaceAll('\\', '/')
64
65
  .match(/\/content.+\//)[0]
@@ -67,51 +68,47 @@ export const updateImagesPath = (dirPath: string) => {
67
68
  filePath,
68
69
  /!\[(.*)\]\((.*?)\)/g,
69
70
  `![$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
- )
71
+ ).then(() => {
72
+ // Заменяем кастомные тэги
73
+ replaceFileContent(
74
+ filePath,
75
+ /\{\{ *< *hint *(info) *> *\}\}|\{\{ *< *\/hint *> *\}\}/g,
76
+ (_match: any, hintInfo: string) => {
77
+ return hintInfo ? '\n::hint\n' : '\n::\n'
78
+ }
79
+ )
80
+ })
92
81
  }
93
82
  }
94
83
  })
95
84
  }
96
85
 
97
- export const replaceFileContent = (
86
+ export const replaceFileContent = async (
98
87
  filePath: string,
99
88
  searchString: string | RegExp,
100
89
  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) => {
90
+ ): Promise<void> => {
91
+ return new Promise((resolve, reject) => {
92
+ fs.readFile(filePath, 'utf8', (err: any, data: string) => {
112
93
  if (err) {
94
+ reject()
113
95
  return console.log(err)
114
96
  }
97
+
98
+ if (data.match(replacementString)) {
99
+ resolve()
100
+ return
101
+ }
102
+
103
+ const updatedContent = data.replace(searchString, replacementString)
104
+
105
+ fs.writeFile(filePath, updatedContent, 'utf8', (err: any) => {
106
+ if (err) {
107
+ reject()
108
+ return console.log(err)
109
+ }
110
+ resolve()
111
+ })
115
112
  })
116
113
  })
117
114
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bfg-common",
3
3
  "private": false,
4
- "version": "1.1.2",
4
+ "version": "1.1.3",
5
5
  "scripts": {
6
6
  "build": "nuxt build",
7
7
  "dev": "nuxt dev --port=3002",