-
Notifications
You must be signed in to change notification settings - Fork 30
/
setup.js
105 lines (84 loc) · 4.28 KB
/
setup.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
'use strict';
var fse = require('fs-extra'),
request = require('request'),
url = require('url'),
path = require('path'),
fs = require('fs'),
AdmZip = require('adm-zip');
function copyFolder(fromDir, toDir) {
fse.copySync(fromDir, toDir);
console.log('Copied ' + fromDir + ' to ' + toDir);
}
function overlayFiles(targetDir, overlayItems) {
var overlayItems = (overlayItems) ? overlayItems : [ { from:'Files/BeginFiles', to: 'Begin', }, { from: 'Files/EndFiles', to: 'End' }];
overlayItems.forEach(function(overlayItem) {
if (fse.existsSync(targetDir + '/' + overlayItem.from)) {
copyFolder(targetDir + '/' + overlayItem.from, targetDir + '/' + overlayItem.to);
}
});
}
function downloadAndExtractProjects(callback) {
var repos = [{ name: 'angular-jumpstart', url: 'https://github.com/DanWahlin/Angular-JumpStart/archive/main.zip' },
{ name: 'angular-helloworld', url: 'https://github.com/DanWahlin/Angular-HelloWorld/archive/main.zip' },
{ name: 'angular-forms', url: 'https://github.com/DanWahlin/Angular-Forms/archive/master.zip' } ];
let pending = repos.length;
//if (!pending) { return callback(new Error('No files found to download')); }
repos.forEach(function(repo) {
var filePath = './' + repo.name + '.zip';
request(repo.url).pipe(
fse.createWriteStream(filePath).addListener('finish', function() {
console.log('Extracting: ' + filePath);
var zip = new AdmZip(filePath);
zip.extractAllTo('./', true);
fse.unlink(filePath,function(err) {
if (err) {
console.log(err);
return callback(err);
}
if (!--pending) { callback(null); }
});
})
);
});
}
//Start process
downloadAndExtractProjects(function(err) {
// var sampleFolders = ['./Samples/Introduction-To-Angular',
// './Samples/Components-And-Modules',
// './Samples/Template-Expressions-And-Pipes',
// './Samples/Component-Properties-And-Data-Binding',
// './Samples/Services-Providers-And-Http'];
// sampleFolders.forEach(function(sampleFolder) {
// copyFolder('./Angular-HelloWorld-main', sampleFolder + '/Begin');
// copyFolder('./Angular-HelloWorld-main', sampleFolder + '/End');
// //Overlay Begin/End Files into respective Begin/End folder
// overlayFiles(sampleFolder);
// });
//Lab 1 (Angular CLI - instructor-led)
//Lab 2 (TypeScript - instructor-led)
//Lab 3 (Uses the Angular-JumpStart-main source code)
//Lab 4
copyFolder('./Angular-JumpStart-main', './Labs/Components and Modules/Begin');
overlayFiles('./Labs/Components and Modules');
//Lab 5
copyFolder('./Angular-HelloWorld-main', './Labs/Interpolation Expressions and Pipes/BeginPipesAndBindings');
copyFolder('./Angular-HelloWorld-main', './Labs/Interpolation Expressions and Pipes/EndPipesAndBindings');
overlayFiles('./Labs/Interpolation Expressions and Pipes', [ { from:'Files/BeginPipesAndBindingsFiles', to: 'BeginPipesAndBindings', }, { from: 'Files/EndPipesAndBindingsFiles', to: 'EndPipesAndBindings' }]);
copyFolder('./Angular-JumpStart-main', './Labs/Interpolation Expressions and Pipes/Begin');
overlayFiles('./Labs/Interpolation Expressions and Pipes');
//Lab 6
copyFolder('./Angular-JumpStart-main', './Labs/Component Properties and Angular Directives/Begin');
overlayFiles('./Labs/Component Properties and Angular Directives');
//Lab 7
copyFolder('./Angular-JumpStart-main', './Labs/Services Providers and HttpClient/Begin');
overlayFiles('./Labs/Services Providers and HttpClient');
//Lab 8
copyFolder('./Angular-JumpStart-main', './Labs/Working with Routing/Begin');
overlayFiles('./Labs/Working with Routing');
//Lab 9
copyFolder('./Angular-JumpStart-main', './Labs/Route Guards and Lazy Loading/Begin');
overlayFiles('./Labs/Route Guards and Lazy Loading');
//Lab 10
copyFolder('./Angular-JumpStart-main', './Labs/Template and Reactive Forms/Begin');
overlayFiles('./Labs/Template and Reactive Forms');
});