Skip to content
This repository was archived by the owner on Jul 2, 2020. It is now read-only.

Commit 53c9e1f

Browse files
author
oraclejet
committed
Update 0.0.8
1 parent 054d9b4 commit 53c9e1f

File tree

11 files changed

+124
-120
lines changed

11 files changed

+124
-120
lines changed

common/template/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ var _WEB = "web";
1313
var _BOTH = "both";
1414

1515
var BLANK_TEMPLATE = blankTemplate.BLANK_TEMPLATE;
16-
var _TEMPLATE_URL_ROOT = "https://github.com/oracle/oraclejet/releases/download/0.0.1/";
16+
var _TEMPLATE_URL_ROOT = "https://github.com/oracle/oraclejet/releases/download/0.0.2/";
1717

1818
var _TEMPLATES =
1919
{

generators/app/templates/common/bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
"version": "1.0.0",
44
"dependencies":
55
{
6-
"oraclejet": "0.0.1"
6+
"oraclejet": "0.0.2"
77
}
88
}

generators/hybrid/templates/common/bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
"version": "1.0.0",
44
"dependencies":
55
{
6-
"oraclejet": "0.0.1"
6+
"oraclejet": "0.0.2"
77
}
88
}

generators/hybrid/templates/common/scripts/common/injector.js

Lines changed: 5 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,9 @@ var hookInjector = require("../hooks/injector.js");
1818

1919
module.exports =
2020
{
21-
injectLiveReloadScript: function(updatePlatformFile)
21+
injectCordovaScript: function(updatePlatformFile, platform)
2222
{
23-
// note that this function will be invoked only for non-web case
24-
// and it's purpose is to inject content from the copied over src/index.html
25-
var injectSourceContent = _getInjectSourceContent(updatePlatformFile);
26-
var indexHTML = injectSourceContent.indexHTML;
27-
var document = injectSourceContent.document;
28-
29-
// per discussion the below cordova injection will be removed in the
30-
// future when the cordova.js is added to the quick start templates +
31-
// addeventlistener (mock) added in
32-
_injectLiveReloadScript(injectSourceContent);
33-
34-
fs.writeFileSync(indexHTML, document);
35-
},
36-
37-
injectCordovaScript: function(updatePlatformFile)
38-
{
39-
var injectSourceContent = _getInjectSourceContent(updatePlatformFile);
23+
var injectSourceContent = _getInjectSourceContent(updatePlatformFile, platform);
4024
var indexHTML = injectSourceContent.indexHTML;
4125
var document = injectSourceContent.document;
4226

@@ -49,21 +33,19 @@ module.exports =
4933
}
5034
},
5135

52-
injectPlatformStyleClasses: function()
36+
updateIndexHtml: function(platform)
5337
{
54-
var platform = process.env[constants.PLATFORM_ENV_KEY];
55-
hookInjector.injectPlatformStyleClasses(platform, true);
38+
hookInjector.updateIndexHtml(platform, true);
5639
}
5740

5841
};
5942

60-
function _getInjectSourceContent(updatePlatformFile)
43+
function _getInjectSourceContent(updatePlatformFile, platform)
6144
{
6245
var indexHTML;
6346

6447
if (updatePlatformFile)
6548
{
66-
var platform = process.env[constants.PLATFORM_ENV_KEY];
6749
var root = platformPaths[platform].ROOT;
6850
indexHTML = path.resolve(root, "index.html");
6951
}
@@ -77,36 +59,6 @@ function _getInjectSourceContent(updatePlatformFile)
7759
return {indexHTML: indexHTML, document: document};
7860
}
7961

80-
function _injectLiveReloadScript(injectSourceContent)
81-
{
82-
var document = injectSourceContent.document;
83-
var liveReloadElement;
84-
85-
if (_isLiveReloadEnabled())
86-
{
87-
liveReloadElement = _createLiveReloadElement(document);
88-
if (liveReloadElement)
89-
{
90-
_inject(injectSourceContent, liveReloadElement);
91-
}
92-
}
93-
}
94-
95-
function _isLiveReloadEnabled()
96-
{
97-
return process.env[constants.LIVERELOAD_ENABLED_ENV_KEY] !== "false";
98-
}
99-
100-
function _createLiveReloadElement(document)
101-
{
102-
var liveReloadPort = process.env[constants.LIVERELOAD_PORT_ENV_KEY];
103-
var platform = process.env[constants.PLATFORM_ENV_KEY];
104-
105-
var liveReloadSrc = "http://" + util.getLocalIp(platform) + ":" + liveReloadPort + "/livereload.js";
106-
107-
return _createScriptLibraryElement(document, liveReloadSrc);
108-
}
109-
11062
function _createScriptLibraryElement(document, src)
11163
{
11264
if (_scriptSrcExists(document, src))

generators/hybrid/templates/common/scripts/common/util.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,19 @@ module.exports =
4646

4747
getCordovaBuildConfig: function(grunt)
4848
{
49-
var bConfig = grunt.option("buildConfig");
49+
var bConfig = grunt.option("buildConfig") || "";
5050

51-
return bConfig ? "--buildConfig=" + bConfig : "";
51+
if(bConfig)
52+
{
53+
var bcPath = path.resolve(bConfig);
54+
55+
if(!fs.existsSync(bcPath))
56+
{
57+
throw new Error("Please ensure location of buildConfig is correct, current : " + bcPath);
58+
}
59+
bConfig = "--buildConfig=" + bcPath;
60+
}
61+
62+
return bConfig;
5263
}
5364
};

generators/hybrid/templates/common/scripts/grunt/fileChangeHandler.js

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ module.exports =
2828
{
2929
// from src directory to www + platform directories
3030
_copyFileOver(filePath);
31-
_indexHTMLPlatformInjection(filePath);
3231
}
3332
else if (target === "platformFiles")
3433
{
@@ -46,9 +45,26 @@ function _copyFileOver(filePath)
4645
var index = filePath.indexOf(constants.APP_SRC_DIRECTORY);
4746
var begPath = filePath.substring(0, index);
4847
var endPath = filePath.substring(index+3);
49-
48+
5049
_copyFileToWWW(filePath, begPath, endPath);
51-
_copyFileToPlatforms(filePath, begPath, endPath);
50+
51+
// if index.html need an additional step of performing inject
52+
var splitted = filePath.split(path.sep);
53+
var length = splitted.length;
54+
55+
if (length > 1 &&
56+
splitted[length-1] === "index.html" &&
57+
splitted[length-2] === constants.APP_SRC_DIRECTORY)
58+
{
59+
// inject the cordova.js script and use the new file as the source for copy
60+
injector.injectCordovaScript(false);
61+
var newIndexSrc = begPath + CORDOVA_WWW_DIRECTORY + endPath;
62+
_copyFileToPlatforms(newIndexSrc, begPath, endPath);
63+
_indexHTMLPlatformInjection();
64+
}
65+
else {
66+
_copyFileToPlatforms(filePath, begPath, endPath);
67+
}
5268
}
5369

5470
function _copyFileToWWW(filePath, begPath, endPath)
@@ -58,12 +74,11 @@ function _copyFileToWWW(filePath, begPath, endPath)
5874

5975
function _copyFileToPlatforms(filePath, begPath, endPath)
6076
{
61-
var platformJsonPath = path.resolve(constants.CORDOVA_DIRECTORY + "/platforms/platforms.json");
62-
var parsed = JSON.parse(fs.readFileSync(platformJsonPath), 'utf8');
77+
var platforms = _getInstalledPlatforms();
6378
var configXML = path.resolve(constants.CORDOVA_DIRECTORY + "/config.xml");
6479
var appName = util.getAppName(configXML);
6580

66-
Object.keys(parsed).forEach(function(platform)
81+
platforms.forEach(function(platform)
6782
{
6883
var paths = platformPaths[platform].getCopyPaths(begPath, endPath, appName);
6984

@@ -79,20 +94,13 @@ function _copyFileToPlatforms(filePath, begPath, endPath)
7994
});
8095
}
8196

82-
function _indexHTMLPlatformInjection(filePath)
97+
function _indexHTMLPlatformInjection()
8398
{
84-
// if index.html need an additional step of performing inject
85-
var splitted = filePath.split(path.sep);
86-
var length = splitted.length;
87-
88-
if (length > 1 &&
89-
splitted[length-1] === "index.html" &&
90-
splitted[length-2] === constants.APP_SRC_DIRECTORY)
99+
var platforms = _getInstalledPlatforms();
100+
platforms.forEach(function(platform)
91101
{
92-
injector.injectPlatformStyleClasses();
93-
injector.injectCordovaScript(true);
94-
injector.injectLiveReloadScript(true);
95-
}
102+
injector.updateIndexHtml(platform);
103+
});
96104
}
97105

98106
function _copyMergesFileChange(action, filePath, target)
@@ -118,3 +126,17 @@ function _copyMergesFileChange(action, filePath, target)
118126
});
119127
});
120128
}
129+
130+
function _getInstalledPlatforms()
131+
{
132+
var platforms = [];
133+
var platformJsonPath = path.resolve(constants.CORDOVA_DIRECTORY + "/platforms/platforms.json");
134+
var parsed = JSON.parse(fs.readFileSync(platformJsonPath), 'utf8');
135+
136+
Object.keys(parsed).forEach(function(platform)
137+
{
138+
platforms.push(platform);
139+
});
140+
141+
return platforms;
142+
}

generators/hybrid/templates/common/scripts/grunt/tasks/serve.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,6 @@ function _updateProcessEnv(grunt, platform, target, disableLiveReload)
177177

178178
function _runTasks(grunt, disableLiveReload, web, target)
179179
{
180-
if (!web)
181-
{
182-
injector.injectLiveReloadScript(false);
183-
}
184180
var tasks = _getTasks(grunt, disableLiveReload, web, target);
185181
grunt.task.run(tasks);
186182
}

generators/hybrid/templates/common/scripts/hooks/injector.js

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ var LOAD_URL_TIMEOUT_VALUE = "loadUrlTimeoutValue";
1717

1818
module.exports =
1919
{
20-
injectPlatformStyleClasses: function(platform, external)
20+
updateIndexHtml: function(platform, external)
2121
{
2222
var indexHtmlPath = _getIndexHtmlPath(platform, external);
2323
var content;
@@ -30,18 +30,19 @@ module.exports =
3030
try
3131
{
3232
content = fs.readFileSync(indexHtmlPath, "utf-8");
33-
content = _getNewHtmlContent(content, platform);
34-
if (content)
33+
content = _addPlatformStyleClasses(content, platform);
34+
if (_isLiveReloadEnabled())
3535
{
36-
fs.writeFileSync(indexHtmlPath, content);
36+
content = _addLiveReloadElement(content, platform);
3737
}
38+
fs.writeFileSync(indexHtmlPath, content);
3839
}
3940
catch (e)
4041
{
4142
}
4243
},
4344

44-
updateConfig: function(platform)
45+
updateConfigXml: function(platform)
4546
{
4647
if (!process || !process.env || !process.env["PLATFORM"])
4748
{
@@ -98,13 +99,13 @@ function _getIndexHtmlPath(platform, external)
9899
return indexHtmlPath;
99100
}
100101

101-
function _getNewHtmlContent(content, platform)
102+
function _addPlatformStyleClasses(content, platform)
102103
{
103104
var bodyTag;
104105
var classAttrValue;
105106
var newBodyTag;
106107
var newClassAttrValue;
107-
var newContent;
108+
var newContent = content;
108109

109110
var classStr = " oj-platform-cordova";
110111
if (platform === "android")
@@ -117,26 +118,35 @@ function _getNewHtmlContent(content, platform)
117118
}
118119

119120
bodyTag = _getXmlTag(content, "body");
120-
if (!bodyTag)
121-
{
122-
return null;
123-
}
124-
125-
classAttrValue = _getXmlAttrValue(bodyTag, "class");
126-
if (classAttrValue)
121+
if (bodyTag)
127122
{
128-
newClassAttrValue = classAttrValue + classStr;
129-
}
130-
else
131-
{
132-
newClassAttrValue = classStr;
133-
}
134-
newBodyTag = _setXmlAttrValue(bodyTag, "class", newClassAttrValue);
135-
newContent = content.replace(bodyTag, newBodyTag);
136-
123+
classAttrValue = _getXmlAttrValue(bodyTag, "class");
124+
if (classAttrValue)
125+
{
126+
newClassAttrValue = classAttrValue + classStr;
127+
}
128+
else
129+
{
130+
newClassAttrValue = classStr;
131+
}
132+
newBodyTag = _setXmlAttrValue(bodyTag, "class", newClassAttrValue);
133+
newContent = content.replace(bodyTag, newBodyTag);
134+
}
137135
return newContent;
138136
}
139137

138+
function _addLiveReloadElement(content, platform)
139+
{
140+
var newContent = content;
141+
var liveReloadPort = process.env["LIVERELOAD_PORT"];
142+
var liveReloadSrc = "http://" + _getLocalIpAddress(platform) + ":" + liveReloadPort + "/livereload.js";
143+
var scriptTag = '<script type="text/javascript" src="' + liveReloadSrc + '"></script>';
144+
145+
newContent = content.replace("</body>", " " + scriptTag + "\n </body>");
146+
return newContent;
147+
}
148+
149+
140150
function _getConfigXmlPath(platform)
141151
{
142152
var configXmlPath;
@@ -177,7 +187,7 @@ function _processConfigSrcAttribute(document)
177187

178188
// due to how emulator/devices work; localhost does not point to your
179189
// laptop and etc but its internal one, need to use ip address
180-
var newSrcValue = "http://" + _getLocalIpAddress() + ":" + serverPort + "/" + platform + "/www/index.html";
190+
var newSrcValue = "http://" + _getLocalIpAddress(platform) + ":" + serverPort + "/" + platform + "/www/index.html";
181191
var contentTag = _getXmlTag(document, "content");
182192
var newContentTag = _setXmlAttrValue(contentTag, "src", newSrcValue);
183193

@@ -216,11 +226,12 @@ function _addNavigationPermission(document)
216226
{
217227
// need to update the config src for livereloading
218228
var newDocument = document;
229+
var platform = process.env["PLATFORM"];
219230
var contentTag = _getXmlTag(document, "content");
220231

221232
if (contentTag)
222233
{
223-
var newAllowTag = contentTag + '\n <allow-navigation href="http://' + _getLocalIpAddress() + '/*" />';
234+
var newAllowTag = contentTag + '\n <allow-navigation href="http://' + _getLocalIpAddress(platform) + '/*" />';
224235
newDocument = document.replace(contentTag, newAllowTag);
225236
}
226237

@@ -233,9 +244,8 @@ function _isLiveReloadEnabled()
233244
return (liveReloadEnabled !== "false");
234245
}
235246

236-
function _getLocalIpAddress()
247+
function _getLocalIpAddress(platform)
237248
{
238-
var platform = process.env["PLATFORM"];
239249
return (platform === "android") ? ANDROID_LOCAL_IP_ADDRESS : LOCAL_IP_ADDRESS;
240250
}
241251

generators/hybrid/templates/common/scripts/hooks/jetAfterPrepare.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ module.exports = function(context)
1616
{
1717
platforms.forEach(function(value)
1818
{
19-
injector.injectPlatformStyleClasses(value);
20-
injector.updateConfig(value);
19+
injector.updateIndexHtml(value);
20+
injector.updateConfigXml(value);
2121
}
2222
);
2323
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "generator-oraclejet",
3-
"version": "0.0.7",
3+
"version": "0.0.8",
44
"license":"UPL-1.0",
55
"description": "initial",
66
"keywords":

0 commit comments

Comments
 (0)