Skip to content

Commit

Permalink
[grunt] added release file size (index.htm.gz)
Browse files Browse the repository at this point in the history
  • Loading branch information
Grovkillen committed Feb 21, 2020
1 parent 59a6edf commit 523e3e1
Show file tree
Hide file tree
Showing 12 changed files with 112 additions and 20 deletions.
89 changes: 80 additions & 9 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,19 +171,55 @@ module.exports = function(grunt) {
]
}
},
// file sizes
folder_list : {
// file size report
size_report: {
source_files: {
options: {
header: 'source files:'
},
files: {
list: ['src/*']
}
},
release_files: {
options: {
files: true,
folders: true
header: 'release files:'
},
files:
files: {
list: ['build/temp/*/*.gz']
}
}
},
// source report
folder_list : {
files :
{
src: ['**'],
dest: 'build/temp/info/source_files.json',
cwd: 'src/'
}
},
// release files
filesize: {
release: {
files: [
{
expand: true,
cwd: 'build/temp',
src: ['main/*.gz', 'noDash/*.gz', 'mini/*.gz']
}
],
options: {
output: [
{
path: "build/release_sizes.txt",
format: "{filename}:{size}",
append: true
}
]
}
}
},
// copy release info
copy: {
releaseInfo : {
Expand Down Expand Up @@ -211,6 +247,8 @@ module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-processhtml');
grunt.loadNpmTasks('grunt-file-append');
grunt.loadNpmTasks('grunt-folder-list');
grunt.loadNpmTasks('grunt-size-report');
grunt.loadNpmTasks('grunt-filesize');

// the 'default' task can be run just by typing "grunt" on the command line
grunt.registerTask('default', [
Expand Down Expand Up @@ -242,14 +280,12 @@ module.exports = function(grunt) {
let packageJSON = grunt.file.read('package.json');
packageJSON = JSON.parse(packageJSON);
packageJSON.version = guiEasy.major + '.' + guiEasy.minor + '.' + guiEasy.minimal;
packageJSON.versionName = version;
packageJSON.main["index.html.gz"] = "build/main/" + version + "/";
packageJSON.timestamp = Date.now();
grunt.file.write('package.json',
JSON.stringify(packageJSON,null,2)
);
grunt.file.write('release.txt',
'timestamp:' + packageJSON.timestamp + '\nmajor:' + guiEasy.major + '\nminor:' + guiEasy.minor + '\nminimal:' + guiEasy.minimal + '\nrc:' + guiEasy.releaseCandidate + '\ndev:' + guiEasy.development
);
grunt.log.ok(version);
// add version as a property for the grunt ini loop
grunt.config("version", version);
Expand All @@ -266,11 +302,20 @@ module.exports = function(grunt) {
'clean:tempFiles',
'clean:noDash',
'folder_list',
'filesize',
'size_report',
'copy',
'rename',
'clean:releaseInfo',
'listBuilds'
'listBuilds',
'releaseFileSizes'
);

grunt.log.ok('writing release info file');
grunt.file.write('release.txt',
'timestamp:' + packageJSON.timestamp + '\nmajor:' + guiEasy.major + '\nminor:' + guiEasy.minor + '\nminimal:' + guiEasy.minimal + '\nrc:' + guiEasy.releaseCandidate + '\ndev:' + guiEasy.development
);
grunt.log.ok('DONE!');
});

grunt.registerTask('verifyCopyright', function () {
Expand Down Expand Up @@ -329,13 +374,39 @@ module.exports = function(grunt) {
});

grunt.registerTask('listBuilds', function () {
grunt.log.ok('looking for release folders...');
let folders = "";
grunt.file.expand(
{filter: 'isDirectory', cwd: 'build/'},
['*'])
.forEach(function (dir) {
folders += dir + "\n";
});
grunt.log.ok((folders.split(/\n/).length - 1) + " releases found.");
grunt.file.write( 'build/releases.txt', folders);
});

grunt.registerTask('releaseFileSizes', function () {
grunt.log.ok('parsing release file sizes...');
let files = "files:[";
let packageJSON = grunt.file.read('package.json');
let version = JSON.parse(packageJSON).versionName;
let releaseInfo = grunt.file.read('build/' + version + '/info/release.txt');
let fileSizes = grunt.file.read('build/release_sizes.txt');
grunt.file.delete('build/release_sizes.txt');
fileSizes = fileSizes.split(/\n/);
fileSizes.forEach(function (file) {
if (file.length > 0) {
let build = file.split(":")[0].split(/[\\/]/);
build = build[(build.length - 2)];
let size = file.split(":")[1];
files += '{"build":"' + build + '","size":' + size + "}";
}
}
);
files += "]";
files = files.replace(/}{/g, "},{");
files = files.replace(/\r?\n|\r/g, "");
grunt.file.write( 'build/' + version + '/info/release.txt', releaseInfo + "\n" + files);
});
};
7 changes: 5 additions & 2 deletions build/0.0.nightly.1/info/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gui-easy",
"timestamp": 1582300231096,
"timestamp": 1582313235629,
"version": "0.0.1",
"author": "Jimmy 'Grovkillen' Westberg <jimmy@grovkillen.com> (https://grovkillen.com)",
"description": "Front End for ESP Easy",
Expand Down Expand Up @@ -28,6 +28,8 @@
"grunt-file-append": "^0.0.7",
"grunt-contrib-copy": "^1.0.0",
"grunt-folder-list": "^1.1.0",
"grunt-size-report": "^0.1.4",
"grunt-filesize": "^0.0.7",
"npm": "^6.13.4"
},
"scripts": {
Expand All @@ -38,5 +40,6 @@
"CSS framework",
"GUI",
"Frontend"
]
],
"versionName": "0.0.nightly.1"
}
5 changes: 3 additions & 2 deletions build/0.0.nightly.1/info/release.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
timestamp:1582300231096
timestamp:1582313235629
major:0
minor:0
minimal:1
rc:0
dev:true
dev:true
files:[{"build":"main","size":77228},{"build":"noDash","size":66181},{"build":"mini","size":1451}]
2 changes: 1 addition & 1 deletion build/0.0.nightly.1/info/source_files.json

Large diffs are not rendered by default.

Binary file modified build/0.0.nightly.1/main/index.htm.gz
Binary file not shown.
Binary file modified build/0.0.nightly.1/mini/index.htm.gz
Binary file not shown.
Binary file modified build/0.0.nightly.1/noDash/index.htm.gz
Binary file not shown.
Binary file modified build/0.0.nightly.1/src-0.0.nightly.1.zip
Binary file not shown.
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gui-easy",
"timestamp": 1582300231096,
"timestamp": 1582313235629,
"version": "0.0.1",
"author": "Jimmy 'Grovkillen' Westberg <jimmy@grovkillen.com> (https://grovkillen.com)",
"description": "Front End for ESP Easy",
Expand Down Expand Up @@ -28,6 +28,8 @@
"grunt-file-append": "^0.0.7",
"grunt-contrib-copy": "^1.0.0",
"grunt-folder-list": "^1.1.0",
"grunt-size-report": "^0.1.4",
"grunt-filesize": "^0.0.7",
"npm": "^6.13.4"
},
"scripts": {
Expand All @@ -38,5 +40,6 @@
"CSS framework",
"GUI",
"Frontend"
]
],
"versionName": "0.0.nightly.1"
}
11 changes: 11 additions & 0 deletions src/gui_easy_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,17 @@ const helpEasy = {
array[index].stats["configDat"].run = Date.now() - timeStart;
array[index].stats["configDat"].timestamp = timeStart;
})
.catch(error => {
helpEasy.addToLogDOM('Error fetching (config.dat): ' + error, 0, "error");
array[index].stats.error++;
let nextRun = Date.now() + array[index].stats[endpoint].TTL_fallback;
array[index]["scheduler"].push([nextRun, endpoint]);
array[index]["scheduler"].sort();
array[index].stats["lastRun"] = Date.now();
array[index].stats["configDat"].run = Date.now() - timeStart;
array[index].stats["configDat"].timestamp = Date.now();
guiEasy.fetchCount.error++;
});
},
'parseConfigDat': function (data, config, start) {
//part of ppisljar's code
Expand Down
2 changes: 1 addition & 1 deletion src/gui_easy_settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const guiEasy = {
'get':[
{'endpoint':'json', 'ttl_fallback':2000},
{'endpoint':'buildinfo', 'ttl_fallback':99999999}, //will not update very often...
{'endpoint':'logjson'}, //Fallback of 29999 will not be part of first boot fetch
{'endpoint':'logjson'}, //Fallback of 29999 will not be part of first boot fetch
{'endpoint':'sysinfo_json'},
{'endpoint':'node_list_json'},
{'endpoint':'filelist_json'},
Expand Down
9 changes: 6 additions & 3 deletions src/index-minimal.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,17 @@
await fetch(releaseList)
.then(res => res.text())
.then((list) => {
let temp = list.split(/\n/);
releases = temp;
releases = list.split(/\n/);
})
.catch(error => {
console.warn('Error fetching releases: ' + error, 0, "error");
});
return releases;
};
download = function () {
//start downloading gui
console.log(fetchReleases());
const releases = fetchReleases();
console.log(releases);
const t = document.getElementById("t"); //text
t.style.color = "red";
}
Expand Down

0 comments on commit 523e3e1

Please sign in to comment.