autofront 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 (3) hide show
  1. package/README.md +35 -0
  2. package/index.js +103 -0
  3. package/package.json +50 -0
package/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # Autofront
2
+
3
+ Gulp settings for projects.
4
+
5
+ ## Tasks
6
+
7
+ - `gulp` or `gulp serve` are for running a test (development) server with live reload.
8
+ - With `gulp serve:dist`, the server is production, but without the reload.
9
+ - `gulp build` builds the distributable version.
10
+
11
+ ## Folder structure
12
+
13
+ Here is the essential basic organization you must to put in your project:
14
+
15
+ ```text
16
+ ├─ bower_components/
17
+ ├─ nodes_modules/
18
+ ├─ src/
19
+ │ ├─ fonts/
20
+ │ ├─ styles/
21
+ │ │ └─ index.less
22
+ │ └─ index.html
23
+ ├─ .gitignore
24
+ ├─ bower.json
25
+ ├─ gulpfile.js
26
+ ├─ package-lock.json
27
+ └─ package.json
28
+ ```
29
+
30
+ The disposition of the other files present in `src` is merely indicative; and its content, adjustable and optional.
31
+
32
+ ## Pending
33
+
34
+ - Once the server waits for changes, synchronize also the deletion of files (from `src`).
35
+ - Bower should be replaced as a dependency manager. It is currently [under maintenance](https://bower.io/blog/2017/how-to-migrate-away-from-bower/) and, therefore, its use is not recommended.
package/index.js ADDED
@@ -0,0 +1,103 @@
1
+ const gulp = require('gulp'),
2
+ mainBowerFiles = require('main-bower-files'),
3
+ $ = require('gulp-load-plugins')(),
4
+ injStr = $.injectString,
5
+ gulpSync = $.sync(gulp),
6
+ browserSync = require('browser-sync').create(),
7
+ deleteEmpty = require('delete-empty');
8
+
9
+ const allFiles = getFiles(),
10
+ indexHtmlFile = 'index.html',
11
+ stylesFolder = 'styles/',
12
+ cssFilename = stylesFolder+'index',
13
+ jsTemplatesFile = 'scripts/templates.js';
14
+
15
+ const paths = {
16
+ src: 'src/',
17
+ tmp: '.tmp/',
18
+ dist: 'dist/'
19
+ };
20
+ paths.srcIndexHtml = paths.src+indexHtmlFile;
21
+ paths.srcLess = paths.src+getFiles('less');
22
+ paths.srcJs = paths.src+getFiles('js');
23
+ paths.srcOthers = [paths.src+allFiles, '!'+paths.srcIndexHtml, '!'+paths.srcLess, '!'+paths.srcJs];
24
+
25
+ const nl = '\n',
26
+ tab = ' ';
27
+
28
+ gulp.task('del', () => delFolder(paths.tmp));
29
+ gulp.task('index', () => gulp.src(paths.srcIndexHtml).pipe(injStr.after('<!-- endbuild -->', nl+tab+'<link rel="stylesheet" href="'+cssFilename+'.css">')).pipe($.wiredep()).pipe($.useref()).pipe(gulp.dest(paths.tmp)));
30
+ gulp.task('styles', () => gulp.src(paths.src+cssFilename+'.less').pipe(injStr.prepend('// bower:less'+nl+'// endbower'+nl)).pipe($.wiredep()).pipe($.less()).on('error', $.notify.onError(error => error.message)).pipe(gulp.dest(paths.tmp+stylesFolder)));
31
+ gulp.task('fonts', () => gulp.src(mainBowerFiles()).pipe(filter(['eot','otf','svg','ttf', 'woff', 'woff2'], true)).pipe(gulp.dest(paths.tmp+'fonts/')));
32
+ gulp.task('others', () => gulp.src(paths.srcOthers).pipe(gulp.dest(paths.tmp)));
33
+ gulp.task('about', () => gulp.src('package.json').pipe($.about()).pipe(gulp.dest(paths.tmp)));
34
+ gulp.task('build:tmp', gulpSync.sync([
35
+ 'del',
36
+ ['index', 'styles', 'fonts', 'others', 'about']
37
+ ]));
38
+ gulp.task('browser', ['build:tmp'], () => browserSyncInit(paths.tmp));
39
+ gulp.task('serve', ['browser'], () => {
40
+ gulp.watch([paths.srcIndexHtml, paths.srcJs], ['index']);
41
+ gulp.watch(paths.srcLess, ['styles']);
42
+ gulp.watch(paths.srcOthers, ['others']);
43
+ gulp.watch(paths.tmp+allFiles, function(event) {
44
+ browserSync.reload(event.path);
45
+ });
46
+ });
47
+
48
+ gulp.task('del:dist', () => delFolder(paths.dist));
49
+ gulp.task('copy', ['del:dist'], () => gulp.src(paths.tmp+allFiles).pipe(gulp.dest(paths.dist)));
50
+ gulp.task('templates-build', () => gulp.src([paths.dist+getFiles('html'), '!'+paths.dist+indexHtmlFile]).pipe($.cleanDest(paths.dist)).pipe($.htmlmin({collapseWhitespace: true, conservativeCollapse: true})).pipe($.angularTemplatecache(jsTemplatesFile, {module: 'app'})).pipe(gulp.dest(paths.dist)));
51
+ gulp.task('templates-clean', () => deleteEmpty(paths.dist));
52
+ gulp.task('templates', gulpSync.sync([
53
+ 'templates-build',
54
+ 'templates-clean'
55
+ ]));
56
+ gulp.task('build', gulpSync.sync([
57
+ 'build:tmp',
58
+ 'copy',
59
+ 'templates'
60
+ ]), () => {
61
+ const indexHtmlFilter = filter('html'),
62
+ cssFilter = filter('css'),
63
+ jsFilter = filter('js'),
64
+ cssAndJsFilter = filter(['css','js']),
65
+ imgFilter = filter(['png','jpg','gif','svg']),
66
+ jsonFilter = filter('json');
67
+ return gulp.src(paths.dist+allFiles)
68
+ .pipe(indexHtmlFilter).pipe(injStr.before('</body>', '<script src="'+jsTemplatesFile+'"></script>'+nl)).pipe($.htmlmin({collapseWhitespace: true})).pipe(indexHtmlFilter.restore)
69
+ .pipe(cssFilter).pipe($.cssnano({zindex: false})).pipe(cssFilter.restore)
70
+ .pipe(jsFilter).pipe($.ngAnnotate()).pipe($.uglify()).pipe(jsFilter.restore)
71
+ .pipe(cssAndJsFilter).pipe($.rev()).pipe($.revDeleteOriginal()).pipe(cssAndJsFilter.restore)
72
+ .pipe($.revReplace())
73
+ .pipe(imgFilter).pipe($.imagemin()).pipe(imgFilter.restore)
74
+ .pipe(jsonFilter).pipe($.jsonmin()).pipe(jsonFilter.restore)
75
+ .pipe($.size({showFiles: true}))
76
+ .pipe(gulp.dest(paths.dist));
77
+ });
78
+ gulp.task('serve:dist', ['build'], () => browserSyncInit(paths.dist));
79
+
80
+ gulp.task('default', ['serve']);
81
+
82
+ function getFiles(ext) {
83
+ ext = ext || '*';
84
+ const isArray = typeof ext != 'string';
85
+ return '**/*.'+(isArray?'{':'')+(isArray?ext.join():ext)+(isArray?'}':'');
86
+ }
87
+
88
+ function delFolder(path) {
89
+ return gulp.src(path, {read: false})
90
+ .pipe($.clean());
91
+ }
92
+
93
+ function filter(ext, isUnrestored) {
94
+ return $.filter(getFiles(ext), {restore: !isUnrestored});
95
+ }
96
+
97
+ function browserSyncInit(path) {
98
+ return browserSync.init({
99
+ server: {
100
+ baseDir: path
101
+ }
102
+ });
103
+ }
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "autofront",
3
+ "version": "1.0.0",
4
+ "description": "Gulp settings for projects.",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/mvicens/autofront.git"
12
+ },
13
+ "keywords": [
14
+ "gulp"
15
+ ],
16
+ "author": "Miquel Alejandro Vicens Dalmau",
17
+ "license": "ISC",
18
+ "bugs": {
19
+ "url": "https://github.com/mvicens/autofront/issues"
20
+ },
21
+ "homepage": "https://github.com/mvicens/autofront#readme",
22
+ "dependencies": {
23
+ "browser-sync": "^2.24.4",
24
+ "delete-empty": "^2.0.0",
25
+ "gulp": "^3.9.1",
26
+ "gulp-about": "^1.1.0",
27
+ "gulp-angular-templatecache": "^2.2.1",
28
+ "gulp-clean": "^0.4.0",
29
+ "gulp-clean-dest": "^0.2.0",
30
+ "gulp-cssnano": "^2.1.3",
31
+ "gulp-filter": "^5.1.0",
32
+ "gulp-htmlmin": "^4.0.0",
33
+ "gulp-imagemin": "^4.1.0",
34
+ "gulp-inject-string": "^1.1.1",
35
+ "gulp-jsonmin": "^1.1.0",
36
+ "gulp-less": "^3.5.0",
37
+ "gulp-load-plugins": "^1.5.0",
38
+ "gulp-ng-annotate": "^2.1.0",
39
+ "gulp-notify": "^3.2.0",
40
+ "gulp-rev": "^8.1.1",
41
+ "gulp-rev-delete-original": "^0.2.3",
42
+ "gulp-rev-replace": "^0.4.4",
43
+ "gulp-size": "^3.0.0",
44
+ "gulp-sync": "^0.1.4",
45
+ "gulp-uglify": "^3.0.0",
46
+ "gulp-useref": "^3.1.5",
47
+ "gulp-wiredep": "^1.2.0",
48
+ "main-bower-files": "^2.13.1"
49
+ }
50
+ }