dorky 2.0.0 → 2.1.2

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 CHANGED
@@ -1,6 +1,7 @@
1
1
  # dorky
2
+
2
3
  ```
3
- __ __
4
+ __ __
4
5
  .--| .-----.----| |--.--.--.
5
6
  | _ | _ | _| <| | |
6
7
  |_____|_____|__| |__|__|___ |
@@ -17,26 +18,72 @@ 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
- ## Steps to use:
25
+ ### Steps to use with S3:
23
26
 
24
27
  > Create a S3 bucket, AWS_ACCESS_KEY and AWS_SECRET_KEY.
25
28
 
26
- ![Dorky Usage](dorky-usage.svg "Dorky usage")
29
+ ![Dorky Usage](dorky-usage-aws.svg "Dorky usage")
27
30
 
28
31
  > Please use your own repository, this repository `sample_project` is just for demonstration.
29
32
 
30
- ### To push files to S3 bucket.
31
- 1. Initialize dorky setup in the root folder of your project, using `dorky init`.
32
- 2. List the files using `dorky list`, (make sure to add excluded file or folder patterns to .dorkyignore, to minimize the list).
33
- 3. Add files to stage-1 using `dorky add file-name`.
34
- 4. Push files to S3 bucket using `dorky push`.
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
+ ![Dorky Usage](dorky-usage-google-drive.svg "Dorky usage")
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
- ### To remove a file from project.
37
- 1. Remove files using `dorky reset file-name`.
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
- const exclusions = fs.readFileSync(".dorkyignore").toString().split(EOL);
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();