@newlogic-digital/core 0.9.15 → 1.0.0

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.
Files changed (36) hide show
  1. package/README.md +20 -47
  2. package/index.js +270 -43
  3. package/package.json +14 -55
  4. package/LICENSE +0 -674
  5. package/modules/Core.js +0 -626
  6. package/modules/Emails.js +0 -123
  7. package/modules/Icons.js +0 -140
  8. package/modules/Scripts.js +0 -321
  9. package/modules/Serve.js +0 -124
  10. package/modules/Styles.js +0 -298
  11. package/modules/Templates.js +0 -478
  12. package/modules/Utils.js +0 -299
  13. package/modules/Watch.js +0 -75
  14. package/modules/tailwind/index.cjs +0 -84
  15. package/modules/tailwind/index.js +0 -75
  16. package/packages/gulp-clean-css/LICENSE +0 -20
  17. package/packages/gulp-clean-css/README.md +0 -79
  18. package/packages/gulp-clean-css/index.js +0 -66
  19. package/packages/gulp-clean-css/package.json +0 -68
  20. package/packages/gulp-twig2html/CHANGELOG.md +0 -77
  21. package/packages/gulp-twig2html/LICENSE +0 -22
  22. package/packages/gulp-twig2html/README.md +0 -112
  23. package/packages/gulp-twig2html/index.js +0 -30
  24. package/packages/gulp-twig2html/package.json +0 -47
  25. package/packages/postcss-inset/CHANGELOG.md +0 -5
  26. package/packages/postcss-inset/LICENSE.md +0 -106
  27. package/packages/postcss-inset/README.md +0 -121
  28. package/packages/postcss-inset/index.cjs.js +0 -49
  29. package/packages/postcss-inset/index.es.mjs +0 -47
  30. package/packages/postcss-inset/index.js +0 -47
  31. package/packages/postcss-inset/package.json +0 -58
  32. package/packages/twig-renderer/CHANGELOG.md +0 -66
  33. package/packages/twig-renderer/LICENSE +0 -22
  34. package/packages/twig-renderer/README.md +0 -93
  35. package/packages/twig-renderer/package.json +0 -49
  36. package/packages/twig-renderer/twig-renderer.js +0 -90
@@ -1,478 +0,0 @@
1
- import fs from "fs";
2
- import path from "path";
3
- import lazypipe from "lazypipe";
4
- import gulpif from "gulp-if";
5
- import twig from "../packages/gulp-twig2html/index.js";
6
- import lodash from "lodash";
7
- import gulp from "gulp";
8
- import plumber from "gulp-plumber";
9
- import minifier from "html-minifier";
10
- import through from "through2";
11
- import Prism from 'prismjs'
12
- import loadLanguages from 'prismjs/components/index.js'
13
- import NormalizeWhitespace from 'prismjs/plugins/normalize-whitespace/prism-normalize-whitespace.js'
14
- import {Config, Exists, Functions, Modules, root} from "./Core.js";
15
-
16
- loadLanguages(['markup', 'css', 'javascript'])
17
-
18
- export class Templates {
19
- get functions() {
20
- return Object.assign(Config.templates.functions, {
21
- "color": (color, theme) => {
22
- if (typeof theme === "undefined") {
23
- theme = "main"
24
- }
25
-
26
- if (!Exists.styles) {
27
- return "inherit"
28
- }
29
-
30
- if ((theme || color) && Config.styles.themePath.length !== 0) {
31
- let pathColors = Config.styles.themePath.replace("{THEME}", theme).replace("{FORMAT}", Config.styles.format);
32
-
33
- if (fs.existsSync(`${root + Config.paths.input.styles}/${pathColors}`)) {
34
- let colors = fs.readFileSync(`${root + Config.paths.input.styles}/${pathColors}`, 'utf8').toString();
35
- let parse = colors.substring(colors.indexOf(color)+color.length+1,colors.length);
36
-
37
- return parse.substring(0,parse.indexOf(";")).replace(" ", "");
38
- }
39
- }
40
- },
41
- "fetch": (data) => {
42
- if (typeof data !== "undefined") {
43
- if (!fs.existsSync(root + Config.paths.cdn)){
44
- fs.mkdirSync(root + Config.paths.cdn);
45
- }
46
- if (data.indexOf("http") > -1) {
47
- if (data.indexOf("googleapis.com") > -1) {
48
- let google_name = data.substring(data.indexOf("=") + 1, data.length).toLowerCase(),
49
- google_name_path = root + Config.paths.cdn + "/inline." + google_name.substring(0,google_name.indexOf(":")) + ".css";
50
-
51
- if (fs.existsSync(google_name_path)) {
52
- return fs.readFileSync(google_name_path, 'utf8').toString();
53
- } else {
54
- (async() => await Functions.download(data, google_name_path))()
55
-
56
- return fs.readFileSync(google_name_path, 'utf8').toString();
57
- }
58
- } else {
59
- let font_name = data.substring(data.lastIndexOf("/") + 1, data.length).toLowerCase(),
60
- font_name_path = root + Config.paths.cdn + "/inline." + font_name;
61
-
62
- if (fs.existsSync(font_name_path)) {
63
- return fs.readFileSync(font_name_path, 'utf8').toString();
64
- } else {
65
- (async() => await Functions.download(data, font_name_path))()
66
-
67
- return fs.readFileSync(font_name_path, 'utf8').toString();
68
- }
69
- }
70
- } else {
71
- let slash = data.indexOf("/")+1;
72
- if (slash > 1) {
73
- slash = 0;
74
- }
75
-
76
- return fs.readFileSync(root + data.substring(slash,data.length),'utf8').toString();
77
- }
78
- }
79
- },
80
- "randomColor": () => {
81
- return "#" + Math.random().toString(16).slice(2, 8);
82
- },
83
- "placeholder": (width, height, picsum, colors) => {
84
- if (typeof colors === "undefined") {
85
- colors = ["333", "444", "666", "222", "777", "888", "111"];
86
- } else {
87
- colors = [colors]
88
- }
89
- if (Config.local === false) {
90
- let webp = "";
91
- if (Config.templates.placeholder.webp === true) {
92
- webp = ".webp"
93
- }
94
- if (!Config.templates.placeholder.picsum) {
95
- if(Config.templates.placeholder.lorempixel === ""){
96
-
97
- return "https://via.placeholder.com/"+width+"x"+height+"/"+colors[Math.floor(Math.random()*colors.length)]+`${webp}`;
98
- }
99
- else {
100
- return "https://lorempixel.com/"+width+"/"+height+"/"+Config.templates.placeholder.lorempixel+"/"+Math.floor(Math.random()*10);
101
- }
102
- } else {
103
- if (!isNaN(picsum)) {
104
- return "https://picsum.photos/"+width+"/"+height+webp+"?image="+ picsum;
105
- } else {
106
- return "https://picsum.photos/"+width+"/"+height+webp+"?image="+ Math.floor(Math.random() * 100);
107
- }
108
- }
109
- } else {
110
- let text = width+"x"+height,
111
- svg = encodeURIComponent(Functions.stripIndent('<svg width="'+width+'" height="'+height+'" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 '+width+' '+height+'" preserveAspectRatio="none"><defs><style type="text/css">#holder text {fill: #969696;font-family: sans-serif;font-size: 18px;font-weight: normal}</style></defs><g id="holder"><rect width="100%" height="100%" fill="#'+colors[Math.floor(Math.random()*colors.length)]+'"></rect><g><text text-anchor="middle" x="50%" y="50%" dy=".3em">'+text+'</text></g></g></svg>'));
112
-
113
- return "data:image/svg+xml;charset=UTF-8,"+svg;
114
- }
115
- },
116
- "lazy": (width, height) => {
117
- let svg = encodeURIComponent(Functions.stripIndent('<svg width="'+width+'" height="'+height+'" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 '+width+' '+height+'"></svg>'));
118
-
119
- return "data:image/svg+xml;charset=UTF-8,"+svg;
120
- },
121
- "ratio": (width, height) => {
122
- return (height/width) * 100;
123
- },
124
- "webfont": (data) => {
125
- let urls = [];
126
-
127
- if (typeof data["google"] !== "undefined") {
128
- data["google"]["families"].forEach(function(i){
129
- urls.push("https://fonts.googleapis.com/css2?family="+i);
130
- });
131
- }
132
-
133
- if (typeof data["typekit"] !== "undefined") {
134
- urls.push(`https://use.typekit.net/${data["typekit"]["id"]}.css`);
135
- }
136
-
137
- if (typeof data["custom"] !== "undefined") {
138
- data["custom"]["urls"].forEach(function(i){
139
- urls.push(i);
140
- });
141
- }
142
-
143
- return urls;
144
- }
145
- })
146
- }
147
- get filters() {
148
- return Object.assign(Config.templates.filters, {
149
- "asset": (url) => {
150
- let directoryPath = "";
151
-
152
- if (Config.serve.mode === "dev" && url.indexOf("/" + Config.paths.input.root) === 0 || url.includes("https://") || url.includes("http://")) {
153
- return url;
154
- }
155
-
156
- if (Config.serve.mode !== "dev" && url.indexOf("/" + Config.paths.input.root) === 0) {
157
- url = url
158
- .replace(`/${Config.paths.input.styles}`, `/${Config.paths.output.styles}`)
159
- .replace(`/${Config.paths.input.scripts}`, `/${Config.paths.output.scripts}`)
160
- .replace(`/${Config.paths.input.assets}`, `/${Config.paths.output.assets}`)
161
- .replace(`/${Config.paths.input.icons}`, `/${Config.paths.output.icons}`)
162
- .replace(".less", ".css")
163
- }
164
-
165
- directoryPath = url.substr(0, url.lastIndexOf("/"));
166
-
167
- if (directoryPath.indexOf("/") === 0) {
168
- directoryPath = directoryPath.slice(1);
169
- }
170
-
171
- if (fs.existsSync(root + `${directoryPath}/rev-manifest.json`)) {
172
- let rev = JSON.parse(fs.readFileSync(root + `${directoryPath}/rev-manifest.json`, 'utf8').toString());
173
-
174
- Object.keys(rev).forEach(function eachKey(key) {
175
- if (url.indexOf(key) > -1) {
176
- url = url.replace(key,rev[key]);
177
- }
178
- })
179
- } else if (directoryPath.indexOf(Config.paths.output.assets) !== -1 && fs.existsSync(`${root + Config.paths.output.assets}/rev-manifest.json`)) {
180
- let rev = JSON.parse(fs.readFileSync(root + Config.paths.output.assets + '/rev-manifest.json', 'utf8').toString());
181
-
182
- Object.keys(rev).forEach(function eachKey(key) {
183
- if (url.indexOf(key) > -1) {
184
- url = url.replace(key,rev[key]);
185
- }
186
- })
187
- }
188
-
189
- if (Config.paths.output.rewrite && url.indexOf(`/${Config.paths.output.root}`) === 0) {
190
- url = url.replace(`/${Config.paths.output.root}`, Config.paths.base.length > 0 ? `/${Config.paths.base}` : "")
191
- }
192
-
193
- return url;
194
- },
195
- "rem": (value) => {
196
- return `${value/16}rem`;
197
- },
198
- "encode64": (path) => {
199
- let svg = encodeURIComponent(Functions.stripIndent(path));
200
-
201
- return "data:image/svg+xml;charset=UTF-8,"+svg;
202
- },
203
- "exists": (path) => {
204
- if (path.indexOf("/") === 0) {
205
- path = path.slice(1);
206
- }
207
-
208
- return fs.existsSync(root + path)
209
- },
210
- "tel": (value) => {
211
- return value.replace(/\s+/g, '').replace("(","").replace(")","");
212
- }
213
- })
214
- }
215
- get tags() {
216
- return Config.templates.tags.concat([
217
- (Twig) => {
218
- Twig.exports.extendTag({
219
- type: "code",
220
- regex: /^code\s+(.+)$/,
221
- next: ["endcode"], // match the type of the end tag
222
- open: true,
223
- compile: function (token) {
224
- const expression = token.match[1];
225
-
226
- token.stack = Reflect.apply(Twig.expression.compile, this, [{
227
- type: Twig.expression.type.expression,
228
- value: expression
229
- }]).stack;
230
-
231
- delete token.match;
232
- return token;
233
- },
234
- parse: function (token, context, chain) {
235
- let type = Reflect.apply(Twig.expression.parse, this, [token.stack, context]);
236
- let output = this.parse(token.output, context);
237
- let mirror = false;
238
-
239
- if (type.includes(":mirror")) {
240
- mirror = true;
241
- type = type.replace(":mirror", "")
242
- }
243
-
244
- const Normalize = new NormalizeWhitespace({
245
- 'remove-trailing': true,
246
- 'remove-indent': true,
247
- 'left-trim': true,
248
- 'right-trim': true,
249
- });
250
-
251
- const wrap = (code, lang) => {
252
- return `<pre class="language-${lang}"><code>${code}</code></pre>`
253
- }
254
-
255
- const highlight = (str, lang) => {
256
- if (!lang) {
257
- return wrap(str, 'text')
258
- }
259
- lang = lang.toLowerCase()
260
- const rawLang = lang
261
- if (lang === 'vue' || lang === 'html') {
262
- lang = 'markup'
263
- }
264
- if (lang === 'md') {
265
- lang = 'markdown'
266
- }
267
- if (lang === 'ts') {
268
- lang = 'typescript'
269
- }
270
- if (lang === 'py') {
271
- lang = 'python'
272
- }
273
- if (!Prism.languages[lang]) {
274
- try {
275
- loadLanguages([lang])
276
- } catch (e) {
277
- console.warn(`Syntax highlight for language "${lang}" is not supported.`)
278
- }
279
- }
280
- if (Prism.languages[lang]) {
281
- const code = Prism.highlight(Normalize.normalize(str), Prism.languages[lang], lang)
282
- return wrap(code, rawLang)
283
- }
284
- return wrap(str, 'text')
285
- }
286
-
287
- return {
288
- chain: chain,
289
- output: `${mirror ? output : ""}${highlight(output, type)}`
290
- };
291
- }
292
- });
293
- Twig.exports.extendTag({
294
- type: "endcode",
295
- regex: /^endcode$/,
296
- next: [ ],
297
- open: false
298
- });
299
- },
300
- (Twig) => {
301
- Twig.exports.extendTag({
302
- type: "json",
303
- regex: /^json\s+(.+)$|^json$/,
304
- next: ["endjson"],
305
- open: true,
306
- compile: function (token) {
307
- const expression = token.match[1] ?? `'_null'`;
308
-
309
- token.stack = Reflect.apply(Twig.expression.compile, this, [{
310
- type: Twig.expression.type.expression,
311
- value: expression
312
- }]).stack;
313
-
314
- delete token.match;
315
- return token;
316
- },
317
- parse: function (token, context, chain) {
318
- let name = Reflect.apply(Twig.expression.parse, this, [token.stack, context]);
319
- let output = this.parse(token.output, context);
320
-
321
- const minify = minifier.minify(output, {
322
- collapseWhitespace: true,
323
- collapseInlineTagWhitespace: false,
324
- minifyCSS: true,
325
- minifyJS: true
326
- })
327
-
328
- if (name === '_null') {
329
- return {
330
- chain: chain,
331
- output: JSON.stringify(minify)
332
- };
333
- } else {
334
- return {
335
- chain: chain,
336
- output: JSON.stringify({
337
- [name]: minify
338
- })
339
- };
340
- }
341
- }
342
- });
343
- Twig.exports.extendTag({
344
- type: "endjson",
345
- regex: /^endjson$/,
346
- next: [ ],
347
- open: false
348
- });
349
- }
350
- ])
351
- }
352
- async build(type) {
353
- const data = (await import('gulp-data')).default;
354
- const htmlmin = (await import('gulp-htmlmin')).default;
355
- const rename = (await import('gulp-rename')).default;
356
-
357
- const opts = {
358
- collapseWhitespace: type === "production",
359
- collapseInlineTagWhitespace: false,
360
- minifyCSS: true,
361
- minifyJS: true
362
- }
363
-
364
- let outputDir = "/" + Config.paths.output.root;
365
-
366
- if (Config.paths.output.root === Config.paths.output.assets) {
367
- outputDir = ""
368
- }
369
-
370
- const contextParams = {
371
- config: Config,
372
- lang: Config.lang,
373
- outputPath: "/" + Config.paths.output.root,
374
- inputPath: "/" + Config.paths.input.root,
375
- resolvePath: Config.serve.mode === "dev" ? "" : outputDir,
376
- }
377
-
378
- const twigParams = {
379
- functions: this.functions,
380
- filters: this.filters,
381
- extensions: this.tags,
382
- context: lodash.merge(contextParams, {
383
- layout: {template: Config.templates.layout}
384
- }),
385
- namespaces: {
386
- 'src': Config.paths.input.root,
387
- 'templates': Config.paths.input.templates
388
- },
389
- globals: root + Config.paths.input.main
390
- }
391
-
392
- const clearFile = () => {
393
- return through.obj((file, enc, cb) => {
394
- if (file.isBuffer()) {
395
- if (file.extname === ".json") {
396
- file = null;
397
- }
398
-
399
- cb(null, file);
400
- }
401
- });
402
- };
403
-
404
- const fileJSON = (file) => {
405
- if (path.basename(file.path).indexOf("json") > -1 || path.basename(file.path).indexOf("dialog") > -1) {
406
- return true;
407
- }
408
- }
409
-
410
- const fileTemplate = (file) => {
411
- if (fs.existsSync(file.path.replace('.json',`.${Config.templates.format}`))) {
412
- return true;
413
- }
414
- }
415
-
416
- const hbsData = (file) => {
417
- let fileName = path.basename(file.path);
418
- let filePath = `${root + Config.paths.input.templates}/${fileName.replace(`.${Config.templates.format}`,'.json')}`;
419
- let main = {};
420
-
421
- if (fs.existsSync(root + Config.paths.input.main)) {
422
- main = lodash.merge({layout: {template: Config.templates.layout}}, JSON.parse(fs.readFileSync(root + Config.paths.input.main).toString()));
423
- }
424
-
425
- if (fs.existsSync(filePath)) {
426
- return lodash.merge(main, JSON.parse(fs.readFileSync(filePath).toString()));
427
- } else {
428
- return main;
429
- }
430
- }
431
-
432
- const hbsLayout = () => {
433
- return through.obj((file, enc, cb) => {
434
- if (file.isBuffer()) {
435
-
436
- file.contents = Buffer.from("{{> (lookup layout 'template')}}");
437
-
438
- cb(null, file);
439
- }
440
- });
441
- }
442
-
443
- const hbsPartials = `${root + Config.paths.input.templates}/**/*.hbs`;
444
- const hbsHelpers = Modules.hbs.helpers(Object.assign(this.filters, this.functions));
445
-
446
- const renameJson = lazypipe().pipe(rename, { extname: '.json' });
447
- const renameHtml = lazypipe().pipe(rename, { extname: '.html' }).pipe(htmlmin,opts);
448
-
449
- const buildLayoutClear = lazypipe().pipe(() => gulpif(fileTemplate, clearFile()));
450
- const buildLayoutTwig = lazypipe().pipe(() => gulpif(Config.templates.format === "twig", twig(lodash.merge(twigParams, {data: "{% include layout.template %}"}))));
451
- const buildLayoutHbs = lazypipe()
452
- .pipe(() => gulpif(Config.templates.format === "hbs", hbsLayout()))
453
- .pipe(() => gulpif(Config.templates.format === "hbs", data((file) => hbsData(file))))
454
- .pipe(() => gulpif(Config.templates.format === "hbs", Modules.hbs.module(hbsPartials, hbsHelpers, contextParams)));
455
-
456
- const buildClassic = lazypipe()
457
- .pipe(() => gulpif("*.twig", twig(twigParams)))
458
- .pipe(() => gulpif("*.hbs", data((file) => hbsData(file))))
459
- .pipe(() => gulpif("*.hbs", Modules.hbs.module(hbsPartials, hbsHelpers, contextParams)));
460
-
461
- return Promise.all([
462
- new Promise(resolve => gulp.src([`${root + Config.paths.input.templates}/*.{hbs,html,twig}`])
463
- .pipe(plumber(Functions.plumber))
464
- .pipe(buildClassic())
465
- .pipe(gulpif(fileJSON, renameJson(), renameHtml()))
466
- .pipe(gulp.dest(root + Config.paths.output.root))
467
- .on("end", resolve)),
468
- new Promise(resolve => gulp.src([`${root + Config.paths.input.templates}/*.json`])
469
- .pipe(plumber(Functions.plumber))
470
- .pipe(buildLayoutClear())
471
- .pipe(buildLayoutTwig())
472
- .pipe(buildLayoutHbs())
473
- .pipe(renameHtml())
474
- .pipe(gulp.dest(root + Config.paths.output.root))
475
- .on("end", resolve))
476
- ])
477
- }
478
- }