dorky 2.0.0 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +61 -14
- package/bin/index.js +17 -18
- package/google-drive-credentials.json +16 -0
- package/package.json +2 -2
- package/To-Do +0 -24
package/README.md
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# dorky
|
|
2
|
+
|
|
2
3
|
```
|
|
3
|
-
__ __
|
|
4
|
+
__ __
|
|
4
5
|
.--| .-----.----| |--.--.--.
|
|
5
6
|
| _ | _ | _| <| | |
|
|
6
7
|
|_____|_____|__| |__|__|___ |
|
|
@@ -17,9 +18,11 @@ Let us assume that we need to create a project.
|
|
|
17
18
|
|
|
18
19
|
The project obviously contains some code and some secret variables like database information, API keys, etc. This data cannot be shared on public VCS (GitHub), but at times is required to be accessible remotely to be shared among reliable sources.
|
|
19
20
|
|
|
20
|
-
Anyhow, we shall store it on a private storage, using **dorky**, that stores it on a S3.
|
|
21
|
+
Anyhow, we shall store it on a private storage, using **dorky**, that stores it on a S3 or Google-Drive.
|
|
22
|
+
|
|
23
|
+
## AWS S3
|
|
21
24
|
|
|
22
|
-
|
|
25
|
+
### Steps to use with S3:
|
|
23
26
|
|
|
24
27
|
> Create a S3 bucket, AWS_ACCESS_KEY and AWS_SECRET_KEY.
|
|
25
28
|
|
|
@@ -27,16 +30,60 @@ Anyhow, we shall store it on a private storage, using **dorky**, that stores it
|
|
|
27
30
|
|
|
28
31
|
> Please use your own repository, this repository `sample_project` is just for demonstration.
|
|
29
32
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
#### To list files in the project.
|
|
34
|
+
|
|
35
|
+
1. Initialize dorky setup in the root folder of your project, using `dorky --init aws`.
|
|
36
|
+
2. List the files using `dorky --list`.
|
|
37
|
+
> This command will not list the files that are excluded in `.dorkyignore`.
|
|
38
|
+
|
|
39
|
+
#### To push files to S3 bucket.
|
|
40
|
+
|
|
41
|
+
1. Initialize dorky setup in the root folder of your project, using `dorky --init aws`.
|
|
42
|
+
2. List the files using `dorky --list`, (make sure to add excluded file or folder patterns to .dorkyignore, to minimize the list).
|
|
43
|
+
3. Add files to stage-1 using `dorky --add file-name`.
|
|
44
|
+
4. Push files to S3 bucket using `dorky --push`.
|
|
45
|
+
|
|
46
|
+
#### To remove a file from project.
|
|
47
|
+
|
|
48
|
+
1. Remove files using `dorky --rm file-name`. [Removes file from stage-1 <local>]
|
|
49
|
+
2. Push files to S3 bucket using `dorky --push`. [Removes file from S3 bucket <remote>]
|
|
50
|
+
|
|
51
|
+
#### To pull files from S3 bucket.
|
|
52
|
+
|
|
53
|
+
1. Use `dorky --pull` to pull the files from S3 bucket.
|
|
54
|
+
|
|
55
|
+
## Google Drive
|
|
56
|
+
|
|
57
|
+
### Steps to use with Google Drive:
|
|
58
|
+
|
|
59
|
+

|
|
60
|
+
|
|
61
|
+
> Please use your own repository, this repository `sample_project` is just for demonstration.
|
|
62
|
+
|
|
63
|
+
#### To list files in the project.
|
|
64
|
+
|
|
65
|
+
1. Initialize dorky setup in the root folder of your project, using `dorky --init google-drive`.
|
|
66
|
+
2. List the files using `dorky --list`.
|
|
67
|
+
> This command will not list the files that are excluded in `.dorkyignore`.
|
|
68
|
+
|
|
69
|
+
#### To push files to Google Drive.
|
|
70
|
+
|
|
71
|
+
1. Initialize dorky setup in the root folder of your project, using `dorky --init google-drive`.
|
|
72
|
+
2. List the files using `dorky --list`, (make sure to add excluded file or folder patterns to .dorkyignore, to minimize the list).
|
|
73
|
+
3. Add files to stage-1 using `dorky --add file-name`.
|
|
74
|
+
4. Push files to Google Drive using `dorky --push`.
|
|
75
|
+
|
|
76
|
+
#### To remove a file from project.
|
|
77
|
+
|
|
78
|
+
1. Remove files using `dorky --rm file-name`. [Removes file from stage-1 <local>]
|
|
79
|
+
2. Push files to Google Drive using `dorky --push`. [Removes file from Google Drive <remote>]
|
|
80
|
+
|
|
81
|
+
#### To pull files from Google Drive.
|
|
82
|
+
|
|
83
|
+
1. Use `dorky --pull` to pull the files from Google Drive.
|
|
84
|
+
|
|
85
|
+
## To-Do
|
|
35
86
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
2. Push files to S3 bucket using `dorky push`.
|
|
87
|
+
[ ] Add stages for variables.
|
|
88
|
+
[ ] Convert to TypeScript.
|
|
39
89
|
|
|
40
|
-
### To pull files from S3 bucket.
|
|
41
|
-
1. Initialize dorky project using `dorky init`.
|
|
42
|
-
2. Use `dorky pull` to pull the files from S3 bucket.
|
package/bin/index.js
CHANGED
|
@@ -33,7 +33,6 @@ do {
|
|
|
33
33
|
const randomHex = Math.floor(Math.random() * 16777215).toString(16);
|
|
34
34
|
randomColor = `#${randomHex}`;
|
|
35
35
|
} while (randomColor[2] === "f" || randomColor[3] === "f");
|
|
36
|
-
// randomColor[2].match(/[a-f]/g).length ? true : false || randomColor[3].match(/[a-f]/g).length ? true : false
|
|
37
36
|
console.log(chalk.bgHex(randomColor)(usage));
|
|
38
37
|
|
|
39
38
|
if (process.argv.slice(2).length === 0) {
|
|
@@ -56,6 +55,13 @@ if (Object.keys(args).length == 2) {
|
|
|
56
55
|
yargs.showHelp()
|
|
57
56
|
}
|
|
58
57
|
|
|
58
|
+
function checkIfDorkyProject() {
|
|
59
|
+
if (!existsSync(".dorky") && !existsSync(".dorkyignore")) {
|
|
60
|
+
console.log(chalk.red("This is not a dorky project. Please run `dorky --init [aws|google-drive]` to initialize a dorky project."));
|
|
61
|
+
process.exit(1);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
59
65
|
function setupFilesAndFolders(metaData, credentials) {
|
|
60
66
|
console.log("Initializing dorky project");
|
|
61
67
|
if (existsSync(".dorky")) {
|
|
@@ -113,17 +119,19 @@ async function init(storage) {
|
|
|
113
119
|
}
|
|
114
120
|
|
|
115
121
|
async function list() {
|
|
122
|
+
checkIfDorkyProject();
|
|
116
123
|
console.log(chalk.red("Listing files that can be added:"));
|
|
117
|
-
|
|
124
|
+
var exclusions = fs.readFileSync(".dorkyignore").toString().split(EOL);
|
|
125
|
+
exclusions = exclusions.filter((exclusion) => exclusion !== "");
|
|
118
126
|
const src = process.cwd();
|
|
119
|
-
const files = await glob(path.join(src, "**/*"));
|
|
127
|
+
const files = await glob(path.join(src, "**/*"), { dot: true });
|
|
120
128
|
const filteredFiles = files.filter((file) => {
|
|
121
129
|
for (let i = 0; i < exclusions.length; i++) {
|
|
122
130
|
if (file.includes(exclusions[i])) return false;
|
|
123
131
|
}
|
|
124
132
|
return true;
|
|
125
133
|
});
|
|
126
|
-
filteredFiles.forEach((file) => console.log(chalk.red(`- ${file}`)));
|
|
134
|
+
filteredFiles.forEach((file) => console.log(chalk.red(`- ${path.relative(process.cwd(), file)}`)));
|
|
127
135
|
console.log(chalk.green("\nList of files that are already added:"));
|
|
128
136
|
const metaData = JSON.parse(fs.readFileSync(".dorky/metadata.json"));
|
|
129
137
|
const addedFiles = Object.keys(metaData["stage-1-files"]);
|
|
@@ -131,6 +139,7 @@ async function list() {
|
|
|
131
139
|
}
|
|
132
140
|
|
|
133
141
|
function add(listOfFiles) {
|
|
142
|
+
checkIfDorkyProject();
|
|
134
143
|
console.log("Adding files to stage-1 to push to storage");
|
|
135
144
|
const metaData = JSON.parse(fs.readFileSync(".dorky/metadata.json"));
|
|
136
145
|
listOfFiles.forEach((file) => {
|
|
@@ -150,6 +159,7 @@ function add(listOfFiles) {
|
|
|
150
159
|
}
|
|
151
160
|
|
|
152
161
|
function rm(listOfFiles) {
|
|
162
|
+
checkIfDorkyProject();
|
|
153
163
|
console.log(chalk.red("Removing files from stage-1"));
|
|
154
164
|
const metaData = JSON.parse(fs.readFileSync(".dorky/metadata.json"));
|
|
155
165
|
listOfFiles = listOfFiles.filter((file) => {
|
|
@@ -176,6 +186,7 @@ function checkCredentials() {
|
|
|
176
186
|
}
|
|
177
187
|
|
|
178
188
|
function push() {
|
|
189
|
+
checkIfDorkyProject();
|
|
179
190
|
if (!checkCredentials()) {
|
|
180
191
|
console.log(chalk.red("Please setup credentials in environment variables or in .dorky/credentials.json"));
|
|
181
192
|
return;
|
|
@@ -294,6 +305,7 @@ async function pushToGoogleDrive(files) {
|
|
|
294
305
|
}
|
|
295
306
|
|
|
296
307
|
function pull() {
|
|
308
|
+
checkIfDorkyProject();
|
|
297
309
|
if (!checkCredentials()) {
|
|
298
310
|
console.log(chalk.red("Please setup credentials in environment variables or in .dorky/credentials.json"));
|
|
299
311
|
return;
|
|
@@ -368,19 +380,6 @@ async function pullFromGoogleDrive(files) {
|
|
|
368
380
|
}
|
|
369
381
|
fs.writeFileSync(file.name, await _file.data.text(), "utf-8");
|
|
370
382
|
console.log(chalk.green(`Pulled ${file.name} from storage.`));
|
|
371
|
-
// const res = await drive.files.list({
|
|
372
|
-
// q: `name='${file.name}'`,
|
|
373
|
-
// fields: 'files(id, name)',
|
|
374
|
-
// spaces: 'drive'
|
|
375
|
-
// });
|
|
376
|
-
// const _file = await drive.files.get({ fileId: res.data.files[0].id, alt: "media" });
|
|
377
|
-
// fs.writeFile(file.name, await _file.data.text(), "utf-8", (err) => {
|
|
378
|
-
// if (err) {
|
|
379
|
-
// console.log(err);
|
|
380
|
-
// throw err;
|
|
381
|
-
// }
|
|
382
|
-
// console.log(chalk.green(`Pulled ${file.name} from storage.`));
|
|
383
|
-
// });
|
|
384
383
|
});
|
|
385
384
|
} catch (err) {
|
|
386
385
|
throw err;
|
|
@@ -392,4 +391,4 @@ if (Object.keys(args).includes("list")) list(args.list);
|
|
|
392
391
|
if (Object.keys(args).includes("add")) add(args.add);
|
|
393
392
|
if (Object.keys(args).includes("rm")) rm(args.rm);
|
|
394
393
|
if (Object.keys(args).includes("push")) push();
|
|
395
|
-
if (Object.keys(args).includes("pull")) pull();
|
|
394
|
+
if (Object.keys(args).includes("pull")) pull();
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"web": {
|
|
3
|
+
"client_id": "624017989162-l9r3hqnv0urve3e3eg0eika5oq81mgin.apps.googleusercontent.com",
|
|
4
|
+
"project_id": "sonic-mile-426408-u2",
|
|
5
|
+
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
|
6
|
+
"token_uri": "https://oauth2.googleapis.com/token",
|
|
7
|
+
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
|
|
8
|
+
"client_secret": "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",
|
|
9
|
+
"javascript_origins": [
|
|
10
|
+
"http://localhost:3000"
|
|
11
|
+
],
|
|
12
|
+
"redirect_uris": [
|
|
13
|
+
"http://localhost:3000/oauth2callback"
|
|
14
|
+
]
|
|
15
|
+
}
|
|
16
|
+
}
|
package/package.json
CHANGED
package/To-Do
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
Add stages for variables.
|
|
2
|
-
Fix workflow with CI instead of npm i.
|
|
3
|
-
Convert to TypeScript.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
Possible commands to add =>
|
|
7
|
-
- node bin/index.js --init [aws|google-drive]
|
|
8
|
-
- node bin/index.js --add [file-names]
|
|
9
|
-
- node bin/index.js --list
|
|
10
|
-
- node bin/index.js --push
|
|
11
|
-
- node bin/index.js --pull
|
|
12
|
-
|
|
13
|
-
{
|
|
14
|
-
"stage-1-files": {
|
|
15
|
-
"abc.txt": {
|
|
16
|
-
"mime-type": "text/plain",
|
|
17
|
-
"checksum": ""
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
"uploaded-files": ["uid1"]
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
checksum of the file contents will be the encrypted string in md5
|
|
24
|
-
option to avoid checksum (used when file size is large)
|