autofront 2.2.2 → 2.2.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 +2 -3
- package/index.js +143 -68
- package/package.json +10 -1
package/README.md
CHANGED
|
@@ -64,7 +64,7 @@ Other command options, that appear immediately below, are available. And to use
|
|
|
64
64
|
|
|
65
65
|
### Tasks
|
|
66
66
|
|
|
67
|
-
|
|
67
|
+
The Gulp ones are the following:
|
|
68
68
|
|
|
69
69
|
- `gulp` or `gulp serve` are for running a test server and develop with live reload.
|
|
70
70
|
- `gulp build` only builds production code, the distributable application (`dist` folder).
|
|
@@ -123,8 +123,7 @@ Any asset (e.g. a PDF document) will keep the location path and, particularly at
|
|
|
123
123
|
|
|
124
124
|
## Pending
|
|
125
125
|
|
|
126
|
-
|
|
126
|
+
Improvements to do:
|
|
127
127
|
|
|
128
|
-
- Once the server watch for changes, synchronize also the deletion of source files.
|
|
129
128
|
- Replace Bower as dependency manager.
|
|
130
129
|
- Migrate AngularJS to new [Angular](https://angular.io).
|
package/index.js
CHANGED
|
@@ -9,33 +9,39 @@ const gulp = require('gulp'),
|
|
|
9
9
|
injStr = $.injectString,
|
|
10
10
|
gulpSass = $.sass(require('sass')),
|
|
11
11
|
notifyError = $.notify.onError(error => error.message),
|
|
12
|
-
browserSync = require('browser-sync').create()
|
|
12
|
+
browserSync = require('browser-sync').create(),
|
|
13
|
+
deleteEmpty = require('delete-empty');
|
|
13
14
|
|
|
14
15
|
let domain = undefined;
|
|
15
16
|
|
|
16
|
-
const allFiles =
|
|
17
|
+
const allFiles = getGlob(),
|
|
17
18
|
indexHtmlFile = 'index.html',
|
|
19
|
+
jsFiles = getGlob('js'),
|
|
18
20
|
cssFilename = 'index',
|
|
19
|
-
|
|
20
|
-
let
|
|
21
|
+
cssFile = cssFilename + '.css';
|
|
22
|
+
let stylesDir = 'styles/',
|
|
21
23
|
jsTemplatesFile = 'scripts/templates.js';
|
|
22
24
|
|
|
23
|
-
const
|
|
25
|
+
const globs = {
|
|
24
26
|
src: 'src/',
|
|
25
27
|
tmp: '.tmp/',
|
|
26
28
|
dist: 'dist/'
|
|
27
29
|
};
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
globs.srcIndexHtml = globs.src + indexHtmlFile;
|
|
31
|
+
globs.srcJs = globs.src + jsFiles;
|
|
32
|
+
globs.srcIndexAndSrcJs = [globs.srcIndexHtml, globs.srcJs];
|
|
33
|
+
globs.srcStyles = [globs.src + stylesDir + cssFile, globs.src + getGlob('less'), globs.src + getGlob('scss')];
|
|
34
|
+
globs.srcOthers = [globs.src + allFiles, ...[...globs.srcIndexAndSrcJs, ...globs.srcStyles].map(glob => '!' + glob)];
|
|
35
|
+
globs.tmpAllFiles = globs.tmp + allFiles;
|
|
34
36
|
|
|
35
37
|
const nl = '\n',
|
|
36
38
|
tab = ' ';
|
|
37
39
|
|
|
38
|
-
|
|
40
|
+
function clean() {
|
|
41
|
+
return delDir(globs.tmp);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function manageDomain() {
|
|
39
45
|
const pckg = require(path.resolve('package.json')),
|
|
40
46
|
domains = pckg.domains;
|
|
41
47
|
let domainIndex = args[0] || 'local';
|
|
@@ -49,63 +55,124 @@ gulp.task('check', () => {
|
|
|
49
55
|
domain = domains[domainIndex];
|
|
50
56
|
}
|
|
51
57
|
const isMatched = domain !== undefined;
|
|
52
|
-
return gulp.src(
|
|
58
|
+
return gulp.src(globs.src, { read: false })
|
|
53
59
|
.pipe($.notify(isMatched ? `Matching domain: "${domainIndex}".` : 'No domain matched.'));
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
gulp.
|
|
61
|
-
|
|
62
|
-
.pipe($.
|
|
63
|
-
.pipe(gulp.dest(
|
|
60
|
+
}
|
|
61
|
+
manageDomain.displayName = 'manage-domain';
|
|
62
|
+
|
|
63
|
+
function buildIndex() {
|
|
64
|
+
return gulp.src(globs.srcIndexHtml)
|
|
65
|
+
.pipe(injStr.after('<!-- endbuild -->', nl + tab + `<link rel="stylesheet" href="${stylesDir + cssFile}">`))
|
|
66
|
+
.pipe($.inject(gulp.src(globs.srcJs).pipe($.angularFilesort()), { relative: true })).on('error', notifyError)
|
|
67
|
+
.pipe($.wiredep())
|
|
68
|
+
.pipe($.useref())
|
|
69
|
+
.pipe(gulp.dest(globs.tmp));
|
|
70
|
+
}
|
|
71
|
+
buildIndex.displayName = 'build-index';
|
|
72
|
+
|
|
73
|
+
function injectDomain() {
|
|
74
|
+
return gulp.src(globs.tmp + jsFiles)
|
|
75
|
+
.pipe(injStr.replace('{{AUTOFRONT_DOMAIN}}', domain))
|
|
76
|
+
.pipe(gulp.dest(globs.tmp));
|
|
77
|
+
}
|
|
78
|
+
injectDomain.displayName = 'inject-domain';
|
|
79
|
+
|
|
80
|
+
const indexAndJs = gulp.series(buildIndex, injectDomain);
|
|
81
|
+
|
|
82
|
+
function styles() {
|
|
83
|
+
return mergeStream(getStream('css'), getStream('less', $.less), getStream('scss', gulpSass, '@import "variables";'))
|
|
84
|
+
.pipe($.concat(cssFile))
|
|
85
|
+
.pipe(gulp.dest(globs.tmp + stylesDir))
|
|
64
86
|
.pipe(browserSync.stream());
|
|
65
87
|
|
|
66
|
-
function
|
|
67
|
-
let stream = gulp.src(
|
|
88
|
+
function getStream(ext, process, extraCode) {
|
|
89
|
+
let stream = gulp.src(globs.src + stylesDir + cssFilename + '.' + ext, { allowEmpty: true });
|
|
68
90
|
if (process)
|
|
69
|
-
return stream
|
|
91
|
+
return stream
|
|
92
|
+
.pipe(injStr.prepend((extraCode ? extraCode + nl : '') + '// bower:' + ext + nl + '// endbower' + nl))
|
|
93
|
+
.pipe($.wiredep())
|
|
94
|
+
.pipe(process()).on('error', notifyError);
|
|
70
95
|
return stream;
|
|
71
96
|
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function fonts() {
|
|
100
|
+
return gulp.src(mainBowerFiles())
|
|
101
|
+
.pipe(filter(['eot', 'otf', 'svg', 'ttf', 'woff', 'woff2'], true))
|
|
102
|
+
.pipe(gulp.dest(globs.tmp + 'fonts/'));
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function others() {
|
|
75
106
|
const pugFilter = filter('pug');
|
|
76
|
-
return gulp.src(
|
|
107
|
+
return gulp.src(globs.srcOthers)
|
|
77
108
|
.pipe(pugFilter).pipe($.pug()).on('error', notifyError).pipe(pugFilter.restore)
|
|
78
|
-
.pipe(gulp.dest(
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
gulp.
|
|
83
|
-
|
|
109
|
+
.pipe(gulp.dest(globs.tmp));
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function about() {
|
|
113
|
+
return gulp.src('package.json')
|
|
114
|
+
.pipe($.about())
|
|
115
|
+
.pipe(gulp.dest(globs.tmp));
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const buildTmp = gulp.series(
|
|
119
|
+
gulp.parallel(clean, manageDomain),
|
|
120
|
+
gulp.parallel(indexAndJs, styles, fonts, others, about)
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
function browser(cb) {
|
|
124
|
+
browserSyncInit(globs.tmp);
|
|
84
125
|
cb();
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
gulp.watch(
|
|
89
|
-
gulp.watch(
|
|
90
|
-
gulp.watch(
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function watch() {
|
|
129
|
+
gulp.watch(globs.srcIndexAndSrcJs, indexAndJs);
|
|
130
|
+
gulp.watch(globs.srcStyles, styles);
|
|
131
|
+
gulp.watch(globs.srcOthers, others).on('unlink', function (path) {
|
|
132
|
+
gulp.src(path.replaceAll('\\', '/').replace(globs.src, globs.tmp).replace('.pug', '.html'), { read: false })
|
|
133
|
+
.pipe($.clean());
|
|
134
|
+
deleteEmpty(globs.tmp);
|
|
135
|
+
});
|
|
136
|
+
gulp.watch([globs.tmpAllFiles, '!' + globs.tmp + stylesDir + cssFile], function (cb) {
|
|
91
137
|
browserSync.reload();
|
|
92
138
|
cb();
|
|
93
139
|
});
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
gulp.task('
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
gulp.task('serve', gulp.series(buildTmp, browser, watch));
|
|
143
|
+
|
|
144
|
+
function cleanDist() {
|
|
145
|
+
return delDir(globs.dist);
|
|
146
|
+
}
|
|
147
|
+
cleanDist.displayName = 'clean:dist';
|
|
148
|
+
|
|
149
|
+
function copy() {
|
|
150
|
+
return gulp.src(globs.tmpAllFiles)
|
|
151
|
+
.pipe(gulp.dest(globs.dist));
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function buildTemplates() {
|
|
155
|
+
return gulp.src([globs.dist + getGlob('html'), '!' + globs.dist + indexHtmlFile])
|
|
156
|
+
.pipe($.cleanDest(globs.dist))
|
|
157
|
+
.pipe(minifyHtml())
|
|
158
|
+
.pipe($.angularTemplatecache(jsTemplatesFile, { module: 'app', transformUrl: function (url) { return url.slice(1); } }))
|
|
159
|
+
.pipe(gulp.dest(globs.dist));
|
|
160
|
+
}
|
|
161
|
+
buildTemplates.displayName = 'build-templates';
|
|
162
|
+
|
|
163
|
+
function cleanTemplates() {
|
|
164
|
+
return deleteEmpty(globs.dist);
|
|
165
|
+
}
|
|
166
|
+
cleanTemplates.displayName = 'clean-templates';
|
|
167
|
+
|
|
168
|
+
function finishBuild() {
|
|
102
169
|
const indexHtmlFilter = filter('html'),
|
|
103
170
|
cssFilter = filter('css'),
|
|
104
171
|
jsFilter = filter('js'),
|
|
105
172
|
cssAndJsFilter = filter(['css', 'js']),
|
|
106
173
|
imgFilter = filter(['png', 'jpg', 'gif', 'svg']),
|
|
107
174
|
jsonFilter = filter('json');
|
|
108
|
-
return gulp.src(
|
|
175
|
+
return gulp.src(globs.dist + allFiles)
|
|
109
176
|
.pipe(indexHtmlFilter).pipe(injStr.before('</body>', `<script src="${jsTemplatesFile}"></script>` + nl)).pipe(minifyHtml()).pipe(indexHtmlFilter.restore)
|
|
110
177
|
.pipe(cssFilter).pipe($.cssnano({ zindex: false })).pipe(cssFilter.restore)
|
|
111
178
|
.pipe(jsFilter).pipe($.ngAnnotate()).pipe($.terser()).pipe(jsFilter.restore)
|
|
@@ -114,38 +181,46 @@ gulp.task('build', gulp.series('build:tmp', 'copy', 'templates', () => {
|
|
|
114
181
|
.pipe(imgFilter).pipe($.imagemin()).pipe(imgFilter.restore)
|
|
115
182
|
.pipe(jsonFilter).pipe($.jsonmin()).pipe(jsonFilter.restore)
|
|
116
183
|
.pipe($.size({ showFiles: true }))
|
|
117
|
-
.pipe(gulp.dest(
|
|
118
|
-
}
|
|
119
|
-
|
|
184
|
+
.pipe(gulp.dest(globs.dist));
|
|
185
|
+
}
|
|
186
|
+
finishBuild.displayName = 'finish-build';
|
|
187
|
+
|
|
188
|
+
gulp.task('build', gulp.series(buildTmp, cleanDist, copy, buildTemplates, cleanTemplates, finishBuild));
|
|
189
|
+
|
|
190
|
+
function browserDist(cb) {
|
|
191
|
+
browserSyncInit(globs.dist);
|
|
192
|
+
cb();
|
|
193
|
+
}
|
|
194
|
+
browserDist.displayName = 'browser:dist';
|
|
195
|
+
|
|
196
|
+
gulp.task('serve:dist', gulp.series('build', browserDist));
|
|
120
197
|
|
|
121
198
|
gulp.task('default', gulp.task('serve'));
|
|
122
199
|
|
|
123
200
|
function html5Mode() {
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
jsTemplatesFile =
|
|
201
|
+
const prefix = '/';
|
|
202
|
+
stylesDir = prefix + stylesDir;
|
|
203
|
+
jsTemplatesFile = prefix + jsTemplatesFile;
|
|
127
204
|
}
|
|
128
205
|
|
|
129
|
-
function
|
|
130
|
-
const
|
|
131
|
-
|
|
206
|
+
function getGlob(ext = '*') {
|
|
207
|
+
const glob = '**/*.';
|
|
208
|
+
if (typeof ext == 'string')
|
|
209
|
+
return glob + ext;
|
|
210
|
+
return glob + '{' + ext.join() + '}';
|
|
132
211
|
}
|
|
133
212
|
|
|
134
|
-
function
|
|
135
|
-
return gulp.src(
|
|
213
|
+
function delDir(glob) {
|
|
214
|
+
return gulp.src(glob, { allowEmpty: true, read: false })
|
|
136
215
|
.pipe($.clean());
|
|
137
216
|
}
|
|
138
217
|
|
|
139
218
|
function filter(ext, isUnrestored) {
|
|
140
|
-
return $.filter(
|
|
219
|
+
return $.filter(getGlob(ext), { restore: !isUnrestored });
|
|
141
220
|
}
|
|
142
221
|
|
|
143
222
|
function browserSyncInit(path) {
|
|
144
|
-
browserSync.init({
|
|
145
|
-
server: {
|
|
146
|
-
baseDir: path
|
|
147
|
-
}
|
|
148
|
-
});
|
|
223
|
+
browserSync.init({ server: path });
|
|
149
224
|
}
|
|
150
225
|
|
|
151
226
|
function minifyHtml() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "autofront",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.3",
|
|
4
4
|
"description": "Automatisation of front-end by Gulp and Bower.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -62,5 +62,14 @@
|
|
|
62
62
|
"main-bower-files": "^2.13.1",
|
|
63
63
|
"merge-stream": "^1.0.1",
|
|
64
64
|
"sass": "^1.38.2"
|
|
65
|
+
},
|
|
66
|
+
"domains": {
|
|
67
|
+
"local": "http://localhost:8081/",
|
|
68
|
+
"development": "http://dev.mydomain/",
|
|
69
|
+
"production": "http://mydomain/"
|
|
70
|
+
},
|
|
71
|
+
"domainAliases": {
|
|
72
|
+
"prod": "production",
|
|
73
|
+
"dev": "development"
|
|
65
74
|
}
|
|
66
75
|
}
|