@newlogic-digital/core 0.9.14 → 1.0.0-beta.3
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 +15 -45
- package/index.js +262 -43
- package/package.json +13 -57
- package/LICENSE +0 -674
- package/modules/Core.js +0 -626
- package/modules/Emails.js +0 -110
- package/modules/Icons.js +0 -140
- package/modules/Scripts.js +0 -321
- package/modules/Serve.js +0 -124
- package/modules/Styles.js +0 -298
- package/modules/Templates.js +0 -477
- package/modules/Utils.js +0 -299
- package/modules/Watch.js +0 -75
- package/modules/tailwind/index.cjs +0 -84
- package/modules/tailwind/index.js +0 -75
- package/packages/gulp-clean-css/LICENSE +0 -20
- package/packages/gulp-clean-css/README.md +0 -79
- package/packages/gulp-clean-css/index.js +0 -66
- package/packages/gulp-clean-css/package.json +0 -68
- package/packages/gulp-twig2html/CHANGELOG.md +0 -77
- package/packages/gulp-twig2html/LICENSE +0 -22
- package/packages/gulp-twig2html/README.md +0 -112
- package/packages/gulp-twig2html/index.js +0 -30
- package/packages/gulp-twig2html/package.json +0 -47
- package/packages/postcss-inset/CHANGELOG.md +0 -5
- package/packages/postcss-inset/LICENSE.md +0 -106
- package/packages/postcss-inset/README.md +0 -121
- package/packages/postcss-inset/index.cjs.js +0 -49
- package/packages/postcss-inset/index.es.mjs +0 -47
- package/packages/postcss-inset/index.js +0 -47
- package/packages/postcss-inset/package.json +0 -58
- package/packages/twig-renderer/CHANGELOG.md +0 -66
- package/packages/twig-renderer/LICENSE +0 -22
- package/packages/twig-renderer/README.md +0 -93
- package/packages/twig-renderer/package.json +0 -49
- package/packages/twig-renderer/twig-renderer.js +0 -90
package/modules/Serve.js
DELETED
@@ -1,124 +0,0 @@
|
|
1
|
-
import autoprefixer from "autoprefixer";
|
2
|
-
import lodash from "lodash";
|
3
|
-
import {Config, Exists, Styles, Utils} from "./Core.js";
|
4
|
-
import fs from "fs";
|
5
|
-
import path from "path";
|
6
|
-
import os from "os";
|
7
|
-
import {createRequire} from "module";
|
8
|
-
import chalk from "chalk";
|
9
|
-
const require = createRequire(import.meta.url);
|
10
|
-
|
11
|
-
export const Serve = new class {
|
12
|
-
init() {
|
13
|
-
return new Promise(async (resolve) => {
|
14
|
-
const { createServer } = (await import('vite'));
|
15
|
-
const tailwindcss = (await import("tailwindcss")).default;
|
16
|
-
|
17
|
-
const ratio = {
|
18
|
-
name: 'ratio',
|
19
|
-
transformIndexHtml(html) {
|
20
|
-
return html.replace("</head>", `<style>${new Styles().ratio(Config.styles.ratio.content)}</style></head>`)
|
21
|
-
}
|
22
|
-
}
|
23
|
-
|
24
|
-
const middleware = {
|
25
|
-
name: 'middleware',
|
26
|
-
apply: 'serve',
|
27
|
-
configureServer(viteDevServer) {
|
28
|
-
return () => {
|
29
|
-
viteDevServer.middlewares.use(async (context, res, next) => {
|
30
|
-
if (!context.originalUrl.endsWith(".html") && context.originalUrl !== "/") {
|
31
|
-
context.url = `/${Config.paths.output.root}` + context.originalUrl + ".html";
|
32
|
-
} else if (context.url === "/index.html") {
|
33
|
-
context.url = `/${Config.paths.output.root}` + context.url;
|
34
|
-
}
|
35
|
-
|
36
|
-
next();
|
37
|
-
});
|
38
|
-
};
|
39
|
-
}
|
40
|
-
}
|
41
|
-
|
42
|
-
const reload = {
|
43
|
-
name: 'reload',
|
44
|
-
handleHotUpdate({ file, server }) {
|
45
|
-
if ((!file.includes('.json') && !file.includes('.html') && file.includes(`/${Config.paths.output.root}/`)) || Config.serve.reload(file)) {
|
46
|
-
server.ws.send({
|
47
|
-
type: 'full-reload',
|
48
|
-
path: '*',
|
49
|
-
});
|
50
|
-
}
|
51
|
-
}
|
52
|
-
}
|
53
|
-
|
54
|
-
const reloadTailwind = {
|
55
|
-
name: 'reload-tailwind',
|
56
|
-
transformIndexHtml(html) {
|
57
|
-
return html.replace('tailwind.css', 'tailwind.css?v=' + new Date().getTime())
|
58
|
-
}
|
59
|
-
}
|
60
|
-
|
61
|
-
let config = {
|
62
|
-
plugins: (Config.serve.mode === "dev" && Config.styles.ratio.enabled) ? [middleware, ratio, reload, reloadTailwind] : [middleware, reload, reloadTailwind],
|
63
|
-
publicDir: `${Config.paths.output.root}`,
|
64
|
-
server: {
|
65
|
-
open: Config.serve.index,
|
66
|
-
host: true,
|
67
|
-
fsServe: {
|
68
|
-
strict: false
|
69
|
-
},
|
70
|
-
watch: {
|
71
|
-
ignored: ['**/node_modules/**', '**/.git/**', '**/src/templates/**', '**/src/main.json', `**/${Config.paths.output.root}/*.html`]
|
72
|
-
}
|
73
|
-
},
|
74
|
-
root: process.cwd(),
|
75
|
-
};
|
76
|
-
|
77
|
-
if (fs.existsSync(path.join(os.homedir(),`.ssh/${Config.serve.cert}.pem`)) && Config.serve.https) {
|
78
|
-
lodash.merge(config, {
|
79
|
-
server: {
|
80
|
-
https: {
|
81
|
-
key: fs.readFileSync(path.join(os.homedir(),`.ssh/${Config.serve.cert}-key.pem`)),
|
82
|
-
cert: fs.readFileSync(path.join(os.homedir(),`.ssh/${Config.serve.cert}.pem`)),
|
83
|
-
},
|
84
|
-
hmr: {
|
85
|
-
host: 'localhost'
|
86
|
-
}
|
87
|
-
}
|
88
|
-
})
|
89
|
-
}
|
90
|
-
|
91
|
-
let tailwindcssConfig = {}
|
92
|
-
|
93
|
-
if (!Exists.tailwindConfig) {
|
94
|
-
tailwindcssConfig = { config: Config.tailwind }
|
95
|
-
}
|
96
|
-
|
97
|
-
let css = {
|
98
|
-
css: {
|
99
|
-
postcss: {
|
100
|
-
plugins: new Utils().postcssPlugins(Config.styles.postcss, [tailwindcss(tailwindcssConfig), autoprefixer])
|
101
|
-
}
|
102
|
-
}
|
103
|
-
}
|
104
|
-
|
105
|
-
if (!Exists.postcssConfig && Config.serve.mode === "dev") {
|
106
|
-
config = lodash.merge(config, css)
|
107
|
-
}
|
108
|
-
|
109
|
-
lodash.merge(config, Config.serve.vite);
|
110
|
-
|
111
|
-
this.server = await createServer(config)
|
112
|
-
|
113
|
-
await this.server.listen()
|
114
|
-
|
115
|
-
console.log(chalk.cyan(`\n vite v${require('vite/package.json').version}`) + chalk.green(` dev server running at:\n`))
|
116
|
-
|
117
|
-
this.server.printUrls()
|
118
|
-
|
119
|
-
console.log(" ");
|
120
|
-
|
121
|
-
resolve();
|
122
|
-
})
|
123
|
-
}
|
124
|
-
}
|
package/modules/Styles.js
DELETED
@@ -1,298 +0,0 @@
|
|
1
|
-
import lodash from "lodash";
|
2
|
-
import fs from "fs";
|
3
|
-
import lazypipe from "lazypipe";
|
4
|
-
import gulp from "gulp";
|
5
|
-
import plumber from "gulp-plumber";
|
6
|
-
import gulpif from "gulp-if";
|
7
|
-
import postcss from "gulp-postcss";
|
8
|
-
import autoprefixer from "autoprefixer";
|
9
|
-
import glob from "glob";
|
10
|
-
import through from "through2";
|
11
|
-
import {Config, Exists, Functions, Modules, Utils, root} from "./Core.js";
|
12
|
-
|
13
|
-
const aspectRatio = () => {
|
14
|
-
return {
|
15
|
-
postcssPlugin: 'aspect-ratio',
|
16
|
-
Declaration: {
|
17
|
-
'aspect-ratio': (decl, {Rule, Declaration}) => {
|
18
|
-
const rule = decl.parent
|
19
|
-
const selector = rule.selector
|
20
|
-
const beforeRule = new Rule({selector: `${selector}:before`, raws: {after: rule.raws.after, semicolon: rule.raws.semicolon}})
|
21
|
-
const ratio = decl.value.replace(/['"]?((?:\d*\.?\d*)?)(?:\s*[:|\/]\s*)(\d*\.?\d*)['"]?/g, (match, width, height) => {
|
22
|
-
return (height / width) * 100 + '%'
|
23
|
-
})
|
24
|
-
|
25
|
-
beforeRule.append([
|
26
|
-
new Declaration({prop: 'padding-bottom', value: ratio}),
|
27
|
-
])
|
28
|
-
|
29
|
-
rule.after(beforeRule)
|
30
|
-
|
31
|
-
rule.nodes.length === 1 ? rule.remove() : decl.remove()
|
32
|
-
},
|
33
|
-
}
|
34
|
-
}
|
35
|
-
}
|
36
|
-
|
37
|
-
aspectRatio.postcss = true;
|
38
|
-
|
39
|
-
export class Styles {
|
40
|
-
get purge() {
|
41
|
-
return {
|
42
|
-
files: () => {
|
43
|
-
let purgeFiles = Config.styles.purge.content;
|
44
|
-
let dependencies = JSON.parse(fs.readFileSync(`package.json`).toString()).dependencies;
|
45
|
-
|
46
|
-
if (typeof dependencies !== "undefined" && Config.styles.purge.nodeResolve) {
|
47
|
-
Object.keys(dependencies).map(lib => {
|
48
|
-
if (!Config.styles.purge.nodeResolveIgnore.includes(lib)) {
|
49
|
-
purgeFiles.push(`node_modules/${lib}/**/*.js`)
|
50
|
-
}
|
51
|
-
});
|
52
|
-
}
|
53
|
-
|
54
|
-
if (Config.styles.purge.docs) {
|
55
|
-
purgeFiles = purgeFiles.toString().replace("/*." + Config.templates.format, "/!(Ui)." + Config.templates.format).split(",");
|
56
|
-
}
|
57
|
-
|
58
|
-
return purgeFiles;
|
59
|
-
},
|
60
|
-
config: () => {
|
61
|
-
return Object.assign({
|
62
|
-
content: this.purge.files(),
|
63
|
-
extractors: [
|
64
|
-
{
|
65
|
-
extractor: content => content.match(/[\w-/:]+(?<!:)/g) || [],
|
66
|
-
extensions: ['html', 'js', 'hbs', 'tpl', 'latte', 'twig']
|
67
|
-
}
|
68
|
-
]
|
69
|
-
}, Config.styles.purge.options)
|
70
|
-
}
|
71
|
-
}
|
72
|
-
}
|
73
|
-
ratio(source, file) {
|
74
|
-
let sourceFiles = [],
|
75
|
-
ratios = [];
|
76
|
-
|
77
|
-
source.forEach((pathPattern) => {
|
78
|
-
let files = glob.sync(pathPattern);
|
79
|
-
sourceFiles = sourceFiles.concat(files);
|
80
|
-
});
|
81
|
-
|
82
|
-
sourceFiles.forEach((path) => {
|
83
|
-
let data = fs.readFileSync(path);
|
84
|
-
if (data.toString().indexOf('data-ratio') >= 0) {
|
85
|
-
ratios = ratios.concat(data.toString().match(/data-ratio="([0-9-/ _]*)"/g));
|
86
|
-
}
|
87
|
-
});
|
88
|
-
|
89
|
-
let ratiosFinal = Array.from(new Set(ratios)),
|
90
|
-
ratiosStyles = [];
|
91
|
-
|
92
|
-
const ratio = (val) => {
|
93
|
-
let value = `[${val}]{aspect-ratio: ${val.match(/\d+/g)[0]} / ${val.match(/\d+/g)[1]}}`;
|
94
|
-
|
95
|
-
if (typeof file !== "undefined" && file.extname === ".less") {
|
96
|
-
let calc = (val.match(/\d+/g)[1] / val.match(/\d+/g)[0]) * 100;
|
97
|
-
value = `[${val}]:before{padding-bottom: ${calc}%}`
|
98
|
-
}
|
99
|
-
|
100
|
-
return value;
|
101
|
-
}
|
102
|
-
|
103
|
-
ratiosFinal.forEach((val) => {
|
104
|
-
ratiosStyles.push(ratio(val));
|
105
|
-
});
|
106
|
-
|
107
|
-
return ratiosStyles.join("\n");
|
108
|
-
}
|
109
|
-
importResolution() {
|
110
|
-
return new Promise(resolve => {
|
111
|
-
Config.styles.importResolution.directories.map(directory => {
|
112
|
-
if (!fs.existsSync(`${root + Config.paths.input.styles}/${directory}`)) {
|
113
|
-
console.log("\x1b[31m", `importResolution - ${root + Config.paths.input.styles}/${directory} doesn't exists`, "\x1b[0m");
|
114
|
-
return false;
|
115
|
-
}
|
116
|
-
|
117
|
-
let items = fs.readdirSync(`${root + Config.paths.input.styles}/${directory}`);
|
118
|
-
|
119
|
-
function findPaths(items, directory) {
|
120
|
-
let imports = "";
|
121
|
-
|
122
|
-
items.map(item => {
|
123
|
-
let path = `${directory}/${item}`;
|
124
|
-
|
125
|
-
if (fs.statSync(path).isFile()) {
|
126
|
-
if (path.includes(`.${Config.styles.format}`) && !path.includes(Config.styles.importResolution.filename)) {
|
127
|
-
imports = imports + `@import "${item}";\r\n`
|
128
|
-
}
|
129
|
-
} else {
|
130
|
-
if (Config.styles.importResolution.subDir) {
|
131
|
-
imports = imports + `@import "${item}/${Config.styles.importResolution.filename}";\r\n`
|
132
|
-
}
|
133
|
-
findPaths(fs.readdirSync(path), path);
|
134
|
-
}
|
135
|
-
});
|
136
|
-
|
137
|
-
let path = `${directory}/${Config.styles.importResolution.filename}`;
|
138
|
-
|
139
|
-
if (imports.length !== 0) {
|
140
|
-
if (fs.existsSync(path) && fs.readFileSync(path).toString() !== imports || !fs.existsSync(path)) {
|
141
|
-
fs.writeFileSync(path, imports);
|
142
|
-
}
|
143
|
-
} else if (fs.readFileSync(path).toString() !== "/* empty */") {
|
144
|
-
fs.writeFileSync(path, "/* empty */");
|
145
|
-
}
|
146
|
-
}
|
147
|
-
|
148
|
-
findPaths(items, `${root + Config.paths.input.styles}/${directory}`);
|
149
|
-
});
|
150
|
-
|
151
|
-
if (Config.styles.ratio.enabled) {
|
152
|
-
fs.writeFileSync(`${root + Config.paths.temp}/ratio.css`, new Styles().ratio(Config.styles.ratio.content))
|
153
|
-
}
|
154
|
-
|
155
|
-
resolve();
|
156
|
-
})
|
157
|
-
}
|
158
|
-
async tailwind() {
|
159
|
-
const cleanCSS = (await import("../packages/gulp-clean-css/index.js")).default;
|
160
|
-
const tailwindcss = (await import("tailwindcss")).default;
|
161
|
-
const purgeCSS = (await import("gulp-purgecss")).default;
|
162
|
-
|
163
|
-
if (!fs.existsSync(`${root + Config.paths.input.styles}/${Config.styles.tailwind.basename}`)) {
|
164
|
-
return new Promise(resolve => resolve())
|
165
|
-
}
|
166
|
-
|
167
|
-
return new Promise(resolve => {
|
168
|
-
if (fs.existsSync(`${root + Config.paths.temp}/${Config.styles.tailwind.basename}`) && Config.styles.tailwind.cache) {
|
169
|
-
resolve();
|
170
|
-
return false;
|
171
|
-
}
|
172
|
-
|
173
|
-
const clean = lazypipe().pipe(cleanCSS, lodash.merge({
|
174
|
-
inline: Config.styles.import,
|
175
|
-
level: {1: {specialComments: 0}, 2: {all: false}}
|
176
|
-
}, Config.styles.clean), (details) => {
|
177
|
-
if (details.warnings.length > 0) {
|
178
|
-
details.warnings.map(warning => console.log("\x1b[32m", warning, "\x1b[0m"))
|
179
|
-
}
|
180
|
-
});
|
181
|
-
|
182
|
-
let tailwindcssConfig = {};
|
183
|
-
|
184
|
-
if (!Exists.tailwindConfig) {
|
185
|
-
tailwindcssConfig = { config: Config.tailwind }
|
186
|
-
}
|
187
|
-
|
188
|
-
gulp.src(`${root + Config.paths.input.styles}/${Config.styles.tailwind.basename}`)
|
189
|
-
.pipe(postcss(new Utils().postcssPlugins(Config.styles.tailwind.postcss, [tailwindcss(tailwindcssConfig), aspectRatio, autoprefixer])))
|
190
|
-
.pipe(gulpif(Config.styles.optimizations, clean()))
|
191
|
-
.pipe(gulp.dest(root + Config.paths.temp))
|
192
|
-
.on("end", resolve)
|
193
|
-
})
|
194
|
-
}
|
195
|
-
async build() {
|
196
|
-
const cleanCSS = (await import("../packages/gulp-clean-css/index.js")).default;
|
197
|
-
const purgeCSS = (await import("gulp-purgecss")).default;
|
198
|
-
const revision = (await import("gulp-rev")).default;
|
199
|
-
const revRewrite = (await import("gulp-rev-rewrite")).default;
|
200
|
-
const inset = (await import("../packages/postcss-inset/index.es.mjs")).default;
|
201
|
-
|
202
|
-
const clean = lazypipe().pipe(cleanCSS, lodash.merge({
|
203
|
-
inline: Config.styles.import,
|
204
|
-
level: {1: {specialComments: 0}, 2: {removeEmpty: true}}
|
205
|
-
}, Config.styles.clean), (details) => {
|
206
|
-
if (details.warnings.length > 0) {
|
207
|
-
details.warnings.map(warning => console.log("\x1b[32m", warning, "\x1b[0m"))
|
208
|
-
}
|
209
|
-
});
|
210
|
-
|
211
|
-
const purge = lazypipe().pipe(purgeCSS, new Styles().purge.config());
|
212
|
-
|
213
|
-
const rev = lazypipe().pipe(revision).pipe(Functions.revUpdate, true, "styles")
|
214
|
-
.pipe(revRewrite, {manifest: fs.existsSync(`${root + Config.paths.output.assets}/rev-manifest.json`) ? fs.readFileSync(`${root + Config.paths.output.assets}/rev-manifest.json`) : ""});
|
215
|
-
|
216
|
-
const ratio = (source) => {
|
217
|
-
return through.obj((file, enc, cb) => {
|
218
|
-
if (!Config.styles.ratio.files.includes(file.basename)) {
|
219
|
-
cb(null, file);
|
220
|
-
return false;
|
221
|
-
}
|
222
|
-
|
223
|
-
if (file.isNull()) {
|
224
|
-
cb(null, file);
|
225
|
-
}
|
226
|
-
|
227
|
-
if (file.isBuffer()) {
|
228
|
-
file.contents = Buffer.from(file.contents.toString() + "\n" + new Styles().ratio(source, file));
|
229
|
-
cb(null, file);
|
230
|
-
}
|
231
|
-
});
|
232
|
-
};
|
233
|
-
|
234
|
-
const vendor = () => {
|
235
|
-
return through.obj((file, enc, cb) => {
|
236
|
-
if (file.isNull()) {
|
237
|
-
cb(null, file);
|
238
|
-
}
|
239
|
-
if (file.isBuffer()) {
|
240
|
-
if (Config.styles.vendor.path.length !== 0 && (fs.existsSync(`${root + Config.paths.input.styles}/${Config.styles.vendor.path}`) && Config.local === true || fs.existsSync(`${root + Config.paths.input.styles}/${Config.styles.vendor.path}`) && Config.styles.vendor.cache === true)) {
|
241
|
-
let vendorUrl = fs.readFileSync(`${root + Config.paths.input.styles}/${Config.styles.vendor.path}`).toString().replace(/url\((.*)\//g,`url(../../${Config.paths.cdn}/`);
|
242
|
-
|
243
|
-
file.contents = Buffer.from(file.contents.toString().replace(`@import "${Config.styles.vendor.path}";`, vendorUrl));
|
244
|
-
}
|
245
|
-
cb(null, file);
|
246
|
-
}
|
247
|
-
});
|
248
|
-
}
|
249
|
-
|
250
|
-
const join = () => {
|
251
|
-
return through.obj((file, enc, cb) => {
|
252
|
-
if (file.isNull()) {
|
253
|
-
cb(null, file);
|
254
|
-
}
|
255
|
-
if (file.isBuffer()) {
|
256
|
-
Object.keys(Config.styles.join).forEach(joinFile => {
|
257
|
-
if (joinFile === file.basename) {
|
258
|
-
let contents = file.contents.toString();
|
259
|
-
|
260
|
-
Config.styles.join[joinFile].forEach(targetFile => {
|
261
|
-
if (fs.existsSync(root + targetFile)) {
|
262
|
-
contents += fs.readFileSync(root + targetFile).toString();
|
263
|
-
}
|
264
|
-
})
|
265
|
-
|
266
|
-
file.contents = Buffer.from(contents);
|
267
|
-
}
|
268
|
-
});
|
269
|
-
cb(null, file);
|
270
|
-
}
|
271
|
-
});
|
272
|
-
}
|
273
|
-
|
274
|
-
const build = lazypipe().pipe(() => gulpif("*.css", postcss(new Utils().postcssPlugins(Config.styles.postcss, [autoprefixer, aspectRatio, inset])))
|
275
|
-
).pipe(() => gulpif("*.less", Modules.less.module()));
|
276
|
-
|
277
|
-
return new Promise(resolve => {
|
278
|
-
gulp.src([`${root + Config.paths.input.styles}/*.{css,less}`, `!${root + Config.paths.input.styles}/${Config.styles.tailwind.basename}`, `!${root + Config.paths.input.styles}/*-modifiers.less`])
|
279
|
-
.pipe(plumber(Functions.plumber))
|
280
|
-
.pipe(gulpif(Config.styles.ratio.enabled, ratio(Config.styles.ratio.content)))
|
281
|
-
.pipe(vendor())
|
282
|
-
.pipe(build())
|
283
|
-
.pipe(Functions.revRewriteOutput())
|
284
|
-
.pipe(gulpif(Config.styles.purge.enabled, purge()))
|
285
|
-
.pipe(Modules.autoprefixer.pipe())
|
286
|
-
.pipe(gulpif(Config.styles.optimizations, clean()))
|
287
|
-
.pipe(join())
|
288
|
-
.pipe(gulpif(Config.styles.revision, rev()))
|
289
|
-
.pipe(gulp.dest(root + Config.paths.output.styles))
|
290
|
-
.pipe(revision.manifest(root + Config.paths.output.styles + "/rev-manifest.json",{
|
291
|
-
merge: true,
|
292
|
-
base: root + Config.paths.output.styles
|
293
|
-
}))
|
294
|
-
.pipe(gulp.dest(root + Config.paths.output.styles))
|
295
|
-
.on("end", resolve)
|
296
|
-
})
|
297
|
-
}
|
298
|
-
}
|