-
Notifications
You must be signed in to change notification settings - Fork 247
/
Gruntfile.js
1319 lines (1047 loc) · 41.4 KB
/
Gruntfile.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//------------------------------------------------------
//-- Grunt configuration file
//-- Grunt is a tool for Automating tasks
//-- More information: https://gruntjs.com/
//------------------------------------------------------
//------------------------------------------------------
//-- HOW to invoke the tasks defined in Grunt:
//--
//-- $ grunt serve --> Start Icestudio
//-- $ grunt dist --> Create the Icestudio package for all
//-- the architectures
//-- $ grunt jshint --> Validate the Javascript files
//-- $ grunt clean --> Clean all the generated files from
//-- the dist tasks (building packages)
//-- $ grunt gettext--> Extract all the English strings and
//-- write them in the app/resources/locale/template.pot
//-- for being translated into other languages later
//--------------------------------------------------------------
//--------------------------------------------------------------------
//-- How the translation process works
//--
//-- * The text strings 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
//-- (an additional step 'msgmerge' is provided externally, which is
//-- required to re-baseline all the language .po files to the latest
//-- template.pot structure & contents)
//-- * The human translator imports the template.pot file (in PoEdit) and
//-- writes the translation into their language, in the corresponding
//-- .po file
//-- * When 'grunt compiletext' is invoked, the .po files are converted into
//-- .json
//-- * When Icestudio starts ('grunt serve'), the .json files are read
//--------------------------------------------------------------------
//--------------------------------------------------------------------
//-- How to upgrade to a new version of NW
//--
//-- NOTE: The building process is done by the nw-builder. But it is
//-- only implemented for Linux64, Win64 and OXS64, but NOT for ARM
//-- So it has to be done "manually"
//
//-- 1. Set the new NW version in the package.json and package-lock.json
//-- files:
//-- Ex.
//-- [...]
//-- "nw": "0.58.0",
//-- [...]
//--
//-- 2. Remove the cache and dist folders and Execute the command
//-- "npm install" for installing the updated version
//--
//-- 3. It is enough for building for Linux, Win and Mac..
//-- You can test it by generating the packages for these platformas
//-- Ex. npm run buildLinux64
//--
//-- 4. More steps are needed for ARM:
//-- -Open this link and check the name of the NW ARM release
//-- It will be something like: "nw60-arm64_2022-01-08"
//-- -https://github.com/LeonardLaszlo/nw.js-armv7-binaries/releases
//--
//-- 5. Copy that name and place it on the NWJS_ARM_RELEASE_NAME
//-- constant
//--
//-- 6. Check that it works ok: "npm run buildAarch64"
//--
//--
//-- NOTE: In case of error, check the constant: NWJS_ARM_NAME for the
//-- the correct name
//-------------------------------------------------------------------------
"use strict";
// Disable Deprecation Warnings
// (node:18670) [DEP0022] DeprecationWarning: os.tmpDir() is deprecated.
// Use os.tmpdir() instead.
let os = require("os");
os.tmpDir = os.tmpdir;
//-- This is for debugging...
console.log("Executing Gruntfile.js...");
//---------------------------------------------------------------------------
//-- 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
//-- Check the API here: https://gruntjs.com/api/grunt
//----------------------------------------------------------------------------
module.exports = function (grunt) {
//----------------------------------------------------------
//-- 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 JSON file
const BUILDINFO_JSON = "buildinfo.json";
//-- Timestamp file. This file is created everytime grunt
//-- is executed. Icestudio reads this file
const APP_TIMESTAMP_FILE = APPDIR + '/' + BUILDINFO_JSON;
//-- Folder with the Icestudio Javascript files
const APP_SCRIPTS = APPDIR + "/scripts";
//-- Folder with the Icestudio resources
const APP_RESOURCES = APPDIR + "/resources";
//-- Folder to store the default collection
const DEFAULT_COLLECTION_FOLDER = APP_RESOURCES + "/collection";
//-- Folder with the Default collection translations
const DEFAULT_COLLECTION_LOCALE = DEFAULT_COLLECTION_FOLDER + "/locale";
//-- Folder with the Translations
const APP_LOCALE = APP_RESOURCES + "/locale";
//-- Folder for the HTML files
const APP_HTML = APPDIR + "/views";
//-- Cache folder for downloading NW
const CACHE = "cache";
//-- Icestudio HTML mail file
const INDEX_HTML = "index.html";
//-- 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_OSXARM64 = "osxarm64";
const TARGET_LINUX64 = "linux64";
const TARGET_WIN64 = "win64";
const TARGET_AARCH64 = "aarch64";
//-------------------------------------------------------------
//-- Constants for the EXEC TASK
//-------------------------------------------------------------
//-- Command for executing the NW. You should add the folder where
//-- your app (index.html) is placed
//-- Ej. nw app
const NWJS_EXEC_CMD = ["nw", APPDIR].join(" ");
//-- Command for stoping NWjs on Windows
const NWJS_WIN_STOP = "taskkill /F /IM nw.exe >NUL 2>&1";
//-- command for stoping NWjs on Unix like systems (Linux, Mac)
const NWJS_UNIX_STOP = "killall nw 2>/dev/null || " +
"killall nwjs 2>/dev/null ||" +
"(exit 0)";
//-- Final command for stoping NWjs
const NWJS_STOP = WIN32 ? NWJS_WIN_STOP : NWJS_UNIX_STOP;
//--------------------------------------------------------------------------
//-- Python executable. Used for generating the Windows installer
//--------------------------------------------------------------------------
const PYTHON_EXE = "python-3.12.1-amd64.exe";
const PYTHON_URL = "https://www.python.org/ftp/python/3.12.1/" + PYTHON_EXE;
//-- Destination folder where to download the python executable
const CACHE_PYTHON_EXE = CACHE + "/python/" + PYTHON_EXE;
//-- Script for cleaning the dist/icestudio/osx64 folder in MAC
//-- before creating the OSX package
const SCRIPT_OSX = "scripts/repairOSX.sh";
const SCRIPT_OSXARM64 = "scripts/repairOSXarm64.sh";
//-- after creating the OSX package
const SCRIPT_OSX_DMG = "scripts/repairOSXdmg.sh";
const SCRIPT_OSXARM64_DMG = "scripts/repairOSXarm64dmg.sh";
//----------------------------------------------------------------
//-- BUILD DIR. Folder where all the packages for the different
//-- platforms are stored
//------------------------------------------------------------------
const DIST = "./dist";
//-- Temp folder for building the packages
const DIST_TMP = DIST + "/tmp";
//-- Temp folder for storing the fonts
const DIST_TMP_FONTS = DIST_TMP + "/fonts";
//-- Icestudio Build dir: Final files for the given architecture are placed
//-- here before building the package
const DIST_ICESTUDIO = DIST + "/icestudio";
//-- Folder for the AARCH build package
const DIST_ICESTUDIO_AARCH64 = DIST_ICESTUDIO + "/" + TARGET_AARCH64;
//-- Folder for the LINUX64 build package
const DIST_ICESTUDIO_LINUX64 = DIST_ICESTUDIO + "/" + TARGET_LINUX64;
//-- Folder for the Win64 build package
const DIST_ICESTUDIO_WIN64 = DIST_ICESTUDIO + "/" + TARGET_WIN64;
//-- Folder for the OSX64 build package
const DIST_ICESTUDIO_OSX64 = DIST_ICESTUDIO + "/" + TARGET_OSX64;
//-- Folder for the OSX64 build package
const DIST_ICESTUDIO_OSXARM64 = DIST_ICESTUDIO + "/" + TARGET_OSXARM64;
//---------------------------------------------------------------
//-- Define the ICESTUDIO_PKG_NAME: ICESTUDIO PACKAGE NAME that
//-- is created as target, for the DIST TASK
//---------------------------------------------------------------
//-- Read the Icestudio json package
let pkg = grunt.file.readJSON(APP_PACKAGE_JSON);
//-- Read the timestamp. It is added to the Icestudio package version
let timestamp = grunt.template.today("yyyymmddhhmm");
//-- In the Stable Releases there is NO timestamp
if (!WIP) {
timestamp = "";
}
//-- Create the version
//-- Stable releases: No timestamp
//-- WIP: with timestamp
pkg.version = pkg.version.replace(/w/, "w" + timestamp);
//-- Icestudio package name (with version)
//-- Ex. icestudio-0.9.1w202203161003
const ICESTUDIO_PKG_NAME = `${pkg.name}-${pkg.version}`;
//-------------------------------------------------------------
//-- Constants for the WGET TASK
//-------------------------------------------------------------
//-- Default collection source .zip filename (Ej. v0.3.3.zip)
const DEFAULT_COLLECTION_ZIP_FILE = `v${pkg.collection}.zip`;
//-- The collection .zip file contains all the files in
//-- this folder name:
const DEFAULT_COLLECTION_SRC_DIR = `collection-default-${pkg.collection}`;
//-- Destination folder and filename for the default collection
//-- The collection version is removed from the .zip file
const CACHE_DEFAULT_COLLECTION_FILE =
CACHE + "/collection/collection-default.zip";
//-- URL for downloading the .zip file of the Default collection
const DEFAULT_COLLECTION_URL_FILE =
"https://github.com/FPGAwars/collection-default/archive/" +
DEFAULT_COLLECTION_ZIP_FILE;
//-- DEBUG!!
console.log(`DEFAULT_COLLECTION_ZIP_FILE: ${DEFAULT_COLLECTION_ZIP_FILE}`);
console.log(`DEFAULT_COLLECTION_URL_FILE: ${DEFAULT_COLLECTION_URL_FILE}`);
//-------------------------------------------------------------------------
//-- EXEC TASK:
//-------------------------------------------------------------------------
//-- Command for making the Windows installer
//-- Execute NSIS, for creating the Icestudio Windows installer (.exe)
//-- The installation script is located in scripts/windows_installer.nsi
const MAKE_INSTALLER = `makensis -DARCH=win64 -DPYTHON=${PYTHON_EXE} \
-DVERSION=${pkg.version} \
-V3 scripts/windows_installer.nsi`;
//---------------------------------------------------------------
//-- NW TASK: Build the app
//---------------------------------------------------------------
//-- Read the top level package.json
//-- (**not** the Icestudio package, but the one in the top level)
let topPkg = grunt.file.readJSON(PACKAGE_JSON);
//-- Get the NW version from the package (the one that is installed)
const NW_VERSION = topPkg.devDependencies["nw"];
//-- Select the NW build flavor
//-- Currently the "sdk" flavour is selected always
//-- for Either WIP or stable versions
//const NW_FLAVOR = "sdk";
const NW_FLAVOR = "sdk";
//-- Path to the Windows ICO icon file for Icestudio
const WIN_ICON = "docs/resources/images/logo/icestudio-logo.ico";
//-- Path to the MAC ICNS icon file for Icestudio
const MAC_ICON = "docs/resources/images/logo/icestudio-logo.icns";
//-- The NW for ARM is not included in the nw-build, so all the prrocess
//-- of generating the target binary should de done manually
//-- NWJS URL FOR downloading NW for ARM
const NWJS_ARM_BASE_URL =
"https://github.com/LeonardLaszlo/nw.js-armv7-binaries/releases/download/";
//-- You should copy & paste the release ID from Github:
//-- https://github.com/LeonardLaszlo/nw.js-armv7-binaries/releases
//-- Ej: nw60-arm64_2022-01-08
const NWJS_ARM_RELEASE_NAME = "nw60-arm64_2022-01-08";
//-- Name of the NW tarball. The project is abandoned by author
//-- for the moment linux arm 64 bits is stucked at 0.60 nwjs version
const NWJS_ARM_NAME = `nwjs-v0.60.1-linux-arm64`;
//-- Folder and filename for the NW ARM
const NWJS_ARM_FILENAME =
NWJS_ARM_RELEASE_NAME + "/" + NWJS_ARM_RELEASE_NAME + ".tar.gz";
//-- NW FOR ARM. Final binary to download
const NWJS_ARM_BINARY = NWJS_ARM_BASE_URL + NWJS_ARM_FILENAME;
//-- NW for ARM. Local destination file
const NWJS_ARM_PACKAGE = CACHE + "/nwjsAarch64/nwjs.tar.gz";
//-- NW-dist ARM destination folder when uncompressed
const DIST_TMP_ARM = DIST_TMP + "/nwjsAarch64";
//-- NW tarball name
const NW_NAME_TAR_GZ = NWJS_ARM_NAME + ".tar.gz";
//-- NW Path
const NW_PATH = DIST_TMP_ARM +
"/usr/docker/dist/nwjs-chromium-ffmpeg-branding";
//-- NW TARBALL with path
const NW_TARBALL = NW_PATH + "/" + NW_NAME_TAR_GZ;
//-- SRC path where the NW files (for ARM) are locted
const NW_SRC_PATH = DIST_TMP_ARM + "/" + NWJS_ARM_NAME;
//----------------------------------------------------------------------
//-- COPY TASK
//----------------------------------------------------------------------
//-- SRC files to include in the Release
//-- They are copied to the TMP folder, were more files are added before
//-- compressing into the final .zip file
const APP_SRC_FILES = [
INDEX_HTML, //-- Main html file
PACKAGE_JSON, //-- Package.json file
BUILDINFO_JSON, //-- Timestamp
"resources/**", //-- APP_RESOURCES folder
"scripts/**", //-- JS Files
"styles/**", //-- CSS files
"views/*.html", //-- HTML files
"node_modules/**", //-- Node modules files
];
//-- Source folder with the Fonts
const APP_FONTS = APPDIR + "/node_modules/bootstrap/fonts";
//-- ALL files and directories
const ALL = ["**"];
//----------------------------------------------------------------------
//-- COMPRESS TASK: Build the release package. Constants
//----------------------------------------------------------------------
//-- Package name for the different platforms
//-- Sintax: icestudio-{version}-{platform}
//-- Linux
const ICESTUDIO_PKG_NAME_LINUX64 = ICESTUDIO_PKG_NAME + "-" +
TARGET_LINUX64;
//-- windows
const ICESTUDIO_PKG_NAME_WIN64 = ICESTUDIO_PKG_NAME + "-" +
TARGET_WIN64;
//-- MAC
const ICESTUDIO_PKG_NAME_OSX64 = ICESTUDIO_PKG_NAME + "-" +
TARGET_OSX64;
//-- MAC
const ICESTUDIO_PKG_NAME_OSXARM64 = ICESTUDIO_PKG_NAME + "-" +
TARGET_OSXARM64;
//-- ARM
const ICESTUDIO_PKG_NAME_AARCH64 = ICESTUDIO_PKG_NAME + "-" +
TARGET_AARCH64;
//-- Full Packages names (with the local path + .zip) for the
//-- diferent platforms
//-- Linux
const DIST_TARGET_LINUX64_ZIP = DIST + "/" + ICESTUDIO_PKG_NAME_LINUX64 +
".zip";
//-- Windows
const DIST_TARGET_WIN64_ZIP = DIST + "/" + ICESTUDIO_PKG_NAME_WIN64 +
".zip";
//-- MAC
const DIST_TARGET_OSX64_ZIP = DIST + "/" + ICESTUDIO_PKG_NAME_OSX64 +
".zip";
//-- MAC ARM64
const DIST_TARGET_OSXARM64_ZIP = DIST + "/" + ICESTUDIO_PKG_NAME_OSXARM64 +
".zip";
//-- Linux ARM64
const DIST_TARGET_AARCH64_ZIP = DIST + "/" + ICESTUDIO_PKG_NAME_AARCH64 +
".zip";
//----------------------------------------------------------------------
//-- APPIMAGE TASK: Build the appimage Linux executable. Constants
//----------------------------------------------------------------------
//-- Linux final APPIMAGE_FILENAME
const LINUX_APPIMAGE_FILE = DIST + "/" + ICESTUDIO_PKG_NAME_LINUX64 +
".AppImage";
//----------------------------------------------------------------------
//-- APPDMG TASK: Build the dmg MAC executable. Constants
//----------------------------------------------------------------------
//-- Background image for the installer
const MAC_DMG_BACKGROUND_IMAGE =
"docs/resources/images/installation/installer-background.png";
//-- MAC executable filename (inside the DMG image folder)
let MAC_EXEC_FILE = DIST_ICESTUDIO_OSX64 + "/icestudio.app";
//-- MAC final DMG image
let MAC_DMG_IMAGE = DIST + "/" + ICESTUDIO_PKG_NAME_OSX64 + ".dmg";
//----------------------------------------------------------------------
//-- Create the TIMESTAMP FILE
//----------------------------------------------------------------------
//-- Write the timestamp information in a file
//-- It will be read by Icestudio to add the timestamp to the version
grunt.file.write(APP_TIMESTAMP_FILE, JSON.stringify({ ts: timestamp }));
//-----------------------------------------------------------------------
//-- TASK DIST: Define the task to execute for creating the executable
//-- final package for all the platforms
//-----------------------------------------------------------------------
//-- Tasks to perform for the grunt dist task: Create the final packages
//-- Task common to ALL Platforms
let DIST_COMMON_TASKS = [
"jshint", //-- Check the js files
"clean:dist", //-- Delete the DIST folder, with all the generated packages
"nggettext_compile", //-- Extract English texts to the template file
"copy:dist", //-- Copy the files to be included in the build package
"json-minify", //-- Minify JSON files
//-- Build the executable package with nwjs by default, and skip this task
//-- when the flag --dont-build-nwjs is passed
... grunt.option('dont-build-nwjs') ? [] : ["nwjs"],
//-- The clean:tmp task is also a common task, but it is
//-- executed after the specific platform task
//-- So it is added later
];
//-- Specific tasks to be executed depending on the target architecture
//-- They are executed after the COMMON tasks
const DIST_PLATFORM_TASKS = {
//-- TARGET_LINUX64
"linux64": [
"compress:linux64", //-- Create the Icestudio .zip package
"shell:appImageLinux64", //-- Create the Icestudio appimage package
],
//-- TARGET_WIN64
"win64": [
"shell:winico",
"compress:win64", //-- Create the Icestudio .zip package
"wget:python64", //-- Download the python package for windows
"exec:nsis64", //-- Build the Windows installer
],
//-- TARGET_OSX64
"osx64": [
"exec:repairOSX", //-- Execute a script for MAC
"compress:osx64", //-- Create the Icestudio .zip package
"appdmg", //-- Build the Icestudio appmdg package
"exec:repairOSXdmg" //-- Execute a script for MAC
],
//-- TARGET_OSX64
"osxarm64": [
"exec:repairOSXARM64", //-- Execute a script for MAC
"compress:osxarm64", //-- Create the Icestudio .zip package
"appdmg", //-- Build the Icestudio appmdg package
"exec:repairOSXARM64dmg" //-- Execute a script for MAC
],
//-- TARGET_AARCH64
"aarch64": [
"wget:nwjsAarch64", //-- Download the ARM NW dist Tarball
"copy:aarch64", //-- Copy the Linux build dir to ARM build dir
"shell:mergeAarch64",
"compress:Aarch64"
],
//-- NO TARGET
//-- Use this to skip running platform-specific tasks
"none": []
};
//---------------------------------------------------------------
//-- Configure the platform variables for the current system
//--
//--- Building only for one platform
//--- Set with the `platform` argument when calling grunt
//--- Read if there is a platform argument set
//--- If not, the default target is Linux64
// Verifica el script npm que se está ejecutando
const npmLifecycleEvent = process.env.npmLifecycleEvent;
let platform = grunt.option("platform") || false;
let ocpu = grunt.option("cpu");
let cpu = (typeof ocpu !== 'undefined' && ocpu !== false && ocpu !== '') ? ocpu : process.arch;
const cpuIsARM = (cpu === 'arm64');
console.log('CPU', cpu, 'NPM', npmLifecycleEvent);
//-- Aditional options for the platforms
let options = { scope: ["devDependencies"] };
//-- If it is run from MACOS, the target is set to OSX64
//-- Aditional options are needed
if ((platform === false && DARWIN) || platform === "darwin") {
if (cpuIsARM) {
platform = TARGET_OSXARM64;
options["scope"].push("darwinDependencies");
//-- MAC executable filename (inside the DMG image folder)
MAC_EXEC_FILE = DIST_ICESTUDIO_OSXARM64 + "/icestudio.app";
//-- MAC final DMG image
MAC_DMG_IMAGE = DIST + "/" + ICESTUDIO_PKG_NAME_OSXARM64 + ".dmg";
} else {
platform = TARGET_OSX64;
options["scope"].push("darwinDependencies");
}
}
if (platform === false) {
platform = TARGET_LINUX64;
}
//-- Get the specific task to perform for the current platform
let distPlatformTasks = DIST_PLATFORM_TASKS[platform];
//-- Special case: For the AARCH64, the platform is set to Linux64
/*if (platform === TARGET_AARCH64) {
platform = TARGET_LINUX64;
}*/
let NWJS_PLATFORM = 'linux';
let NWJS_ARCH = 'x64';
let DIST_BUILD = false;
switch (platform) {
case TARGET_AARCH64:
NWJS_PLATFORM = 'linux';
NWJS_ARCH = 'x64';
DIST_BUILD = DIST_ICESTUDIO_AARCH64;
break;
case TARGET_LINUX64:
NWJS_PLATFORM = 'linux';
NWJS_ARCH = 'x64';
DIST_BUILD = DIST_ICESTUDIO_LINUX64;
break;
case TARGET_OSX64:
NWJS_PLATFORM = 'osx';
NWJS_ARCH = 'x64';
DIST_BUILD = DIST_ICESTUDIO_OSX64;
break;
case TARGET_OSXARM64:
NWJS_PLATFORM = 'osx';
NWJS_ARCH = 'arm64';
DIST_BUILD = DIST_ICESTUDIO_OSXARM64;
break;
case TARGET_WIN64:
NWJS_PLATFORM = 'win';
NWJS_ARCH = 'x64';
DIST_BUILD = DIST_ICESTUDIO_WIN64;
break;
}
//------------------------------------------------------------------
//-- CLEAN:tmp
//-- Add the "clean:tmp" command to the list of commands to execute
//-- It will be the last taks
//------------------------------------------------------------------
distPlatformTasks = distPlatformTasks.concat(["clean:tmp"]);
//------------------------------------------------------------------
//-- Task to perform for the DIST target
//-- There are common task that should be
//-- executed for ALL the platforms, and tasks specific for
//-- every platform
//------------------------------------------------------------------
const DIST_TASKS = DIST_COMMON_TASKS.concat(distPlatformTasks);
//------------------------------------------------------------
//-- DEBUG
//-- Display information on the console, for debugging
//-- purposes
//------------------------------------------------------------
console.log("------------ INFORMATION FOR DEBUGGING -------------------");
console.log("* Package name: " + ICESTUDIO_PKG_NAME);
console.log("* NW Version: " + NW_VERSION);
console.log("* APPIMAGE: " + LINUX_APPIMAGE_FILE);
console.log("* DMGIMAGE: " + MAC_DMG_IMAGE);
console.log("* DMGARM64IMAGE: " + MAC_DMG_IMAGE);
console.log("* Target platform: " + platform);
console.log("* SubTASK for the DIST task:");
console.table(DIST_TASKS);
console.log("---------------------------------------------------------");
//--------------------------------------------------------------------------
//-- Configure the grunt TASK
//--------------------------------------------------------------------------
//-- Load all grunt tasks
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-angular-gettext');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-exec');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-wget');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-json-minify');
grunt.loadNpmTasks('grunt-nw-builder');
grunt.loadNpmTasks('grunt-contrib-compress');
grunt.loadNpmTasks('grunt-shell');
grunt.loadNpmTasks('grunt-zip');
//-- Load an additional task for MAC
if (platform === TARGET_OSX64) {
grunt.loadNpmTasks('grunt-appdmg');
}
//-- Load an additional task for MAC ARM64
if (platform === TARGET_OSXARM64) {
grunt.loadNpmTasks('grunt-appdmg');
}
//-- grunt gettext
//-- Extract the English text and write them into the
//-- template file (app/resources/localte/template.pot)
//-- More information: https://www.npmjs.com/package/grunt-angular-gettext
grunt.registerTask("gettext", [
"nggettext_extract"
]);
//-- grunt compiletext
grunt.registerTask("compiletext", [
"nggettext_compile"
]);
//-- grunt getcollection
//-- Download the default collection and install it
//-- in the app/resources/collection folder
//-- This task is called in the npm postinstallation
//-- (after npm install is executed)
grunt.registerTask("getcollection", [
"clean:collection", //-- Remove previously installed collection
"wget:collection", //-- Download the collection
"unzip", //-- Unzip the collection (install it)
"clean:collectionFile" //-- Remove cached collection file
]);
//-- grunt server
//-- Start Icestudio
grunt.registerTask("serve", [
"nggettext_compile", //-- Get the translation in json files
"watch:scripts", //-- Watch the given files. When there is change
//-- Icestudio is restarted
]);
// grunt dist: Create the app package
grunt.registerTask(
"dist",
DIST_TASKS //-- Tasks to perform
);
//-----------------------------------------------------------------------
// PROJECT CONFIGURATION
// All the TASKs used are defined here
//-----------------------------------------------------------------------
grunt.initConfig({
//-- Information about the package (read from the app/package.json file)
pkg: pkg,
// TASK: Clean
//-- Clean the temporary folders: grunt-contrib-clean
//-- https://github.com/gruntjs/grunt-contrib-clean
clean: {
//-- Remove temporary folder
tmp: {
src: [".tmp", DIST_TMP],
options: {
'no-write': grunt.option('dont-clean-tmp')
}
},
//-- Remove folder with generated executable packages
dist: [DIST],
//-- Remove the default collection (which is installed when
//-- npm install is executed initially
collection: [DEFAULT_COLLECTION_FOLDER],
//-- Remove the downloaded collection file
//-- that is fetched with wget:collection
collectionFile: [CACHE_DEFAULT_COLLECTION_FILE],
},
//-- Get the English texts from the .js and .html files
//-- and write them in the template (.pot) file
//-- https://www.npmjs.com/package/grunt-angular-gettext
//-- Disable jshint warning:
/* jshint camelcase: false */
nggettext_extract: {
pot: {
files: {
//-- Target template file
"app/resources/locale/template.pot": [
//-- Src files
APP_HTML + "/*.html",
APP_SCRIPTS + "/**/*.js",
],
},
},
},
//-- TASK: nggettext_compile
// Convert all the .po files (with the translations)
// to JSON format. The json file is the one read by Icestudio when
// it is started
//-- Disable jshint Warning:
/* jshint camelcase: false */
nggettext_compile: {
all: {
options: {
format: "json",
},
files: [
//-- Icestudio .po files to be converted to json
{
expand: true,
cwd: APP_LOCALE,
dest: APP_LOCALE,
src: ["**/*.po"],
ext: ".json",
},
//-- Default collection .po files to be converted to json
{
expand: true,
cwd: DEFAULT_COLLECTION_LOCALE,
dest: DEFAULT_COLLECTION_LOCALE,
src: ["**/*.po"],
ext: ".json",
},
],
},
},
// TASK Wget: Download packages from internet
// NWjs for ARM, Python installer, Default collection
// More information: https://github.com/shootaroo/grunt-wget
wget: {
//-- Download the Default collection from its github repo
collection: {
options: {
overwrite: false,
},
//-- URL where the src file is located
src: DEFAULT_COLLECTION_URL_FILE,
//-- Write to this new folder with a new name
dest: CACHE_DEFAULT_COLLECTION_FILE,
},
//-- Download the python executable. It is used for generating
//-- the Windows installer
//-- ONLY WINDOWS
python64: {
options: {
overwrite: false,
},
//-- URL where the file is localted
src: PYTHON_URL,
//-- Write the file to this folder
dest: CACHE_PYTHON_EXE,
},
//-- Download NWjs for ARM arquitecture, as it is not part of the
//-- oficial NWjs project
//-- It is downloaded during the ARM build process
//-- Only ARM
nwjsAarch64: {
options: {
//-- If the destination file already exists,it is not downloaded
overwrite: false,
},
//-- Download the NW ARM binary from the github repo
src: NWJS_ARM_BINARY,
//-- Local destination file. It is stored in the cache folder
dest: NWJS_ARM_PACKAGE,
},
},
//-- Install the Default collection
//-- The .zip file is unzipped in the destination folder
//-- https://www.npmjs.com/package/grunt-zip
unzip: {
'using-router': {
router: function (filepath) {
//-- Change the folder name of the compress files to 'collection'
//-- (The original name contains a folder with the version. We want
//-- it to be removed)
return filepath.replace(DEFAULT_COLLECTION_SRC_DIR, "collection");
},
//-- Original .zip file, previously downloaded
src: CACHE_DEFAULT_COLLECTION_FILE,
//-- Destination folder for its installation
//-- The collection is unzipped in folder APP_RESOURCES/collection
dest: APP_RESOURCES
}
},
//-- Execute shell commands
//-- More info: https://github.com/sindresorhus/grunt-shell#readme
shell: {
winico: {
command: [
//-- Create a temp DIR
`mkdir -p ${DIST_ICESTUDIO_WIN64}/resources/images`,
//-- Uncompress the NW-dist package
`cp ${WIN_ICON} ${DIST_ICESTUDIO_WIN64}/resources/images`
].join(' && ')
},
//-- Uncompress the NW for arm, and merge the files
//-- with the linux build
mergeAarch64: {
command: [
`sync`,
//-- Create a temp DIR
`mkdir -p ${DIST_TMP_ARM}`,
//-- Uncompress the NW-dist package
`tar xzf ${NWJS_ARM_PACKAGE} -C ${DIST_TMP_ARM}`,
//-- Uncompress the NW tarball (inside the NW-dist)
`tar xzf ${NW_TARBALL} -C ${DIST_TMP_ARM}`,
//-- Copy the ARM NW files to the Icestudio dist folder
`cp -R ${NW_SRC_PATH}/* ${DIST_ICESTUDIO_AARCH64}/`,
//-- Rename the binary file to icestudio
`mv ${DIST_ICESTUDIO_AARCH64}/nw ` +
`${DIST_ICESTUDIO_AARCH64}/icestudio`,
//-- Give execution permissions to icestudio file
`chmod +x ${DIST_ICESTUDIO_AARCH64}/icestudio`
].join(' && ')
},
//-- TASK: APPIMAGE
//-- ONLY LINUX: generate AppImage package
appImageLinux64: {
command: [
`sync`,
`ICESTUDIO_BUILD_ID=${pkg.version} scripts/appimageBuild.sh`
].join(' && ')
},
},
//-- TASK EXEC: Define the Commands and scripts that can be executed
//-- More information: https://www.npmjs.com/package/grunt-exec
exec: {
nw: NWJS_EXEC_CMD, //-- Launch NWjs
stopNW: NWJS_STOP, //-- Stop NWjs
nsis64: MAKE_INSTALLER, //-- Create the Icestudio Windows installer
repairOSX: SCRIPT_OSX, //-- Shell script for mac
repairOSXARM64: SCRIPT_OSXARM64, //-- Shell script for mac
repairOSXdmg: SCRIPT_OSX_DMG, //-- Shell script for mac
repairOSXARM64dmg: SCRIPT_OSXARM64_DMG, //-- Shell script for mac
},
//-- 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,
},
},
//-- TASK: Copy. Copy the Icestudio files needed for building
//-- the executable package
//-- More information: https://www.npmjs.com/package/grunt-contrib-copy
copy: {
//-- Copy files to the DIST folder for building the executable package
dist: {
files: [
//-- Copy the Icestudio files
{
expand: true,
cwd: APPDIR, //-- working folder
dest: DIST_TMP, //-- Target folder
src: APP_SRC_FILES //-- Src files to copy
},
//-- Copy the Fonts
{
expand: true,
cwd: APP_FONTS, //-- Working folder
dest: DIST_TMP_FONTS, //-- Target folder
src: ALL, //-- Src files to copy
},
],
},