autofront 2.2.1 → 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.
Files changed (3) hide show
  1. package/README.md +7 -10
  2. package/index.js +145 -66
  3. package/package.json +10 -1
package/README.md CHANGED
@@ -64,11 +64,11 @@ Other command options, that appear immediately below, are available. And to use
64
64
 
65
65
  ### Tasks
66
66
 
67
- Mainly the Gulp ones are the following:
67
+ The Gulp ones are the following:
68
68
 
69
- * `gulp` or `gulp serve` are for running a test server and develop with live reload.
70
- * `gulp build` only builds production code, the distributable application (`dist` folder).
71
- * With `gulp serve:dist`, a combination of the above is achieved: Specifically, the server runs that last version but without reload.
69
+ - `gulp` or `gulp serve` are for running a test server and develop with live reload.
70
+ - `gulp build` only builds production code, the distributable application (`dist` folder).
71
+ - With `gulp serve:dist`, a combination of the above is achieved: Specifically, the server runs that last version but without reload.
72
72
 
73
73
  ### Domains
74
74
 
@@ -123,10 +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
- Fixes and improvements to do:
126
+ Improvements to do:
127
127
 
128
- * Once the server watch for changes:
129
- * Synchronize also the deletion of source files.
130
- * Resolve overwriting bug between pure CSS and preprocessors (Less/Sass).
131
- * Replace Bower as dependency manager.
132
- * Migrate AngularJS to new [Angular](https://angular.io).
128
+ - Replace Bower as dependency manager.
129
+ - Migrate AngularJS to new [Angular](https://angular.io).
package/index.js CHANGED
@@ -9,32 +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 = getFiles(),
17
+ const allFiles = getGlob(),
17
18
  indexHtmlFile = 'index.html',
19
+ jsFiles = getGlob('js'),
18
20
  cssFilename = 'index',
19
- cssFullFilename = cssFilename + '.css';
20
- let stylesFolder = 'styles/',
21
+ cssFile = cssFilename + '.css';
22
+ let stylesDir = 'styles/',
21
23
  jsTemplatesFile = 'scripts/templates.js';
22
24
 
23
- const paths = {
25
+ const globs = {
24
26
  src: 'src/',
25
27
  tmp: '.tmp/',
26
28
  dist: 'dist/'
27
29
  };
28
- paths.srcIndexHtml = paths.src + indexHtmlFile;
29
- paths.srcSass = paths.src + getFiles('scss');
30
- paths.srcLess = paths.src + getFiles('less');
31
- paths.srcJs = paths.src + getFiles('js');
32
- paths.srcOthers = [paths.src + allFiles, '!' + paths.srcIndexHtml, '!' + paths.srcSass, '!' + paths.srcLess, '!' + paths.srcJs];
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;
33
36
 
34
37
  const nl = '\n',
35
38
  tab = ' ';
36
39
 
37
- gulp.task('check', () => {
40
+ function clean() {
41
+ return delDir(globs.tmp);
42
+ }
43
+
44
+ function manageDomain() {
38
45
  const pckg = require(path.resolve('package.json')),
39
46
  domains = pckg.domains;
40
47
  let domainIndex = args[0] || 'local';
@@ -48,60 +55,124 @@ gulp.task('check', () => {
48
55
  domain = domains[domainIndex];
49
56
  }
50
57
  const isMatched = domain !== undefined;
51
- return gulp.src(paths.src)
58
+ return gulp.src(globs.src, { read: false })
52
59
  .pipe($.notify(isMatched ? `Matching domain: "${domainIndex}".` : 'No domain matched.'));
53
- });
54
-
55
- gulp.task('del', () => delFolder(paths.tmp));
56
- gulp.task('index-build', () => gulp.src(paths.srcIndexHtml).pipe(injStr.after('<!-- endbuild -->', nl + tab + `<link rel="stylesheet" href="${stylesFolder}${cssFullFilename}">`)).pipe($.inject(gulp.src(paths.srcJs).pipe($.angularFilesort()), { relative: true })).on('error', notifyError).pipe($.wiredep()).pipe($.useref()).pipe(gulp.dest(paths.tmp)));
57
- gulp.task('index-domain', () => gulp.src(paths.tmp + getFiles('js')).pipe(injStr.replace('{{AUTOFRONT_DOMAIN}}', domain)).pipe(gulp.dest(paths.tmp)));
58
- gulp.task('index', gulp.series('index-build', 'index-domain'));
59
- gulp.task('styles', () => {
60
- return mergeStream(getCssStream('scss', gulpSass, '@import "variables";'), getCssStream('less', $.less))
61
- .pipe($.concat(cssFullFilename))
62
- .pipe(gulp.dest(paths.tmp + stylesFolder))
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))
63
86
  .pipe(browserSync.stream());
64
87
 
65
- function getCssStream(ext, process, extraCode) {
66
- return gulp.src(paths.src + stylesFolder + cssFilename + '.' + ext, { allowEmpty: true }).pipe(injStr.prepend((extraCode ? extraCode + nl : '') + '// bower:' + ext + nl + '// endbower' + nl)).pipe($.wiredep()).pipe(process()).on('error', notifyError);
88
+ function getStream(ext, process, extraCode) {
89
+ let stream = gulp.src(globs.src + stylesDir + cssFilename + '.' + ext, { allowEmpty: true });
90
+ if (process)
91
+ return stream
92
+ .pipe(injStr.prepend((extraCode ? extraCode + nl : '') + '// bower:' + ext + nl + '// endbower' + nl))
93
+ .pipe($.wiredep())
94
+ .pipe(process()).on('error', notifyError);
95
+ return stream;
67
96
  }
68
- });
69
- gulp.task('fonts', () => gulp.src(mainBowerFiles()).pipe(filter(['eot', 'otf', 'svg', 'ttf', 'woff', 'woff2'], true)).pipe(gulp.dest(paths.tmp + 'fonts/')));
70
- gulp.task('others', () => {
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() {
71
106
  const pugFilter = filter('pug');
72
- return gulp.src(paths.srcOthers)
107
+ return gulp.src(globs.srcOthers)
73
108
  .pipe(pugFilter).pipe($.pug()).on('error', notifyError).pipe(pugFilter.restore)
74
- .pipe(gulp.dest(paths.tmp));
75
- });
76
- gulp.task('about', () => gulp.src('package.json').pipe($.about()).pipe(gulp.dest(paths.tmp)));
77
- gulp.task('build:tmp', gulp.series('del', 'check', gulp.parallel('index', 'styles', 'fonts', 'others', 'about')));
78
- gulp.task('browser', gulp.series('build:tmp', (cb) => {
79
- browserSyncInit(paths.tmp);
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);
80
125
  cb();
81
- }));
82
- gulp.task('serve', gulp.series('browser', () => {
83
- gulp.watch([paths.srcIndexHtml, paths.srcJs], gulp.task('index'));
84
- gulp.watch([paths.srcSass, paths.srcLess], gulp.task('styles'));
85
- gulp.watch(paths.srcOthers, gulp.task('others'));
86
- gulp.watch([paths.tmp + allFiles, '!' + paths.tmp + stylesFolder + cssFullFilename], function (cb) {
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) {
87
137
  browserSync.reload();
88
138
  cb();
89
139
  });
90
- }));
91
-
92
- gulp.task('del:dist', () => delFolder(paths.dist));
93
- gulp.task('copy', gulp.series('del:dist', () => gulp.src(paths.tmp + allFiles).pipe(gulp.dest(paths.dist))));
94
- gulp.task('templates-build', () => gulp.src([paths.dist + getFiles('html'), '!' + paths.dist + indexHtmlFile]).pipe($.cleanDest(paths.dist)).pipe(minifyHtml()).pipe($.angularTemplatecache(jsTemplatesFile, { module: 'app', transformUrl: function (url) { return url.slice(1); } })).pipe(gulp.dest(paths.dist)));
95
- gulp.task('templates-clean', () => require('delete-empty')(paths.dist));
96
- gulp.task('templates', gulp.series('templates-build', 'templates-clean'));
97
- gulp.task('build', gulp.series('build:tmp', 'copy', 'templates', () => {
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() {
98
169
  const indexHtmlFilter = filter('html'),
99
170
  cssFilter = filter('css'),
100
171
  jsFilter = filter('js'),
101
172
  cssAndJsFilter = filter(['css', 'js']),
102
173
  imgFilter = filter(['png', 'jpg', 'gif', 'svg']),
103
174
  jsonFilter = filter('json');
104
- return gulp.src(paths.dist + allFiles)
175
+ return gulp.src(globs.dist + allFiles)
105
176
  .pipe(indexHtmlFilter).pipe(injStr.before('</body>', `<script src="${jsTemplatesFile}"></script>` + nl)).pipe(minifyHtml()).pipe(indexHtmlFilter.restore)
106
177
  .pipe(cssFilter).pipe($.cssnano({ zindex: false })).pipe(cssFilter.restore)
107
178
  .pipe(jsFilter).pipe($.ngAnnotate()).pipe($.terser()).pipe(jsFilter.restore)
@@ -110,38 +181,46 @@ gulp.task('build', gulp.series('build:tmp', 'copy', 'templates', () => {
110
181
  .pipe(imgFilter).pipe($.imagemin()).pipe(imgFilter.restore)
111
182
  .pipe(jsonFilter).pipe($.jsonmin()).pipe(jsonFilter.restore)
112
183
  .pipe($.size({ showFiles: true }))
113
- .pipe(gulp.dest(paths.dist));
114
- }));
115
- gulp.task('serve:dist', gulp.series('build', () => browserSyncInit(paths.dist)));
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));
116
197
 
117
198
  gulp.task('default', gulp.task('serve'));
118
199
 
119
200
  function html5Mode() {
120
- const pathPrefix = '/';
121
- stylesFolder = pathPrefix + stylesFolder;
122
- jsTemplatesFile = pathPrefix + jsTemplatesFile;
201
+ const prefix = '/';
202
+ stylesDir = prefix + stylesDir;
203
+ jsTemplatesFile = prefix + jsTemplatesFile;
123
204
  }
124
205
 
125
- function getFiles(ext = '*') {
126
- const isArray = typeof ext != 'string';
127
- return '**/*.' + (isArray ? '{' : '') + (isArray ? ext.join() : ext) + (isArray ? '}' : '');
206
+ function getGlob(ext = '*') {
207
+ const glob = '**/*.';
208
+ if (typeof ext == 'string')
209
+ return glob + ext;
210
+ return glob + '{' + ext.join() + '}';
128
211
  }
129
212
 
130
- function delFolder(path) {
131
- return gulp.src(path, { allowEmpty: true, read: false })
213
+ function delDir(glob) {
214
+ return gulp.src(glob, { allowEmpty: true, read: false })
132
215
  .pipe($.clean());
133
216
  }
134
217
 
135
218
  function filter(ext, isUnrestored) {
136
- return $.filter(getFiles(ext), { restore: !isUnrestored });
219
+ return $.filter(getGlob(ext), { restore: !isUnrestored });
137
220
  }
138
221
 
139
222
  function browserSyncInit(path) {
140
- browserSync.init({
141
- server: {
142
- baseDir: path
143
- }
144
- });
223
+ browserSync.init({ server: path });
145
224
  }
146
225
 
147
226
  function minifyHtml() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "autofront",
3
- "version": "2.2.1",
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
  }