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

Commit ba46114

Browse files
author
dvtdev
committed
Initial commit
0 parents  commit ba46114

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+10905
-0
lines changed

LICENSE.md

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
Copyright (c) 2014, 2016 Oracle and/or its affiliates
3+
The Universal Permissive License (UPL), Version 1.0
4+
5+
Subject to the condition set forth below, permission is hereby granted to any person obtaining a copy of this software, associated documentation and/or data
6+
(collectively the "Software"), free of charge and under any and all copyright rights in the Software, and any and all patent rights owned or freely licensable by each
7+
licensor hereunder covering either (i) the unmodified Software as contributed to or provided by such licensor, or (ii) the Larger Works (as defined below), to deal in
8+
both
9+
10+
(a) the Software, and
11+
12+
(b) any piece of software and/or hardware listed in the lrgrwrks.txt file if one is included with the Software (each a “Larger Work” to which the Software is
13+
contributed by such licensors),
14+
15+
without restriction, including without limitation the rights to copy, create derivative works of, display, perform, and distribute the Software and make, use, sell, offer
16+
for sale, import, export, have made, and have sold the Software and the Larger Work(s), and to sublicense the foregoing rights on either these or other terms.
17+
18+
This license is subject to the following condition:
19+
20+
The above copyright notice and either this complete permission notice or at a minimum a reference to the UPL must be included in all copies or substantial portions
21+
of the Software.
22+
23+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
25+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

common/grunt/ports.js

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* Copyright (c) 2014, 2016, Oracle and/or its affiliates.
3+
* The Universal Permissive License (UPL), Version 1.0
4+
*/
5+
'use strict';
6+
/*
7+
*Port-related grunt utilities
8+
*/
9+
module.exports = {
10+
configurePort: function(grunt, portName)
11+
{
12+
var portOpt = grunt.option(portName + "Port");
13+
if(portOpt)
14+
{
15+
var port = /[^\d]/.test(portOpt) ? NaN : parseInt(portOpt);
16+
if (!port || port < _MIN_PORT || port > _MAX_PORT)
17+
{
18+
_portError(grunt, portName, portOpt);
19+
}
20+
grunt.config.set('oraclejet.ports.' + portName, port);
21+
}
22+
}
23+
};
24+
25+
function _portError(grunt, portName, portOpt)
26+
{
27+
grunt.fail.fatal(
28+
"Invalid value '"+ portOpt + "' for " + portName +
29+
". Please specify a number between " + _MIN_PORT + " and " + _MAX_PORT);
30+
}
31+
32+
var _MIN_PORT = 1024;
33+
var _MAX_PORT = 65535;

common/index.js

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/**
2+
* Copyright (c) 2014, 2016, Oracle and/or its affiliates.
3+
* The Universal Permissive License (UPL), Version 1.0
4+
*/
5+
'use strict';
6+
//common helpers for generators
7+
var fs = require('fs-extra');
8+
var path = require('path');
9+
module.exports = {
10+
11+
gruntSpawnCommandPromise: function _gruntSpawnCommandPromise(context, cmd, args, logMessage)
12+
{
13+
var generator = context.generator;
14+
args = args || [];
15+
16+
generator.log(logMessage);
17+
18+
return new Promise(function (resolve, reject)
19+
{
20+
21+
generator.spawnCommand(cmd, args)
22+
.on("exit", function(err)
23+
{
24+
if(err)
25+
{
26+
return reject(err);
27+
}
28+
29+
resolve(context);
30+
})
31+
.on("error", function(err)
32+
{
33+
reject(err);
34+
});
35+
36+
});
37+
},
38+
39+
writeCommonGruntScripts: function _writeCommonGruntScripts(generator)
40+
{
41+
var gruntSource = generator.templatePath('../../../common/grunt');
42+
var gruntDest = generator.destinationPath(generator.appDir + '/scripts/grunt/common/');
43+
44+
return new Promise(function (resolve,reject)
45+
{
46+
fs.copy(gruntSource, gruntDest, function(err)
47+
{
48+
if(err)
49+
{
50+
reject(err);
51+
}
52+
53+
resolve(generator);
54+
});
55+
});
56+
},
57+
58+
validateAppDirNotExistsOrIsEmpty: function _validateAppDirNotExistsOrIsEmpty(appDir)
59+
{
60+
return new Promise(function (resolve,reject)
61+
{
62+
appDir = path.resolve(appDir);
63+
fs.stat(appDir, function (err,stats)
64+
{
65+
if(err)
66+
{
67+
//Proceed to scaffold if appDir directory doesn't exist
68+
resolve();
69+
}
70+
else
71+
{
72+
fs.readdir(appDir, function(err,items)
73+
{
74+
var isEmpty = (!items || !items.length);
75+
if(isEmpty)
76+
{
77+
//Proceed to scaffold if appDir directory is empty
78+
resolve();
79+
}
80+
else
81+
{
82+
reject("Path already exists and is not empty: " + appDir );
83+
}
84+
});
85+
}
86+
});
87+
});
88+
}
89+
};

common/restore.js

+188
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
/**
2+
* Copyright (c) 2014, 2016, Oracle and/or its affiliates.
3+
* The Universal Permissive License (UPL), Version 1.0
4+
*/
5+
'use strict';
6+
7+
var fs = require('fs-extra');
8+
var path = require('path');
9+
10+
var constants = require("../util/constants");
11+
var fetchZip = require ("../util/fetchZip");
12+
var util = require("../util");
13+
var common = require("./index");
14+
15+
var ORACLE_JET_CONFIG_FILE = "oraclejetconfig.json";
16+
var TEMP_ORACLE_ZIP_URL = "http://den00pwq.us.oracle.com:8080/hudson/job/OJET_Code_V2.0.X/lastSuccessfulBuild/artifact/code/oraclejet.zip";
17+
18+
module.exports = {
19+
20+
writeOracleJetConfigFile: function _writeOracleJetConfigFile(context)
21+
{
22+
var generator = context.generator;
23+
var destinationRoot = generator.destinationRoot();
24+
25+
generator.log("Writing ", ORACLE_JET_CONFIG_FILE);
26+
27+
var versionDirectory = _getOracleJetVersion(generator);
28+
29+
//need to place the oracletjetconfig.json at origDestRoot
30+
31+
fs.stat(path.resolve(generator.destinationRoot(),ORACLE_JET_CONFIG_FILE), function (err,stats)
32+
{
33+
if(err)
34+
{
35+
generator.log("No config file...writing the default config");
36+
fs.writeJSONSync(path.resolve(destinationRoot, ORACLE_JET_CONFIG_FILE), {"version": versionDirectory, "oraclejet_zip_url":TEMP_ORACLE_ZIP_URL});
37+
}
38+
else
39+
{
40+
generator.log("Config file exists...checking version..");
41+
}
42+
43+
});
44+
45+
context.versionDirectory = versionDirectory;
46+
return context;
47+
},
48+
49+
invokeBowerCopyScript: function _invokeBowerCopyScript(context)
50+
{
51+
return common.gruntSpawnCommandPromise(context, "grunt", ["bowercopy"], "Invoking grunt bowercopy.");
52+
},
53+
54+
npmBowerInstall: function _npmBowerInstall(context)
55+
{
56+
var generator = context.generator;
57+
var self = this;
58+
59+
return new Promise(function (resolve, reject)
60+
{
61+
62+
Promise.all([
63+
_tempOracleJetFetchZip(context),
64+
common.gruntSpawnCommandPromise(context, "npm", ["install"], "Invoking npm install"),
65+
common.gruntSpawnCommandPromise(context, "bower", ["install"], "Invoking bower install")
66+
])
67+
.then(function(values)
68+
{
69+
//rejection will be handled by each promise which will
70+
//halt the generator
71+
resolve(context);
72+
})
73+
.catch(function(err)
74+
{
75+
reject(err);
76+
});
77+
78+
});
79+
},
80+
81+
removeTempZipLib: function _removeDuplicateLibInZip (context)
82+
{
83+
var generator = context.generator;
84+
//remove buildnum and revnum
85+
fs.remove(path.resolve('bower_components/oraclejet/revnum'), function(err){
86+
if (err) return generator.log(err)
87+
});
88+
fs.remove(path.resolve('bower_components/oraclejet/buildnum'), function(err){
89+
if (err) return generator.log(err)
90+
});
91+
//Cleaning dupliate lib file from oraclejetzip
92+
var lib_dir = 'bower_components/oraclejet/js/libs';
93+
fs.readdir(lib_dir, function (error, files)
94+
{ if (error) generator.log(error);
95+
files.filter(function (fileName)
96+
{
97+
return (/hammer|require|js-signals|es6-promise/).test(fileName);
98+
}).forEach(function(dir)
99+
{
100+
fs.remove(path.resolve(lib_dir, dir), function (err) {
101+
if (err) return generator.log(err)
102+
})
103+
104+
});
105+
});
106+
return context;
107+
}
108+
109+
};
110+
111+
function _tempOracleJetFetchZip(context)
112+
{
113+
var generator = context.generator;
114+
115+
generator.log("Fetching oraclejet zip");
116+
117+
return new Promise(function(resolve, reject)
118+
{
119+
var zip_url = TEMP_ORACLE_ZIP_URL;
120+
var config_file_exist = false;
121+
122+
fs.stat(path.resolve(generator.destinationRoot(),ORACLE_JET_CONFIG_FILE), function (err,stats)
123+
{
124+
if(err)
125+
{
126+
generator.log("No config file...using default oraclejet url");
127+
}
128+
else
129+
{
130+
generator.log("Config file exists...reading from oraclejetconfig.json");
131+
config_file_exist = true;
132+
zip_url = fs.readJSONSync(path.resolve(generator.destinationRoot(), ORACLE_JET_CONFIG_FILE)).oraclejet_zip_url;
133+
}
134+
135+
fs.remove('bower_components/oraclejet', function (err)
136+
{
137+
if(err)
138+
{
139+
return reject(err);
140+
}
141+
142+
fetchZip( zip_url )
143+
.then(function (values)
144+
{
145+
var temp_path = path.resolve(generator.destinationRoot(), "bower_components/oraclejet");
146+
fs.ensureDirSync(temp_path);
147+
values.extractAllTo(temp_path);
148+
149+
if ( config_file_exist ) _checkOracleJetVersion(generator);
150+
return resolve();
151+
})
152+
.catch(function(err)
153+
{
154+
return reject(err);
155+
});
156+
157+
});
158+
159+
});
160+
161+
});
162+
163+
}
164+
165+
/*
166+
* Gets the jet version by inspecting the directory and returning the directory name
167+
* Note that the directory must exist; otherwise an error will be triggered.
168+
*/
169+
function _getOracleJetVersion(generator)
170+
{
171+
var oracleJetCssLibs = generator.destinationPath("bower_components/oraclejet/css/libs/oj/");
172+
return util.getDirectories(oracleJetCssLibs).sort()[0];
173+
}
174+
/*
175+
* Compare the jet version in oraclejetconfig.json and the actual version, update
176+
* oraclejetconfig.json accordingly
177+
*/
178+
function _checkOracleJetVersion(generator)
179+
{
180+
var versionDirectory = _getOracleJetVersion(generator);
181+
var configJSON = fs.readJSONSync(path.resolve(generator.destinationRoot(),ORACLE_JET_CONFIG_FILE));
182+
183+
if (configJSON.version !== versionDirectory)
184+
{
185+
configJSON.version = versionDirectory;
186+
fs.writeJSONSync(path.resolve(generator.destinationRoot(), ORACLE_JET_CONFIG_FILE), configJSON);
187+
}
188+
}

common/template/blank.js

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* Copyright (c) 2014, 2016, Oracle and/or its affiliates.
3+
* The Universal Permissive License (UPL), Version 1.0
4+
*/
5+
'use strict';
6+
7+
var fs = require('fs-extra');
8+
module.exports = {
9+
BLANK_TEMPLATE: "blank",
10+
11+
handle: function _handle(generator, destination)
12+
{
13+
var source = generator.templatePath(this.BLANK_TEMPLATE);
14+
15+
return new Promise(function(resolve, reject)
16+
{
17+
18+
try
19+
{
20+
fs.copySync(source, destination, {clobber:true});
21+
resolve(generator);
22+
}
23+
catch(err)
24+
{
25+
return reject(err);
26+
}
27+
28+
});
29+
}
30+
31+
};

0 commit comments

Comments
 (0)