mage-obsidian 1.0.10 → 1.0.11
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 +1 -1
- package/src/service/cssResolver.js +54 -173
- package/src/service/moduleResolver.js +1 -1
package/package.json
CHANGED
|
@@ -1,192 +1,73 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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";
|
|
1
|
+
import themeResolver from './themeResolverSync.js';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { MODULE_WEB_PATH, THEME_CSS_FOLDER, THEME_MODULE_WEB_PATH } from '../config/default.js';
|
|
4
|
+
import { resolveFileByTheme, getAllJsVueFilesWithInheritanceCached } from './moduleResolver.js';
|
|
5
|
+
import configResolver from './configResolver.js';
|
|
6
|
+
import fs from 'node:fs/promises';
|
|
12
7
|
|
|
13
|
-
const
|
|
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 = {};
|
|
30
|
-
|
|
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
|
-
}
|
|
44
|
-
|
|
45
|
-
async function getAllJsVueFilesFromTheme(themeName) {
|
|
46
|
-
let result = {};
|
|
47
|
-
const theme = configResolver.getMagentoConfig().themes[themeName];
|
|
48
|
-
if (!theme) {
|
|
49
|
-
return {}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if (theme.parent) {
|
|
53
|
-
result = await getAllJsVueFilesFromTheme(theme.parent)
|
|
54
|
-
}
|
|
55
|
-
|
|
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;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
function getAllJsVueFilesWithInheritanceCached(themeName) {
|
|
78
|
-
themeName = themeName ?? process.env.CURRENT_THEME;
|
|
79
|
-
if (cachedModulesByTheme[themeName]) {
|
|
80
|
-
return cachedModulesByTheme[themeName];
|
|
81
|
-
}
|
|
82
|
-
//check if exits
|
|
8
|
+
const { getMagentoConfig, getModuleDefinition, getThemeDefinition, getModulesConfigArray } = configResolver;
|
|
83
9
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
const data = JSON.parse(fileContent);
|
|
87
|
-
cachedModulesByTheme[themeName] = data;
|
|
88
|
-
return data;
|
|
89
|
-
}
|
|
10
|
+
const MODULE_CSS_EXTEND_FILE = getMagentoConfig().MODULE_CSS_EXTEND_FILE;
|
|
11
|
+
const THEME_CSS_SOURCE_FILE = getMagentoConfig().THEME_CSS_SOURCE_FILE;
|
|
90
12
|
|
|
91
|
-
async function
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
return cachedModulesByTheme[themeName];
|
|
13
|
+
async function getThemeImports(themeName, themeConfig) {
|
|
14
|
+
if (!themeConfig) {
|
|
15
|
+
themeConfig = themeResolver.getThemeConfig(themeName);
|
|
95
16
|
}
|
|
96
|
-
const
|
|
97
|
-
const
|
|
98
|
-
cachedModulesByTheme[themeName] = deepmerge(allJsVueFilesFromModules, allJsVueFilesFromThemes);
|
|
99
|
-
return cachedModulesByTheme[themeName];
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
const moduleConfigByThemeCache = new Map();
|
|
103
|
-
|
|
104
|
-
const MODULE_CONFIG_FILE = configResolver.getMagentoConfig().MODULE_CONFIG_FILE;
|
|
17
|
+
const themeDefinition = getThemeDefinition(themeName);
|
|
18
|
+
const themePath = themeDefinition.src;
|
|
105
19
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
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;
|
|
20
|
+
let imports = '';
|
|
21
|
+
if (themeConfig.includeCssSourceFromParentThemes && themeDefinition.parent) {
|
|
22
|
+
imports += await getThemeImports(themeDefinition.parent, themeConfig);
|
|
120
23
|
}
|
|
121
24
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
}
|
|
125
|
-
return null;
|
|
25
|
+
imports += `@import "${path.join(themePath, THEME_MODULE_WEB_PATH, THEME_CSS_FOLDER, THEME_CSS_SOURCE_FILE)}";\n`;
|
|
26
|
+
return imports;
|
|
126
27
|
}
|
|
127
28
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
let moduleConfigSourcePath = resolveFileByTheme(themeName, moduleName, MODULE_CONFIG_FILE, includeTailwindConfigFromParentThemes);
|
|
131
|
-
|
|
132
|
-
if (!moduleConfigSourcePath && !module) {
|
|
133
|
-
return null;
|
|
134
|
-
}
|
|
29
|
+
function resolveModuleCssSourcePath(moduleName, themeName) {
|
|
30
|
+
let moduleConfigSourcePath = resolveFileByTheme(themeName, moduleName, 'css', MODULE_CSS_EXTEND_FILE);
|
|
135
31
|
if (!moduleConfigSourcePath) {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
if (!fs.existsSync(moduleConfigSourcePath)) {
|
|
139
|
-
return null;
|
|
32
|
+
const moduleDefinition = getModuleDefinition(moduleName);
|
|
33
|
+
moduleConfigSourcePath = path.join(moduleDefinition.src, MODULE_WEB_PATH, 'css', MODULE_CSS_EXTEND_FILE);
|
|
140
34
|
}
|
|
141
|
-
|
|
142
|
-
// Importación dinámica común en ESModules
|
|
143
|
-
const moduleConfig = await import(moduleConfigSourcePath);
|
|
144
|
-
return moduleConfig.default ?? moduleConfig;
|
|
35
|
+
return moduleConfigSourcePath;
|
|
145
36
|
}
|
|
146
37
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
if (moduleConfigByThemeCache.has(themeName)) {
|
|
156
|
-
return moduleConfigByThemeCache.get(themeName);
|
|
157
|
-
}
|
|
158
|
-
if (!themeConfig) return null;
|
|
159
|
-
const modules = configResolver.getAllMagentoModulesEnabled();
|
|
160
|
-
let modulesConfig = {};
|
|
38
|
+
async function getVueComponentsSource(themeName) {
|
|
39
|
+
const vueComponents = await getAllJsVueFilesWithInheritanceCached(themeName);
|
|
40
|
+
// split with @source al inicio
|
|
41
|
+
const vueComponentSources = Object.entries(vueComponents).map(([name, url]) => {
|
|
42
|
+
return `@source "${url}";\n`;
|
|
43
|
+
})
|
|
44
|
+
return vueComponentSources.join('');
|
|
45
|
+
}
|
|
161
46
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
);
|
|
47
|
+
async function getCssImports(themeName) {
|
|
48
|
+
const themeConfig = themeResolver.getThemeConfig(themeName);
|
|
49
|
+
const excludedModules = new Set(themeConfig.ignoredCssFromModules || []);
|
|
50
|
+
const modulesConfig = getModulesConfigArray();
|
|
51
|
+
|
|
52
|
+
let cssSource = await getVueComponentsSource(themeName);
|
|
53
|
+
let cssImports = '';
|
|
54
|
+
|
|
55
|
+
if (themeConfig.ignoredCssFromModules !== 'all') {
|
|
56
|
+
for (const [moduleName, moduleConfig] of modulesConfig) {
|
|
57
|
+
if (excludedModules.has(moduleName)) continue;
|
|
58
|
+
|
|
59
|
+
const filePath = resolveModuleCssSourcePath(moduleName, themeName);
|
|
60
|
+
try {
|
|
61
|
+
await fs.access(filePath);
|
|
62
|
+
cssImports += `@import "${filePath}";\n`;
|
|
63
|
+
} catch {
|
|
64
|
+
// ignore if file doesn't exist
|
|
65
|
+
}
|
|
175
66
|
}
|
|
176
|
-
|
|
177
|
-
modulesConfig = deepmerge(modulesConfig, moduleConfig);
|
|
178
67
|
}
|
|
179
68
|
|
|
180
|
-
|
|
181
|
-
return
|
|
69
|
+
cssImports += await getThemeImports(themeName);
|
|
70
|
+
return `${cssSource}\n${cssImports}`;
|
|
182
71
|
}
|
|
183
72
|
|
|
184
|
-
export default
|
|
185
|
-
getAllJsVueFilesWithInheritance,
|
|
186
|
-
getAllJsVueFilesWithInheritanceCached,
|
|
187
|
-
getModuleConfigByThemeConfig,
|
|
188
|
-
resolveFileByTheme
|
|
189
|
-
};
|
|
190
|
-
|
|
191
|
-
export { getModuleConfigByThemeConfig, resolveFileByTheme, getAllJsVueFilesWithInheritance, getAllJsVueFilesWithInheritanceCached };
|
|
192
|
-
|
|
73
|
+
export default getCssImports;
|