generated from themetalfleece/nodejs-typescript-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
521e21e
commit 5f8e3d2
Showing
38 changed files
with
12,911 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"extends": [ | ||
"@commitlint/config-conventional" | ||
] | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,2 @@ | ||
# node modules | ||
node_modules | ||
# build path | ||
dist | ||
# environmental variables | ||
.env | ||
# yarn error log | ||
yarn-error.log | ||
# vscode config | ||
.vscode | ||
# test coverage | ||
coverage | ||
/* | ||
!/src |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
name: Release | ||
on: | ||
push: | ||
branches: | ||
- master | ||
|
||
permissions: | ||
contents: read # for checkout | ||
|
||
jobs: | ||
release: | ||
name: Release | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: write # to be able to publish a GitHub release | ||
issues: write # to be able to comment on released issues | ||
pull-requests: write # to be able to comment on released pull requests | ||
id-token: write # to enable use of OIDC for npm provenance | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- uses: actions/setup-node@v3 | ||
with: | ||
cache: npm | ||
node-version-file: '.nvmrc' | ||
|
||
- run: npm ci | ||
- run: npm audit signatures | ||
- run: npm run build | ||
|
||
- run: npx semantic-release | ||
env: | ||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,6 @@ | ||
# node modules | ||
node_modules | ||
# build path | ||
dist | ||
# environmental variables | ||
.env | ||
# yarn error log | ||
yarn-error.log | ||
# vscode config | ||
.vscode | ||
#coverage | ||
coverage | ||
*.tsbuildinfo | ||
src/generated/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/env sh | ||
. "$(dirname -- "$0")/_/husky.sh" | ||
|
||
npx commitlint --edit $1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/sh | ||
. "$(dirname "$0")/_/husky.sh" | ||
|
||
npx lint-staged |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"*.ts": "eslint --fix --quiet" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
v18.16.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,4 @@ | |
"tabWidth": 2, | ||
"semi": true, | ||
"singleQuote": true | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,120 @@ | ||
#### This project was created using [themetalfleece/nodejs-typescript-template](https://github.com/themetalfleece/nodejs-typescript-template) | ||
# Unity CCD Locker | ||
|
||
# This template gets updated daily so the latest dependencies are always used! | ||
A git-based locking mechanism for Unity CCD bucket operations. Can be used to prevent simultaneous operations. | ||
|
||
## What to do after using this template | ||
## Requirements | ||
|
||
1. Edit `package.json` to set the project name, version, description, and author. | ||
2. Edit the `LICENSE` file to use your name in the Copyright section. | ||
3. Edit the `.prettierrc.json` file with your preferred values. | ||
4. Remove the `.github/workflows/upgrade-dependencies.yml` files, since it contains the workflow to upgrade all dependencies on a daily basis. | ||
* In case you would like to keep it, remove lines 7, 30, 32 from it. Also, change the git user name in line 28. | ||
5. Delete this section from the `README.md` file. | ||
6. Start coding by editing the `src/app.ts` file! | ||
- Node.js version `8.0.0` or higher. | ||
- You have Git installed and it is in your PATH. | ||
|
||
## Install | ||
## Installation | ||
|
||
1. Install [node.js](https://nodejs.org/en/download/), [yarn](https://yarnpkg.com/getting-started/install) (or use npm). | ||
2. Clone this repository, and using a terminal navigate to its directory. | ||
3. Run `yarn` or `npm install` to install the dependencies. | ||
```sh | ||
npm i -g unity-ccd-locker | ||
``` | ||
|
||
## Build & Run | ||
## Usage | ||
|
||
1. Copy the contents of the `.env.example` file to a `.env` next to it, and edit it with your values. | ||
2. Run `yarn build` or `npm build` to build the files. | ||
3. Run `yarn start` or `npm start` to start the application. | ||
``` | ||
unity-ccd-locker <command> <arguments> | ||
``` | ||
|
||
- You can run `yarn dev` or `npm dev` to combine the 2 steps above, while listening to changes and restarting automatically. | ||
You can also call `ucl` instead of `unity-ccd-locker`. | ||
|
||
## Run with Docker | ||
### Setup a locks repository | ||
|
||
1. Build: | ||
`unity-ccd-locker` requires a git reposiory to store the locks. : | ||
|
||
``` | ||
docker build -t my-app . | ||
``` | ||
1. Create an empty repository. | ||
2. Run `unity-ccd-locker init --repoUrl <REPO URL>`. | ||
3. (Optional) Set up a config file to prevent providing all arguments in the command line every time. | ||
|
||
Replacing `my-app` with the image name. | ||
Notes: | ||
|
||
2. Run | ||
``` | ||
docker run -d -p 3000:3000 my-app | ||
``` | ||
Replacing `my-app` with the image name, and `3000:3000` with the `host:container` ports to publish. | ||
- You only need to perform the setup once per locks repository. | ||
- You can use the same locks repository for everything. You can also have multiple locks repositories for different purposes. | ||
- Do not use the locks repositories for any purpose other than `unity-ccd-locker` usage. | ||
- It is highly recommended to use brand new empty repositories for setup. However, you can use existing repositories as well. If you are using an existing repository, run `unity-ccd-locker clean-init` instead of `unity-ccd-locker init`. | ||
|
||
## Developing | ||
### Working with locks | ||
|
||
### Visual Studio Code | ||
After you have a repo set up, then you can work with locks. This is the recommended workflow: | ||
|
||
- Installing the Eslint (`dbaeumer.vscode-eslint`) and Prettier - Code formatter (`esbenp.prettier-vscode`) extensions is recommended. | ||
1. Acquire the lock on a bucket. | ||
2. Perform any CCD operations you wish. | ||
3. Release the lock on the bucket. | ||
|
||
## Linting & Formatting | ||
### Cleaning a locks repository | ||
|
||
- Run `yarn lint` or `npm lint` to lint the code. | ||
- Run `yarn format` or `npm format` to format the code. | ||
If your locks repository got corrupted, or if for some reason you want to start over, you can clean it by running `unity-ccd-locker clean --repoUrl <REPO URL>`. This will delete everything in the repository except the main branch and the initial commit. | ||
|
||
## Testing | ||
Notes: | ||
- After cleaning, a locks repository needs to be setup again before usage. | ||
- If you want to clean and re-setup the repository in one go, you can use `unity-ccd-locker clean-init` instead of running `unity-ccd-locker clean` followed by `unity-ccd-locker init`. | ||
|
||
Check the placeholder test examples to get started : | ||
### Commands | ||
|
||
- `/src/app.ts` that provide a function `sum` | ||
- `/test/app.spec.ts` who test the `sum` function | ||
| Name | Aliases | Description | | ||
| --- | --- | --- | | ||
| `init` | `i` | Initialize the repository as a locks repository. | | ||
| `clean` | `x` | Delete everything in a locks repository. | | ||
| `clean-init` | `xi` | Perform a clean, followed by an init. | | ||
| `acquire` | `a` | Acquire the lock for a bucket. | | ||
| `release` | `r` | Release the lock on a bucket. | | ||
| `show` | `s` | Print the lock status of a bucket. | | ||
|
||
This files are just an example, feel free to remove it | ||
### Arguments | ||
|
||
- Run `yarn test` or `npm test` to execute all tests. | ||
- Run `yarn test:watch` or `npm test:watch` to run tests in watch (loop) mode. | ||
- Run `yarn test:coverage` or `npm test:coverage` to see the tests coverage report. | ||
| Name | Aliases | Type | Required | Description | | ||
| --- | --- | --- | --- | --- | | ||
| `--help` | `-h`, `-?` | flag | No | Print help. | | ||
| `--version` | `-v` | flag | No | Print version info. | | ||
| `--config` | `-c` | string | No | Path to a JSON config file. | | ||
| `--repoUrl` | `-u` | string | Yes | The URL of the locks repository. | | ||
| `--projectId` | `-p` | string | For lock commands | CCD project ID. | | ||
| `--envId` | `-e` | string | For lock commands | CCD environment ID. | | ||
| `--bucketId` | `-b` | string | For lock commands | CCD bucket ID. | | ||
| `--message` | `-m` | string | For lock commands | The message to associate with the operation. | | ||
| `--force` | `-f` | flag | No | Bypass safety checks. | | ||
|
||
Lock commands = `acquire`, `release`, `show` | ||
|
||
### Config Files | ||
|
||
You can optionally have a JSON config file that you can pass with the `--config` argument that defines some of the arguments in it, so you don't have to write them all the time. | ||
|
||
Keys should correspond to argument names without the dashes. This is how it should look like: | ||
|
||
```json | ||
{ | ||
"repoUrl": "<URL OF THE LOCKS REPO>", | ||
"projectId": "<YOUR PROJECT ID>", | ||
"envId": "<YOUR ENVIRONMENT ID>" | ||
} | ||
``` | ||
|
||
Notes: | ||
|
||
- Arguments provided in the CLI have a higher priority than the arguments provided in the config file. This means that if the same argument is provided in both, then the CLI argument will be used. | ||
|
||
## Motivation | ||
|
||
CCD misbehaves when doing simultaneous operations on the same bucket. If you have ever seen one of these errors, then you very well know what I am talking about: | ||
|
||
``` | ||
Error! The state of the bucket changed unexpectedly. Please retry this operation. | ||
``` | ||
|
||
``` | ||
You have an entry specified, but the matching file has not been uploaded, or the file size, or md5 hash of what was uploaded does not match | ||
``` | ||
|
||
Sometimes simply retrying works. Other times however, the bucket state gets corrupted and no further operations work properly. | ||
|
||
This tool provides a way for you to have _locks_ on buckets, just like how some source control software allows you to lock files to prevent other people from changing them, or how an OS provides file locks to prevent files being altered by multiple processes. | ||
|
||
## License | ||
|
||
MIT License. Refer to the [LICENSE.md](LICENSE.md) file. | ||
|
||
Copyright (c) 2023 [S. Tarık Çetin](https://github.com/starikcetin) |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.