Skip to content
This repository was archived by the owner on Nov 25, 2023. It is now read-only.

Commit 4c881ea

Browse files
committed
base project scaffolding + gitignore parsing and watching
0 parents  commit 4c881ea

File tree

7 files changed

+174
-0
lines changed

7 files changed

+174
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.idea
2+
node_modules

LICENSE.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 jackyzha0
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

fs/parse.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// parses gitignores
2+
import fs from 'fs'
3+
import path from 'path'
4+
import parse from 'parse-gitignore'
5+
6+
export const readGitIgnore = (providedPath) => {
7+
const resolved = path.resolve(providedPath)
8+
const filePaths = parse(fs.readFileSync(`${resolved}/.gitignore`))
9+
filePaths.push('.git')
10+
return filePaths
11+
}

fs/watcher.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// watches files and emits events
2+
import chokidar from 'chokidar'
3+
import { readGitIgnore } from "./parse.js"
4+
5+
const registerWatcher = (dir) => {
6+
const watcher = chokidar.watch(dir, {
7+
ignored: readGitIgnore(dir), // ignore dotfiles
8+
persistent: true
9+
})
10+
11+
watcher
12+
.on('add', path => console.log(`File ${path} has been added`))
13+
.on('change', path => console.log(`File ${path} has been changed`))
14+
.on('unlink', path => console.log(`File ${path} has been removed`));
15+
}
16+
17+
registerWatcher('.')

index.js

Whitespace-only changes.

package.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "portal",
3+
"version": "1.0.0",
4+
"description": "p2p folder syncing",
5+
"main": "index.js",
6+
"author": "jackyzha0 <[email protected]>",
7+
"license": "MIT",
8+
"type": "module",
9+
"dependencies": {
10+
"chokidar": "^3.5.1",
11+
"parse-gitignore": "^1.0.1"
12+
}
13+
}

yarn.lock

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2+
# yarn lockfile v1
3+
4+
5+
anymatch@~3.1.1:
6+
version "3.1.2"
7+
resolved "https://registry.yarnpkg.com/anymatch/-/anymatch-3.1.2.tgz#c0557c096af32f106198f4f4e2a383537e378716"
8+
integrity sha512-P43ePfOAIupkguHUycrc4qJ9kz8ZiuOUijaETwX7THt0Y/GNK7v0aa8rY816xWjZ7rJdA5XdMcpVFTKMq+RvWg==
9+
dependencies:
10+
normalize-path "^3.0.0"
11+
picomatch "^2.0.4"
12+
13+
binary-extensions@^2.0.0:
14+
version "2.2.0"
15+
resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-2.2.0.tgz#75f502eeaf9ffde42fc98829645be4ea76bd9e2d"
16+
integrity sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==
17+
18+
braces@~3.0.2:
19+
version "3.0.2"
20+
resolved "https://registry.yarnpkg.com/braces/-/braces-3.0.2.tgz#3454e1a462ee8d599e236df336cd9ea4f8afe107"
21+
integrity sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==
22+
dependencies:
23+
fill-range "^7.0.1"
24+
25+
chokidar@^3.5.1:
26+
version "3.5.1"
27+
resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-3.5.1.tgz#ee9ce7bbebd2b79f49f304799d5468e31e14e68a"
28+
integrity sha512-9+s+Od+W0VJJzawDma/gvBNQqkTiqYTWLuZoyAsivsI4AaWTCzHG06/TMjsf1cYe9Cb97UCEhjz7HvnPk2p/tw==
29+
dependencies:
30+
anymatch "~3.1.1"
31+
braces "~3.0.2"
32+
glob-parent "~5.1.0"
33+
is-binary-path "~2.1.0"
34+
is-glob "~4.0.1"
35+
normalize-path "~3.0.0"
36+
readdirp "~3.5.0"
37+
optionalDependencies:
38+
fsevents "~2.3.1"
39+
40+
fill-range@^7.0.1:
41+
version "7.0.1"
42+
resolved "https://registry.yarnpkg.com/fill-range/-/fill-range-7.0.1.tgz#1919a6a7c75fe38b2c7c77e5198535da9acdda40"
43+
integrity sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==
44+
dependencies:
45+
to-regex-range "^5.0.1"
46+
47+
fsevents@~2.3.1:
48+
version "2.3.2"
49+
resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.2.tgz#8a526f78b8fdf4623b709e0b975c52c24c02fd1a"
50+
integrity sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==
51+
52+
glob-parent@~5.1.0:
53+
version "5.1.2"
54+
resolved "https://registry.yarnpkg.com/glob-parent/-/glob-parent-5.1.2.tgz#869832c58034fe68a4093c17dc15e8340d8401c4"
55+
integrity sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==
56+
dependencies:
57+
is-glob "^4.0.1"
58+
59+
is-binary-path@~2.1.0:
60+
version "2.1.0"
61+
resolved "https://registry.yarnpkg.com/is-binary-path/-/is-binary-path-2.1.0.tgz#ea1f7f3b80f064236e83470f86c09c254fb45b09"
62+
integrity sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==
63+
dependencies:
64+
binary-extensions "^2.0.0"
65+
66+
is-extglob@^2.1.1:
67+
version "2.1.1"
68+
resolved "https://registry.yarnpkg.com/is-extglob/-/is-extglob-2.1.1.tgz#a88c02535791f02ed37c76a1b9ea9773c833f8c2"
69+
integrity sha1-qIwCU1eR8C7TfHahueqXc8gz+MI=
70+
71+
is-glob@^4.0.1, is-glob@~4.0.1:
72+
version "4.0.1"
73+
resolved "https://registry.yarnpkg.com/is-glob/-/is-glob-4.0.1.tgz#7567dbe9f2f5e2467bc77ab83c4a29482407a5dc"
74+
integrity sha512-5G0tKtBTFImOqDnLB2hG6Bp2qcKEFduo4tZu9MT/H6NQv/ghhy30o55ufafxJ/LdH79LLs2Kfrn85TLKyA7BUg==
75+
dependencies:
76+
is-extglob "^2.1.1"
77+
78+
is-number@^7.0.0:
79+
version "7.0.0"
80+
resolved "https://registry.yarnpkg.com/is-number/-/is-number-7.0.0.tgz#7535345b896734d5f80c4d06c50955527a14f12b"
81+
integrity sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==
82+
83+
normalize-path@^3.0.0, normalize-path@~3.0.0:
84+
version "3.0.0"
85+
resolved "https://registry.yarnpkg.com/normalize-path/-/normalize-path-3.0.0.tgz#0dcd69ff23a1c9b11fd0978316644a0388216a65"
86+
integrity sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==
87+
88+
parse-gitignore@^1.0.1:
89+
version "1.0.1"
90+
resolved "https://registry.yarnpkg.com/parse-gitignore/-/parse-gitignore-1.0.1.tgz#8b9dc57f17b810d495c5dfa62eb07caffe7758c7"
91+
integrity sha512-UGyowyjtx26n65kdAMWhm6/3uy5uSrpcuH7tt+QEVudiBoVS+eqHxD5kbi9oWVRwj7sCzXqwuM+rUGw7earl6A==
92+
93+
picomatch@^2.0.4, picomatch@^2.2.1:
94+
version "2.3.0"
95+
resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.3.0.tgz#f1f061de8f6a4bf022892e2d128234fb98302972"
96+
integrity sha512-lY1Q/PiJGC2zOv/z391WOTD+Z02bCgsFfvxoXXf6h7kv9o+WmsmzYqrAwY63sNgOxE4xEdq0WyUnXfKeBrSvYw==
97+
98+
readdirp@~3.5.0:
99+
version "3.5.0"
100+
resolved "https://registry.yarnpkg.com/readdirp/-/readdirp-3.5.0.tgz#9ba74c019b15d365278d2e91bb8c48d7b4d42c9e"
101+
integrity sha512-cMhu7c/8rdhkHXWsY+osBhfSy0JikwpHK/5+imo+LpeasTF8ouErHrlYkwT0++njiyuDvc7OFY5T3ukvZ8qmFQ==
102+
dependencies:
103+
picomatch "^2.2.1"
104+
105+
to-regex-range@^5.0.1:
106+
version "5.0.1"
107+
resolved "https://registry.yarnpkg.com/to-regex-range/-/to-regex-range-5.0.1.tgz#1648c44aae7c8d988a326018ed72f5b4dd0392e4"
108+
integrity sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==
109+
dependencies:
110+
is-number "^7.0.0"

0 commit comments

Comments
 (0)