-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgruntfile.js
137 lines (126 loc) · 4.12 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
var path = require("path");
var fs = require("fs");
module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-ts');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-shell');
var nsDistPath = process.env.NSDIST || './deps/NativeScript/bin/dist';
var androidAvd = grunt.option('avd') || "nexus"
var genyDevice = grunt.option('geny') || "nexus7"
var iOSDevice = grunt.option('device') || "iPhone-6"
var androidPlatfrom = "platforms/android/";
var hasAndroidPlatform = false;
try {
hasAndroidPlatform = fs.statSync(androidPlatfrom) && fs.statSync(androidPlatfrom).isDirectory();
}
catch (e) {
// ...
}
grunt.initConfig({
ts: {
build: {
tsconfig: './tsconfig.json',
options: {
fast: "never",
compiler: "node_modules/typescript/bin/tsc"
},
},
},
copy: {
widgets: {
src: "widgets.jar",
dest: path.join(androidPlatfrom, "libs") + "/",
cwd: "deps/android-widgets",
expand: true
},
localInstallModules: {
src: "<%= nsPackagePath %>",
dest: "deps/tns-core-modules.tgz"
}
},
clean: {
app: {
cwd: 'app',
expand: true,
src: [
'**/*.js',
'**/*.map',
]
},
nodeModulesGz: {
// HACK: Work around a {N} CLI bug that prevents you from using
// NPM packages containing *.gz files.
// https://github.com/NativeScript/nativescript-cli/issues/393
expand: true,
cwd: './node_modules',
src: [
'**/*.gz',
]
},
},
shell: {
depNSInit: {
command: [
'npm install',
'grunt --no-runtslint',
].join('&&'),
options: {
execOptions: {
cwd: 'deps/NativeScript',
}
}
},
localInstallModules: {
command: "npm install 'deps/tns-core-modules.tgz'"
},
emulateGeny: {
command: "tns emulate android --geny '" + genyDevice + "'"
},
emulateAndroid: {
command: "tns emulate android --avd '" + androidAvd + "'"
},
emulateIOS: {
command: "tns emulate ios --device '" + iOSDevice + "'"
},
removeAndroid: {
command: "tns platform remove android"
},
addAndroid: {
command: "tns platform add android"
}
}
});
grunt.registerTask("updateModules", [
"getNSPackage",
"copy:localInstallModules",
"shell:localInstallModules",
]);
grunt.registerTask("getNSPackage", function () {
var packageFiles = grunt.file.expand({
cwd: nsDistPath
}, [
'tns-core-modules*.tgz'
]);
var nsPackagePath = path.join(nsDistPath, packageFiles[0]);
grunt.config('nsPackagePath', nsPackagePath);
});
grunt.registerTask("app", [
"ts:build",
]);
// Copy custom version of widgets.jar to be up to date
grunt.registerTask("fix-android-widgets", hasAndroidPlatform ? ["copy:widgets"] : [])
grunt.registerTask("prepare", [
"shell:depNSInit",
"updateModules",
"clean:nodeModulesGz",
"fix-android-widgets"
]);
grunt.registerTask("app-full", [
"clean:app",
"app",
]);
grunt.registerTask("refresh-android", ["shell:removeAndroid", "shell:addAndroid", "fix-android-widgets"])
grunt.registerTask("run-android", ["app", "shell:emulateAndroid"])
grunt.registerTask("run-ios", ["app", "shell:emulateIOS"])
}