@newlogic-digital/core 0.9.14 → 1.0.0-beta.3
Sign up to get free protection for your applications and to get access to all the features.
- 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/Emails.js
DELETED
@@ -1,110 +0,0 @@
|
|
1
|
-
import lazypipe from "lazypipe";
|
2
|
-
import gulpif from "gulp-if";
|
3
|
-
import postcss from "gulp-postcss";
|
4
|
-
import autoprefixer from "autoprefixer";
|
5
|
-
import twig from "../packages/gulp-twig2html/index.js";
|
6
|
-
import gulp from "gulp";
|
7
|
-
import fs from "fs";
|
8
|
-
import {Config, Modules, Templates, Utils, root} from "./Core.js";
|
9
|
-
|
10
|
-
export class Emails {
|
11
|
-
async build() {
|
12
|
-
const inlineCss = (await import('gulp-inline-css')).default;
|
13
|
-
const replace = (await import('gulp-replace')).default;
|
14
|
-
const rename = (await import('gulp-rename')).default;
|
15
|
-
const postcssCustomProperties = (await import('postcss-custom-properties')).default;
|
16
|
-
|
17
|
-
const inlineCssOpt = {
|
18
|
-
applyStyleTags: true,
|
19
|
-
applyLinkTags: true,
|
20
|
-
removeStyleTags: Config.emails.inlineOnly
|
21
|
-
}
|
22
|
-
|
23
|
-
const buildCss = lazypipe().pipe(() => gulpif("*.css", postcss(new Utils().postcssPluginsEmails(Config.emails.postcss, [postcssCustomProperties({
|
24
|
-
preserve: false
|
25
|
-
}), autoprefixer])))
|
26
|
-
).pipe(() => gulpif("*.less", Modules.less.module()))
|
27
|
-
|
28
|
-
return new Promise(resolve => {
|
29
|
-
let twigFiles = "*.twig";
|
30
|
-
let hbsFiles = "*.hbs";
|
31
|
-
|
32
|
-
if (Config.emails.format === "twig") {
|
33
|
-
twigFiles = twigFiles.replace("twig", "{twig,latte,tpl}")
|
34
|
-
} else if (Config.emails.format === "hbs") {
|
35
|
-
hbsFiles = hbsFiles.replace("hbs", "{hbs,latte,tpl}")
|
36
|
-
}
|
37
|
-
|
38
|
-
const build = lazypipe().pipe(() => gulpif(twigFiles, twig({
|
39
|
-
functions: new Templates().functions,
|
40
|
-
filters: new Templates().filters,
|
41
|
-
extensions: new Templates().tags
|
42
|
-
})))
|
43
|
-
.pipe(() => gulpif(hbsFiles, Modules.hbs.module(`${root + Config.paths.input.emails}/**/*.hbs`, Modules.hbs.helpers(Object.assign(new Templates().filters, new Templates().functions)))))
|
44
|
-
.pipe(() => gulpif("*.{hbs,twig}", rename({ extname: ".html" })))
|
45
|
-
|
46
|
-
gulp.series(
|
47
|
-
function styles() {
|
48
|
-
return gulp.src(root + Config.paths.input.emails + '/*.{css,less}')
|
49
|
-
.pipe(buildCss())
|
50
|
-
.pipe(gulp.dest(root + Config.paths.temp + "/emails"));
|
51
|
-
},
|
52
|
-
function templates() {
|
53
|
-
return gulp.src(root + Config.paths.input.emails + '/*.{hbs,twig,tpl,latte}')
|
54
|
-
.pipe(build())
|
55
|
-
.pipe(replace('<table', '<table border="0" cellpadding="0" cellspacing="0"'))
|
56
|
-
.pipe(inlineCss(inlineCssOpt))
|
57
|
-
.pipe(gulpif(Config.emails.removeClasses,replace(/class="([A-Za-z0-9 _]*)"/g, '')))
|
58
|
-
.pipe(gulpif(("*.html"), gulp.dest(root + Config.paths.output.emails)))
|
59
|
-
.pipe(gulpif("*.{latte,tpl}", gulp.dest(root + Config.paths.output.emailsWww)))
|
60
|
-
}
|
61
|
-
)(resolve)
|
62
|
-
})
|
63
|
-
}
|
64
|
-
zip() {
|
65
|
-
return new Promise(async (resolve) => {
|
66
|
-
const AdmZip = (await import('adm-zip')).default;
|
67
|
-
|
68
|
-
let files = fs.readdirSync(root + Config.paths.output.emails);
|
69
|
-
let prefixes = Config.emails.zipPrefix;
|
70
|
-
|
71
|
-
function zipFile(file, imageSubfolder) {
|
72
|
-
let zip = new AdmZip();
|
73
|
-
|
74
|
-
if (typeof imageSubfolder !== "undefined" && fs.existsSync(`${root + Config.paths.output.emailsImg}/${imageSubfolder}`)) {
|
75
|
-
if (imageSubfolder.endsWith("-")) {
|
76
|
-
imageSubfolder.slice(0, imageSubfolder.length - 1)
|
77
|
-
}
|
78
|
-
imageSubfolder = "/" + imageSubfolder
|
79
|
-
} else {
|
80
|
-
imageSubfolder = ""
|
81
|
-
}
|
82
|
-
|
83
|
-
zip.addFile("index.html", fs.readFileSync(`${root + Config.paths.output.emails}/${file}`));
|
84
|
-
zip.toBuffer();
|
85
|
-
|
86
|
-
if (fs.existsSync(`${root + Config.paths.output.emailsImg}${imageSubfolder}`)) {
|
87
|
-
zip.addLocalFolder(`${root + Config.paths.output.emailsImg}${imageSubfolder}`, `images${imageSubfolder}`);
|
88
|
-
}
|
89
|
-
|
90
|
-
zip.writeZip(`${root + Config.paths.output.emails}/${file.replace(".html", ".zip")}`);
|
91
|
-
}
|
92
|
-
|
93
|
-
files.forEach((file) => {
|
94
|
-
if (file.endsWith(".html")) {
|
95
|
-
if (Config.emails.zipPrefix) {
|
96
|
-
prefixes.filter((prefix) => {
|
97
|
-
if (file.startsWith(prefix)) {
|
98
|
-
zipFile(file, prefix);
|
99
|
-
}
|
100
|
-
});
|
101
|
-
} else {
|
102
|
-
zipFile(file);
|
103
|
-
}
|
104
|
-
}
|
105
|
-
});
|
106
|
-
|
107
|
-
resolve();
|
108
|
-
})
|
109
|
-
}
|
110
|
-
}
|
package/modules/Icons.js
DELETED
@@ -1,140 +0,0 @@
|
|
1
|
-
import path from "path";
|
2
|
-
import fs from "fs";
|
3
|
-
import lazypipe from "lazypipe";
|
4
|
-
import gulpif from "gulp-if";
|
5
|
-
import postcss from "gulp-postcss";
|
6
|
-
import autoprefixer from "autoprefixer";
|
7
|
-
import gulp from "gulp";
|
8
|
-
import plumber from "gulp-plumber";
|
9
|
-
import {Config, Functions, Modules, Utils, root} from "./Core.js";
|
10
|
-
|
11
|
-
export class Icons {
|
12
|
-
async fetch() {
|
13
|
-
const http = (await import("https")).default;
|
14
|
-
|
15
|
-
return new Promise((resolve, reject) => {
|
16
|
-
if (Config.icons.local === true || Config.local === true) {
|
17
|
-
resolve();
|
18
|
-
}
|
19
|
-
|
20
|
-
if (typeof Config.icons.name === "undefined" || Config.icons.name === "") {
|
21
|
-
Config.icons.name = path.basename(path.resolve(root));
|
22
|
-
}
|
23
|
-
|
24
|
-
let files = [
|
25
|
-
`https://i.icomoon.io/public/${Config.icons.id}/${Config.icons.name}/variables.less`,
|
26
|
-
`https://i.icomoon.io/public/${Config.icons.id}/${Config.icons.name}/style.less`,
|
27
|
-
`https://i.icomoon.io/public/${Config.icons.id}/${Config.icons.name}/selection.json`
|
28
|
-
]
|
29
|
-
|
30
|
-
if (!fs.existsSync(root + Config.paths.input.icons)) {
|
31
|
-
fs.mkdirSync(root + Config.paths.input.icons);
|
32
|
-
}
|
33
|
-
|
34
|
-
let variables = {};
|
35
|
-
|
36
|
-
Promise.allSettled(files.map(async (url) => {
|
37
|
-
let name = url.substring(url.indexOf(Config.icons.name) + Config.icons.name.length, url.length).replace("/","");
|
38
|
-
|
39
|
-
return new Promise((resolveFile, rejectFile) => {
|
40
|
-
http.get(url, response => {
|
41
|
-
if (response.statusCode === 200) {
|
42
|
-
if ((name === "variables.less" || name === "style.less") && Config.icons.format !== "less") {
|
43
|
-
response.setEncoding('utf8');
|
44
|
-
let body = "";
|
45
|
-
response.on('data', chunk => body += chunk);
|
46
|
-
response.on('end', () => {
|
47
|
-
|
48
|
-
if (name === "variables.less") {
|
49
|
-
body.match(/@(.+);/gm).filter(variable => {
|
50
|
-
let match = variable.match(/@(.+): "(.+)";/);
|
51
|
-
|
52
|
-
variables[match[1]] = match[2]
|
53
|
-
})
|
54
|
-
|
55
|
-
body = `:root {${Object.keys(variables).map(variable => `--${variable}: "${variables[variable]}";\n`).join("")}}`;
|
56
|
-
|
57
|
-
fs.writeFile(`${root + Config.paths.input.icons}/variables.css`, body, resolveFile);
|
58
|
-
}
|
59
|
-
|
60
|
-
if (name === "style.less") {
|
61
|
-
body = body.replace(`@import "variables";`, `@import "variables.css";`)
|
62
|
-
|
63
|
-
fs.writeFile(`${root + Config.paths.input.icons}/iconfont.css`, body, resolveFile)
|
64
|
-
}
|
65
|
-
});
|
66
|
-
|
67
|
-
} else if (name === "style.less" && Config.icons.format === "less") {
|
68
|
-
response.pipe(fs.createWriteStream(`${root + Config.paths.input.icons}/iconfont.less`)).on("close", resolveFile);
|
69
|
-
} else {
|
70
|
-
response.pipe(fs.createWriteStream(`${root + Config.paths.input.icons}/${name}`)).on("close", resolveFile);
|
71
|
-
}
|
72
|
-
} else {
|
73
|
-
console.error("\x1b[31m", `Error: ${url} returns ${response.statusCode}`, "\x1b[0m");
|
74
|
-
rejectFile()
|
75
|
-
}
|
76
|
-
});
|
77
|
-
})
|
78
|
-
})).then(result => {
|
79
|
-
if (result[0].status !== "rejected") {
|
80
|
-
if (fs.existsSync(`${root + Config.paths.input.icons}/iconfont.css`)) {
|
81
|
-
let file = fs.readFileSync(`${root + Config.paths.input.icons}/iconfont.css`).toString();
|
82
|
-
|
83
|
-
Object.keys(variables).map(variable => {
|
84
|
-
file = file.replace(new RegExp(`@{${variable}}`, 'g'), `${variables[variable]}`)
|
85
|
-
file = file.replace(`@${variable}`, `var(--${variable})`)
|
86
|
-
})
|
87
|
-
|
88
|
-
file = file.replace(new RegExp('-"]', 'g'), '-"]:before')
|
89
|
-
file = file.replace('!important;', ';')
|
90
|
-
|
91
|
-
fs.writeFileSync(`${root + Config.paths.input.icons}/iconfont.css`, file);
|
92
|
-
}
|
93
|
-
|
94
|
-
if (fs.existsSync(`${root + Config.paths.input.icons}/iconfont.less`)) {
|
95
|
-
let file = fs.readFileSync(`${root + Config.paths.input.icons}/iconfont.less`).toString();
|
96
|
-
|
97
|
-
file = file.replace(new RegExp('-"]', 'g'), '-"]:before')
|
98
|
-
file = file.replace('!important;', ';')
|
99
|
-
|
100
|
-
fs.writeFileSync(`${root + Config.paths.input.icons}/iconfont.less`, file);
|
101
|
-
}
|
102
|
-
|
103
|
-
console.log("\x1b[34m", `Icomoon demo - https://i.icomoon.io/public/reference.html#/${Config.icons.id}/${Config.icons.name}/`, "\x1b[0m");
|
104
|
-
resolve();
|
105
|
-
} else {
|
106
|
-
console.error("\x1b[31m", `Is project added in icomoon.app, has the correct name or is quick usage enabled?`, "\x1b[0m");
|
107
|
-
reject();
|
108
|
-
}
|
109
|
-
})
|
110
|
-
})
|
111
|
-
}
|
112
|
-
async build() {
|
113
|
-
const replace = (await import('gulp-replace')).default;
|
114
|
-
const cleanCSS = (await import("../packages/gulp-clean-css/index.js")).default;
|
115
|
-
const rename = (await import('gulp-rename')).default;
|
116
|
-
const revision = (await import("gulp-rev")).default;
|
117
|
-
|
118
|
-
const rev = lazypipe().pipe(revision).pipe(Functions.revUpdate, true, "icons");
|
119
|
-
|
120
|
-
const clean = lazypipe().pipe(cleanCSS);
|
121
|
-
|
122
|
-
const build = lazypipe().pipe(() => gulpif("*.css", postcss(new Utils().postcssPlugins(Config.icons.postcss, [autoprefixer])))
|
123
|
-
).pipe(() => gulpif("*.less", Modules.less.module()))
|
124
|
-
|
125
|
-
return gulp.src(`${root + Config.paths.input.icons}/iconfont.{css,less}`)
|
126
|
-
.pipe(plumber(Functions.plumber))
|
127
|
-
.pipe(rename(function(path){
|
128
|
-
path.basename = Config.icons.filename;
|
129
|
-
}))
|
130
|
-
.pipe(build())
|
131
|
-
.pipe(gulpif(Config.icons.revision, rev()))
|
132
|
-
.pipe(gulpif(Config.icons.optimizations, clean()))
|
133
|
-
.pipe(gulp.dest(root + Config.paths.output.icons))
|
134
|
-
.pipe(revision.manifest(root + Config.paths.output.icons + "/rev-manifest.json",{
|
135
|
-
merge: true,
|
136
|
-
base: root + Config.paths.output.icons
|
137
|
-
}))
|
138
|
-
.pipe(gulp.dest(root + Config.paths.output.icons));
|
139
|
-
}
|
140
|
-
}
|
package/modules/Scripts.js
DELETED
@@ -1,321 +0,0 @@
|
|
1
|
-
import fs from "fs";
|
2
|
-
import fse from "fs-extra";
|
3
|
-
import lodash from "lodash";
|
4
|
-
import {Config, Functions, root} from "./Core.js";
|
5
|
-
|
6
|
-
export class Scripts {
|
7
|
-
importResolution() {
|
8
|
-
return new Promise(resolve => {
|
9
|
-
Config.scripts.importResolution.directories.map(directory => {
|
10
|
-
if (!fs.existsSync(`${root + Config.paths.input.scripts}/${directory}`)) {
|
11
|
-
console.log("\x1b[31m", `importResolution - ${Config.paths.input.scripts}/${directory} doesn't exists`, "\x1b[0m");
|
12
|
-
return false;
|
13
|
-
}
|
14
|
-
|
15
|
-
let items = fs.readdirSync(`${root + Config.paths.input.scripts}/${directory}`);
|
16
|
-
|
17
|
-
function findPaths(items, directory) {
|
18
|
-
let imports = "";
|
19
|
-
|
20
|
-
items.map(item => {
|
21
|
-
let path = `${directory}/${item}`;
|
22
|
-
|
23
|
-
if (fs.statSync(path).isFile()) {
|
24
|
-
if (path.includes(".js") && !path.includes(Config.scripts.importResolution.filename)) {
|
25
|
-
if (fs.readFileSync(path).toString().includes("export default")) {
|
26
|
-
imports = imports + `export { default as ${item.replace(".js","")} } from './${item}'\r\n`
|
27
|
-
} else {
|
28
|
-
imports = imports + `import './${item}'\r\n`
|
29
|
-
}
|
30
|
-
}
|
31
|
-
} else {
|
32
|
-
if (Config.scripts.importResolution.subDir) {
|
33
|
-
imports = imports + `import '${item}/${Config.scripts.importResolution.filename}'\r\n`
|
34
|
-
}
|
35
|
-
findPaths(fs.readdirSync(path), path);
|
36
|
-
}
|
37
|
-
});
|
38
|
-
|
39
|
-
let path = `${directory}/${Config.scripts.importResolution.filename}`;
|
40
|
-
|
41
|
-
if (fs.existsSync(path) && fs.readFileSync(path).toString() !== imports || !fs.existsSync(path)) {
|
42
|
-
fs.writeFileSync(path, imports);
|
43
|
-
}
|
44
|
-
}
|
45
|
-
|
46
|
-
findPaths(items, `${root + Config.paths.input.scripts}/${directory}`);
|
47
|
-
});
|
48
|
-
|
49
|
-
resolve();
|
50
|
-
});
|
51
|
-
}
|
52
|
-
async concat() {
|
53
|
-
const gulp = (await import("gulp")).default;
|
54
|
-
const plumber = (await import("gulp-plumber")).default;
|
55
|
-
const lazypipe = (await import("lazypipe")).default;
|
56
|
-
const gulpif = (await import("gulp-if")).default;
|
57
|
-
const through = (await import("through2")).default;
|
58
|
-
const revision = (await import("gulp-rev")).default;
|
59
|
-
const revRewrite = (await import("gulp-rev-rewrite")).default;
|
60
|
-
const terser = (await import("terser"));
|
61
|
-
|
62
|
-
function minify() {
|
63
|
-
return through.obj((file, enc, cb) => {
|
64
|
-
if (file.isNull()) {
|
65
|
-
cb(null, file);
|
66
|
-
}
|
67
|
-
if (file.isBuffer()) {
|
68
|
-
terser.minify(file.contents.toString()).then(function (result) {
|
69
|
-
file.contents = Buffer.from(result.code);
|
70
|
-
cb(null, file);
|
71
|
-
});
|
72
|
-
}
|
73
|
-
});
|
74
|
-
}
|
75
|
-
|
76
|
-
const rev = lazypipe().pipe(revision).pipe(Functions.revUpdate, true, "scripts")
|
77
|
-
.pipe(revRewrite, {manifest: fs.existsSync(`${root + Config.paths.output.assets}/rev-manifest.json`) ? fs.readFileSync(`${root + Config.paths.output.assets}/rev-manifest.json`) : ""});
|
78
|
-
|
79
|
-
return new Promise(resolve => {
|
80
|
-
gulp.src(Config.scripts.concat)
|
81
|
-
.pipe(plumber(Functions.plumber))
|
82
|
-
.pipe(Functions.module("gulp-js-import-file", {
|
83
|
-
hideConsole: true,
|
84
|
-
importStack: false,
|
85
|
-
es6import: true
|
86
|
-
}))
|
87
|
-
.pipe(Functions.revRewriteOutput())
|
88
|
-
.pipe(gulpif(Config.scripts.legacy, Functions.module("gulp-babel")))
|
89
|
-
.pipe(gulpif(Config.scripts.optimizations, minify()))
|
90
|
-
.pipe(gulpif(Config.scripts.revision, rev()))
|
91
|
-
.pipe(gulp.dest(root + Config.paths.output.scripts))
|
92
|
-
.pipe(revision.manifest(root + Config.paths.output.scripts + "/rev-manifest.json",{
|
93
|
-
merge: true,
|
94
|
-
base: root + Config.paths.output.scripts
|
95
|
-
}))
|
96
|
-
.pipe(gulp.dest(root + Config.paths.output.scripts))
|
97
|
-
.on('error', Functions.plumber.errorHandler)
|
98
|
-
.on('end', resolve);
|
99
|
-
})
|
100
|
-
}
|
101
|
-
async build() {
|
102
|
-
const {rollup} = await import('rollup');
|
103
|
-
const {nodeResolve} = await import('@rollup/plugin-node-resolve');
|
104
|
-
const commonjs = (await import('@rollup/plugin-commonjs')).default;
|
105
|
-
const {terser} = await import('rollup-plugin-terser');
|
106
|
-
const {rollupImportMapPlugin} = (await import('rollup-plugin-import-map'));
|
107
|
-
const replace = (await import('@rollup/plugin-replace')).default;
|
108
|
-
|
109
|
-
return new Promise(resolve => {
|
110
|
-
fse.removeSync(root + Config.paths.output.scripts);
|
111
|
-
|
112
|
-
const hashManifest = function(opts = {}) {
|
113
|
-
const defaults = {
|
114
|
-
path: root + Config.paths.output.scripts
|
115
|
-
};
|
116
|
-
|
117
|
-
opts = Object.assign({}, defaults, opts);
|
118
|
-
let inputs;
|
119
|
-
|
120
|
-
return {
|
121
|
-
options({ input }) {
|
122
|
-
inputs = input;
|
123
|
-
if (typeof inputs === "string") {
|
124
|
-
inputs = [inputs];
|
125
|
-
}
|
126
|
-
if (typeof inputs === "object") {
|
127
|
-
inputs = Object.values(inputs);
|
128
|
-
}
|
129
|
-
},
|
130
|
-
generateBundle(_outputOptions, bundle) {
|
131
|
-
let map = {};
|
132
|
-
return Promise.all(inputs.map(id => this.resolve(id))).then(
|
133
|
-
resolvedInputs => {
|
134
|
-
for (const key of Object.keys(bundle)) {
|
135
|
-
const idx = resolvedInputs.findIndex(
|
136
|
-
input => input.id in (bundle[key].modules || {})
|
137
|
-
);
|
138
|
-
if (idx !== -1) {
|
139
|
-
const name = inputs[idx].split("/")[inputs[idx].split("/").length - 1];
|
140
|
-
map[name] = bundle[key].fileName;
|
141
|
-
}
|
142
|
-
}
|
143
|
-
|
144
|
-
if (fs.existsSync(opts.path + "/rev-manifest.json")) {
|
145
|
-
map = Object.assign(JSON.parse(fs.readFileSync(opts.path + "/rev-manifest.json").toString()), map);
|
146
|
-
}
|
147
|
-
|
148
|
-
fs.writeFileSync(opts.path + "/rev-manifest.json", JSON.stringify(map, null, " "));
|
149
|
-
}
|
150
|
-
);
|
151
|
-
}
|
152
|
-
};
|
153
|
-
}
|
154
|
-
|
155
|
-
let assetsManifest = fs.existsSync(`${root + Config.paths.output.assets}/rev-manifest.json`) ? JSON.parse(fs.readFileSync(`${root + Config.paths.output.assets}/rev-manifest.json`).toString()) : {};
|
156
|
-
let importMapFile = fs.existsSync(`${root + Config.paths.output.root}/importmap.json`) ? JSON.parse(fs.readFileSync(`${root + Config.paths.output.root}/importmap.json`).toString()) : {};
|
157
|
-
let files = fs.readdirSync(root + Config.paths.input.scripts);
|
158
|
-
|
159
|
-
if (!fs.existsSync(root + Config.paths.output.scripts)){
|
160
|
-
fs.mkdirSync(root + Config.paths.output.scripts);
|
161
|
-
}
|
162
|
-
|
163
|
-
Config.scripts.concat.map(file => lodash.pull(files, file.substr(file.lastIndexOf("/") + 1, file.length)))
|
164
|
-
|
165
|
-
Promise.all(files.map(async file => {
|
166
|
-
if (!fs.statSync(`${root + Config.paths.input.scripts}/${file}`).isDirectory()) {
|
167
|
-
await (async() => {
|
168
|
-
|
169
|
-
const inputOptions = {
|
170
|
-
context: 'window',
|
171
|
-
preserveEntrySignatures: true,
|
172
|
-
plugins: [
|
173
|
-
(Config.serve.mode === "" || Config.paths.output.rewrite) && replace({
|
174
|
-
preventAssignment: true,
|
175
|
-
values: {
|
176
|
-
'/* @vite-ignore */': ''
|
177
|
-
},
|
178
|
-
delimiters: ['', '']
|
179
|
-
}),
|
180
|
-
(Config.scripts.importMap.build && typeof importMapFile["imports"] !== "undefined") && rollupImportMapPlugin(importMapFile),
|
181
|
-
!Config.scripts.importMap.build && nodeResolve({
|
182
|
-
browser: true
|
183
|
-
}),
|
184
|
-
!Config.scripts.importMap.build && commonjs(),
|
185
|
-
replace({
|
186
|
-
preventAssignment: true,
|
187
|
-
values: Object.assign({
|
188
|
-
'process.env.NODE_ENV': JSON.stringify('production'),
|
189
|
-
[Config.paths.input.assets]: `${Config.paths.output.assets.replace(Config.paths.output.root + "/", Config.paths.base.length > 0 ? Config.paths.base + "/" : "")}`
|
190
|
-
}, assetsManifest)
|
191
|
-
}),
|
192
|
-
Config.scripts.optimizations && terser(),
|
193
|
-
Config.scripts.revision && hashManifest()
|
194
|
-
]
|
195
|
-
};
|
196
|
-
|
197
|
-
const outputOptions = {
|
198
|
-
dir: root + Config.paths.output.scripts,
|
199
|
-
format: 'es',
|
200
|
-
sourcemap: false,
|
201
|
-
compact: true,
|
202
|
-
entryFileNames: `[name]${Config.scripts.revision ? ".[hash]" : ""}.js`,
|
203
|
-
chunkFileNames: '[name].[hash].js'
|
204
|
-
};
|
205
|
-
|
206
|
-
const bundle = await rollup(Object.assign({input: root + Config.paths.input.scripts + '/' + file}, inputOptions));
|
207
|
-
|
208
|
-
await bundle.write(outputOptions);
|
209
|
-
|
210
|
-
await bundle.close();
|
211
|
-
})();
|
212
|
-
|
213
|
-
Config.scripts.legacy && await (async() => {
|
214
|
-
|
215
|
-
const {getBabelOutputPlugin} = await import('@rollup/plugin-babel');
|
216
|
-
|
217
|
-
const inputOptions = {
|
218
|
-
context: 'window',
|
219
|
-
preserveEntrySignatures: false,
|
220
|
-
plugins: [
|
221
|
-
(Config.serve.mode === "" || Config.paths.output.rewrite) && replace({
|
222
|
-
preventAssignment: true,
|
223
|
-
values: {
|
224
|
-
'/* @vite-ignore */': ''
|
225
|
-
},
|
226
|
-
delimiters: ['', '']
|
227
|
-
}),
|
228
|
-
nodeResolve({
|
229
|
-
browser: true
|
230
|
-
}),
|
231
|
-
commonjs(),
|
232
|
-
replace({
|
233
|
-
preventAssignment: true,
|
234
|
-
values: Object.assign({
|
235
|
-
'process.env.NODE_ENV': JSON.stringify('production')
|
236
|
-
}, assetsManifest)
|
237
|
-
}),
|
238
|
-
Config.scripts.revision && hashManifest({path: root + Config.paths.output.scripts + "/es5/"})
|
239
|
-
]
|
240
|
-
};
|
241
|
-
|
242
|
-
const outputOptions = {
|
243
|
-
dir: root + Config.paths.output.scripts + "/es5/",
|
244
|
-
format: 'es',
|
245
|
-
sourcemap: false,
|
246
|
-
compact: true,
|
247
|
-
entryFileNames: `[name]${Config.scripts.revision ? ".[hash]" : ""}.js`,
|
248
|
-
chunkFileNames: '[name].[hash].js',
|
249
|
-
plugins: [
|
250
|
-
getBabelOutputPlugin({
|
251
|
-
presets: [['@babel/env', { modules: 'amd',
|
252
|
-
targets: {
|
253
|
-
"ie": "11"
|
254
|
-
},
|
255
|
-
useBuiltIns: 'entry',
|
256
|
-
corejs: "3.8"
|
257
|
-
}]]
|
258
|
-
}),
|
259
|
-
]
|
260
|
-
};
|
261
|
-
|
262
|
-
if (!fs.existsSync(root + Config.paths.output.scripts + "/es5")){
|
263
|
-
fs.mkdirSync(root + Config.paths.output.scripts + "/es5");
|
264
|
-
}
|
265
|
-
|
266
|
-
const bundle = await rollup(Object.assign({input: root + Config.paths.input.scripts + `/${file}`}, inputOptions));
|
267
|
-
|
268
|
-
await bundle.write(outputOptions);
|
269
|
-
|
270
|
-
await bundle.close();
|
271
|
-
})();
|
272
|
-
}
|
273
|
-
})).then(async () => {
|
274
|
-
Config.scripts.legacy && await (async() => {
|
275
|
-
let polyfills = "";
|
276
|
-
|
277
|
-
if (typeof Config.scripts.polyfillUrls !== "undefined") {
|
278
|
-
Config.scripts.polyfillUrls.map((script) => {
|
279
|
-
polyfills = polyfills.concat(`document.write('<script src="${script}"><\\/script>');`)
|
280
|
-
});
|
281
|
-
}
|
282
|
-
|
283
|
-
fs.writeFileSync(root + Config.paths.temp + `/polyfills.js`, Functions.stripIndent(`
|
284
|
-
document.write('<script src="https://polyfill.io/v3/polyfill.min.js?features=${Config.scripts.polyfillFeatures}"><\\/script>');
|
285
|
-
document.write('<script src="https://cdn.jsdelivr.net/npm/whatwg-fetch@3.5.0/dist/fetch.umd.min.js"><\\/script>');
|
286
|
-
document.write('<script src="https://cdn.jsdelivr.net/npm/regenerator-runtime@0.13.7/runtime.min.js"><\\/script>');
|
287
|
-
document.write('<script src="https://cdn.jsdelivr.net/npm/requirejs@2.3.6/require.min.js"><\\/script>');
|
288
|
-
${polyfills}
|
289
|
-
`).replace(/^\s*\n/g, ""));
|
290
|
-
|
291
|
-
const inputOptions = {
|
292
|
-
context: 'window',
|
293
|
-
preserveEntrySignatures: false,
|
294
|
-
plugins: [
|
295
|
-
Config.scripts.revision && hashManifest({path: root + Config.paths.output.scripts + "/es5/"})
|
296
|
-
]
|
297
|
-
};
|
298
|
-
|
299
|
-
const outputOptions = {
|
300
|
-
dir: root + Config.paths.output.scripts + "/es5/",
|
301
|
-
format: 'es',
|
302
|
-
sourcemap: false,
|
303
|
-
compact: true,
|
304
|
-
entryFileNames: `[name]${Config.scripts.revision ? ".[hash]" : ""}.js`
|
305
|
-
};
|
306
|
-
const bundle = await rollup(Object.assign({input: root + Config.paths.temp + `/polyfills.js`}, inputOptions));
|
307
|
-
|
308
|
-
await bundle.write(outputOptions);
|
309
|
-
|
310
|
-
await bundle.close();
|
311
|
-
})();
|
312
|
-
|
313
|
-
if (Config.scripts.concat.length > 0) {
|
314
|
-
await new Scripts().concat();
|
315
|
-
}
|
316
|
-
|
317
|
-
resolve();
|
318
|
-
});
|
319
|
-
});
|
320
|
-
}
|
321
|
-
}
|