Skip to content

Commit

Permalink
Displays hidden files too and checks if dorky project is initialized …
Browse files Browse the repository at this point in the history
…for a protected commands.
  • Loading branch information
trishantpahwa committed Oct 13, 2024
1 parent 9914cb8 commit 9a6ae7c
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 42 deletions.
75 changes: 61 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# dorky

```
__ __
__ __
.--| .-----.----| |--.--.--.
| _ | _ | _| <| | |
|_____|_____|__| |__|__|___ |
Expand All @@ -17,26 +18,72 @@ Let us assume that we need to create a project.

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.

Anyhow, we shall store it on a private storage, using **dorky**, that stores it on a S3.
Anyhow, we shall store it on a private storage, using **dorky**, that stores it on a S3 or Google-Drive.

## AWS S3

## Steps to use:
### Steps to use with S3:

> Create a S3 bucket, AWS_ACCESS_KEY and AWS_SECRET_KEY.
![Dorky Usage](dorky-usage.svg "Dorky usage")

> Please use your own repository, this repository `sample_project` is just for demonstration.
### To push files to S3 bucket.
1. Initialize dorky setup in the root folder of your project, using `dorky init`.
2. List the files using `dorky list`, (make sure to add excluded file or folder patterns to .dorkyignore, to minimize the list).
3. Add files to stage-1 using `dorky add file-name`.
4. Push files to S3 bucket using `dorky push`.
#### To list files in the project.

1. Initialize dorky setup in the root folder of your project, using `dorky --init aws`.
2. List the files using `dorky --list`.
> This command will not list the files that are excluded in `.dorkyignore`.
#### To push files to S3 bucket.

1. Initialize dorky setup in the root folder of your project, using `dorky --init aws`.
2. List the files using `dorky --list`, (make sure to add excluded file or folder patterns to .dorkyignore, to minimize the list).
3. Add files to stage-1 using `dorky --add file-name`.
4. Push files to S3 bucket using `dorky --push`.

#### To remove a file from project.

1. Remove files using `dorky --rm file-name`. [Removes file from stage-1 <local>]
2. Push files to S3 bucket using `dorky --push`. [Removes file from S3 bucket <remote>]

#### To pull files from S3 bucket.

1. Use `dorky --pull` to pull the files from S3 bucket.

## Google Drive

### Steps to use with Google Drive:

![Dorky Usage](dorky-usage.svg "Dorky usage")

> Please use your own repository, this repository `sample_project` is just for demonstration.
#### To list files in the project.

1. Initialize dorky setup in the root folder of your project, using `dorky --init google-drive`.
2. List the files using `dorky --list`.
> This command will not list the files that are excluded in `.dorkyignore`.
#### To push files to Google Drive.

1. Initialize dorky setup in the root folder of your project, using `dorky --init google-drive`.
2. List the files using `dorky --list`, (make sure to add excluded file or folder patterns to .dorkyignore, to minimize the list).
3. Add files to stage-1 using `dorky --add file-name`.
4. Push files to Google Drive using `dorky --push`.

#### To remove a file from project.

1. Remove files using `dorky --rm file-name`. [Removes file from stage-1 <local>]
2. Push files to Google Drive using `dorky --push`. [Removes file from Google Drive <remote>]

#### To pull files from Google Drive.

1. Use `dorky --pull` to pull the files from Google Drive.

## To-Do

### To remove a file from project.
1. Remove files using `dorky reset file-name`.
2. Push files to S3 bucket using `dorky push`.
[ ] Add stages for variables.
[ ] Convert to TypeScript.

### To pull files from S3 bucket.
1. Initialize dorky project using `dorky init`.
2. Use `dorky pull` to pull the files from S3 bucket.
24 changes: 0 additions & 24 deletions To-Do

This file was deleted.

19 changes: 16 additions & 3 deletions bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ if (Object.keys(args).length == 2) {
yargs.showHelp()
}

function checkIfDorkyProject() {
if (!existsSync(".dorky") && !existsSync(".dorkyignore")) {
console.log(chalk.red("This is not a dorky project. Please run `dorky --init [aws|google-drive]` to initialize a dorky project."));
process.exit(1);
}
}

function setupFilesAndFolders(metaData, credentials) {
console.log("Initializing dorky project");
if (existsSync(".dorky")) {
Expand Down Expand Up @@ -112,24 +119,27 @@ async function init(storage) {
}

async function list() {
checkIfDorkyProject();
console.log(chalk.red("Listing files that can be added:"));
const exclusions = fs.readFileSync(".dorkyignore").toString().split(EOL);
var exclusions = fs.readFileSync(".dorkyignore").toString().split(EOL);
exclusions = exclusions.filter((exclusion) => exclusion !== "");
const src = process.cwd();
const files = await glob(path.join(src, "**/*"));
const files = await glob(path.join(src, "**/*"), { dot: true });
const filteredFiles = files.filter((file) => {
for (let i = 0; i < exclusions.length; i++) {
if (file.includes(exclusions[i])) return false;
}
return true;
});
filteredFiles.forEach((file) => console.log(chalk.red(`- ${file}`)));
filteredFiles.forEach((file) => console.log(chalk.red(`- ${path.relative(process.cwd(), file)}`)));
console.log(chalk.green("\nList of files that are already added:"));
const metaData = JSON.parse(fs.readFileSync(".dorky/metadata.json"));
const addedFiles = Object.keys(metaData["stage-1-files"]);
addedFiles.forEach((file) => console.log(chalk.green(`- ${file}`)));
}

function add(listOfFiles) {
checkIfDorkyProject();
console.log("Adding files to stage-1 to push to storage");
const metaData = JSON.parse(fs.readFileSync(".dorky/metadata.json"));
listOfFiles.forEach((file) => {
Expand All @@ -149,6 +159,7 @@ function add(listOfFiles) {
}

function rm(listOfFiles) {
checkIfDorkyProject();
console.log(chalk.red("Removing files from stage-1"));
const metaData = JSON.parse(fs.readFileSync(".dorky/metadata.json"));
listOfFiles = listOfFiles.filter((file) => {
Expand All @@ -175,6 +186,7 @@ function checkCredentials() {
}

function push() {
checkIfDorkyProject();
if (!checkCredentials()) {
console.log(chalk.red("Please setup credentials in environment variables or in .dorky/credentials.json"));
return;
Expand Down Expand Up @@ -293,6 +305,7 @@ async function pushToGoogleDrive(files) {
}

function pull() {
checkIfDorkyProject();
if (!checkCredentials()) {
console.log(chalk.red("Please setup credentials in environment variables or in .dorky/credentials.json"));
return;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dorky",
"version": "2.0.0",
"version": "2.1.1",
"description": "DevOps Records Keeper.",
"bin": {
"dorky": "bin/index.js"
Expand Down

0 comments on commit 9a6ae7c

Please sign in to comment.