forked from spryker-shop/suite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.js
308 lines (258 loc) · 9.86 KB
/
settings.js
1
2
3
4
5
6
7
8
9
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
const { join, resolve } = require('path');
// define global settings
const globalSettings = {
// define the current context (root)
context: process.cwd(),
// build modes
modes: {
dev: 'development',
watch: 'development-watch',
prod: 'production',
},
// build modules
buildVariants: {
esm: 'esm',
legacy: 'legacy',
},
paths: {
// locate the typescript configuration json file
tsConfig: './tsconfig.yves.json',
// path to frontend build config json file
namespaceConfig: './config/Yves/frontend-build-config.json',
// core folders
core: './vendor/spryker-shop',
// eco folders
eco: './vendor/spryker-eco',
// project folders
project: './src/Pyz/Yves',
},
expectedModeArgument: 2,
};
const imageOptimizationOptions = {
enabledInModes: {
'development': false,
'development-watch': false,
'production': false,
},
// available options https://github.com/imagemin/imagemin-mozjpeg#api
jpg: {
quality: 60,
},
// available options https://github.com/imagemin/imagemin-pngquant#api
png: {
quality: [0.6, 0.7],
},
// available options https://github.com/svg/svgo#what-it-can-do
svg: {
removeViewBox: false,
},
// available options https://github.com/imagemin/imagemin-gifsicle#api
gif: {
optimizationLevel: 2,
},
};
const buildVariantArray = process.argv.filter(argv => argv.includes('module'));
const buildVariant = buildVariantArray.length ? buildVariantArray[0].replace('module:', '') : '';
const buildVariantSettings = {
buildVariant,
isES6Module: buildVariant === globalSettings.buildVariants.esm,
};
const getAppSettingsByTheme = (namespaceConfig, theme, pathToConfig) => {
const entryPointsParts = [
'components/atoms/*/index.ts',
'components/molecules/*/index.ts',
'components/organisms/*/index.ts',
'templates/*/index.ts',
'views/*/index.ts'
];
// getting collection of entry points by pattern
const entryPointsCollection = pathPattern => entryPointsParts.map(element => `${pathPattern}/${element}`);
// define the application name
const name = 'yves_default';
// get namespace config
const namespaceJson = require(pathToConfig);
// get public url path according to pattern from config
const getPublicUrl = () => (
namespaceJson.path
.replace(/%SPRYKER_BUILD_HASH%/gi, process.env.SPRYKER_BUILD_HASH || 'current')
.replace(/%namespace%/gi, namespaceConfig.namespace)
.replace(/%theme%/gi, theme)
);
const getPublicStaticUrl = () => namespaceJson.staticPath;
// get array of available module suffixes
const getAllCodeBuckets = () => namespaceJson.namespaces.map(namespace => namespace.codeBucket);
// get array of ignored modules
const ignoreModulesCollection = () => (
getAllCodeBuckets()
.filter(suffix => suffix !== namespaceConfig.codeBucket)
.map(suffix => `!**/*${suffix}/Theme/**`)
);
// define ignore patterns
const ignoreFiles = [
'!config',
'!data',
'!deploy',
'!node_modules',
'!public',
'!test',
...ignoreModulesCollection()
];
// define relative urls to site host (/)
const urls = {
// assets base url
assets: getPublicUrl(),
// static assets base url
staticAssets: getPublicStaticUrl(),
};
// define project relative paths to context
const paths = {
// locate the typescript configuration json file
tsConfig: globalSettings.paths.tsConfig,
// getting assets paths collection
assets: {
// global assets folder
globalAssets: `./frontend/assets/global/${theme}`,
// static assets source folder
staticAssets: `./frontend/static`,
// assets folder for current theme into namespace
currentAssets: join('./frontend/assets', namespaceConfig.namespace, theme)
},
// public folder with all assets
publicAll: globalSettings.paths.publicAll,
// current namespace and theme public assets folder
public: join('./public/Yves', urls.assets),
publicStatic: resolve('./public/Yves', urls.staticAssets),
// core folders
core: globalSettings.paths.core,
// eco folders
eco: globalSettings.paths.eco,
// project folders
project: globalSettings.paths.project
};
// define if current theme is empty
const isDefaultTheme = theme === namespaceConfig.defaultTheme;
const getThemeName = isFallbackPattern => isFallbackPattern ? namespaceConfig.defaultTheme : theme;
const isFallbackPatternAndDefaultTheme = isFallbackPattern => (isFallbackPattern && isDefaultTheme);
// define entry point patterns for current theme, if current theme is defined
const customThemeEntryPointPatterns = (isFallbackPattern = false) => {
return isFallbackPatternAndDefaultTheme(isFallbackPattern) ? [] : [
...entryPointsCollection(`**/Theme/${getThemeName(isFallbackPattern)}`),
...entryPointsCollection(`**/*${namespaceConfig.codeBucket}/Theme/${getThemeName(isFallbackPattern)}`),
...ignoreFiles
]
};
const shopUiEntryPointsPattern = (isFallbackPattern = false) => (
isFallbackPatternAndDefaultTheme(isFallbackPattern) ? [] : [
`./ShopUi/Theme/${getThemeName(isFallbackPattern)}`,
`./ShopUi${namespaceConfig.codeBucket}/Theme/${getThemeName(isFallbackPattern)}`
]
);
// define if current mode is production
const isProductionMode = () => {
const currentMode = process.argv.slice(globalSettings.expectedModeArgument)[0];
return currentMode === globalSettings.modes.prod;
};
// array of patterns for the critical components
const criticalPatterns = [
'**/ShopUi/**',
'**/CatalogPage/**',
'**/HomePage/**',
'**/ProductDetailPage/**'
];
// return settings
return {
name,
namespaceConfig,
theme,
paths,
urls,
imageOptimizationOptions,
criticalPatterns,
context: globalSettings.context,
isProductionMode: isProductionMode(),
// define settings for suite-frontend-builder finder
find: {
// entry point patterns (components)
componentEntryPoints: {
// absolute dirs in which look for
dirs: [
join(globalSettings.context, paths.core),
join(globalSettings.context, paths.eco),
join(globalSettings.context, paths.project)
],
// files/dirs patterns
patterns: customThemeEntryPointPatterns(),
fallbackPatterns: customThemeEntryPointPatterns(true)
},
// style entry point patterns (components)
stylesEntryPoints: {
core: {
// absolute dirs in which look for
dirs: [
join(globalSettings.context, paths.core),
],
// files/dirs patterns
patterns: [`**/Theme/${namespaceConfig.defaultTheme}/**/style.scss`],
},
nonCore: {
// absolute dirs in which look for
dirs: [
join(globalSettings.context, paths.eco),
join(globalSettings.context, paths.project),
],
// files/dirs patterns
patterns: [
`**/Theme/${namespaceConfig.defaultTheme}/components/**/*.scss`,
`**/Theme/${namespaceConfig.defaultTheme}/templates/**/*.scss`,
`**/Theme/${namespaceConfig.defaultTheme}/views/**/*.scss`,
],
},
},
// core component styles finder settings
// important: this part is used in shared scss environment
// do not change unless necessary
componentStyles: {
// absolute dirs in which look for
dirs: [
join(globalSettings.context, paths.core)
],
// files/dirs patterns
patterns: [
`**/Theme/${namespaceConfig.defaultTheme}/components/atoms/*/*.scss`,
`**/Theme/${namespaceConfig.defaultTheme}/components/molecules/*/*.scss`,
`**/Theme/${namespaceConfig.defaultTheme}/components/organisms/*/*.scss`,
`**/Theme/${namespaceConfig.defaultTheme}/templates/*/*.scss`,
`**/Theme/${namespaceConfig.defaultTheme}/views/*/*.scss`,
`!**/Theme/${namespaceConfig.defaultTheme}/**/style.scss`,
...ignoreFiles
]
},
// entry point patterns (application files)
shopUiEntryPoints: {
dirs: [
join(globalSettings.context, paths.project)
],
patterns: [
...shopUiEntryPointsPattern()
],
fallbackPatterns: [
...shopUiEntryPointsPattern(true)
]
}
}
}
};
const getAppSettings = (namespaceConfigList, pathToConfig) => {
const appSettings = [];
namespaceConfigList.forEach(namespaceConfig => {
namespaceConfig.themes.forEach(theme => {
appSettings.push(getAppSettingsByTheme(namespaceConfig, theme, pathToConfig));
})
});
return appSettings;
};
module.exports = {
globalSettings,
getAppSettings,
buildVariantSettings,
};