mage-obsidian 1.0.9 → 1.0.10
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/package.json
CHANGED
|
@@ -1,63 +1,192 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import path from "path";
|
|
2
|
+
import configResolver from "./configResolver.js";
|
|
3
|
+
import {
|
|
4
|
+
ALL_JS_VUE_FILES_WITH_INHERITANCE_FILE_NAME,
|
|
5
|
+
MODULE_WEB_PATH,
|
|
6
|
+
PRECOMPILED_FOLDER,
|
|
7
|
+
THEME_MODULE_WEB_PATH
|
|
8
|
+
} from "../config/default.js";
|
|
9
|
+
import getFilesFromFolders from '../utils/findComponents.js'
|
|
10
|
+
import fs from "fs";
|
|
11
|
+
import deepmerge from "deepmerge";
|
|
7
12
|
|
|
8
|
-
const
|
|
13
|
+
const defaultFoldersToMap = [
|
|
14
|
+
{
|
|
15
|
+
src: configResolver.getMagentoConfig().VUE_COMPONENTS_PATH,
|
|
16
|
+
ext: [
|
|
17
|
+
'vue',
|
|
18
|
+
'js'
|
|
19
|
+
]
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
src: configResolver.getMagentoConfig().JS_PATH,
|
|
23
|
+
ext: [
|
|
24
|
+
'js'
|
|
25
|
+
]
|
|
26
|
+
}
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
const cachedModulesByTheme = {};
|
|
9
30
|
|
|
10
|
-
|
|
11
|
-
|
|
31
|
+
async function getAllJsVueFilesFromActiveModules() {
|
|
32
|
+
let result = {};
|
|
33
|
+
for (const entry of configResolver.getModulesConfigArray()) {
|
|
34
|
+
const [moduleName, moduleConfig] = entry;
|
|
35
|
+
const moduleResult = await getFilesFromFolders(
|
|
36
|
+
moduleName,
|
|
37
|
+
path.resolve(moduleConfig.src, MODULE_WEB_PATH),
|
|
38
|
+
defaultFoldersToMap
|
|
39
|
+
);
|
|
40
|
+
Object.assign(result, moduleResult);
|
|
41
|
+
}
|
|
42
|
+
return result;
|
|
43
|
+
}
|
|
12
44
|
|
|
13
|
-
async function
|
|
14
|
-
|
|
15
|
-
|
|
45
|
+
async function getAllJsVueFilesFromTheme(themeName) {
|
|
46
|
+
let result = {};
|
|
47
|
+
const theme = configResolver.getMagentoConfig().themes[themeName];
|
|
48
|
+
if (!theme) {
|
|
49
|
+
return {}
|
|
16
50
|
}
|
|
17
|
-
const themeDefinition = getThemeDefinition(themeName);
|
|
18
|
-
const themePath = themeDefinition.src;
|
|
19
51
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
imports += await getThemeImports(themeDefinition.parent, themeConfig);
|
|
52
|
+
if (theme.parent) {
|
|
53
|
+
result = await getAllJsVueFilesFromTheme(theme.parent)
|
|
23
54
|
}
|
|
24
55
|
|
|
25
|
-
|
|
26
|
-
|
|
56
|
+
for (const moduleName of configResolver.getAllMagentoModulesEnabled()) {
|
|
57
|
+
const modulePath = path.resolve(theme.src, moduleName, THEME_MODULE_WEB_PATH);
|
|
58
|
+
const moduleResult = await getFilesFromFolders(
|
|
59
|
+
moduleName,
|
|
60
|
+
modulePath,
|
|
61
|
+
defaultFoldersToMap
|
|
62
|
+
);
|
|
63
|
+
if (moduleResult) {
|
|
64
|
+
result = deepmerge(result, moduleResult);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
const moduleResult = await getFilesFromFolders(
|
|
68
|
+
'Theme',
|
|
69
|
+
path.resolve(theme.src, THEME_MODULE_WEB_PATH),
|
|
70
|
+
defaultFoldersToMap
|
|
71
|
+
);
|
|
72
|
+
result = deepmerge(result, moduleResult);
|
|
73
|
+
return result;
|
|
27
74
|
}
|
|
28
75
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
76
|
+
|
|
77
|
+
function getAllJsVueFilesWithInheritanceCached(themeName) {
|
|
78
|
+
themeName = themeName ?? process.env.CURRENT_THEME;
|
|
79
|
+
if (cachedModulesByTheme[themeName]) {
|
|
80
|
+
return cachedModulesByTheme[themeName];
|
|
34
81
|
}
|
|
35
|
-
|
|
82
|
+
//check if exits
|
|
83
|
+
|
|
84
|
+
const filePath = path.join(PRECOMPILED_FOLDER, themeName, ALL_JS_VUE_FILES_WITH_INHERITANCE_FILE_NAME);
|
|
85
|
+
const fileContent = fs.readFileSync(filePath, "utf-8");
|
|
86
|
+
const data = JSON.parse(fileContent);
|
|
87
|
+
cachedModulesByTheme[themeName] = data;
|
|
88
|
+
return data;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
async function getAllJsVueFilesWithInheritance(themeName) {
|
|
92
|
+
themeName = themeName ?? process.env.CURRENT_THEME;
|
|
93
|
+
if (cachedModulesByTheme[themeName]) {
|
|
94
|
+
return cachedModulesByTheme[themeName];
|
|
95
|
+
}
|
|
96
|
+
const allJsVueFilesFromModules = await getAllJsVueFilesFromActiveModules();
|
|
97
|
+
const allJsVueFilesFromThemes = await getAllJsVueFilesFromTheme(themeName);
|
|
98
|
+
cachedModulesByTheme[themeName] = deepmerge(allJsVueFilesFromModules, allJsVueFilesFromThemes);
|
|
99
|
+
return cachedModulesByTheme[themeName];
|
|
36
100
|
}
|
|
37
101
|
|
|
38
|
-
|
|
39
|
-
const themeConfig = themeResolver.getThemeConfig(themeName);
|
|
40
|
-
const excludedModules = new Set(themeConfig.ignoredCssFromModules || []);
|
|
41
|
-
const modulesConfig = getModulesConfigArray();
|
|
102
|
+
const moduleConfigByThemeCache = new Map();
|
|
42
103
|
|
|
43
|
-
|
|
104
|
+
const MODULE_CONFIG_FILE = configResolver.getMagentoConfig().MODULE_CONFIG_FILE;
|
|
44
105
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
106
|
+
/**
|
|
107
|
+
* Gets the theme configuration file path.
|
|
108
|
+
* @param {string} moduleSrc
|
|
109
|
+
* @returns {string} Full path to the configuration file.
|
|
110
|
+
*/
|
|
111
|
+
function getModuleConfigPath(moduleSrc) {
|
|
112
|
+
return path.join(moduleSrc, 'view/frontend/web/', MODULE_CONFIG_FILE);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function resolveFileByTheme(themeName, moduleName, filePath, includeTailwindConfigFromParentThemes) {
|
|
116
|
+
const theme = configResolver.getMagentoConfig().themes[themeName];
|
|
117
|
+
const fullFilePath = path.join(theme.src, moduleName, 'web', filePath);
|
|
118
|
+
if (fs.existsSync(fullFilePath)) {
|
|
119
|
+
return fullFilePath;
|
|
120
|
+
}
|
|
48
121
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
122
|
+
if (includeTailwindConfigFromParentThemes && theme.parent) {
|
|
123
|
+
return resolveFileByTheme(theme.parent, moduleName, filePath, includeTailwindConfigFromParentThemes);
|
|
124
|
+
}
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
async function resolveModuleConfig(moduleName, themeName, includeTailwindConfigFromParentThemes) {
|
|
129
|
+
const module = configResolver.getMagentoConfig().modules[moduleName];
|
|
130
|
+
let moduleConfigSourcePath = resolveFileByTheme(themeName, moduleName, MODULE_CONFIG_FILE, includeTailwindConfigFromParentThemes);
|
|
131
|
+
|
|
132
|
+
if (!moduleConfigSourcePath && !module) {
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
if (!moduleConfigSourcePath) {
|
|
136
|
+
moduleConfigSourcePath = getModuleConfigPath(module.src);
|
|
137
|
+
}
|
|
138
|
+
if (!fs.existsSync(moduleConfigSourcePath)) {
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// Importación dinámica común en ESModules
|
|
143
|
+
const moduleConfig = await import(moduleConfigSourcePath);
|
|
144
|
+
return moduleConfig.default ?? moduleConfig;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Retrieves the Tailwind configuration for a theme synchronously.
|
|
149
|
+
* Uses a cache system to optimize performance.
|
|
150
|
+
* @param {string} themeName - Name of the theme.
|
|
151
|
+
* @param {object} themeConfig
|
|
152
|
+
* @returns {object|null} Tailwind configuration object.
|
|
153
|
+
*/
|
|
154
|
+
async function getModuleConfigByThemeConfig(themeName, themeConfig) {
|
|
155
|
+
if (moduleConfigByThemeCache.has(themeName)) {
|
|
156
|
+
return moduleConfigByThemeCache.get(themeName);
|
|
157
|
+
}
|
|
158
|
+
if (!themeConfig) return null;
|
|
159
|
+
const modules = configResolver.getAllMagentoModulesEnabled();
|
|
160
|
+
let modulesConfig = {};
|
|
161
|
+
|
|
162
|
+
for (const moduleName of modules) {
|
|
163
|
+
let moduleConfig = await resolveModuleConfig(moduleName, themeName, themeConfig.includeTailwindConfigFromParentThemes);
|
|
164
|
+
if (!moduleConfig) continue;
|
|
165
|
+
if (
|
|
166
|
+
themeConfig.ignoredTailwindConfigFromModules === 'all' ||
|
|
167
|
+
themeConfig.ignoredTailwindConfigFromModules.includes(moduleName)
|
|
168
|
+
) {
|
|
169
|
+
moduleConfig.tailwind = {};
|
|
170
|
+
} else if (moduleConfig.tailwind?.content) {
|
|
171
|
+
const moduleSrc = configResolver.getMagentoConfig().modules[moduleName].src;
|
|
172
|
+
moduleConfig.tailwind.content = moduleConfig.tailwind.content.map((content) =>
|
|
173
|
+
path.join(moduleSrc, 'view/frontend/web', content)
|
|
174
|
+
);
|
|
56
175
|
}
|
|
176
|
+
|
|
177
|
+
modulesConfig = deepmerge(modulesConfig, moduleConfig);
|
|
57
178
|
}
|
|
58
179
|
|
|
59
|
-
|
|
60
|
-
return
|
|
180
|
+
moduleConfigByThemeCache.set(themeName, modulesConfig);
|
|
181
|
+
return modulesConfig;
|
|
61
182
|
}
|
|
62
183
|
|
|
63
|
-
export default
|
|
184
|
+
export default {
|
|
185
|
+
getAllJsVueFilesWithInheritance,
|
|
186
|
+
getAllJsVueFilesWithInheritanceCached,
|
|
187
|
+
getModuleConfigByThemeConfig,
|
|
188
|
+
resolveFileByTheme
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
export { getModuleConfigByThemeConfig, resolveFileByTheme, getAllJsVueFilesWithInheritance, getAllJsVueFilesWithInheritanceCached };
|
|
192
|
+
|
|
@@ -10,7 +10,7 @@ export default async (themeName) => {
|
|
|
10
10
|
execSync('rm -rf .precompiled/*', { stdio: 'inherit' });
|
|
11
11
|
execSync(`mkdir -p .precompiled/${themeName}`, { stdio: 'inherit' });
|
|
12
12
|
console.log('Generating precompiled files');
|
|
13
|
-
await precompileCss(themeName);
|
|
14
13
|
await precompileJs(themeName);
|
|
14
|
+
await precompileCss(themeName);
|
|
15
15
|
isPrecompiled = true;
|
|
16
16
|
}
|