forked from liorgrossman/darkness
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
123 lines (107 loc) · 5.19 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
"use strict";
var fs = require('fs');
var gulp = require('gulp');
var sass = require('gulp-sass');
var sourcemaps = require('gulp-sourcemaps');
var gutil = require('gulp-util');
var rename = require('gulp-rename');
var del = require('del');
var zip = require('gulp-zip');
const zipFilename = 'Darkness-CWS-latest.zip';
const chromeDevelopmentDir = 'chrome-extension';
const chromeProductionDir = 'chrome-production';
const chromeZipsDir = 'chrome-zips';
var manifestJson = JSON.parse(fs.readFileSync(chromeDevelopmentDir + '/manifest.json'));
//----------------------------------------------------------------------------------------------------------------------------------------------------
// Preapre a ZIP that is uploaded to Chrome Web Store:
// https://chrome.google.com/webstore/detail/darkness-beautiful-dark-t/imilbobhamcfahccagbncamhpnbkaenm
//----------------------------------------------------------------------------------------------------------------------------------------------------
// Replicate dev to production
gulp.task('cws:replicate', function() {
gutil.log("Replicate started");
// Delete any existing production dir
var deletedFiles = del.sync([chromeProductionDir, chromeZipsDir + '/' + zipFilename], {force: true, dryRun: false});
for (var i in deletedFiles) gutil.log("Deleted: ", deletedFiles[i]);
// Copy dev dir recursively to production dir
return gulp.src([chromeDevelopmentDir + '/**/*']).pipe(gulp.dest(chromeProductionDir));
});
// Clean up unnecessary files
gulp.task('cws:cleanup', ['cws:replicate'], function() {
gutil.log("Cleanup started");
var deletedFiles = del.sync(
[chromeProductionDir + '/themes',
chromeProductionDir + '/style'],
{force: true, dryRun: false});
for (var i in deletedFiles) gutil.log("Deleted directory: ", deletedFiles[i]);
deletedFiles = del.sync(
[chromeProductionDir + '/**/*.scss',
chromeProductionDir + '/**/*.map'],
{force: true, dryRun: false});
for (var i in deletedFiles) gutil.log("Deleted file: ", deletedFiles[i]);
});
// Zip the production directory
gulp.task('cws:zip', ['cws:cleanup'], function() {
gutil.log("Zipping...");
// Create a zip file
return gulp.src(chromeProductionDir + '/**/*')
.pipe(zip(zipFilename))
.pipe(gulp.dest(chromeZipsDir));
});
// Zip the production directory
gulp.task('cws:archive', ['cws:zip'], function() {
var archiveFilename = 'Darkness-CWS-v' + manifestJson.version + '_(' + (new Date()).toISOString().slice(0,19).replace('T', '__').replace(/:/g, '-') + ').zip';
gutil.log("Copying to archive: " + archiveFilename);
// Copy to archive
return gulp.src(chromeZipsDir + '/' + zipFilename).pipe(rename(archiveFilename)).pipe(gulp.dest(chromeZipsDir));
});
gulp.task('cws', ['cws:replicate', 'cws:cleanup', 'cws:zip', 'cws:archive']);
//----------------------------------------------------------------------------------------------------------------------------------------------------
// SASS compilation
//----------------------------------------------------------------------------------------------------------------------------------------------------
// Clean up all existing (complied) CSS files
gulp.task('sass:cleanup', function() {
gutil.log("Cleaning up .css and .css.map files");
var deletedFiles = del.sync([
chromeDevelopmentDir + '/themes/**/*.css',
chromeDevelopmentDir + '/themes/**/*.css.map',
chromeDevelopmentDir + '/themes-css',
chromeDevelopmentDir + '/style/**/*.css',
chromeDevelopmentDir + '/style/**/*.css.map',
chromeDevelopmentDir + '/style-css'
],
{force: true, dryRun: false});
for (var i in deletedFiles) gutil.log("Deleted: ", deletedFiles[i]);
});
// Compile all SCSS files to CSS & map files
gulp.task('sass:compile', function() {
gulp.src(chromeDevelopmentDir + '/style/*.scss')
.pipe(sourcemaps.init())
.pipe(sass().on('error', sass.logError))
.pipe(sourcemaps.write("./"))
.pipe(gulp.dest(chromeDevelopmentDir + '/style-css'));
gulp.src(chromeDevelopmentDir + '/themes/*.scss')
.pipe(sourcemaps.init())
.pipe(sass().on('error', sass.logError))
.pipe(sourcemaps.write("./"))
.pipe(gulp.dest(chromeDevelopmentDir + '/themes-css'));
});
// Compile all SCSS files to CSS & map files + keep watching them
gulp.task('sass:watch', function() {
gutil.log("Watching for changes in .scss files");
gulp.start('sass:compile');
gulp.watch(chromeDevelopmentDir + '/themes/**/*.scss', ['sass:compile']);
gulp.watch(chromeDevelopmentDir + '/style/**/*.scss', ['sass:compile']);
});
//----------------------------------------------------------------------------------------------------------------------------------------------------
// Installation
//----------------------------------------------------------------------------------------------------------------------------------------------------
// Compile all SCSS files to CSS & map files + keep watching them
gulp.task('install', function() {
gulp.start('sass:cleanup');
gulp.start('sass:compile');
gutil.log("\nInstallation complete!\n" +
"You may use the following commands:\n" +
"$ gulp sass:compile compile all .scss files to .css and .css.map\n" +
"$ gulp sass:cleanup delete all compiled .css and .css.map files\n" +
"$ gulp sass:watch watch all .scss files and compile when changed (recommended)\n");
});