autofront 3.1.1 → 3.1.2

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 +24 -1
  2. package/index.js +45 -33
  3. package/package.json +3 -3
package/README.md CHANGED
@@ -100,4 +100,27 @@ Defining with:
100
100
  | <!-- 〃 --> | <!-- 〃 --> | `template` | Boolean | Templates loaded by [`$templateCache`](https://docs.angularjs.org/api/ng/service/$templateCache)? | `true` |
101
101
  | <!-- 〃 --> | `envs` | | Object | Environment variables list, with names as keys and data (whatever can be JSON parsed) as values. | `{}` |
102
102
 
103
- [^3]: It can be disabled assigning a falsy value.
103
+ [^3]: It can be disabled assigning a falsy value.
104
+
105
+ ## Pending
106
+
107
+ Fixes and improvements to do:
108
+
109
+ - Achieve detection of unnamed files (like `.gitkeep`, `.nomedia`...).
110
+ - Implement new settings, such as:
111
+ - `js`:
112
+ - Folder (`scripts/`) where to locate source code from Bower (`.tmp`), to avoid conflicts with own files in `src`.
113
+ - Indication about when Babel compilation (during serve or build?).
114
+ - List of CDNs to load.
115
+ - Exclusion folder(s) (whose any files will be forcely treated as "others").
116
+ - Settings changes (major releases):
117
+ - All "extra" (not HTML, CSS or JS) languages/libraries defaultly disabled?
118
+ - No CSS preprocessors configured? To activate one, pass info: extension file, Gulp plugin...
119
+ - Use [Gulp If](https://www.npmjs.com/package/gulp-if), [Gulp Plumber](https://www.npmjs.com/package/gulp-plumber), [Gulp Newer](https://www.npmjs.com/package/gulp-newer), [Gulp Changed](https://www.npmjs.com/package/gulp-changed), [Gulp Count](https://www.npmjs.com/package/gulp-count)...?
120
+ - Support:
121
+ - Markdown (compilation to HTML).
122
+ - [React](https://reactjs.org) (JSX), [Vue](https://vuejs.org)...?
123
+ - [Stylus](https://stylus-lang.com) and other CSS preprocessors?
124
+ - Avoid to build distributable CSS if no content?
125
+ - Create Gulp task to add new folder with files of template, AngularJS controller and styles in directory `app/`?
126
+ - Use [Typrod](https://github.com/mvicens/typrod) as Bower dependency in demo.
package/index.js CHANGED
@@ -49,8 +49,8 @@ const allFiles = getGlob(),
49
49
  cssComment = '<!-- autofrontcss -->',
50
50
  endCssComment = '<!-- endautofrontcss -->',
51
51
  jsComment = '<!-- autofrontjs -->',
52
- html5ModeJsFile = scriptsDir + 'html5-mode.js',
53
- jsTemplatesFile = scriptsDir + 'templates.js',
52
+ html5ModeFile = scriptsDir + 'html5-mode.js',
53
+ templatesFile = scriptsDir + 'templates.js',
54
54
  endJsComment = '<!-- endautofrontjs -->',
55
55
  cssFile = 'index.css',
56
56
  jsFile = 'index.js';
@@ -64,12 +64,15 @@ const globs = {
64
64
  dist: 'dist/'
65
65
  };
66
66
  globs.hiddenDist = '.' + globs.dist;
67
+ globs.srcStyles = globs.src;
67
68
  globs.srcIndex = globs.src + indexFile;
68
- globs.srcJs = globs.src + jsFiles;
69
+ globs.srcJss = globs.src + jsFiles;
69
70
  globs.srcOthers = [globs.src + allFiles];
70
- globs.tmpAllFiles = globs.tmp + allFiles;
71
- globs.distIndexFile = globs.dist + indexFile;
72
- globs.distTmpls = [globs.dist + getGlob('html'), '!' + globs.distIndexFile];
71
+ globs.tmpAll = globs.tmp + allFiles;
72
+ globs.tmpStyles = globs.tmp;
73
+ globs.distIndex = globs.dist + indexFile;
74
+ globs.distTmpls = [globs.dist + getGlob('html'), '!' + globs.distIndex];
75
+ globs.distCss = globs.dist + cssFile;
73
76
 
74
77
  const nl = '\r\n',
75
78
  tab = ' ';
@@ -83,6 +86,8 @@ setDefaultEnv.displayName = 'set-default-env';
83
86
  function setVariables(cb) {
84
87
  stylesDir = getSetting('cssFolder');
85
88
  stylesFilename = getSetting('filename');
89
+ for (const prop of ['srcStyles', 'tmpStyles'])
90
+ globs[prop] += stylesDir;
86
91
 
87
92
  for (const cssExt of [
88
93
  {
@@ -98,8 +103,8 @@ function setVariables(cb) {
98
103
  name: 'scss',
99
104
  process: $.sass(require('sass')),
100
105
  getExtraCode: () => {
101
- const file = globs.src + stylesDir + getSetting('variables') + '.scss';
102
- return fileExists(file) ? `@import "${file}";` : '';
106
+ const file = globs.srcStyles + getSetting('variables') + '.scss';
107
+ return fileExists(file) ? `@import "./${file}";` : '';
103
108
  },
104
109
  isPreprocessor: true
105
110
  }
@@ -110,13 +115,13 @@ function setVariables(cb) {
110
115
  }
111
116
  cssExtensions = cssExtensions.sort((a, b) => a.order - b.order);
112
117
 
113
- const srcStyles = [];
118
+ const srcStylesFiles = [];
114
119
  for (const cssExt of cssExtensions) {
115
120
  const glob = globs.src + getGlob(cssExt.name);
116
- srcStyles.push(glob);
121
+ srcStylesFiles.push(glob);
117
122
  cssExt.glob = glob;
118
123
  }
119
- globs.srcOthers.push(...[globs.srcIndex, globs.srcJs, ...srcStyles].map(glob => '!' + glob));
124
+ globs.srcOthers.push(...[globs.srcIndex, globs.srcJss, ...srcStylesFiles].map(glob => '!' + glob));
120
125
 
121
126
  cb();
122
127
  }
@@ -171,11 +176,11 @@ function index() {
171
176
  );
172
177
  if (getSetting('html5Mode')) {
173
178
  strs.unshift('<base href="/">');
174
- strs.push(getScriptTag(html5ModeJsFile));
179
+ strs.push(getScriptTag(html5ModeFile));
175
180
  }
176
181
  strs.push(endJsComment);
177
182
 
178
- let stream = gulp.src(globs.srcJs);
183
+ let stream = gulp.src(globs.srcJss);
179
184
  if (getSetting('ng'))
180
185
  stream = stream.pipe($.angularFilesort());
181
186
 
@@ -188,7 +193,7 @@ function index() {
188
193
  }
189
194
 
190
195
  function js() {
191
- return gulp.src(globs.srcJs)
196
+ return gulp.src(globs.srcJss)
192
197
  .pipe(replace('AUTOFRONT_ENV', JSON.stringify(envValue, undefined, tab)))
193
198
  .pipe(gulp.dest(globs.tmp));
194
199
  }
@@ -206,9 +211,10 @@ const styles = gulp.parallel(css, less, scss);
206
211
  function html5Mode(cb) {
207
212
  if (getSetting('html5Mode'))
208
213
  return $.addFiles([{
209
- name: html5ModeJsFile,
214
+ name: html5ModeFile,
210
215
  content: `(function () {
211
- angular.module('${getSetting('module')}')
216
+ angular
217
+ .module('${getSetting('module')}')
212
218
  .config(config);
213
219
 
214
220
  function config($locationProvider) {
@@ -264,7 +270,7 @@ function reload(cb) {
264
270
 
265
271
  function watch() {
266
272
  gulp.watch(globs.srcIndex, index);
267
- gulp.watch(globs.srcJs)
273
+ gulp.watch(globs.srcJss)
268
274
  .on('add', indexAndJs)
269
275
  .on('change', gulp.series(js))
270
276
  .on('unlink', gulp.series(index))
@@ -278,7 +284,7 @@ function watch() {
278
284
  .on('change', gulp.series(others))
279
285
  .on('unlink', path => { delFile(path, replaceExt); });
280
286
 
281
- gulp.watch([globs.tmpAllFiles, '!' + globs.tmp + stylesDir + getGlob('css')], reload).on('unlink', () => { deleteEmpty(globs.tmp); });
287
+ gulp.watch([globs.tmpAll, '!' + globs.tmpStyles + getGlob('css')], reload).on('unlink', () => { deleteEmpty(globs.tmp); });
282
288
 
283
289
  function delFile(path, fn) {
284
290
  path = path.replaceAll('\\', '/').replace(globs.src, globs.tmp);
@@ -295,7 +301,7 @@ function watch() {
295
301
  }
296
302
  }
297
303
 
298
- gulp.task('serve', gulp.series(
304
+ defineTask('serve', gulp.series(
299
305
  gulp.parallel(setDefaultEnv, setVariables),
300
306
  buildTmp, browser, watch
301
307
  ));
@@ -306,7 +312,7 @@ function removeFolderDist() {
306
312
  removeFolderDist.displayName = 'remove-folder:dist';
307
313
 
308
314
  function copy() {
309
- return gulp.src(globs.tmpAllFiles)
315
+ return gulp.src(globs.tmpAll)
310
316
  .pipe($.size())
311
317
  .pipe(gulp.dest(globs.dist));
312
318
  }
@@ -315,7 +321,7 @@ function templates() {
315
321
  let stream = gulp.src(globs.distTmpls)
316
322
  .pipe(gulpHtmlmin());
317
323
  if (getSetting('template'))
318
- stream = stream.pipe($.angularTemplatecache(jsTemplatesFile, { module: getSetting('module'), transformUrl: url => url.slice(1) }));
324
+ stream = stream.pipe($.angularTemplatecache(templatesFile, { module: getSetting('module'), transformUrl: url => url.slice(1) }));
319
325
  return stream.pipe(gulp.dest(globs.dist));
320
326
  }
321
327
 
@@ -326,9 +332,9 @@ function indexDist() {
326
332
  [jsComment]: `<!-- build:js ${jsFile} defer -->`,
327
333
  [endJsComment]: '<!-- endbuild -->'
328
334
  });
329
- let stream = gulp.src(globs.distIndexFile);
330
- if (getSetting('template') && fileExists(globs.dist + jsTemplatesFile))
331
- stream = stream.pipe($.injectString.before(endJsComment, getScriptTag(jsTemplatesFile) + nl + tab));
335
+ let stream = gulp.src(globs.distIndex);
336
+ if (getSetting('template') && fileExists(globs.dist + templatesFile))
337
+ stream = stream.pipe($.injectString.before(endJsComment, getScriptTag(templatesFile) + nl + tab));
332
338
  for (const [search, str] of replaces)
333
339
  stream = stream.pipe($.injectString.replace(search, str));
334
340
  return stream
@@ -338,7 +344,7 @@ function indexDist() {
338
344
  indexDist.displayName = 'index:dist';
339
345
 
340
346
  function purgeCss() {
341
- return gulp.src(globs.dist + cssFile)
347
+ return gulp.src(globs.distCss)
342
348
  .pipe($.purgecss({ content: [globs.dist + getGlob('html')] }))
343
349
  .pipe(gulp.dest(globs.dist));
344
350
  }
@@ -347,7 +353,7 @@ purgeCss.displayName = 'purge-css';
347
353
  function rebase() {
348
354
  const str = 'url(',
349
355
  quotes = ["'", '"'];
350
- let stream = gulp.src(globs.dist + cssFile)
356
+ let stream = gulp.src(globs.distCss)
351
357
  .pipe(replace(str + '\\s*', str));
352
358
  for (char of ['', ...quotes])
353
359
  for (str2 of ['http://', 'https://', '//', '/', 'data:', '#'])
@@ -363,7 +369,7 @@ function rebase() {
363
369
  function cleanFiles() {
364
370
  return gulp.src([
365
371
  ...(getSetting('template') ? globs.distTmpls : []),
366
- globs.dist + getGlob('css'), '!' + globs.dist + cssFile,
372
+ globs.dist + getGlob('css'), '!' + globs.distCss,
367
373
  globs.dist + jsFiles, '!' + globs.dist + jsFile
368
374
  ], { read: false })
369
375
  .pipe($.clean());
@@ -406,11 +412,11 @@ function finishBuild() {
406
412
  }
407
413
  finishBuild.displayName = 'finish-build';
408
414
 
409
- gulp.task('build', gulp.series(
415
+ defineTask('build', gulp.series(
410
416
  setVariables,
411
417
  gulp.parallel(buildTmp, removeFolderDist),
412
418
  copy, templates, indexDist, purgeCss, rebaseAndClean, compatible, minify, finishBuild
413
- ));
419
+ ), 'Build the project.');
414
420
 
415
421
  function hideFolderDist(cb) {
416
422
  hideDir(globs.dist);
@@ -424,9 +430,9 @@ function browserDist(cb) {
424
430
  }
425
431
  browserDist.displayName = 'browser:dist';
426
432
 
427
- gulp.task('serve:dist', gulp.series(setDefaultEnv, 'build', hideFolderDist, browserDist));
433
+ defineTask('serve:dist', gulp.series(setDefaultEnv, 'build', hideFolderDist, browserDist), 'Serve the built project.');
428
434
 
429
- gulp.task('default', gulp.series('serve'));
435
+ defineTask('default', gulp.series('serve'));
430
436
 
431
437
  function getGlob(ext = '*') {
432
438
  const glob = '**/*.';
@@ -507,7 +513,7 @@ function getStylesTask(ext) {
507
513
  const cssExt = cssExtensions.find(({ name }) => name == ext);
508
514
  if (cssExt) {
509
515
  const stylesFile = stylesFilename + '.' + ext,
510
- srcStylesFile = globs.src + stylesDir + stylesFile,
516
+ srcStylesFile = globs.srcStyles + stylesFile,
511
517
  isPreprocessor = cssExt.isPreprocessor,
512
518
  extraCode = cssExt.getExtraCode(),
513
519
  sep = nl + nl,
@@ -527,7 +533,7 @@ function getStylesTask(ext) {
527
533
  if (isPreprocessor)
528
534
  stream = stream.pipe($.rename({ suffix: '.' + ext }));
529
535
  return stream
530
- .pipe(gulp.dest(globs.tmp + stylesDir))
536
+ .pipe(gulp.dest(globs.tmpStyles))
531
537
  .pipe(browserSync.stream());
532
538
  }
533
539
 
@@ -541,6 +547,12 @@ function browserSyncInit(path) {
541
547
  browserSync.init({ server: path });
542
548
  }
543
549
 
550
+ function defineTask(name, composing, description) {
551
+ composing.description = description || 'Serve the project.';
552
+ composing.flags = { '--env': 'Environment name' };
553
+ gulp.task(name, composing);
554
+ }
555
+
544
556
  function getCompatibleTask(ext, getProcessedStream) {
545
557
  return getProcessingTask('compatible', ext, getProcessedStream);
546
558
  }
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "autofront",
3
- "version": "3.1.1",
3
+ "version": "3.1.2",
4
4
  "description": "Automation of front-end by Gulp and Bower.",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
7
  "serve": "gulp",
8
- "serve:dist": "gulp serve:dist --env=preproduction",
9
- "build": "gulp build"
8
+ "build": "gulp build",
9
+ "serve:dist": "gulp serve:dist --env=preproduction"
10
10
  },
11
11
  "repository": {
12
12
  "type": "git",