forked from NathanWalker/nativescript-plugin-seed
-
-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathpostclone.js
720 lines (629 loc) · 25.8 KB
/
postclone.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
var fs = require('fs');
var prompt = require('prompt');
var rimraf = require('rimraf');
var exec = require('child_process').exec;
const spawn = require('child_process').spawn;
const pathModule = require("path");
var class_name,
inputParams = {
plugin_name: undefined,
github_username: undefined,
init_git: undefined,
include_javascript_demo: undefined,
include_typescript_demo: undefined,
include_angular_demo: undefined,
include_vue_demo: undefined,
templates_branch: undefined
},
seed_plugin_name = "yourplugin",
seed_class_name = "YourPlugin",
seed_demo_property_name = "yourPlugin",
seed_github_username = "YourName",
tsAppName = "demo",
angularAppName = "demo-angular",
// vueAppName = "demo-vue",
demoTsFolder = "../" + tsAppName,
demoAngularFolder = "../" + angularAppName,
// demoVueFolder = "../" + vueAppName,
screenshots_dir = "../screenshots",
templates_dir = "../nativescript-app-templates",
seed_tests_dir = "../seed-tests",
scripts_dir = "scripts",
filesToReplace = {
readmeFile: {
source: "README.md",
destination: "../README.md"
},
travisFile: {
source: ".travis.yml",
destination: "../.travis.yml"
}
},
appsToCreate = [],
appsToInstallPluginIn = [],
demoTsSearchTerm = ".bindingContext =",
demoAngularSearchTerm = 'templateUrl: "app.component.html"',
demoVueSearchTerm = '<Page class="page">',
preDefinedInclude = [
"../src",
"**/*"
],
preDefinedExclude = [
"../src/node_modules",
"node_modules",
"platforms"
],
preDefinedPaths = [
{
key: "*",
value: [
"./node_modules/*"
]
}
],
appNamePlaceholderStr = "appNamePlaceholder",
pluginNamePlaceholderStr = "pluginNamePlaceholder",
appPathPlaceholderStr = "appPathPlaceholder",
removeAddPluginCommand = "cd appNamePlaceholder && tns plugin remove pluginNamePlaceholder && tns plugin add ../src",
removeAddPluginCommandPlaceholderStr = "removeAddPluginCommandPlaceholder",
cleanAppsScriptPlaceholderStr = "cleanAppsScriptPlaceholder",
preDefinedAppScripts = [
{
key: "appNamePlaceholder.ios",
value: "npm i && cd appPathPlaceholder && tns run ios"
},
{
key: "appNamePlaceholder.android",
value: "npm i && cd appPathPlaceholder && tns run android"
}],
preDefinedPrepareScript =
{
key: "plugin.prepare",
value: "npm run build removeAddPluginCommandPlaceholder"
},
preDefinedResetScript = {
key: "appNamePlaceholder.reset",
value: "cd appPathPlaceholder && npx rimraf -- hooks node_modules platforms package-lock.json"
},
preDefinedCleanScript = {
key: "clean",
value: "cleanAppsScriptPlaceholder && npx rimraf -- node_modules package-lock.json && npm i",
};
console.log('NativeScript Plugin Seed Configuration');
// Expected order: `gitHubUsername` `pluginName` `initGit` `includeTypeScriptDemo` `includeAngularDemo`
// Example: gitHubUsername=PluginAuthor pluginName=myPluginClassName initGit=n includeTypeScriptDemo=y includeAngularDemo=n
var parseArgv = function () {
var argv = Array.prototype.slice.call(process.argv, 2);
var result = {};
argv.forEach(function (pairString) {
var pair = pairString.split('=');
result[pair[0]] = pair[1];
});
return result;
};
var argv = parseArgv();
if (argv) {
inputParams.github_username = argv.gitHubUsername;
inputParams.plugin_name = argv.pluginName;
inputParams.init_git = argv.initGit;
inputParams.include_typescript_demo = argv.includeTypeScriptDemo;
inputParams.include_angular_demo = argv.includeAngularDemo;
// inputParams.include_vue_demo = argv.includeVueDemo;
inputParams.templates_branch = argv.templatesBranch;
}
if (!isInteractive() && (!inputParams.github_username || !inputParams.plugin_name || !inputParams.init_git || !inputParams.include_typescript_demo || !inputParams.include_angular_demo)) {
console.log("Using default values for plugin creation since your shell is not interactive.");
inputParams.github_username = "PluginAuthor";
inputParams.plugin_name = "myPluginClassName";
inputParams.init_git = "y";
inputParams.include_typescript_demo = "y";
inputParams.include_angular_demo = "n";
// inputParams.include_vue_demo = "n";
}
askGithubUsername();
function askGithubUsername() {
if (inputParams.github_username !== undefined) {
askPluginName();
} else {
prompt.start();
prompt.get({
name: 'github_username',
description: 'What is your GitHub username (used for updating package.json)? Example: NathanWalker'
}, function (err, result) {
if (err) {
return console.log(err);
}
if (!result.github_username) {
return console.log("Your GitHub username is required to configure plugin's package.json.");
}
inputParams.github_username = result.github_username;
askPluginName();
});
}
}
function askPluginName() {
if (inputParams.plugin_name !== undefined) {
generateClassName();
} else {
prompt.get({
name: 'plugin_name',
description: 'What will be the name of your plugin? Use lowercase characters and dashes only. Example: yourplugin / google-maps / bluetooth'
}, function (err, result) {
if (err) {
return console.log(err);
}
if (!result.plugin_name) {
return console.log("Your plugin name is required to correct the file names and classes.");
}
inputParams.plugin_name = result.plugin_name;
if (inputParams.plugin_name.startsWith("nativescript-")) {
inputParams.plugin_name = inputParams.plugin_name.replace("nativescript-", "");
}
generateClassName();
});
}
}
function askTypeScriptDemo() {
if (inputParams.include_typescript_demo !== undefined) {
askAngularDemo();
} else {
prompt.start();
prompt.get({
name: 'include_typescript_demo',
description: 'Do you want to include a "TypeScript NativeScript" application linked with your plugin to make development easier (y/n)?',
default: 'y'
}, function (err, result) {
if (err) {
return console.log(err);
}
inputParams.include_typescript_demo = result.include_typescript_demo;
askAngularDemo();
});
}
}
function askAngularDemo() {
if (inputParams.include_angular_demo !== undefined) {
// askVueDemo();
prepareDemoAppsFromTemplates();
} else {
prompt.start();
prompt.get({
name: 'include_angular_demo',
description: 'Do you want to include an "Angular NativeScript" application linked with your plugin to make development easier (y/n)?',
default: 'n'
}, function (err, result) {
if (err) {
return console.log(err);
}
inputParams.include_angular_demo = result.include_angular_demo;
// askVueDemo();
prepareDemoAppsFromTemplates();
});
}
}
// function askVueDemo() {
// if (inputParams.include_vue_demo !== undefined) {
// prepareDemoAppsFromTemplates();
// } else {
// prompt.start();
// prompt.get({
// name: 'include_vue_demo',
// description: 'Do you want to include a "Vue NativeScript" application linked with your plugin to make development easier (y/n)?',
// default: 'n'
// }, function (err, result) {
// if (err) {
// return console.log(err);
// }
// inputParams.include_vue_demo = result.include_vue_demo;
// prepareDemoAppsFromTemplates();
// });
// }
// }
function prepareDemoAppsFromTemplates() {
let templatesOrigin = inputParams.templates_branch ?
"nativescript-app-templates/packages/template-blank" :
"tns-template-blank";
let templatesOriginName = inputParams.templates_branch ?
"branch " + inputParams.templates_branch :
"latest published template";
if (inputParams.include_typescript_demo && inputParams.include_typescript_demo.toLowerCase() === "y") {
appsToCreate.push({
command: "cd ../ && tns create " + tsAppName + " --template " + templatesOrigin + "-ts && cd " + tsAppName + " && cd ../src/",
startMessage: "Creating 'TypeScript' application from " + templatesOriginName + "...",
successMessage: "TypeScript-NativeScript application created at: " + demoTsFolder,
type: "TypeScript"
});
appsToInstallPluginIn.push(demoTsFolder);
}
if (inputParams.include_angular_demo && inputParams.include_angular_demo.toLowerCase() === "y") {
appsToCreate.push({
command: "cd ../ && tns create " + angularAppName + " --template " + templatesOrigin + "-ng && cd " + angularAppName + " && cd ../src/",
startMessage: "Creating 'Angular' application from " + templatesOriginName + "...",
successMessage: "Angular-NativeScript application created at: " + demoAngularFolder,
type: "Angular"
});
appsToInstallPluginIn.push(demoAngularFolder);
}
// if (inputParams.include_vue_demo && inputParams.include_vue_demo.toLowerCase() === "y") {
// appsToCreate.push({
// command: "cd ../ && tns create " + vueAppName + " --vue && cd " + vueAppName + " && cd ../src/",
// startMessage: "Creating 'Vue' application from " + templatesOriginName + "...",
// successMessage: "Vue-NativeScript application created at: /demo-vue",
// type: "Vue"
// });
// appsToInstallPluginIn.push(demoVueFolder);
// }
if (appsToCreate.length > 0 && inputParams.templates_branch) {
console.log("Cloning repository NativeScript/nativescript-app-templates...");
exec('cd ../ && git clone https://github.com/NativeScript/nativescript-app-templates.git', function (err, stdout, stderr) {
if (err) {
console.log(err);
} else {
console.log("Repository cloned.");
exec('cd ../nativescript-app-templates && git checkout ' + inputParams.templates_branch, function (err, stdout, stderr) {
if (err) {
console.log(err);
} else {
console.log("Checked out branch " + inputParams.templates_branch);
}
});
createDemoAppsFromTemplates();
}
});
} else {
createDemoAppsFromTemplates();
}
}
function createDemoAppsFromTemplates() {
let appObject = appsToCreate.pop();
if (appObject) {
startProcess(appObject);
} else {
adjustScripts();
}
}
function startProcess(commandAndMessage) {
if (commandAndMessage.startMessage) {
console.log(commandAndMessage.startMessage);
}
let mainChildProcess = spawn(commandAndMessage.command, [], { stdio: 'inherit', shell: true, detached: false });
mainChildProcess.on("close", function (code, signal) {
if (commandAndMessage.successMessage) {
console.log(commandAndMessage.successMessage);
}
if (appsToCreate.length == 0) {
adjustScripts();
} else {
let appObject = appsToCreate.pop();
startProcess(appObject);
}
});
}
function generateClassName() {
// the class_name becomes 'GoogleMaps' when plugin_name is 'google-maps'
class_name = "";
var plugin_name_parts = inputParams.plugin_name.split("-");
for (var p in plugin_name_parts) {
var part = plugin_name_parts[p];
class_name += (part[0].toUpperCase() + part.substr(1));
}
console.log('Using ' + class_name + ' as the TypeScript Class name..');
renameFiles();
}
function renameFiles() {
console.log('Will now rename some files..');
var files = fs.readdirSync(".");
for (var f in files) {
var file = files[f];
if (file.indexOf(seed_plugin_name) === 0) {
var newName = inputParams.plugin_name + file.substr(file.indexOf("."));
fs.renameSync(file, newName);
}
}
askTypeScriptDemo();
}
function adjustScripts() {
console.log('Adjusting scripts..');
// add all files in the root
var files = fs.readdirSync(".");
// add include.gradle
files.push("platforms/android/include.gradle");
// add the demo files
let demoAppPath = pathModule.join(demoTsFolder + "/app/home/");
if (fs.existsSync(demoAppPath)) {
files.push(demoTsFolder + "/package.json");
var demoFiles = fs.readdirSync(demoAppPath);
for (var d in demoFiles) {
var demoFile = demoFiles[d];
files.push(demoAppPath + demoFile);
}
updateAppsTsConfigFile(pathModule.resolve(__dirname, pathModule.join("../" + demoTsFolder)));
}
// add the demo-angular files
let demoAngularAppPath = pathModule.join(demoAngularFolder + "/src/app/");
if (fs.existsSync(demoAngularAppPath)) {
files.push(demoAngularFolder + "/package.json");
var demoFiles = fs.readdirSync(demoAngularAppPath);
for (var d in demoFiles) {
var demoFile = demoFiles[d];
files.push(demoAngularAppPath + demoFile);
}
updateAppsTsConfigFile(pathModule.resolve(__dirname, pathModule.join("../" + demoAngularFolder)));
}
// add the demo-angular files
// let demoVueAppPath = path.join(demoVueFolder + "/app/components/");
// if (fs.existsSync(demoVueAppPath)) {
// files.push(demoVueFolder + "/package.json");
// var demoFiles = fs.readdirSync(demoVueAppPath);
// for (var d in demoFiles) {
// var demoFile = demoFiles[d];
// files.push(demoVueAppPath + demoFile);
// }
// updateAppsTsConfigFile(path.resolve(__dirname, path.join("../" + demoVueFolder)));
// }
// prepare and cache a few Regexp thingies
var regexp_seed_plugin_name = new RegExp(seed_plugin_name, "g");
var regexp_seed_class_name = new RegExp(seed_class_name, "g");
var regexp_seed_demo_property_name = new RegExp(seed_demo_property_name, "g");
var regexp_seed_github_username = new RegExp(seed_github_username, "g");
for (var f in files) {
var file = files[f];
if (fs.lstatSync(file).isFile()) {
var contents = fs.readFileSync(file, 'utf8');
// Adds an 'import' and console.log() of the 'message' filed of 'nativescript-yourplugin' to the includes apps
contents = file.includes(pathModule.join(demoTsFolder)) ? updateApp(contents, file, demoTsSearchTerm) : contents;
contents = file.includes(pathModule.join(demoAngularFolder)) ? updateApp(contents, file, demoAngularSearchTerm) : contents;
// contents = file.includes(pathModule.join(demoVueFolder)) ? updateDemoVueApp(contents, file) : contents;
var result = contents.replace(regexp_seed_plugin_name, inputParams.plugin_name);
result = result.replace(regexp_seed_class_name, class_name);
result = result.replace(regexp_seed_demo_property_name, class_name[0].toLowerCase() + class_name.substr(1));
result = result.replace(regexp_seed_github_username, inputParams.github_username);
fs.writeFileSync(file, result);
}
}
replaceFiles();
updateSrcJson();
}
function updateAppsTsConfigFile(path) {
let jsonPath = pathModule.join(path + "/tsconfig.json");
let jsonFile = fs.readFileSync(jsonPath);
let jsonObject = JSON.parse(jsonFile);
var jsonInclude = ensureJsonArray(jsonObject["include"]);
var newInclude = updateJsonArray(preDefinedInclude, jsonInclude);
jsonObject["include"] = newInclude;
var jsonExclude = ensureJsonArray(jsonObject["exclude"]);
var newExclude = updateJsonArray(preDefinedExclude, jsonExclude);
jsonObject["exclude"] = newExclude;
var jsonPaths = ensureJsonArray(jsonObject["compilerOptions"])["paths"];
var newPaths = updateObject(preDefinedPaths, jsonPaths);
jsonObject["compilerOptions"]["paths"] = newPaths;
fs.writeFileSync(jsonPath, JSON.stringify(jsonObject, null, "\t"));
}
function updateSrcJson() {
let jsonPath = pathModule.join(pathModule.resolve(__dirname, "../") + "/package.json");
let jsonFile = fs.readFileSync(jsonPath);
let jsonObject = JSON.parse(jsonFile);
var jsonScripts = ensureJsonArray(jsonObject["scripts"]);
let pluginScripts = getPluginScripts();
var newScripts = updateObject(pluginScripts, jsonScripts);
delete newScripts["postclone"];
jsonObject["scripts"] = newScripts;
fs.writeFileSync(jsonPath, JSON.stringify(jsonObject, null, "\t"));
}
function getPluginScripts() {
let scripts = [];
let prepareScriptCommand;
let clearScriptResetCommands = [];
let pluginName = `nativescript-` + inputParams.plugin_name;
if (inputParams.include_typescript_demo === "y") {
preDefinedAppScripts.forEach((script) => {
scripts.push(
{
key: script.key.replace(appNamePlaceholderStr, tsAppName),
value: script.value.replace(appPathPlaceholderStr, demoTsFolder)
});
});
let resetScriptKey = preDefinedResetScript.key.replace(appNamePlaceholderStr, tsAppName);
scripts.push({
key: resetScriptKey,
value: preDefinedResetScript.value.replace(appPathPlaceholderStr, demoTsFolder)
});
clearScriptResetCommands.push(resetScriptKey);
let updatedRemoveAddPluginCommand = removeAddPluginCommand.replace(appNamePlaceholderStr, demoTsFolder);
prepareScriptCommand = "&& " + updatedRemoveAddPluginCommand.replace(pluginNamePlaceholderStr, pluginName);
}
if (inputParams.include_angular_demo === "y") {
preDefinedAppScripts.forEach((script) => {
scripts.push(
{
key: script.key.replace(appNamePlaceholderStr, angularAppName),
value: script.value.replace(appPathPlaceholderStr, demoAngularFolder)
});
});
let resetScriptKey = preDefinedResetScript.key.replace(appNamePlaceholderStr, angularAppName);
scripts.push({
key: resetScriptKey,
value: preDefinedResetScript.value.replace(appPathPlaceholderStr, demoAngularFolder)
});
clearScriptResetCommands.push(resetScriptKey);
let updatedRemoveAddPluginCommand = removeAddPluginCommand.replace(appNamePlaceholderStr, demoAngularFolder);
prepareScriptCommand += " && " + updatedRemoveAddPluginCommand.replace(pluginNamePlaceholderStr, pluginName);
}
if (inputParams.include_vue_demo) {
preDefinedAppScripts.forEach((script) => {
scripts.push(
{
key: script.key.replace(appNamePlaceholderStr, demoVueFolder),
value: script.value.replace(appPathPlaceholderStr, demoVueFolder)
});
});
let resetScriptKey = preDefinedResetScript.key.replace(appNamePlaceholderStr, angularAppName);
scripts.push({
key: resetScriptKey,
value: preDefinedResetScript.value.replace(appPathPlaceholderStr, demoAngularFolder)
});
clearScriptResetCommands.push(resetScriptKey);
let updatedRemoveAddPluginCommand = removeAddPluginCommand.replace(appNamePlaceholderStr, demoVueFolder);
prepareScriptCommand += " && " + updatedRemoveAddPluginCommand.replace(pluginNamePlaceholderStr, pluginName);
}
scripts.push({
key: preDefinedPrepareScript.key,
value: preDefinedPrepareScript.value.replace(removeAddPluginCommandPlaceholderStr, prepareScriptCommand)
});
let fullAppResetCommand = "";
clearScriptResetCommands.forEach((tag) => {
fullAppResetCommand += fullAppResetCommand.length === 0 ? "npm run " + tag : " && npm run " + tag;
});
scripts.push({
key: preDefinedCleanScript.key,
value: preDefinedCleanScript.value.replace(cleanAppsScriptPlaceholderStr, fullAppResetCommand)
});
return scripts;
}
function updateJsonArray(newValues, oldValues) {
newValues.forEach((value) => {
if (!oldValues.includes(value)) {
oldValues.push(value);
}
});
return oldValues;
}
function updateObject(newObjects, oldObjects) {
newObjects.forEach((script) => {
oldObjects[script.key] = script.value;
});
return oldObjects;
}
function ensureJsonArray(jsonSection) {
if (!jsonSection) {
return [];
}
return jsonSection;
}
function updateApp(contents, file, searchTerm) {
if (contents.includes(searchTerm)) {
let fullPluginName = `'nativescript-` + inputParams.plugin_name + `'`;
console.log("Updating " + file + " with " + fullPluginName + " import .");
let typeScriptImportSnippet = `import { ` + class_name + ` } from ` + fullPluginName + `;\n`,
typeScriptAlertSnippet = `console.log(new ` + class_name + `().message);\n`;
contents = typeScriptAlertSnippet + contents;
contents = typeScriptImportSnippet + contents;
}
return contents;
}
// function updateDemoVueApp(contents, file) {
// if (contents.includes(demoVueSearchTerm)) {
// let pluginName = `'nativescript-`+ inputParams.plugin_name + `'`;
// console.log("Updating " + file + " with " + pluginName + " import");
// let typeScriptImportSnippet = `import { ` + class_name + ` } from ` + pluginName + `;\n`,
// typeScriptAlertSnippet = `console.log(new ` + class_name + `().message);\n`;
// // contents = typeScriptAlertSnippet + contents;
// // contents = typeScriptImportSnippet + contents;
// // TODO: insert this after the <script> tag on the next line
// }
// return contents;
// }
function askInitGit() {
if (inputParams.init_git !== undefined) {
initGit();
} else {
prompt.get({
name: 'init_git',
description: 'Do you want to init a fresh local git project? If you previously \'git clone\'d this repo that would be wise (y/n)',
default: 'y'
}, function (err, result) {
if (err) {
return console.log(err);
}
inputParams.init_git = result.init_git;
initGit();
});
}
}
function replaceFiles() {
for (key in filesToReplace) {
var file = filesToReplace[key];
var contents = fs.readFileSync(file.source);
fs.writeFileSync(file.destination, contents);
fs.unlinkSync(file.source);
}
addPluginToDemoApps();
}
function addPluginToDemoApps() {
if (appsToInstallPluginIn.length > 0) {
let appToInstallIn = appsToInstallPluginIn.pop();
console.log("Installing plugin to " + appToInstallIn + " ...");
exec("cd " + appToInstallIn + " && tns plugin add ../src", function (err, stdout, stderr) {
if (err) {
console.log(err);
} else {
if (appsToInstallPluginIn.length == 0) {
rimraf(screenshots_dir, function () {
console.log('Screenshots removed.');
rimraf(seed_tests_dir, function () {
console.log('Seed tests removed.');
rimraf(templates_dir, function () {
console.log('Templates removed.');
// delete postclone.js
rimraf.sync('../CONTRIBUTING.md');
rimraf.sync('../CODE_OF_CONDUCT.md');
rimraf.sync(scripts_dir + '/postclone.js');
askInitGit();
});
});
});
} else {
addPluginToDemoApps();
}
}
});
} else {
askInitGit();
}
}
function isInteractive() {
const result = isRunningInTTY() && !isCIEnvironment();
return result;
}
/**
* Checks if current process is running in Text Terminal (TTY)
*/
function isRunningInTTY() {
return process.stdout &&
process.stdout.isTTY &&
process.stdin &&
process.stdin.isTTY;
}
function isCIEnvironment() {
// The following CI environments set their own environment variables that we respect:
// travis: "CI",
// circleCI: "CI",
// jenkins: "JENKINS_HOME"
return !!(process.env && (process.env.CI || process.env.JENKINS_HOME));
}
function initGit() {
if (inputParams.init_git && inputParams.init_git.toLowerCase() === 'y') {
rimraf.sync('../.git');
exec('git init -q ..', function (err, stdout, stderr) {
if (err) {
console.log(err);
finishSetup();
} else {
exec("git add \"../*\" \"../.*\"", function (err, stdout, stderr) {
if (err) {
console.log(err);
}
finishSetup();
});
}
});
} else {
finishSetup();
}
}
function finishSetup() {
console.log("Configuration finished! If you're not happy with the result please clone the seed again and start over.");
console.log("Visit the NativeScript documentation for detailed steps on how to proceed from here.");
console.log("https://docs.nativescript.org/plugins/building-plugins#step-2-set-up-a-development-workflow");
process.exit();
}