Skip to content

Commit 2ca2d44

Browse files
Merge pull request #4 from NativeScript/amiorkov/child-processes-improvements
Refactored the way child process are executed and split the executing of 'tns' commands and triggered native builds from file watcher
2 parents 0618fbb + 931533b commit 2ca2d44

File tree

4 files changed

+164
-110
lines changed

4 files changed

+164
-110
lines changed

src/scripts/json-tags-helper.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ function getWatchersDictionary(json) {
1818
return getDictionary(json["watch"]);
1919
}
2020

21+
function getBuildCommandsDictionary(json) {
22+
return getDictionary(json["buildCommand"]);
23+
}
24+
2125
function getDictionary(json) {
2226
var result = [];
2327
for (var i in json) {
@@ -31,4 +35,5 @@ module.exports.getScriptsDictionary = getScriptsDictionary;
3135
module.exports.getDescriptionsDictionary = getDescriptionsDictionary;
3236
module.exports.getCategoriesDictionary = getCategoriesDictionary;
3337
module.exports.getShortCommandsDictionary = getShortCommandsDictionary;
34-
module.exports.getWatchersDictionary = getWatchersDictionary;
38+
module.exports.getWatchersDictionary = getWatchersDictionary;
39+
module.exports.getBuildCommandsDictionary = getBuildCommandsDictionary;

src/scripts/postinstall.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ function writeToSrcJson(inputParams) {
330330
const devDepsTag = "devDependencies";
331331
const descriptionsTag = "descriptions";
332332
const shortCommandsTag = "shortCommands";
333+
const buildCommandsTag = "buildCommand"
333334
const categoriesTag = "categories";
334335
var path = inputParams.pluginSrcFolder + "/package.json";
335336
let jsonFile = fs.readFileSync(path);
@@ -360,19 +361,22 @@ function writeToSrcJson(inputParams) {
360361
var ndJson = {};
361362
var pluginScriptsJson = {};
362363
var pluginDescriptionsJson = {};
363-
var pluginDShortCommandsJson = {};
364+
var pluginShortCommandsJson = {};
365+
var pluginBuildCommandJson = {};
364366
var pluginCategoriesJson = {};
365367
var pluginWatchJson = {};
366368
var pluginScripts = updateScripts(predefinedScripts, pluginScriptsJson);
367369
var descriptions = updateDescriptions(predefinedScripts, pluginDescriptionsJson);
368-
var shortCommands = updateShortCommands(predefinedScripts, pluginDShortCommandsJson);
370+
var shortCommands = updateShortCommands(predefinedScripts, pluginShortCommandsJson);
371+
var buildCommand = updateBuildCommands(predefinedScripts, pluginBuildCommandJson);
369372
var categories = updateCategories(predefinedScripts, pluginCategoriesJson);
370373
var pluginWatch = updateWatch(predefinedScripts, pluginWatchJson);
371374
ndJson[scriptsTag] = pluginScripts;
372375
ndJson[watchTag] = pluginWatch;
373376
ndJson[devDepsTag] = newDevDeps;
374377
ndJson[descriptionsTag] = descriptions;
375378
ndJson[shortCommandsTag] = shortCommands;
379+
ndJson[buildCommandsTag] = buildCommand;
376380
ndJson[categoriesTag] = categories;
377381
var ndJsonPath = inputParams.pluginSrcFolder + "/node_modules/nativescript-dev-debugging/scripts/nd-package.json";
378382
fs.writeFileSync(ndJsonPath, JSON.stringify(ndJson, null, "\t"));
@@ -495,6 +499,14 @@ function updateShortCommands(scripts, jsonDevDeps) {
495499
return jsonDevDeps;
496500
}
497501

502+
function updateBuildCommands(scripts, jsonDevDeps) {
503+
scripts.forEach((script) => {
504+
jsonDevDeps[script.key] = script.buildCommand;
505+
});
506+
507+
return jsonDevDeps;
508+
}
509+
498510
function updateCategories(newDevDependencies, json) {
499511
newDevDependencies.forEach((dep) => {
500512
json[dep.key] = dep.category;

src/scripts/predefined-scripts.js

Lines changed: 39 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -46,64 +46,73 @@ function getPluginPreDefinedScripts(srcPath, demoFolder, demoAngularFolder, demo
4646
},
4747
{
4848
key: "nd.demo.android",
49-
value: "npm run nd.build.native.android && npm run nd.open.android.studio && npm run nd.demo.tns.run.android",
49+
value: "npm run nd.open.android.studio && npm run nd.demo.tns.run.android",
5050
description: "Runs your 'demo' app and opens Android Studio. After that use 'Attach debugger to Android process (demo)' to debug the native source code",
51+
buildCommand: "npm run nd.build.native.android",
5152
category: "android debug",
5253
shortCommands: ["demo android simulator attach", "demo android device attach"]
5354
},
5455
{
5556
key: "nd.demo.ios",
56-
value: "npm run nd.build.simulator.native.ios && npm run nd.open.xcode && npm run nd.demo.tns.run.ios",
57+
value: "npm run nd.open.xcode && npm run nd.demo.tns.run.ios",
5758
description: "Runs your 'demo' app and opens Xcode. After that use 'Attach to process by PID or Name (demo)' to debug the native source code. (for simulator)",
59+
buildCommand: "npm run nd.build.simulator.native.ios",
5860
category: "ios debug",
5961
shortCommands: ["demo ios simulator attach"]
6062
},
6163
{
6264
key: "nd.demo.ios.device",
63-
value: "npm run nd.build.device.native.ios && npm run nd.open.xcode && npm run nd.demo.tns.run.ios",
65+
value: "npm run nd.open.xcode && npm run nd.demo.tns.run.ios",
6466
description: "Runs your 'demo' app and opens Xcode. After that use 'Attach to process by PID or Name (demo)' to debug the native source code. (for real device)",
67+
buildCommand: "npm run nd.build.device.native.ios",
6568
category: "ios debug",
6669
shortCommands: ["demo ios device attach"]
6770
},
6871
{
6972
key: "nd.demo.angular.android",
70-
value: "npm run nd.build.native.android && npm run nd.open.android.studio && npm run nd.demo.angular.tns.run.android",
73+
value: "npm run nd.open.android.studio && npm run nd.demo.angular.tns.run.android",
7174
description: "Runs your 'demo-angular' app and opens Android Studio. After that use 'Attach debugger to Android process (demo)' to debug the native source code",
75+
buildCommand: "npm run nd.build.native.android",
7276
category: "android debug",
7377
shortCommands: ["demo-angular android simulator attach", "demo-angular android device attach"]
7478
},
7579
{
7680
key: "nd.demo.angular.ios",
77-
value: "npm run nd.build.simulator.native.ios && npm run nd.open.xcode && npm run nd.demo.angular.tns.run.ios",
81+
value: "npm run nd.open.xcode && npm run nd.demo.angular.tns.run.ios",
7882
description: "Runs your 'demo-angular' app and opens Xcode. After that use 'Attach to process by PID or Name (demo)' to debug the native source code. (for simulator)",
83+
buildCommand: "npm run nd.build.simulator.native.ios",
7984
category: "ios debug",
8085
shortCommands: ["demo-angular ios simulator attach"]
8186
},
8287
{
8388
key: "nd.demo.angular.ios.device",
84-
value: "npm run nd.build.device.native.ios && npm run nd.open.xcode && npm run nd.demo.angular.tns.run.ios",
89+
value: "npm run nd.open.xcode && npm run nd.demo.angular.tns.run.ios",
8590
description: "Runs your 'demo-angular' app and opens Xcode. After that use 'Attach to process by PID or Name (demo)' to debug the native source code. (for real device)",
91+
buildCommand: "npm run nd.build.device.native.ios",
8692
category: "ios debug",
8793
shortCommands: ["demo-angular ios device attach"]
8894
},
8995
{
9096
key: "nd.demo.vue.android",
91-
value: "npm run nd.build.native.android && npm run nd.open.android.studio && npm run nd.demo.vue.tns.run.android",
97+
value: "npm run nd.open.android.studio && npm run nd.demo.vue.tns.run.android",
9298
description: "Runs your 'demo-vue' app and opens Android Studio. After that use 'Attach debugger to Android process (demo)' to debug the native source code",
99+
buildCommand: "npm run nd.build.native.android",
93100
category: "android debug",
94101
shortCommands: ["demo-vue android simulator attach", "demo-vue android device attach"]
95102
},
96103
{
97104
key: "nd.demo.vue.ios",
98-
value: "npm run nd.build.simulator.native.ios && npm run nd.open.xcode && npm run nd.demo.vue.tns.run.ios",
105+
value: "npm run nd.open.xcode && npm run nd.demo.vue.tns.run.ios",
99106
description: "Runs your 'demo-vue' app and opens Xcode. After that use 'Attach to process by PID or Name (demo)' to debug the native source code. (for simulator)",
107+
buildCommand: "npm run nd.build.simulator.native.ios",
100108
category: "ios debug",
101109
shortCommands: ["demo-vue ios simulator attach"]
102110
},
103111
{
104112
key: "nd.demo.vue.ios.device",
105-
value: "npm run nd.build.device.native.ios && npm run nd.open.xcode && npm run nd.demo.vue.tns.run.ios",
113+
value: "npm run nd.open.xcode && npm run nd.demo.vue.tns.run.ios",
106114
description: "Runs your 'demo-vue' app and opens Xcode. After that use 'Attach to process by PID or Name (demo)' to debug the native source code. (for real device)",
115+
buildCommand: "npm run nd.build.device.native.ios",
107116
category: "ios debug",
108117
shortCommands: ["demo-vue ios device attach"]
109118
},
@@ -137,64 +146,11 @@ function getPluginPreDefinedScripts(srcPath, demoFolder, demoAngularFolder, demo
137146
description: "Rebuilds the plugin's native source code and opens it in Xcode. (for real device)",
138147
category: "secondary"
139148
},
140-
{
141-
key: "nd.build.run.device.demo.app.ios",
142-
value: "npm run nd.build.device.native.ios" + " && npm run nd.demo.tns.run.ios",
143-
description: "Build the native code and executes 'tns run ios' for the 'demo' app",
144-
category: "secondary"
145-
},
146-
{
147-
key: "nd.build.run.simulator.demo.app.ios",
148-
value: "npm run nd.build.simulator.native.ios" + " && npm run nd.demo.tns.run.ios",
149-
description: "Build the native code and executes 'tns run ios' for the 'demo' app",
150-
category: "secondary"
151-
},
152-
{
153-
key: "nd.build.run.demo.app.android",
154-
value: "npm run nd.build.native.android" + " && npm run nd.demo.tns.run.android",
155-
description: "Build the native code and executes 'tns run android' for the 'demo' app",
156-
category: "secondary"
157-
},
158-
{
159-
key: "nd.build.run.demo.angular.app.ios",
160-
value: "npm run nd.build.device.native.ios " + " && npm run nd.demo.angular.tns.run.ios",
161-
description: "Build the native code and executes 'tns run ios' for the 'demo angular' app",
162-
category: "secondary"
163-
},
164-
{
165-
key: "nd.build.run.simulator.demo.angular.app.ios",
166-
value: "npm run nd.build.simulator.native.ios " + " && npm run nd.demo.angular.tns.run.ios",
167-
description: "Build the native code and executes 'tns run ios' for the 'demo angular' app",
168-
category: "secondary"
169-
},
170-
{
171-
key: "nd.build.run.demo.angular.app.android",
172-
value: "npm run nd.build.native.android " + " && npm run nd.demo.angular.tns.run.android",
173-
description: "Build the native code and executes 'tns run android' for the 'demo angular' app",
174-
category: "secondary"
175-
},
176-
{
177-
key: "nd.build.run.demo.vue.app.ios",
178-
value: "npm run nd.build.device.native.ios " + " && npm run nd.demo.vue.tns.run.ios",
179-
description: "Build the native code and executes 'tns run ios' for the 'demo vue' app",
180-
category: "secondary"
181-
},
182-
{
183-
key: "nd.build.run.simulator.demo.vue.app.ios",
184-
value: "npm run nd.build.simulator.native.ios " + " && npm run nd.demo.vue.tns.run.ios",
185-
description: "Build the native code and executes 'tns run ios' for the 'demo vue' app",
186-
category: "secondary"
187-
},
188-
{
189-
key: "nd.build.run.demo.vue.app.android",
190-
value: "npm run nd.build.native.android " + " && npm run nd.demo.vue.tns.run.android",
191-
description: "Build the native code and executes 'tns run android' for the 'demo vue' app",
192-
category: "secondary"
193-
},
194149
{
195150
key: "nd.demo.run.watch.android",
196-
value: "npm run nd.open.android.studio && npm run nd.build.run.demo.app.android",
151+
value: "npm run nd.open.android.studio && npm run nd.demo.tns.run.android",
197152
shortCommands: ["demo android simulator attach & watch", "demo android device attach & watch"],
153+
buildCommand: "npm run nd.build.native.android",
198154
patterns: [
199155
androidSourcePath
200156
],
@@ -203,26 +159,29 @@ function getPluginPreDefinedScripts(srcPath, demoFolder, demoAngularFolder, demo
203159
},
204160
{
205161
key: "nd.demo.run.watch.ios",
206-
value: "npm run nd.open.xcode && npm run nd.build.run.simulator.demo.app.ios",
162+
value: "npm run nd.open.xcode && npm run nd.demo.tns.run.ios",
207163
shortCommands: ["demo ios simulator attach & watch"],
164+
buildCommand: "npm run nd.build.simulator.native.ios",
208165
patterns: [
209166
iosSourcePath
210167
],
211168
extensions: ["h", "m"]
212169
},
213170
{
214171
key: "nd.demo.run.watch.device.ios",
215-
value: "npm run nd.open.xcode && npm run nd.build.run.device.demo.app.ios",
172+
value: "npm run nd.open.xcode && npm run npm run nd.demo.tns.run.ios",
216173
shortCommands: ["demo ios device attach & watch"],
174+
buildCommand: "npm run nd.build.device.native.ios",
217175
patterns: [
218176
iosSourcePath
219177
],
220178
extensions: ["h", "m"]
221179
},
222180
{
223181
key: "nd.demo.angular.run.watch.android",
224-
value: "npm run nd.open.android.studio && npm run nd.build.run.demo.angular.app.android",
182+
value: "npm run nd.open.android.studio && npm run nd.demo.angular.tns.run.android",
225183
shortCommands: ["demo-angular android simulator attach & watch", "demo-angular android device attach & watch"],
184+
buildCommand: "npm run nd.build.native.android",
226185
patterns: [
227186
androidSourcePath
228187
],
@@ -231,26 +190,29 @@ function getPluginPreDefinedScripts(srcPath, demoFolder, demoAngularFolder, demo
231190
},
232191
{
233192
key: "nd.demo.angular.run.watch.ios",
234-
value: "npm run nd.open.xcode && npm run nd.build.run.simulator.demo.angular.app.ios",
193+
value: "npm run nd.open.xcode && npm run npm run nd.demo.angular.tns.run.ios",
235194
shortCommands: ["demo-angular ios simulator attach & watch"],
195+
buildCommand: "npm run nd.build.simulator.native.ios",
236196
patterns: [
237197
iosSourcePath
238198
],
239199
extensions: ["h", "m"]
240200
},
241201
{
242202
key: "nd.demo.angular.run.watch.device.ios",
243-
value: "npm run nd.open.xcode && npm run nd.build.run.demo.angular.app.ios",
203+
value: "npm run nd.open.xcode && npm run nd.demo.angular.tns.run.ios",
244204
shortCommands: ["demo-angular ios device attach & watch"],
205+
buildCommand: "npm run nd.build.device.native.ios",
245206
patterns: [
246207
iosSourcePath
247208
],
248209
extensions: ["h", "m"]
249210
},
250211
{
251212
key: "nd.demo.vue.run.watch.android",
252-
value: "npm run nd.open.android.studio && npm run nd.build.run.demo.vue.app.android",
213+
value: "npm run nd.open.android.studio && npm run nd.demo.vue.tns.run.android",
253214
shortCommands: ["demo-vue android simulator attach & watch", "demo-vue android device attach & watch"],
215+
buildCommand: "npm run nd.build.native.android",
254216
patterns: [
255217
androidSourcePath
256218
],
@@ -261,17 +223,19 @@ function getPluginPreDefinedScripts(srcPath, demoFolder, demoAngularFolder, demo
261223
},
262224
{
263225
key: "nd.demo.vue.run.watch.ios",
264-
value: "npm run nd.open.xcode && npm run nd.build.run.simulator.demo.vue.app.ios",
226+
value: "npm run nd.open.xcode && npm run npm run nd.demo.vue.tns.run.ios",
265227
shortCommands: ["demo-vue ios simulator attach & watch"],
228+
buildCommand: "npm run nd.build.simulator.native.ios",
266229
patterns: [
267230
iosSourcePath
268231
],
269232
extensions: ["h", "m"]
270233
},
271234
{
272235
key: "nd.demo.vue.run.watch.device.ios",
273-
value: "npm run nd.open.xcode && npm run nd.build.run.demo.vue.app.ios",
236+
value: "npm run nd.open.xcode && npm run nd.demo.vue.tns.run.ios",
274237
shortCommands: ["demo-vue ios device attach & watch"],
238+
buildCommand: "npm run nd.build.device.native.ios",
275239
patterns: [
276240
iosSourcePath
277241
],
@@ -285,7 +249,7 @@ function getPluginPreDefinedScripts(srcPath, demoFolder, demoAngularFolder, demo
285249
},
286250
{
287251
key: "nd.demo.tns.run.ios",
288-
value: "cd " + demoFolder + " && tns build ios && tns run ios --syncAllFiles" + provisioningParam,
252+
value: "cd " + demoFolder + " && tns run ios --syncAllFiles" + provisioningParam,
289253
description: "Runs the 'demo' app on iOS with '--syncAllFiles' argument",
290254
category: "secondary"
291255
},
@@ -297,7 +261,7 @@ function getPluginPreDefinedScripts(srcPath, demoFolder, demoAngularFolder, demo
297261
},
298262
{
299263
key: "nd.demo.angular.tns.run.ios",
300-
value: "cd " + demoAngularFolder + " && tns build ios && tns run ios --syncAllFiles" + provisioningParam,
264+
value: "cd " + demoAngularFolder + " && tns run ios --syncAllFiles" + provisioningParam,
301265
description: "Runs the 'demo-angular' app on iOS with '--syncAllFiles' argument",
302266
category: "secondary"
303267
},
@@ -309,7 +273,7 @@ function getPluginPreDefinedScripts(srcPath, demoFolder, demoAngularFolder, demo
309273
},
310274
{
311275
key: "nd.demo.vue.tns.run.ios",
312-
value: "cd " + demoVueFolder + " && tns build ios && tns run ios --syncAllFiles" + provisioningParam,
276+
value: "cd " + demoVueFolder + " && tns run ios --syncAllFiles" + provisioningParam,
313277
description: "Runs the 'demo-vue' app on iOS with '--syncAllFiles' argument",
314278
category: "secondary"
315279
},

0 commit comments

Comments
 (0)