Skip to content

Commit

Permalink
[build] Updated build script to also update/add copyright
Browse files Browse the repository at this point in the history
  • Loading branch information
Grovkillen committed Dec 29, 2019
1 parent 313b5c6 commit 0652f5e
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 4 deletions.
86 changes: 85 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
module.exports = function(grunt) {

// Project configuration.
grunt.initConfig({
// minify js
Expand Down Expand Up @@ -107,6 +106,33 @@ module.exports = function(grunt) {
}]
}
},
// copyright
file_append: {
copyright: {
files: [
{
prepend: '<-- GUIEasy Copyright (C) 2019-' + new Date().getFullYear() + ' Jimmy "Grovkillen" Westberg -->',
input: 'build/temp/index.min.html'
},
{
prepend: '/* GUIEasy Copyright (C) 2019-' + new Date().getFullYear() + ' Jimmy "Grovkillen" Westberg */',
input: 'build/temp/gui.min.js'
},
{
prepend: '/* GUIEasy Copyright (C) 2019-' + new Date().getFullYear() + ' Jimmy "Grovkillen" Westberg */',
input: 'build/temp/gui.min.css'
},
{
prepend: '/* GUIEasy Copyright (C) 2019-' + new Date().getFullYear() + ' Jimmy "Grovkillen" Westberg */',
input: 'build/temp/forms.min.js'
},
{
prepend: '/* GUIEasy Copyright (C) 2019-' + new Date().getFullYear() + ' Jimmy "Grovkillen" Westberg */',
input: 'build/temp/dash.min.js'
}
]
}
},
// rename the temp folder
rename: {
temp: {
Expand All @@ -127,6 +153,7 @@ module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-contrib-rename');
grunt.loadNpmTasks('grunt-contrib-compress');
grunt.loadNpmTasks('grunt-processhtml');
grunt.loadNpmTasks('grunt-file-append');

// build gui easy task
grunt.registerTask('buildGuiEasy', 'Will build the project',
Expand All @@ -152,14 +179,71 @@ module.exports = function(grunt) {
'uglify',
'cssmin',
'processhtml',
'file_append',
'compress',
'rename'
)
});

// the 'default' task can be run just by typing "grunt" on the command line
grunt.registerTask('default', [
'verifyCopyright',
'buildGuiEasy'
]);

grunt.registerTask('verifyCopyright', function () {

let fileRead, firstLine, counter = 0, fileExtension, commentWrapper;
let copyrightInfo = 'GUIEasy Copyright (C) 2019-' + new Date().getFullYear() + ' Jimmy "Grovkillen" Westberg';

//get file extension regex
let re = /(?:\.([^.]+))?$/;

grunt.log.writeln();

// read all subdirectories from your modules folder
grunt.file.expand(
{filter: 'isFile', cwd: 'src/'},
["**/*.js", ['**/*.html', ['**/*.css']]])
.forEach(function (dir) {
fileRead = grunt.file.read('src/' + dir).split('\n');
firstLine = fileRead[0];
let startIndex = 0;
//Deleting old copyright.
if (firstLine.search("Copyright") > -1) {
startIndex = 1;
}
//Start updating copyright.
counter++;
if (startIndex > 0) {
grunt.log.ok(dir + " --> updating copyright text");
} else {
grunt.log.ok(dir + " --> doesn't have copyright. Writing it.");
}
fileExtension = re.exec(dir)[1];
switch (fileExtension) {
case 'js':
commentWrapper = '/* ' + copyrightInfo + ' */';
break;
case 'html':
commentWrapper = '<!-- ' + copyrightInfo + ' -->';
break;
case 'css':
commentWrapper = '/* ' + copyrightInfo + ' */';
break;
default:
commentWrapper = null;
grunt.log.writeln('file extension not recognized');
break;
}

if (commentWrapper) {
fileRead.unshift(commentWrapper);
fileRead = fileRead.slice(startIndex).join('\n');
grunt.file.write( 'src/' + dir, fileRead);
}
});

grunt.log.ok('Searched through', counter, 'files.');
});
};
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "compile-gui-easy",
"version": "1.0.0",
"author": "Jimmy 'Grovkillen' Westberg",
"license": "LicenseRef-LICENSE.md",
"license": "GPL-3.0-or-later",
"description": "A packager for the GUI Easy application for ESP Easy",
"bin": {
"index.html.gz": "build/<version>/"
Expand All @@ -19,7 +19,8 @@
"grunt-contrib-clean": "^2.0.0",
"grunt-contrib-compress": "^1.6.0",
"grunt-zopfli-native": "^2.0.0",
"grunt-processhtml": "^0.4.2"
"grunt-processhtml": "^0.4.2",
"grunt-file-append": "^0.0.7"
},
"dependencies": {
"npm": "^6.13.1"
Expand Down
1 change: 0 additions & 1 deletion test.txt

This file was deleted.

0 comments on commit 0652f5e

Please sign in to comment.