1
0
mirror of https://github.com/S2-/gitlit synced 2025-08-03 04:40:05 +02:00
This commit is contained in:
s2
2018-05-18 12:57:15 +02:00
parent f96e61fd63
commit 80699aa7c5
8 changed files with 202 additions and 25 deletions

78
.jscsrc Normal file
View File

@@ -0,0 +1,78 @@
{
"requireCurlyBraces": [
"if",
"else",
"for",
"while",
"do",
"try",
"catch"
],
"requireSpaceAfterKeywords": [
"if",
"else",
"for",
"while",
"do",
"switch",
"case",
"return",
"try"
],
"requireSpaceBeforeKeywords": [
"else",
"catch"
],
"disallowSpaceAfterKeywords": [
"catch"
],
"requireSpaceBeforeBlockStatements": true,
"requireParenthesesAroundIIFE": true,
"requireSpacesInConditionalExpression": true,
"disallowSpacesInNamedFunctionExpression": {
"beforeOpeningRoundBrace": true
},
"disallowSpacesInFunctionDeclaration": {
"beforeOpeningRoundBrace": true
},
"disallowSpacesInFunctionExpression": {
"beforeOpeningRoundBrace": true
},
"requireSpaceBetweenArguments": true,
"disallowMultipleVarDecl": true,
"requireVarDeclFirst": false,
"requireBlocksOnNewline": false,
"disallowEmptyBlocks": true,
"disallowSpacesInsideArrayBrackets": true,
"disallowSpacesInsideObjectBrackets": true,
"disallowSpacesInsideParentheses": true,
"disallowDanglingUnderscores": false,
"requireCommaBeforeLineBreak": true,
"disallowSpaceAfterPrefixUnaryOperators": true,
"disallowSpaceBeforePostfixUnaryOperators": true,
"disallowSpaceBeforeBinaryOperators": [
","
],
"requireSpacesInForStatement": true,
"requireSpacesInAnonymousFunctionExpression": {
"beforeOpeningCurlyBrace": true
},
"requireSpaceBeforeBinaryOperators": true,
"requireSpaceAfterBinaryOperators": true,
"disallowKeywords": [
"with"
],
"validateIndentation": "\t",
"disallowMixedSpacesAndTabs": true,
"disallowTrailingWhitespace": true,
"disallowTrailingComma": true,
"disallowKeywordsOnNewLine": [
"else"
],
"requireLineFeedAtFileEnd": true,
"requireCapitalizedConstructors": true,
"requireDotNotation": false,
"disallowNewlineBeforeBlockStatements": true,
"disallowMultipleLineStrings": true,
"requireSpaceBeforeObjectValues": true
}

View File

@@ -14,9 +14,8 @@
<link href="node_modules/bootstrap/dist/css/bootstrap.css" rel="stylesheet"> <link href="node_modules/bootstrap/dist/css/bootstrap.css" rel="stylesheet">
</head> </head>
<body> <body>
<div class="alert alert-primary" role="alert">
<script> Getting file list...
$('body').html(gitlit.templates.main()); </div>
</script>
</body> </body>
</html> </html>

View File

@@ -1,5 +1,6 @@
(function($) { (function($) {
require('electron').ipcRenderer.on('ping', (event, message) => { let ipcRenderer = require('electron').ipcRenderer;
console.log(message) // Prints 'whoooooooh!' ipcRenderer.on('fileList', (event, files) => {
}) $('body').html(gitlit.templates.main({files: files}));
});
})(jQuery); })(jQuery);

View File

@@ -1,17 +1,26 @@
window.gitlit = window.gitlit || {}; window.gitlit = window.gitlit || {};
gitlit.templates = { gitlit.templates = {
main: ejs.compile(` main: ejs.compile(`
<table class="table table-striped"> <table class="table">
<tr> <tr>
<th>file</th> <th>file</th>
<th>status</th> <th>status</th>
<th>action</th> <th>action</th>
</tr> </tr>
<tr>
<td>ciccio.txt</td> <% files.forEach((file) => { %>
<td>locked</td> <tr class="<%= file.lockedBy ? 'alert alert-danger' : '' %>">
<td></td> <td><%= file.file %></td>
<td><%= file.lockedBy ? file.lockedBy + ' (id: ' + file.id + ')' : 'not locked' %></td>
<td>
<a class="btn btn-<%= file.lockedBy ? 'danger' : 'primary' %>"
href="javascript:///">
<%= file.lockedBy ? 'Unlock' : 'Lock' %>
</a>
</td>
</tr> </tr>
<% }); %>
</table> </table>
`) `)
}; };

View File

@@ -2,8 +2,78 @@ const {app, BrowserWindow} = require('electron');
const path = require('path'); const path = require('path');
const url = require('url'); const url = require('url');
const electronLocalshortcut = require('electron-localshortcut'); const electronLocalshortcut = require('electron-localshortcut');
const exec = require('child_process').exec;
const args = require('minimist')(process.argv.slice(2), {
default: {
_: process.cwd()
}
});
function getLfsFileList(dir, cb) {
exec('git lfs ls-files', {
cwd: dir
},
(error, stdout, stderr) => {
if (error) {
cb(error);
return;
}
if (stdout) {
let files = stdout.split('\n');
let parsedFiles = [];
files.forEach((file) => {
file = file.split(' * ');
if (file[1]) {
parsedFiles.push(file[1].trim());
}
});
cb(null, parsedFiles);
}
});
};
function getLfsLocks(dir, cb) {
exec('git lfs locks', {
cwd: dir
},
(error, stdout, stderr) => {
if (error) {
cb(error);
return;
}
if (stdout) {
let files = stdout.split('\n');
let parsedFiles = [];
files.forEach((file) => {
if (file) {
let fileName = file.split('\t')[0].trim();
let lockedBy = file.split('\t')[1].trim();
let id = file.split('ID:')[1].trim();
parsedFiles.push({
file: fileName,
lockedBy: lockedBy,
id: id
});
}
});
cb(null, parsedFiles);
}
});
};
function getArrayObjectByKey(array, key, value, defaultKeyValue) {
let o = array.filter((e) => {
return e[key] === value;
});
if (o.length > 0) {
return defaultKeyValue ? o[0][defaultKeyValue] : o[0];
}
return undefined;
}
function createWindow() { function createWindow() {
// Create the browser window. // Create the browser window.
win = new BrowserWindow({width: 800, height: 600}); win = new BrowserWindow({width: 800, height: 600});
@@ -21,7 +91,25 @@ function createWindow () {
}); });
win.webContents.on('did-finish-load', () => { win.webContents.on('did-finish-load', () => {
win.webContents.send('ping', 'whoooooooh!') console.log('getting file list and lock status...');
getLfsFileList(args._.join(' '), (err, files) => {
getLfsLocks(args._.join(' '), (err, lockedFiles) => {
let allFiles = [];
files.forEach((file) => {
const t = {
file: file,
lockedBy: getArrayObjectByKey(lockedFiles, 'file', file, 'lockedBy'),
id: getArrayObjectByKey(lockedFiles, 'file', file, 'id')
};
allFiles.push(t);
});
win.webContents.send('fileList', allFiles);
});
});
}); });
} }

View File

@@ -1,21 +1,23 @@
{ {
"_from": "minimist@^1.2.0", "_from": "minimist",
"_id": "minimist@1.2.0", "_id": "minimist@1.2.0",
"_inBundle": false, "_inBundle": false,
"_integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=", "_integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=",
"_location": "/minimist", "_location": "/minimist",
"_phantomChildren": {}, "_phantomChildren": {},
"_requested": { "_requested": {
"type": "range", "type": "tag",
"registry": true, "registry": true,
"raw": "minimist@^1.2.0", "raw": "minimist",
"name": "minimist", "name": "minimist",
"escapedName": "minimist", "escapedName": "minimist",
"rawSpec": "^1.2.0", "rawSpec": "",
"saveSpec": null, "saveSpec": null,
"fetchSpec": "^1.2.0" "fetchSpec": "latest"
}, },
"_requiredBy": [ "_requiredBy": [
"#USER",
"/",
"/electron-download", "/electron-download",
"/meow", "/meow",
"/nugget", "/nugget",
@@ -23,8 +25,8 @@
], ],
"_resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", "_resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz",
"_shasum": "a35008b20f41383eec1fb914f4cd5df79a264284", "_shasum": "a35008b20f41383eec1fb914f4cd5df79a264284",
"_spec": "minimist@^1.2.0", "_spec": "minimist",
"_where": "E:\\projects\\p\\gitlit\\app\\node_modules\\electron-download", "_where": "E:\\projects\\p\\gitlit\\app",
"author": { "author": {
"name": "James Halliday", "name": "James Halliday",
"email": "mail@substack.net", "email": "mail@substack.net",

3
app/package-lock.json generated
View File

@@ -761,8 +761,7 @@
"minimist": { "minimist": {
"version": "1.2.0", "version": "1.2.0",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz",
"integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=", "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ="
"dev": true
}, },
"mkdirp": { "mkdirp": {
"version": "0.5.0", "version": "0.5.0",

View File

@@ -7,7 +7,8 @@
"bootstrap": "^4.1.1", "bootstrap": "^4.1.1",
"ejs": "^2.6.1", "ejs": "^2.6.1",
"electron-localshortcut": "^3.1.0", "electron-localshortcut": "^3.1.0",
"jquery": "^3.3.1" "jquery": "^3.3.1",
"minimist": "^1.2.0"
}, },
"devDependencies": { "devDependencies": {
"electron": "^2.0.1" "electron": "^2.0.1"