Skip to content

Commit 45e5153

Browse files
All hybrid apps now build in prod and dev mode by running npm run build-[dev/prod]-[at/cm/site/vle]. #2022
1 parent e0037f5 commit 45e5153

33 files changed

Lines changed: 256 additions & 242 deletions

File tree

‎package-lock.json‎

Lines changed: 47 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
"@types/node": "^12.7.2",
8181
"autoprefixer": "^9.6.1",
8282
"babel-loader": "^8.0.6",
83+
"cheerio": "^1.0.0-rc.3",
8384
"clean-webpack-plugin": "^3.0.0",
8485
"concurrently": "^4.1.2",
8586
"eslint": "^5.16.0",
@@ -119,11 +120,18 @@
119120
},
120121
"scripts": {
121122
"browser-sync": "./node_modules/browser-sync/bin/browser-sync.js start --config bs-config.js",
122-
"build-all": "npm run build-at; npm run build-cm; npm run build-vle; npm run build-site",
123-
"build-site": "node --max_old_space_size=4096 ./node_modules/@angular/cli/bin/ng build site --configuration=production",
123+
"build-dev-all": "node node_modules/concurrently/bin/concurrently.js \"npm run build-dev-site\" \"npm run build-dev-at\" \"npm run build-dev-cm\" \"npm run build-dev-vle\"",
124+
"build-dev-at": "node node_modules/concurrently/bin/concurrently.js \"node --max_old_space_size=4096 ./node_modules/@angular/cli/bin/ng build at --watch\" \"while node scripts/afterBuild.js at; do sleep 5; done\"",
125+
"build-dev-cm": "node node_modules/concurrently/bin/concurrently.js \"node --max_old_space_size=4096 ./node_modules/@angular/cli/bin/ng build cm --watch\" \"while node scripts/afterBuild.js cm; do sleep 5; done\"",
126+
"build-dev-site": "node node_modules/concurrently/bin/concurrently.js \"ng build site --watch\" \"ng test --source-map=false --karma-config src/main/webapp/site/karma.conf.js --browsers ChromeHeadlessNoSandbox\" \"while node scripts/afterBuild.js site; do sleep 5; done\"",
127+
"build-dev-vle": "node node_modules/concurrently/bin/concurrently.js \"node --max_old_space_size=4096 ./node_modules/@angular/cli/bin/ng build vle --watch\" \"while node scripts/afterBuild.js vle; do sleep 5; done\"",
128+
"build-prod-all": "npm run build-prod-at; npm run build-prod-cm; npm run build-prod-vle; npm run build-prod-site",
129+
"build-prod-at": "node --max_old_space_size=4096 ./node_modules/@angular/cli/bin/ng build at --configuration=production; node scripts/afterBuild.js at",
130+
"build-prod-cm": "node --max_old_space_size=4096 ./node_modules/@angular/cli/bin/ng build cm --configuration=production; node scripts/afterBuild.js cm",
131+
"build-prod-vle": "node --max_old_space_size=4096 ./node_modules/@angular/cli/bin/ng build vle --configuration=production; node scripts/afterBuild.js vle",
132+
"build-prod-site": "node --max_old_space_size=4096 ./node_modules/@angular/cli/bin/ng build site --configuration=production; node scripts/afterBuild.js site",
124133
"bundle-report": "node ./node_modules/webpack-bundle-analyzer/lib/bin/analyzer.js src/main/webapp/site/dist/stats.json",
125134
"watch-all-wise5": "node node_modules/concurrently/bin/concurrently.js \"node ./node_modules/gulp/bin/gulp.js\" \"npm run test-wise5-watch\"",
126-
"watch-all-site": "node node_modules/concurrently/bin/concurrently.js \"ng build site --watch\" \"ng test --source-map=false --karma-config src/main/webapp/site/karma.conf.js --browsers ChromeHeadlessNoSandbox\"",
127135
"watch-sass": "npm rebuild node-sass && node ./node_modules/gulp/bin/gulp.js",
128136
"update-i18n": "node ./node_modules/gulp/bin/gulp.js update-i18n",
129137
"compile-sass": "node ./node_modules/gulp/bin/gulp.js compile-sass",
@@ -135,13 +143,6 @@
135143
"test-e2e-all-comment": "test-e2e-all assumes wise is not running yet.",
136144
"test-e2e-all": "./wise.sh run & sleep 20; ./node_modules/protractor/bin/webdriver-manager update; ./node_modules/protractor/bin/webdriver-manager start & ./node_modules/protractor/bin/protractor src/main/webapp/wise5/test-e2e/conf.js; for pid in $(ps -ef | awk '/tomcat7:run/ {print $2}'); do kill -9 $pid; done",
137145
"ngx-extractor": "./node_modules/.bin/ngx-extractor -i \"src/main/webapp/site/**/*.ts\" -o src/main/webapp/site/src/messages.xlf",
138-
"build-prod-at": "cd ./src/main/webapp/wise5/authoringTool; webpack --config webpack.prod.js",
139-
"build-prod-cm": "cd ./src/main/webapp/wise5/classroomMonitor; webpack --config webpack.prod.js",
140-
"build-prod-vle": "cd ./src/main/webapp/wise5/vle; webpack --config webpack.prod.js",
141-
"build-dev-all": "node node_modules/concurrently/bin/concurrently.js \"npm run watch-all-site\" \"npm run build-dev-at\" \"npm run build-dev-cm\" \"npm run build-dev-vle\"",
142-
"build-dev-at": "ng build at --watch",
143-
"build-dev-cm": "ng build cm --watch",
144-
"build-dev-vle": "ng build vle --watch",
145146
"standalone-server-at": "cd ./src/main/webapp/wise5/authoringTool; webpack-dev-server --open --config webpack.dev.js --history-api-fallback --inline --progress",
146147
"standalone-server-cm": "cd ./src/main/webapp/wise5/classroomMonitor; webpack-dev-server --open --config webpack.dev.js --history-api-fallback --inline --progress",
147148
"standalone-server-vle": "cd ./src/main/webapp/wise5/vle; webpack-dev-server --open --config webpack.dev.js --history-api-fallback --inline --progress"

‎scripts/afterBuild.js‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
const cheerio = require('cheerio')
2+
const fs = require('fs');
3+
const _ = require('lodash');
4+
5+
const args = process.argv.slice(2);
6+
const appType = args[0];
7+
8+
let indexFilePath = '';
9+
let appDir = '';
10+
if (appType === 'vle') {
11+
indexFilePath = 'src/main/webapp/wise5/vle/dist/index.html';
12+
appDir = `/wise5/vle/dist`;
13+
} else if (appType === 'cm') {
14+
indexFilePath = 'src/main/webapp/wise5/classroomMonitor/dist/index.html';
15+
appDir = `/wise5/classroomMonitor/dist`;
16+
} else if (appType === 'at') {
17+
indexFilePath = 'src/main/webapp/wise5/authoringTool/dist/index.html';
18+
appDir = `/wise5/authoringTool/dist`;
19+
} else if (appType === 'site') {
20+
indexFilePath = 'src/main/webapp/site/dist/index.html';
21+
appDir = `/site/dist`;
22+
}
23+
24+
fs.readFile(indexFilePath, 'utf8', function (err,data) {
25+
if (err) {
26+
return;
27+
}
28+
29+
const $ = cheerio.load(data);
30+
//$('body').addClass('vle');
31+
//$('body').prepend('<script>if (global === undefined) { var global = window;}</script>');
32+
//$('app-root').after('<div ng-view style="height:100%"><div ui-view style="height:100%"></div></div>');
33+
$('script[src]').each((i, element) => {
34+
if ($(element).attr('src').indexOf(appDir) === -1) {
35+
$(element).attr('src', `${appDir}/${$(element).attr('src')}`);
36+
}
37+
});
38+
fs.writeFile(indexFilePath, $.html(), function (err) {
39+
if (err) return console.log(err);
40+
});
41+
});

‎src/main/java/org/wise/portal/presentation/web/controllers/VLEController.java‎

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -78,20 +78,12 @@ protected ModelAndView launchVLEWISE4Run(HttpServletRequest request, HttpServlet
7878
}
7979

8080
@GetMapping("/student/run/{runId}")
81-
protected String launchVLEWISE5Run(HttpServletRequest request, @PathVariable Long runId, ModelMap modelMap) {
82-
String contextPath = request.getContextPath();
83-
modelMap.put("configURL", contextPath + "/config/studentRun/" + runId);
84-
return "student";
81+
protected String launchVLEWISE5Run(@PathVariable Long runId) {
82+
return "forward:/wise5/vle/dist/index.html#/run/" + runId;
8583
}
8684

8785
@GetMapping("/project/{projectId}")
88-
protected String launchVLEWISE5Preview(HttpServletRequest request, @PathVariable String projectId, ModelMap modelMap)
89-
throws NumberFormatException, ObjectNotFoundException {
90-
if (!"demo".equals(projectId)) {
91-
projectService.getById(Long.parseLong(projectId));
92-
}
93-
String contextPath = request.getContextPath();
94-
modelMap.put("configURL", contextPath + "/config/preview/" + projectId);
95-
return "student";
86+
protected String launchVLEWISE5Preview(@PathVariable String projectId) {
87+
return "forward:/wise5/vle/dist/index.html#/project/" + projectId;
9688
}
9789
}

‎src/main/java/org/wise/portal/presentation/web/controllers/admin/SiteController.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@
3636
@RequestMapping("/")
3737
public class SiteController {
3838

39-
@GetMapping(value = {"", "/student", "/student/**", "/teacher", "/teacher/**", "/login",
39+
@GetMapping(value = {"", "/student", "/student/**", "/teacher", "/teacher/**", "/login",
4040
"/login/**", "/join", "/join/**", "/news", "/about", "/features", "/privacy", "/news",
4141
"/contact", "/contact/**", "/help", "/help/**", "/forgot", "/forgot/**"})
4242
protected String showSite() {
43-
return "forward:/index.html";
43+
return "forward:/site/dist/index.html";
4444
}
4545
}

‎src/main/java/org/wise/portal/presentation/web/controllers/author/project/WISE5AuthorProjectController.java‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ public class WISE5AuthorProjectController {
106106
private String featuredProjectIconsFolderRelativePath = "wise5/authoringTool/projectIcons";
107107

108108
@GetMapping("/author")
109-
protected String authorProject(HttpServletRequest request, HttpServletResponse response,
110-
ModelMap modelMap) throws ObjectNotFoundException {
109+
protected String authorProject(HttpServletRequest request, HttpServletResponse response)
110+
throws ObjectNotFoundException {
111111
Portal portal = portalService.getById(new Integer(1));
112112
if (!portal.isLoginAllowed()) {
113113
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
@@ -117,9 +117,7 @@ protected String authorProject(HttpServletRequest request, HttpServletResponse r
117117
SecurityContextHolder.getContext().setAuthentication(null);
118118
return "redirect:/index.html";
119119
}
120-
String contextPath = request.getContextPath();
121-
modelMap.put("configURL", contextPath + "/authorConfig");
122-
return "author";
120+
return "forward:/wise5/authoringTool/dist/index.html#/project/24699/node/node11";
123121
}
124122

125123
/**

‎src/main/java/org/wise/portal/presentation/web/controllers/teacher/grading/GradeWorkController.java‎

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
import javax.servlet.http.HttpServletRequest;
4444
import javax.servlet.http.HttpServletResponse;
4545
import java.io.IOException;
46-
import java.util.Properties;
4746

4847
/**
4948
* A Controller for Grading Student Work
@@ -85,7 +84,8 @@ protected ModelAndView launchClassroomMonitor(@PathVariable Integer runId,
8584
* @throws Exception
8685
*/
8786
@RequestMapping(value = "/classroomMonitor/{runId}")
88-
protected ModelAndView launchClassroomMonitorWISE5(HttpServletRequest request, @PathVariable Integer runId) throws Exception {
87+
protected ModelAndView launchClassroomMonitorWISE5(HttpServletRequest request, @PathVariable Integer runId)
88+
throws Exception {
8989
Run run = null;
9090
try {
9191
run = runService.retrieveById(new Long(runId));
@@ -99,11 +99,7 @@ protected ModelAndView launchClassroomMonitorWISE5(HttpServletRequest request, @
9999
if (user.isAdmin() ||
100100
this.runService.hasRunPermission(run, user, BasePermission.WRITE) ||
101101
this.runService.hasRunPermission(run, user, BasePermission.READ)) {
102-
String contextPath = request.getContextPath();
103-
String getClassroomMonitorConfigUrl = contextPath + "/config/classroomMonitor/" + runId;
104-
ModelAndView modelAndView = new ModelAndView("classroomMonitor");
105-
modelAndView.addObject("configURL", getClassroomMonitorConfigUrl);
106-
return modelAndView;
102+
return new ModelAndView("forward:/wise5/classroomMonitor/dist/index.html#/run/" + runId + "/project/");
107103
}
108104
return null;
109105
}

‎src/main/java/org/wise/portal/spring/impl/WebConfig.java‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,11 @@ public void addResourceHandlers(final ResourceHandlerRegistry registry) {
7171
registry.addResourceHandler("/portal/translate/**").addResourceLocations("/portal/translate/");
7272
registry.addResourceHandler("/vle/**").addResourceLocations("/vle/");
7373
registry.addResourceHandler("/wise5/**").addResourceLocations("/wise5/");
74+
registry.addResourceHandler("/site/**").addResourceLocations("/site/");
7475
registry.addResourceHandler("/curriculum/**").addResourceLocations("/curriculum/");
7576
registry.addResourceHandler("/studentuploads/**").addResourceLocations("/studentuploads/");
7677
registry.addResourceHandler("/curriculumWISE5/**").addResourceLocations("/curriculumWISE5/");
77-
registry.addResourceHandler("/index.html").addResourceLocations("/site/dist/");
7878
registry.addResourceHandler("/assets/**").addResourceLocations("/site/dist/assets/");
79-
registry.addResourceHandler("/*.js").addResourceLocations("/site/dist/");
80-
registry.addResourceHandler("/*.js.map").addResourceLocations("/site/dist/");
8179
registry.addResourceHandler("/*.css").addResourceLocations("/site/dist/");
8280
registry.addResourceHandler("/*.ico").addResourceLocations("/site/dist/");
8381
}

‎src/main/webapp/portal/author.jsp‎

Lines changed: 0 additions & 32 deletions
This file was deleted.

‎src/main/webapp/portal/classroomMonitor.jsp‎

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)