Skip to content

Commit

Permalink
Gruntfile: Refactoring and documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Obijuan committed Feb 10, 2022
1 parent 07e56a4 commit b207a77
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 43 deletions.
133 changes: 90 additions & 43 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//------------------------------------------------------

//------------------------------------------------------
//-- HOW to invoke the task defined:
//-- HOW to invoke the tasks defined in Grunt:
//--
//-- $ grunt serve --> Start icestudio
//-- $ grunt dist --> Create the Icestudio package for all
Expand All @@ -18,6 +18,20 @@
//-- for being translated into other languajes later
//--------------------------------------------------------------

//--------------------------------------------------------------------
//-- How the translation process works
//--
//-- * The texts in the .js Javascript files are in English
//-- * When 'grunt gettext' is invoked, the English texts are extracted
//-- to the app/resources/locale/template.pot file
//-- * The human translator import the template.pot file (in PoEdit) and
//-- write the translation into their language, in the corresponding
//-- .po file
//-- * When 'grunt serve' is invoked, the .po files are converted into
//-- .json
//-- * When icestudio starts, the .json files are read
//--------------------------------------------------------------------


"use strict";

Expand All @@ -30,6 +44,46 @@ os.tmpDir = os.tmpdir;
//-- This is for debuging...
console.log("Executing gruntfile.js...");

//----------------------------------------------------------
//-- GLOBAL constants used
//----------------------------------------------------------

//-- Is this a WIP release (Work in Progress) or
//-- a stable release?
//-- WIP = true --> Work in progress
//-- WIP = false --> Stable release
const WIP = true;

//-- ICestudio App dir
const APPDIR = "app";

//-- Icestudio package.json
const PACKAGE_JSON = "package.json";

//-- Icestudio package.json with PATH
const APP_PACKAGE_JSON = APPDIR + '/' + PACKAGE_JSON;

//-- Timestamp file
const APP_TIMESTAMP_FILE = APPDIR + '/' + "buildinfo.json";

//-- Grunt configuration file
const GRUNT_FILE = "Gruntfile.js";

//-- jshint configuration file
const JSHINT_CONFIG_FILE = ".jshintrc";

//-- Constants for the host architecture (Where grunt is run)
const WIN32 = process.platform === "win32";
const DARWIN = process.platform === "darwin";

//-- Constant for the TARGET architectures
const TARGET_OSX64 = "osx64";
const TARGET_LINUX64 = "linux64";
const TARGET_WIN64 = "win64";
const TARGET_AARCH64 ="aarch64";
const TARGET_ALL = "all";


//-- Wrapper function. This function is called when the 'grunt' command is
//-- executed. Grunt exposes all of its methods and properties on the
//-- grunt object passed as an argument
Expand All @@ -39,28 +93,18 @@ module.exports = function (grunt) {
//-- Debug
console.log("-> Grunt Entry point");

//-- Constants for the platformws
const WIN32 = process.platform === "win32";
const DARWIN = process.platform === "darwin";

//-- Is this a WIP release (Work in Progress) or
//-- a stable release?
//-- WIP = true --> Work in progress
//-- WIP = false --> Stable release
const WIP = true;

//-- Read the Package json and the timestamp
let pkg = grunt.file.readJSON("app/package.json");
let pkg = grunt.file.readJSON(APP_PACKAGE_JSON);
let timestamp = grunt.template.today("yyyymmddhhmm");

//-- In the Stables Releases there is NO timestamp
if (!WIP) {
timestamp = "";
}

//-- Write the timestamp information in the buildinfo.json
//-- Write the timestamp information in a file
//-- It will be read by icestudio to add the timestamp to the version
grunt.file.write("app/buildinfo.json", JSON.stringify({ ts: timestamp }));
grunt.file.write(APP_TIMESTAMP_FILE, JSON.stringify({ ts: timestamp }));

//-- Create the version
//-- Stable releases: No timestamp
Expand Down Expand Up @@ -104,18 +148,18 @@ module.exports = function (grunt) {
//--- Set with the `platform` argument when calling grunt

//--- Read if there is a platform argument set
let onlyPlatform = grunt.option("platform") || "all";
let onlyPlatform = grunt.option("platform") || TARGET_ALL;

//-- MAC
if (DARWIN) {
platforms = ["osx64"];
platforms = [TARGET_OSX64];
options = { scope: ["devDependencies", "darwinDependencies"] };
distCommands = ["nwjs", "exec:repairOSX", "compress:osx64", "appdmg"];

//-- Linux 64bits, linux ARM 64bits and Windows (64-bits)
} else {
if (onlyPlatform === "linux64" || onlyPlatform === "all") {
platforms.push("linux64");
if (onlyPlatform === TARGET_LINUX64 || onlyPlatform === TARGET_ALL) {
platforms.push(TARGET_LINUX64);
options = { scope: ["devDependencies"] };
distCommands = distCommands.concat([
"nwjs",
Expand All @@ -124,8 +168,8 @@ module.exports = function (grunt) {
]);
}

if (onlyPlatform === "win64" || onlyPlatform === "all") {
platforms.push("win64");
if (onlyPlatform === TARGET_WIN64 || onlyPlatform === TARGET_ALL) {
platforms.push(TARGET_WIN64);
options = { scope: ["devDependencies"] };
distCommands = distCommands.concat([
"nwjs",
Expand All @@ -135,9 +179,9 @@ module.exports = function (grunt) {
]);
}

if (onlyPlatform === "aarch64" || onlyPlatform === "all") {
if (platforms.indexOf("linux64") < 0) {
platforms.push("linux64");
if (onlyPlatform === TARGET_AARCH64 || onlyPlatform === TARGET_ALL) {
if (platforms.indexOf(TARGET_LINUX64) < 0) {
platforms.push(TARGET_LINUX64);
}
options = { scope: ["devDependencies"] };
if (distCommands.indexOf("nwjs") < 0) {
Expand All @@ -158,7 +202,7 @@ module.exports = function (grunt) {
//-- Files to include in the Icestudio app
let appFiles = [
"index.html", //-- app/index.html: Main HTML file
"package.json", //-- Package file
PACKAGE_JSON, //-- Package file
"resources/**/*.*", //-- Folder app/resources
"scripts/**/*.*", //-- JS files
"styles/**/*.*", //-- CSS files
Expand All @@ -169,13 +213,32 @@ module.exports = function (grunt) {

//-----------------------------------------------------------------------
// PROJECT CONFIGURATION
// All the TASK used are defined here
// All the TASKs used are defined here
//-----------------------------------------------------------------------
grunt.initConfig({

//-- Information about the package (read the app/package.json file)
pkg: pkg,

//-- TASK: jshint: Check the .js files
//-- More information: https://www.npmjs.com/package/grunt-contrib-jshint
jshint: {

//-- These are the js files to check
all: ["app/scripts/**/*.js", GRUNT_FILE],

options: {

//-- jshint configuration file
//-- See: https://jshint.com/docs/
jshintrc: JSHINT_CONFIG_FILE,

//-- Javascript version to check
//-- See: https://jshint.com/docs/options/#esversion
esversion: 11,
},
},

// EXEC TASK: Define the Commands and scripts that can be executed/invoked
exec: {

Expand Down Expand Up @@ -204,7 +267,7 @@ module.exports = function (grunt) {
files: [
{
expand: true,
cwd: "app",
cwd: APPDIR,
dest: "dist/tmp",
src: [
"index.html",
Expand Down Expand Up @@ -274,7 +337,7 @@ module.exports = function (grunt) {
zip: false,
buildDir: "dist/",
winIco: "docs/resources/images/logo/icestudio-logo.ico",
macIcns: "docs/resources/images/logo/nw.icns",
macIcns: "docs/resources/images/logo/icestudio-logo.icns",
macPlist: { CFBundleIconFile: "app" },
platforms: platforms,
},
Expand Down Expand Up @@ -414,18 +477,6 @@ module.exports = function (grunt) {
},
},

//-- TASK: jshint
// Check all js files
jshint: {
//-- This are the js files to check
all: ["app/scripts/**/*.js", "gruntfile.js"],
options: {
//-- jshint configuration file
jshintrc: ".jshintrc",
esversion: 6,
},
},

// TASK Wget: Download packages from internet
// NWjs for ARM, Python installer, Default collection
// More information: https://github.com/shootaroo/grunt-wget
Expand Down Expand Up @@ -543,10 +594,6 @@ module.exports = function (grunt) {
// grunt-json-minification
require("load-grunt-tasks")(grunt, options);

// Default task
grunt.registerTask("default", function () {
console.log("Icestudio");
});
//-- grunt gettext
grunt.registerTask("gettext", ["nggettext_extract"]);

Expand Down
Binary file removed docs/resources/images/logo/nw.icns
Binary file not shown.

0 comments on commit b207a77

Please sign in to comment.