bfg-common 1.0.93 → 1.0.95
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/modules/fixContentBuild/index.ts +65 -118
- package/package.json +1 -1
- package/utils/contentBuild.ts +34 -0
|
@@ -1,118 +1,65 @@
|
|
|
1
|
-
import { defineNuxtModule } from '@nuxt/kit'
|
|
2
|
-
const fs = require('fs')
|
|
3
|
-
const path = require('path')
|
|
4
|
-
import {
|
|
5
|
-
replaceFileContent,
|
|
6
|
-
removeNonImageFiles,
|
|
7
|
-
removeImagesFromContent,
|
|
8
|
-
updateImagesPath,
|
|
9
|
-
} from './utils/methods'
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
//
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
//
|
|
38
|
-
|
|
39
|
-
//
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
//
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
//
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
//
|
|
61
|
-
|
|
62
|
-
//
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
// })
|
|
67
|
-
// @ts-ignore
|
|
68
|
-
export default defineNuxtModule(() => {
|
|
69
|
-
console.log(process.env.npm_command, 111);
|
|
70
|
-
if (
|
|
71
|
-
process.env.NODE_ENV === 'development' ||
|
|
72
|
-
process.env.npm_command !== 'exec'
|
|
73
|
-
)
|
|
74
|
-
return
|
|
75
|
-
|
|
76
|
-
// Правим путь к файлу
|
|
77
|
-
const filePath = path.join(
|
|
78
|
-
__dirname.replace('/modules/fixContentBuild', ''),
|
|
79
|
-
'node_modules',
|
|
80
|
-
'@nuxt',
|
|
81
|
-
'content',
|
|
82
|
-
'dist',
|
|
83
|
-
'runtime',
|
|
84
|
-
'legacy',
|
|
85
|
-
'composables',
|
|
86
|
-
'query.mjs'
|
|
87
|
-
)
|
|
88
|
-
const searchString = '/query/${hash(params)}'
|
|
89
|
-
const replacementString = 'cache'
|
|
90
|
-
replaceFileContent(filePath, searchString, replacementString)
|
|
91
|
-
// End block
|
|
92
|
-
|
|
93
|
-
// Переносим весь контент и удаляем все файлы кроме картинок
|
|
94
|
-
const contentPath = path.join(
|
|
95
|
-
__dirname.replace('/modules/fixContentBuild', ''),
|
|
96
|
-
'content',
|
|
97
|
-
'help'
|
|
98
|
-
)
|
|
99
|
-
if (!fs.existsSync(contentPath)) return;
|
|
100
|
-
|
|
101
|
-
const publicPath = path.join(
|
|
102
|
-
__dirname.replace('/modules/fixContentBuild', ''),
|
|
103
|
-
'public',
|
|
104
|
-
'help',
|
|
105
|
-
'images'
|
|
106
|
-
)
|
|
107
|
-
fs.cp(contentPath, publicPath, { recursive: true }, () => {
|
|
108
|
-
// Удаляем все файлы кроме картинок
|
|
109
|
-
removeNonImageFiles(publicPath)
|
|
110
|
-
|
|
111
|
-
// Удаляем картинки из папки content
|
|
112
|
-
removeImagesFromContent(contentPath)
|
|
113
|
-
})
|
|
114
|
-
// End block
|
|
115
|
-
|
|
116
|
-
// Правим путь к картинкам
|
|
117
|
-
updateImagesPath(contentPath)
|
|
118
|
-
})
|
|
1
|
+
import { defineNuxtModule } from '@nuxt/kit'
|
|
2
|
+
const fs = require('fs')
|
|
3
|
+
const path = require('path')
|
|
4
|
+
import {
|
|
5
|
+
replaceFileContent,
|
|
6
|
+
removeNonImageFiles,
|
|
7
|
+
removeImagesFromContent,
|
|
8
|
+
updateImagesPath,
|
|
9
|
+
} from './utils/methods'
|
|
10
|
+
|
|
11
|
+
export default defineNuxtModule({
|
|
12
|
+
meta: {
|
|
13
|
+
name: 'fix-content-build',
|
|
14
|
+
configKey: 'fixContentBuild',
|
|
15
|
+
},
|
|
16
|
+
setup() {
|
|
17
|
+
if (
|
|
18
|
+
process.env.NODE_ENV === 'development' ||
|
|
19
|
+
process.env.npm_command !== 'exec'
|
|
20
|
+
)
|
|
21
|
+
return
|
|
22
|
+
|
|
23
|
+
// Правим путь к файлу
|
|
24
|
+
const filePath = path.join(
|
|
25
|
+
__dirname.replace('/bfg-common/modules/fixContentBuild', ''),
|
|
26
|
+
'@nuxt',
|
|
27
|
+
'content',
|
|
28
|
+
'dist',
|
|
29
|
+
'runtime',
|
|
30
|
+
'legacy',
|
|
31
|
+
'composables',
|
|
32
|
+
'query.mjs'
|
|
33
|
+
)
|
|
34
|
+
const searchString = '/query/${hash(params)}'
|
|
35
|
+
const replacementString = 'cache'
|
|
36
|
+
replaceFileContent(filePath, searchString, replacementString)
|
|
37
|
+
// End block
|
|
38
|
+
|
|
39
|
+
// Переносим весь контент и удаляем все файлы кроме картинок
|
|
40
|
+
const contentPath = path.join(
|
|
41
|
+
__dirname.replace('/node_modules/bfg-common/modules/fixContentBuild', ''),
|
|
42
|
+
'content',
|
|
43
|
+
'help'
|
|
44
|
+
)
|
|
45
|
+
if (!fs.existsSync(contentPath)) return
|
|
46
|
+
|
|
47
|
+
const publicPath = path.join(
|
|
48
|
+
__dirname.replace('/node_modules/bfg-common/modules/fixContentBuild', ''),
|
|
49
|
+
'public',
|
|
50
|
+
'help',
|
|
51
|
+
'images'
|
|
52
|
+
)
|
|
53
|
+
fs.cp(contentPath, publicPath, { recursive: true }, () => {
|
|
54
|
+
// Удаляем все файлы кроме картинок
|
|
55
|
+
removeNonImageFiles(publicPath)
|
|
56
|
+
|
|
57
|
+
// Удаляем картинки из папки content
|
|
58
|
+
removeImagesFromContent(contentPath)
|
|
59
|
+
})
|
|
60
|
+
// End block
|
|
61
|
+
|
|
62
|
+
// Правим путь к картинкам
|
|
63
|
+
updateImagesPath(contentPath)
|
|
64
|
+
},
|
|
65
|
+
})
|
package/package.json
CHANGED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const fs = require('fs')
|
|
2
|
+
const path = require('path')
|
|
3
|
+
import type{ NuxtPage } from '@nuxt/schema'
|
|
4
|
+
|
|
5
|
+
export const getMaxDepth = (dirPath: string, currentDepth = 0) => {
|
|
6
|
+
let maxDepth = currentDepth
|
|
7
|
+
|
|
8
|
+
const contents = fs.readdirSync(dirPath)
|
|
9
|
+
for (const item of contents) {
|
|
10
|
+
const itemPath = path.join(dirPath, item)
|
|
11
|
+
if (fs.statSync(itemPath).isDirectory()) {
|
|
12
|
+
const depth = getMaxDepth(itemPath, currentDepth + 1)
|
|
13
|
+
maxDepth = Math.max(maxDepth, depth)
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return maxDepth
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const addContentPageRecursion = (
|
|
21
|
+
pages?: NuxtPage[],
|
|
22
|
+
length?: number
|
|
23
|
+
): void => {
|
|
24
|
+
if (!pages || !length) return
|
|
25
|
+
|
|
26
|
+
pages.push({
|
|
27
|
+
name: `help-slug-${length}`,
|
|
28
|
+
path: `:slug${length}()`,
|
|
29
|
+
file: '~/pages/help/[slug].vue',
|
|
30
|
+
children: [],
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
addContentPageRecursion(pages[0].children, length - 1)
|
|
34
|
+
}
|