✂️ Path shortened ! (#1141)

* Fix the "/" bug.

* Update the "hub-test" to make them work everywhere!

* 🤛Fix the "/" bug !

* Fix indentation

* ✂️ My new quest shall be to shorten the file paths !

* 👽 Remove Chokidar from dependencies

* 👽 Remove chokidar from dependencies!
This commit is contained in:
Hector 2021-10-30 08:20:16 +02:00 committed by GitHub
parent 395c2b8f98
commit 3b8eb16960
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 140 additions and 3103 deletions

View File

@ -15,13 +15,14 @@ try { chokidar = require('chokidar') } catch (error) {
* @param {Object} options - https://gun.eco/docs/hub.js#options
*/
function watch(what, options) {
options = options ?? { msg: true, hubignore: false }
options = options ?? { msg: true, hubignore: false, alias: require('os').userInfo().username }
options.msg = options.msg ?? true;
options.hubignore = options.hubignore ?? false;
let modifiedPath = (options.file ?? "");
options.alias = options.alias ?? require('os').userInfo().username
let modifiedPath = options.alias;
let watcher;
try {
@ -57,9 +58,9 @@ function watch(what, options) {
if (options.msg) log(`File ${path} has been added`);
if(path[path.search(/^./gm)] === "/" || ".") {
gun.get('hub').get(modifiedPath + '/' + path).put(fs.readFileSync(path, 'utf-8'))
gun.get('hub').get(modifiedPath + path.split(require('os').userInfo().username)[1]).put(fs.readFileSync(path, 'utf-8'))
} else {
gun.get('hub').get(modifiedPath + '/' + path).put(fs.readFileSync(path, 'utf-8'))
gun.get('hub').get(modifiedPath + '/' + path.split(require('os').userInfo().username)[1]).put(fs.readFileSync(path, 'utf-8'))
}
} else {
@ -78,7 +79,11 @@ function watch(what, options) {
} else if (!path.includes('.hubignore') && !hubignore?.includes(path.substring(path.lastIndexOf('/') + 1))) {
if (options.msg) log(`File ${path} has been changed`);
gun.get('hub').get(modifiedPath + '/' + path).put(fs.readFileSync(path, 'utf-8'))
if(path[path.search(/^./gm)] === "/" || ".") {
gun.get('hub').get(modifiedPath + path.split(require('os').userInfo().username)[1]).put(fs.readFileSync(path, 'utf-8'))
} else {
gun.get('hub').get(modifiedPath + '/' + path.split(require('os').userInfo().username)[1]).put(fs.readFileSync(path, 'utf-8'))
}
} else {
@ -96,7 +101,12 @@ function watch(what, options) {
} else if (!path.includes('.hubignore') && !hubignore?.includes(path.substring(path.lastIndexOf('/') + 1))) {
if(options.msg) log(`File ${path} has been removed`);
gun.get('hub').get(modifiedPath + '/' + path).put(null)
if(path[path.search(/^./gm)] === "/" || ".") {
gun.get('hub').get(modifiedPath + path.split(require('os').userInfo().username)[1]).put(null)
} else {
gun.get('hub').get(modifiedPath + '/' + path.split(require('os').userInfo().username)[1]).put(null)
}
} else {

3205
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,9 +1,9 @@
// const Gun = require('../..');
// const gun = Gun();
const Gun = require('../..');
const gun = Gun();
// gun.get('hub').on(data => {
// console.log(data[`${__dirname}/index.html`])
// })
gun.get('hub').on(data => {
console.log(data)
})
const hub = require('../../lib/hub');
hub.watch(__dirname, {msg: true, hubignore: true})
hub.watch(__dirname, {msg: true, hubignore: true, alias:require('os').userInfo().username})

View File

@ -7,6 +7,6 @@
<title>Document</title>
</head>
<body>
<div>Hi!</div>
</body>
</html>