Skip to content

Commit 6e498cf

Browse files
committed
Merge pull request #411 from NativeScript/plamen5kov/custom_extend_integration
Plamen5kov/custom extend integration
2 parents 595b78d + aaee178 commit 6e498cf

29 files changed

Lines changed: 998 additions & 1943 deletions

File tree

build/project-template-gradle/build-tools/android-static-binding-generator/.gitignore

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

build/project-template-gradle/build-tools/android-static-binding-generator/README.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

build/project-template-gradle/build-tools/android-static-binding-generator/ast-parser/.gitignore

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

build/project-template-gradle/build-tools/android-static-binding-generator/ast-parser/example_command.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
var fs = require("fs"),
2+
path = require("path");
3+
module.exports = function Helpers(config) {
4+
5+
function cleanOutFile(filePath) {
6+
fs.truncateSync(filePath, 0);
7+
if(config && config.logger) {
8+
config.logger.info("+cleared out file: " + filePath);
9+
}
10+
}
11+
12+
function createFile(filePath) {
13+
if(ensureDirectories(filePath)) {
14+
fs.writeFileSync(filePath, "");
15+
if(config && config.logger) {
16+
config.logger.info("+created ast output file: ");
17+
}
18+
}
19+
cleanOutFile(filePath)
20+
}
21+
22+
function ensureDirectories(filePath) {
23+
var parentDir = path.dirname(filePath);
24+
if(fs.existsSync(parentDir)) {
25+
return true;
26+
}
27+
28+
ensureDirectories(parentDir);
29+
fs.mkdirSync(parentDir);
30+
return true;
31+
}
32+
33+
return {
34+
cleanOutFile: cleanOutFile,
35+
createFile: createFile,
36+
ensureDirectories: ensureDirectories
37+
}
38+
};
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
var stringifyOnce = function(obj, replacer, indent){
2+
var printedObjects = [];
3+
var printedObjectKeys = [];
4+
var passingIndent = 4;
5+
if(indent) {
6+
passingIndent = indent;
7+
}
8+
9+
function printOnceReplacer(key, value){
10+
if ( printedObjects.length > 2000){ // browsers will not print more than 20K, I don't see the point to allow 2K.. algorithm will not be fast anyway if we have too many objects
11+
return 'object too long';
12+
}
13+
var printedObjIndex = false;
14+
printedObjects.forEach(function(obj, index){
15+
if(obj===value){
16+
printedObjIndex = index;
17+
}
18+
});
19+
20+
if ( key == ''){ //root element
21+
printedObjects.push(obj);
22+
printedObjectKeys.push("root");
23+
return value;
24+
}
25+
26+
else if(printedObjIndex+"" != "false" && typeof(value)=="object"){
27+
if ( printedObjectKeys[printedObjIndex] == "root"){
28+
return "(pointer to root)";
29+
}else{
30+
return "(see " + ((!!value && !!value.constructor) ? value.constructor.name.toLowerCase() : typeof(value)) + " with key " + printedObjectKeys[printedObjIndex] + ")";
31+
}
32+
}else{
33+
34+
var qualifiedKey = key || "(empty key)";
35+
printedObjects.push(value);
36+
printedObjectKeys.push(qualifiedKey);
37+
if(replacer){
38+
return replacer(key, value);
39+
}else{
40+
return value;
41+
}
42+
}
43+
}
44+
return JSON.stringify(obj, printOnceReplacer, passingIndent);
45+
};
46+
47+
module.exports = stringifyOnce;
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
var fs = require('fs'),
2+
path = require('path'),
3+
os = require('os'),
4+
fileHelpers = require("./file_helpers")();
5+
6+
module.exports = function(setting){
7+
8+
var logDirectory = path.dirname(setting.logPath);
9+
if (!fs.existsSync(logDirectory)){
10+
console.error("couldn't find logDirectory so it will be created in place:" + setting.logPath);
11+
fileHelpers.ensureDirectories(setting.logPath);
12+
}
13+
if (os.type().indexOf('Windows') === -1) {
14+
var appLogStat = fs.statSync(logDirectory);
15+
if (canWrite(process.uid === appLogStat.uid, process.gid === appLogStat.gid, appLogStat.mode)){
16+
console.error("ERROR WRITING TO LOG FILE DIRECTORY : " + logDirectory);
17+
process.exit(-1);
18+
}
19+
}
20+
21+
var appLog = createLog(setting.APP_NAME, logDirectory, setting);
22+
23+
if(setting.disable) {
24+
for(var prop in appLog) {
25+
appLog[prop] = function() {};
26+
}
27+
}
28+
return appLog;
29+
};
30+
31+
function canWrite(owner, inGroup, mode){
32+
return owner && (mode & 00200) || // User is owner and owner can write.
33+
inGroup && (mode & 00020) || // User is in group and group can write.
34+
(mode & 00002); // Anyone can write.
35+
}
36+
37+
function createLog(appName, logDirectory, setting){
38+
39+
var appLog = {};
40+
41+
function getRequestId() {
42+
return (process.domain && process.domain.id) || "";
43+
}
44+
45+
function getLogDate(){
46+
var today = new Date();
47+
48+
var fullYear = today.getFullYear();
49+
var month = today.getMonth();
50+
var day = today.getDate();
51+
var hours = today.getHours();
52+
var minutes = today.getMinutes();
53+
var seconds = today.getSeconds();
54+
55+
var logDate = fullYear + "-" + month + "-" + day + "/" + hours + ":" + minutes + ":" + seconds;
56+
return logDate;
57+
}
58+
59+
function setMessageWithFormat(message) {
60+
var res = getLogDate() + "\t" + message;
61+
return res;
62+
}
63+
64+
function appendToLogFile(line) {
65+
var logFile = logDirectory + path.sep + appName + ".log";
66+
var augmentedLine = getLogDate() + "\t" + line + os.EOL
67+
fs.appendFile(logFile, augmentedLine, function (err) {
68+
if(err) {
69+
throw "couldn't write to " + logFile;
70+
}
71+
});
72+
}
73+
74+
appLog.log = function (input) {
75+
console.log(setMessageWithFormat(input));
76+
appendToLogFile(input);
77+
}
78+
79+
appLog.info = appLog.log;
80+
81+
appLog.warn = function (input) {
82+
console.warn(setMessageWithFormat(input));
83+
appendToLogFile(input);
84+
}
85+
86+
appLog.error = function (input) {
87+
console.error(setMessageWithFormat(input));
88+
appendToLogFile(input);
89+
}
90+
91+
return appLog;
92+
}
93+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*
2+
!.gitignore

0 commit comments

Comments
 (0)