create-template-bricks 0.0.0-stage → 1.0.1
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/README.md +85 -2
- package/bin/cli.js +403 -0
- package/package.json +49 -4
- package/templates/base/.babelrc +18 -0
- package/templates/base/.editorconfig +22 -0
- package/templates/base/.eslintrc.json +130 -0
- package/templates/base/AGENTS.md +49 -0
- package/templates/base/README.md +121 -0
- package/templates/base/gulpfile.js +46 -0
- package/templates/base/package.json +82 -0
- package/templates/base/postcss.config.mjs +6 -0
- package/templates/base/src/assets/css/vendor/.gitkeep +0 -0
- package/templates/base/src/assets/fonts/.gitkeep +0 -0
- package/templates/base/src/assets/img/Logo.svg +32 -0
- package/templates/base/src/assets/img/favicons/favicon.ico +0 -0
- package/templates/base/src/assets/img/sprite/cup-bronze.png +0 -0
- package/templates/base/src/assets/img/sprite/cup-bronze@2x.png +0 -0
- package/templates/base/src/assets/img/sprite.png +0 -0
- package/templates/base/src/assets/img/sprite@2x.png +0 -0
- package/templates/base/src/assets/img/svg-sprite/close.svg +3 -0
- package/templates/base/src/assets/img/svg-sprite/favorite.svg +3 -0
- package/templates/base/src/assets/img/svg-sprite/keyboard.svg +3 -0
- package/templates/base/src/assets/js/vendor/.gitkeep +0 -0
- package/templates/base/src/styles/core/base.scss +31 -0
- package/templates/base/src/styles/core/extends.scss +11 -0
- package/templates/base/src/styles/core/fonts.scss +0 -0
- package/templates/base/src/styles/core/index.scss +10 -0
- package/templates/base/src/styles/core/keyframes.scss +49 -0
- package/templates/base/src/styles/core/layouts/footer.scss +1 -0
- package/templates/base/src/styles/core/layouts/header/index.scss +1 -0
- package/templates/base/src/styles/core/layouts/index.scss +2 -0
- package/templates/base/src/styles/core/page.scss +16 -0
- package/templates/base/src/styles/core/typography.scss +1 -0
- package/templates/base/src/styles/core/ui/icons.scss +31 -0
- package/templates/base/src/styles/core/ui/index.scss +2 -0
- package/templates/base/src/styles/core/ui/scrollbar.scss +14 -0
- package/templates/base/src/styles/core/variables.scss +41 -0
- package/templates/base/src/styles/index.scss +1 -0
- package/templates/base/src/styles/plugins/functions.scss +0 -0
- package/templates/base/src/styles/plugins/media.scss +63 -0
- package/templates/base/src/styles/plugins/mixins.scss +31 -0
- package/templates/base/src/styles/plugins/sprite-mixin.scss +75 -0
- package/templates/base/src/styles/plugins/sprite.scss +154 -0
- package/templates/base/src/styles.scss +2 -0
- package/templates/base/src/tailwind.css +1 -0
- package/templates/base/src/tmplConfig.js +22 -0
- package/templates/base/tailwind.config.js +23 -0
- package/templates/base/tasks/archive.js +37 -0
- package/templates/base/tasks/clean.js +17 -0
- package/templates/base/tasks/config.js +98 -0
- package/templates/base/tasks/copy.js +53 -0
- package/templates/base/tasks/helper.js +31 -0
- package/templates/base/tasks/images/image-optimize.js +46 -0
- package/templates/base/tasks/images/index.js +27 -0
- package/templates/base/tasks/images/plugins/optimize-raster.js +44 -0
- package/templates/base/tasks/images/png-sprite.js +43 -0
- package/templates/base/tasks/template/data.js +28 -0
- package/templates/base/tasks/template/index.js +48 -0
- package/templates/base/tasks/template/plugins/generate-static-path.js +37 -0
- package/templates/base/tasks/template/plugins/nunjucks-relative-paths-includes.js +39 -0
- package/templates/base/tasks/template/plugins/nunjucks-relative-system-loader.js +28 -0
- package/templates/base/tasks/template/plugins/template-dependencies.js +246 -0
- package/templates/base/tasks/template/template.js +172 -0
- package/templates/base/tasks/watcher.js +233 -0
- package/templates/base/tasks/webpack/env.js +21 -0
- package/templates/base/tasks/webpack/plugins/build-status-plugin.js +74 -0
- package/templates/base/tasks/webpack/plugins/current-color-plugin.js +225 -0
- package/templates/base/tasks/webpack/plugins/removeFilesOnlyJs.js +28 -0
- package/templates/base/tasks/webpack/scripts.config.js +147 -0
- package/templates/base/tasks/webpack/styles.config.js +126 -0
- package/templates/base/tasks/webpack/svg-sprite.config.js +95 -0
- package/templates/base/tasks/webpack/watch.js +50 -0
- package/templates/base/tsconfig.json +20 -0
- package/templates/base/user.config.js +102 -0
- package/templates/base/webpack.config.js +9 -0
- package/templates/template-js/js/api/api.js +0 -0
- package/templates/template-js/js/core/core.js +56 -0
- package/templates/template-js/js/main.js +6 -0
- package/templates/template-js/js/modules/header.js +15 -0
- package/templates/template-js/js/modules/index.js +24 -0
- package/templates/template-js/js/services/index.js +1 -0
- package/templates/template-js/js/services/query-params.js +19 -0
- package/templates/template-js/js/styles.js +2 -0
- package/templates/template-js/js/ui/index.js +18 -0
- package/templates/template-js/js/utils/constants.js +0 -0
- package/templates/template-js/js/utils/create-factory.js +65 -0
- package/templates/template-js/js/utils/debounce.js +8 -0
- package/templates/template-js/js/utils/delay.js +4 -0
- package/templates/template-js/js/utils/is-platform.js +15 -0
- package/templates/template-js/js/utils/throttle.js +16 -0
- package/templates/template-mjml/emails/assets/images/address-btn.jpg +0 -0
- package/templates/template-mjml/emails/assets/images/address.jpg +0 -0
- package/templates/template-mjml/emails/assets/images/banner.jpg +0 -0
- package/templates/template-mjml/emails/assets/images/close.png +0 -0
- package/templates/template-mjml/emails/assets/images/confirm-btn.jpg +0 -0
- package/templates/template-mjml/emails/assets/images/facebook.png +0 -0
- package/templates/template-mjml/emails/assets/images/forgot.jpg +0 -0
- package/templates/template-mjml/emails/assets/images/icon-info.png +0 -0
- package/templates/template-mjml/emails/assets/images/img-send.jpg +0 -0
- package/templates/template-mjml/emails/assets/images/instagram.png +0 -0
- package/templates/template-mjml/emails/assets/images/logo.png +0 -0
- package/templates/template-mjml/emails/assets/images/reset-btn.jpg +0 -0
- package/templates/template-mjml/emails/assets/images/twitter.png +0 -0
- package/templates/template-mjml/emails/pages/address.mjml +55 -0
- package/templates/template-mjml/emails/pages/confirm-resend.mjml +63 -0
- package/templates/template-mjml/emails/pages/confirm.mjml +44 -0
- package/templates/template-mjml/emails/pages/forgot-password.mjml +65 -0
- package/templates/template-mjml/emails/shared/ui/head/fonts.mjml +211 -0
- package/templates/template-mjml/emails/shared/ui/head/index.mjml +146 -0
- package/templates/template-mjml/emails/widgets/footer/ui/index.mjml +12 -0
- package/templates/template-nunjucks/templates/layouts/base.njk +23 -0
- package/templates/template-nunjucks/templates/pages/index.njk +9 -0
- package/templates/template-nunjucks/templates/shared/ui/head/data.json +8 -0
- package/templates/template-nunjucks/templates/shared/ui/head/index.njk +13 -0
- package/templates/template-nunjucks/templates/shared/ui/icon/index.njk +5 -0
- package/templates/template-nunjucks/templates/widgets/footer/index.njk +5 -0
- package/templates/template-nunjucks/templates/widgets/footer/model/data.json +4 -0
- package/templates/template-nunjucks/templates/widgets/footer/ui/index.njk +7 -0
- package/templates/template-nunjucks/templates/widgets/home-hero/index.njk +1 -0
- package/templates/template-nunjucks/templates/widgets/home-hero/ui/index.njk +9 -0
- package/templates/template-pug/templates/layouts/base.pug +19 -0
- package/templates/template-pug/templates/pages/index.pug +12 -0
- package/templates/template-pug/templates/shared/lib/blocks.pug +21 -0
- package/templates/template-pug/templates/shared/ui/head/data.json +8 -0
- package/templates/template-pug/templates/shared/ui/head/index.pug +10 -0
- package/templates/template-pug/templates/shared/ui/icon/index.pug +3 -0
- package/templates/template-pug/templates/widgets/footer/index.pug +1 -0
- package/templates/template-pug/templates/widgets/footer/model/data.json +4 -0
- package/templates/template-pug/templates/widgets/footer/ui/index.pug +4 -0
- package/templates/template-pug/templates/widgets/home-hero/index.pug +1 -0
- package/templates/template-pug/templates/widgets/home-hero/ui/index.pug +6 -0
- package/templates/template-ts/ts/api/api.ts +0 -0
- package/templates/template-ts/ts/core/core.ts +66 -0
- package/templates/template-ts/ts/interfaces/factory.ts +5 -0
- package/templates/template-ts/ts/main.ts +6 -0
- package/templates/template-ts/ts/modules/header.ts +17 -0
- package/templates/template-ts/ts/modules/index.ts +26 -0
- package/templates/template-ts/ts/services/index.ts +2 -0
- package/templates/template-ts/ts/services/query-params.ts +23 -0
- package/templates/template-ts/ts/styles.ts +2 -0
- package/templates/template-ts/ts/ui/index.ts +23 -0
- package/templates/template-ts/ts/utils/constants.ts +0 -0
- package/templates/template-ts/ts/utils/create-factory.ts +91 -0
- package/templates/template-ts/ts/utils/debounce.ts +10 -0
- package/templates/template-ts/ts/utils/delay.ts +5 -0
- package/templates/template-ts/ts/utils/is-platform.ts +21 -0
- package/templates/template-ts/ts/utils/throttle.ts +19 -0
- package/templates/template-twig/templates/layouts/base.html.twig +26 -0
- package/templates/template-twig/templates/pages/index.html.twig +8 -0
- package/templates/template-twig/templates/shared/ui/head/data.json +8 -0
- package/templates/template-twig/templates/shared/ui/head/index.html.twig +11 -0
- package/templates/template-twig/templates/shared/ui/icon/index.html.twig +21 -0
- package/templates/template-twig/templates/widgets/footer/index.html.twig +1 -0
- package/templates/template-twig/templates/widgets/footer/model/data.json +4 -0
- package/templates/template-twig/templates/widgets/footer/ui/index.html.twig +5 -0
- package/templates/template-twig/templates/widgets/home-hero/index.html.twig +1 -0
- package/templates/template-twig/templates/widgets/home-hero/ui/index.html.twig +9 -0
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import gulp from 'gulp';
|
|
3
|
+
|
|
4
|
+
import * as config from './config.js';
|
|
5
|
+
import {
|
|
6
|
+
$,
|
|
7
|
+
browser,
|
|
8
|
+
reload
|
|
9
|
+
} from './helper.js';
|
|
10
|
+
|
|
11
|
+
import templateModule from './template/index.js';
|
|
12
|
+
import copyModule from './copy.js';
|
|
13
|
+
import imagesModule from './images/index.js';
|
|
14
|
+
import userConfig from '../user.config.js';
|
|
15
|
+
|
|
16
|
+
const {
|
|
17
|
+
watch,
|
|
18
|
+
series
|
|
19
|
+
} = gulp;
|
|
20
|
+
|
|
21
|
+
const {
|
|
22
|
+
serverIndexPage,
|
|
23
|
+
spritePng,
|
|
24
|
+
folderBuild,
|
|
25
|
+
sourceFolder
|
|
26
|
+
} = userConfig;
|
|
27
|
+
|
|
28
|
+
const {
|
|
29
|
+
watchPath
|
|
30
|
+
} = config;
|
|
31
|
+
|
|
32
|
+
const {
|
|
33
|
+
templates,
|
|
34
|
+
data,
|
|
35
|
+
emails
|
|
36
|
+
} = templateModule;
|
|
37
|
+
|
|
38
|
+
const {
|
|
39
|
+
pngSprite
|
|
40
|
+
} = imagesModule;
|
|
41
|
+
|
|
42
|
+
const {
|
|
43
|
+
assetsCopy
|
|
44
|
+
} = copyModule;
|
|
45
|
+
|
|
46
|
+
const createWatcher = () => {
|
|
47
|
+
return {
|
|
48
|
+
serveWatcher: () => {
|
|
49
|
+
browser.init(
|
|
50
|
+
{
|
|
51
|
+
server: {
|
|
52
|
+
baseDir: `./${folderBuild}`,
|
|
53
|
+
index: serverIndexPage,
|
|
54
|
+
serveStaticOptions: {
|
|
55
|
+
// Cached HTML can omit the BrowserSync client after a prefetch.
|
|
56
|
+
etag: false,
|
|
57
|
+
lastModified: false,
|
|
58
|
+
setHeaders: response => {
|
|
59
|
+
response.setHeader('Cache-Control', 'no-store');
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
open: false,
|
|
64
|
+
online: false,
|
|
65
|
+
port: 4200,
|
|
66
|
+
notify: true,
|
|
67
|
+
logConnections: false,
|
|
68
|
+
ui: false,
|
|
69
|
+
logLevel: 'silent'
|
|
70
|
+
},
|
|
71
|
+
|
|
72
|
+
(error, instance) => {
|
|
73
|
+
if (error) {
|
|
74
|
+
console.error(
|
|
75
|
+
'BrowserSync failed to start:',
|
|
76
|
+
error
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const localUrl = instance.options.getIn([
|
|
83
|
+
'urls',
|
|
84
|
+
'local'
|
|
85
|
+
]);
|
|
86
|
+
|
|
87
|
+
const color = (code, text) => {
|
|
88
|
+
if (!process.stdout.isTTY || 'NO_COLOR' in process.env) {
|
|
89
|
+
return text;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return `\x1b[${code}m${text}\x1b[0m`;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
console.log([
|
|
96
|
+
'',
|
|
97
|
+
` ${color('1;32', 'READY')} ${color('1', 'Development server')}`,
|
|
98
|
+
'',
|
|
99
|
+
` ${color('90', 'Local')} ${color('1;36', localUrl)}`,
|
|
100
|
+
''
|
|
101
|
+
].join('\n'));
|
|
102
|
+
}
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
const deleteEventFile = (
|
|
106
|
+
filePath,
|
|
107
|
+
resolve,
|
|
108
|
+
src = sourceFolder
|
|
109
|
+
) => {
|
|
110
|
+
const sourcesFiles = path.relative(
|
|
111
|
+
path.resolve(src),
|
|
112
|
+
filePath
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
const destFiles = path.resolve(
|
|
116
|
+
resolve,
|
|
117
|
+
sourcesFiles
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
$.del.sync(destFiles);
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const runTemplates = series(
|
|
124
|
+
templates(),
|
|
125
|
+
reload
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
const pendingTemplateChanges = new Set();
|
|
129
|
+
let templateConfigChanged = false;
|
|
130
|
+
|
|
131
|
+
watch(
|
|
132
|
+
watchPath.templates,
|
|
133
|
+
{
|
|
134
|
+
delay: 100
|
|
135
|
+
},
|
|
136
|
+
done => {
|
|
137
|
+
global.templateChangedFiles = [...pendingTemplateChanges];
|
|
138
|
+
global.disableTemplateIncremental = templateConfigChanged;
|
|
139
|
+
pendingTemplateChanges.clear();
|
|
140
|
+
templateConfigChanged = false;
|
|
141
|
+
|
|
142
|
+
runTemplates(error => {
|
|
143
|
+
global.templateChangedFiles = [];
|
|
144
|
+
global.disableTemplateIncremental = false;
|
|
145
|
+
done(error);
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
).on('all', (event, file) => {
|
|
149
|
+
if (path.basename(file) === 'tmplConfig.js') {
|
|
150
|
+
templateConfigChanged = true;
|
|
151
|
+
} else {
|
|
152
|
+
pendingTemplateChanges.add(file);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (event === 'unlink') {
|
|
156
|
+
const page = path.relative(
|
|
157
|
+
path.resolve(sourceFolder, 'templates/pages'),
|
|
158
|
+
path.resolve(file)
|
|
159
|
+
);
|
|
160
|
+
const isPage = page !== '..'
|
|
161
|
+
&& !page.startsWith(`..${path.sep}`)
|
|
162
|
+
&& !path.isAbsolute(page)
|
|
163
|
+
&& !path.basename(page).startsWith('_');
|
|
164
|
+
const extension = /(?:\.html\.twig|\.(?:twig|pug|njk|html))$/i;
|
|
165
|
+
|
|
166
|
+
if (isPage && extension.test(page)) {
|
|
167
|
+
$.del.sync(path.resolve(folderBuild, page.replace(extension, '.html')));
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
watch(
|
|
173
|
+
watchPath.data,
|
|
174
|
+
data()
|
|
175
|
+
);
|
|
176
|
+
|
|
177
|
+
watch(
|
|
178
|
+
watchPath.email,
|
|
179
|
+
emails()
|
|
180
|
+
);
|
|
181
|
+
|
|
182
|
+
watch(
|
|
183
|
+
watchPath.assets,
|
|
184
|
+
series(
|
|
185
|
+
assetsCopy,
|
|
186
|
+
reload
|
|
187
|
+
)
|
|
188
|
+
).on('unlink', filePath => {
|
|
189
|
+
deleteEventFile(
|
|
190
|
+
filePath,
|
|
191
|
+
folderBuild
|
|
192
|
+
);
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
if (spritePng) {
|
|
196
|
+
watch(
|
|
197
|
+
watchPath.sprite,
|
|
198
|
+
series(
|
|
199
|
+
pngSprite,
|
|
200
|
+
reload
|
|
201
|
+
)
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
watch(
|
|
206
|
+
watchPath.webpackStylePaths,
|
|
207
|
+
{
|
|
208
|
+
delay: 100,
|
|
209
|
+
ignoreInitial: true
|
|
210
|
+
}
|
|
211
|
+
).on('all', (event, file) => {
|
|
212
|
+
if (event === 'unlink') {
|
|
213
|
+
browser.reload();
|
|
214
|
+
} else {
|
|
215
|
+
browser.reload(file);
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
watch(
|
|
220
|
+
watchPath.webpackBuildPaths,
|
|
221
|
+
{
|
|
222
|
+
delay: 100,
|
|
223
|
+
ignoreInitial: true
|
|
224
|
+
},
|
|
225
|
+
reload
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
const watcherModule = createWatcher();
|
|
232
|
+
|
|
233
|
+
export default watcherModule;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import userConfig from '../../user.config.js';
|
|
2
|
+
import { isProduction } from '../config.js';
|
|
3
|
+
|
|
4
|
+
export const envCreate = () => {
|
|
5
|
+
const sourceMap = userConfig.sourcemaps ? true : !isProduction;
|
|
6
|
+
let devtool;
|
|
7
|
+
|
|
8
|
+
if (userConfig.sourcemaps) {
|
|
9
|
+
devtool = 'source-map';
|
|
10
|
+
} else if (isProduction) {
|
|
11
|
+
devtool = false;
|
|
12
|
+
} else {
|
|
13
|
+
devtool = 'source-map';
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return { sourceMap, devtool };
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const envModule = envCreate();
|
|
20
|
+
|
|
21
|
+
export default envModule;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
export default class BuildStatusPlugin {
|
|
2
|
+
constructor(options = {}) {
|
|
3
|
+
const config = typeof options === 'string'
|
|
4
|
+
? { name: options }
|
|
5
|
+
: options;
|
|
6
|
+
|
|
7
|
+
this.name = config.name || 'Build';
|
|
8
|
+
this.showDuration = config.showDuration !== false;
|
|
9
|
+
this.durationUnit = config.durationUnit || 'auto';
|
|
10
|
+
this.showWarnings = Boolean(config.showWarnings);
|
|
11
|
+
this.silent = Boolean(config.silent);
|
|
12
|
+
this.successPrefix = config.successPrefix || '✔';
|
|
13
|
+
this.errorPrefix = config.errorPrefix || '✖';
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
formatDuration(duration) {
|
|
17
|
+
if (this.durationUnit === 's') {
|
|
18
|
+
return `${(duration / 1000).toFixed(2)} s`;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (
|
|
22
|
+
this.durationUnit === 'auto'
|
|
23
|
+
&& duration >= 1000
|
|
24
|
+
) {
|
|
25
|
+
return `${(duration / 1000).toFixed(2)} s`;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return `${duration} ms`;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
apply(compiler) {
|
|
32
|
+
compiler.hooks.done.tap(
|
|
33
|
+
'BuildStatusPlugin',
|
|
34
|
+
stats => {
|
|
35
|
+
if (this.silent) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (stats.hasErrors()) {
|
|
40
|
+
console.error(
|
|
41
|
+
`${this.errorPrefix} ${this.name} build failed`
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
let message = `${this.successPrefix} ${this.name} built`;
|
|
48
|
+
|
|
49
|
+
if (this.showDuration) {
|
|
50
|
+
const duration = stats.endTime - stats.startTime;
|
|
51
|
+
|
|
52
|
+
message += ` in ${this.formatDuration(duration)}`;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (
|
|
56
|
+
this.showWarnings
|
|
57
|
+
&& stats.hasWarnings()
|
|
58
|
+
) {
|
|
59
|
+
const { warnings } = stats.toJson({
|
|
60
|
+
all: false,
|
|
61
|
+
warnings: true
|
|
62
|
+
});
|
|
63
|
+
const count = warnings?.length || 0;
|
|
64
|
+
|
|
65
|
+
if (count > 0) {
|
|
66
|
+
message += ` (${count} warning${count === 1 ? '' : 's'})`;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
console.log(message);
|
|
71
|
+
}
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
const currentColorPlugin = {
|
|
2
|
+
name: 'currentColorPlugin',
|
|
3
|
+
description:
|
|
4
|
+
'Processes colors separately for every symbol',
|
|
5
|
+
|
|
6
|
+
fn: () => {
|
|
7
|
+
const walk = (node, callback) => {
|
|
8
|
+
callback(node);
|
|
9
|
+
|
|
10
|
+
node.children?.forEach(child => {
|
|
11
|
+
walk(child, callback);
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const normalize = value => {
|
|
16
|
+
return value?.trim().toLowerCase();
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const isColor = value => {
|
|
20
|
+
const color = normalize(value);
|
|
21
|
+
|
|
22
|
+
return Boolean(
|
|
23
|
+
color
|
|
24
|
+
&& color !== 'none'
|
|
25
|
+
&& color !== 'transparent'
|
|
26
|
+
&& color !== 'currentcolor'
|
|
27
|
+
);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const getStyleValue = (style, property) => {
|
|
31
|
+
if (!style) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const expression = new RegExp(
|
|
36
|
+
`(?:^|;)\\s*${property}\\s*:\\s*([^;]+)`,
|
|
37
|
+
'i'
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
return style.match(expression)?.[1]?.trim() || null;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const replaceStyleColor = (
|
|
44
|
+
style,
|
|
45
|
+
property
|
|
46
|
+
) => {
|
|
47
|
+
const expression = new RegExp(
|
|
48
|
+
`((?:^|;)\\s*${property}\\s*:)\\s*([^;]+)`,
|
|
49
|
+
'gi'
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
return style.replace(
|
|
53
|
+
expression,
|
|
54
|
+
(match, prefix, value) => {
|
|
55
|
+
return isColor(value)
|
|
56
|
+
? `${prefix}currentColor`
|
|
57
|
+
: match;
|
|
58
|
+
}
|
|
59
|
+
);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const processSymbol = symbol => {
|
|
63
|
+
const colors = new Set();
|
|
64
|
+
let containsStroke = false;
|
|
65
|
+
|
|
66
|
+
/*
|
|
67
|
+
* Analyze only the current symbol.
|
|
68
|
+
*/
|
|
69
|
+
walk(symbol, node => {
|
|
70
|
+
if (
|
|
71
|
+
node.type !== 'element'
|
|
72
|
+
|| !node.attributes
|
|
73
|
+
) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const {
|
|
78
|
+
fill,
|
|
79
|
+
stroke,
|
|
80
|
+
style = ''
|
|
81
|
+
} = node.attributes;
|
|
82
|
+
|
|
83
|
+
const styleFill = getStyleValue(
|
|
84
|
+
style,
|
|
85
|
+
'fill'
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
const styleStroke = getStyleValue(
|
|
89
|
+
style,
|
|
90
|
+
'stroke'
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
if (
|
|
94
|
+
isColor(stroke)
|
|
95
|
+
|| isColor(styleStroke)
|
|
96
|
+
) {
|
|
97
|
+
containsStroke = true;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
[
|
|
101
|
+
fill,
|
|
102
|
+
stroke,
|
|
103
|
+
styleFill,
|
|
104
|
+
styleStroke
|
|
105
|
+
].forEach(color => {
|
|
106
|
+
if (isColor(color)) {
|
|
107
|
+
colors.add(normalize(color));
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
const isMulticolor = colors.size > 1;
|
|
113
|
+
|
|
114
|
+
walk(symbol, node => {
|
|
115
|
+
if (
|
|
116
|
+
node.type !== 'element'
|
|
117
|
+
|| !node.attributes
|
|
118
|
+
) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const { attributes } = node;
|
|
123
|
+
|
|
124
|
+
if (
|
|
125
|
+
node.name === 'svg'
|
|
126
|
+
|| node.name === 'symbol'
|
|
127
|
+
) {
|
|
128
|
+
delete attributes.width;
|
|
129
|
+
delete attributes.height;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const style = attributes.style || '';
|
|
133
|
+
|
|
134
|
+
const styleFill = getStyleValue(
|
|
135
|
+
style,
|
|
136
|
+
'fill'
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
const styleStroke = getStyleValue(
|
|
140
|
+
style,
|
|
141
|
+
'stroke'
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
/*
|
|
145
|
+
* Single-color icon:
|
|
146
|
+
* replace fill/stroke with currentColor.
|
|
147
|
+
*/
|
|
148
|
+
if (!isMulticolor) {
|
|
149
|
+
if (
|
|
150
|
+
isColor(attributes.fill)
|
|
151
|
+
) {
|
|
152
|
+
attributes.fill = 'currentColor';
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (
|
|
156
|
+
isColor(attributes.stroke)
|
|
157
|
+
) {
|
|
158
|
+
attributes.stroke = 'currentColor';
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (attributes.style) {
|
|
162
|
+
attributes.style = replaceStyleColor(
|
|
163
|
+
attributes.style,
|
|
164
|
+
'fill'
|
|
165
|
+
);
|
|
166
|
+
|
|
167
|
+
attributes.style = replaceStyleColor(
|
|
168
|
+
attributes.style,
|
|
169
|
+
'stroke'
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/*
|
|
175
|
+
* The path has no fill or stroke,
|
|
176
|
+
* and the icon itself is not outlined.
|
|
177
|
+
*/
|
|
178
|
+
if (
|
|
179
|
+
node.name === 'path'
|
|
180
|
+
&& !containsStroke
|
|
181
|
+
&& attributes.fill == null
|
|
182
|
+
&& attributes.stroke == null
|
|
183
|
+
&& styleFill == null
|
|
184
|
+
&& styleStroke == null
|
|
185
|
+
) {
|
|
186
|
+
attributes.fill = 'currentColor';
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
return {
|
|
192
|
+
root: {
|
|
193
|
+
exit(root) {
|
|
194
|
+
const symbols = [];
|
|
195
|
+
|
|
196
|
+
walk(root, node => {
|
|
197
|
+
if (
|
|
198
|
+
node.type === 'element'
|
|
199
|
+
&& node.name === 'symbol'
|
|
200
|
+
) {
|
|
201
|
+
symbols.push(node);
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
/*
|
|
206
|
+
* Process each symbol independently.
|
|
207
|
+
*/
|
|
208
|
+
if (symbols.length) {
|
|
209
|
+
symbols.forEach(processSymbol);
|
|
210
|
+
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/*
|
|
215
|
+
* Fallback for cases where SVGO processes
|
|
216
|
+
* the source SVG before a symbol is created.
|
|
217
|
+
*/
|
|
218
|
+
processSymbol(root);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
export default currentColorPlugin;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import webpack from 'webpack';
|
|
2
|
+
|
|
3
|
+
export default class RemoveFilesOnlyJsPlugin {
|
|
4
|
+
constructor(options = {}) {
|
|
5
|
+
this.test = options.test ?? /^styles\.js(\.map)?$/;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
apply(compiler) {
|
|
9
|
+
compiler.hooks.thisCompilation.tap('RemoveFilesOnlyJsPlugin', (compilation) => {
|
|
10
|
+
const { Compilation } = webpack;
|
|
11
|
+
|
|
12
|
+
compilation.hooks.processAssets.tap(
|
|
13
|
+
{
|
|
14
|
+
name: 'RemoveFilesOnlyJsPlugin',
|
|
15
|
+
stage: Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE
|
|
16
|
+
},
|
|
17
|
+
(assets) => {
|
|
18
|
+
Object.keys(assets).forEach((name) => {
|
|
19
|
+
if (this.test.test(name)) {
|
|
20
|
+
// eslint-disable-next-line no-param-reassign
|
|
21
|
+
delete compilation.assets[name];
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}
|