Skip to content

Commit

Permalink
Merge pull request #1 from v-nvtsk/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
v-nvtsk authored May 3, 2024
2 parents 802efa4 + 18706dc commit 693e993
Show file tree
Hide file tree
Showing 34 changed files with 14,488 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": [["@babel/preset-env", { "targets": { "node": "current" } }], "@babel/preset-typescript"]
}
40 changes: 40 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
module.exports = {
env: {
node: true,
es2021: true,
jest: true,
},
extends: ["airbnb-base", "airbnb-typescript/base", "prettier"],
parser: "@typescript-eslint/parser",
plugins: ["@stylistic/eslint-plugin-ts", "@typescript-eslint"],
parserOptions: {
ecmaVersion: "latest",
sourceType: "module",
project: ["./tsconfig.eslint.json", "./tsconfig.json"],
// tsconfigRootDir: __dirname,
},
rules: {
semi: ["error", "always"],
"import/no-unresolved": "off",
"import/extensions": ["warn", "never"],
"import/no-extraneous-dependencies": [
"error",
{
devDependencies: ["**/*.test.{ts,tsx}", "**/test-*.{ts,tsx}", "**/jest-setup.ts", "./webpack.config.js"],
},
],
"import/prefer-default-export": "off",
"max-len": [
"error",
{
code: 120,
comments: 120,
tabWidth: 2,
ignoreUrls: true,
ignoreTemplateLiterals: true,
ignoreRegExpLiterals: true,
},
],
},
ignorePatterns: ["node_modules", ".git", "coverage", "dist"],
};
19 changes: 19 additions & 0 deletions .github/workflows/codesandbox-link-comment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Add codesandbox link

on:
pull_request:

jobs:
codesandbox-comment:
name: Add codesandbox link comment
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- uses: mshick/add-pr-comment@v2
with:
message: |
You can check this code at CodeSandbox with the link
https://githubbox.com/${{ github.repository }}/tree/${{ github.head_ref }}
Also, you can check build at CodeSandbox with the link
https://githubbox.com/${{ github.repository }}/tree/gh-pages
27 changes: 27 additions & 0 deletions .github/workflows/lint-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Lint and Test

on: pull_request
permissions:
contents: write
jobs:
lint-test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install Packages
run: |
npm ci
- name: Lint
run: npm run lint

- name: Test
run: npm test

- name: CI Badges
uses: GaelGirodon/[email protected]
with:
gist-id: f9b687636482339cabd6a8c4b369f3eb
token: ${{ secrets.GIST_TOKEN }}
36 changes: 36 additions & 0 deletions .github/workflows/npm-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages

name: Node.js Package

on:
release:
types: [created]
pull_request:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm ci
- run: npm test

publish-npm:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
registry-url: https://registry.npmjs.org/
- run: npm ci
- run: npm run build
- run: cp package.json dist && cd dist
- run: printf '%s\n%s\n' "#!/usr/bin/env -S node" "$(cat ./index.js)" > ./index.js
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
reports
coverage
1 change: 1 addition & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npx --no-install commitlint --edit $1
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npx lint-staged
2 changes: 2 additions & 0 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
npm run tsc --noEmit
npm test
15 changes: 15 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.github
.husky
coverage
node_modules
reports
src
.babelrc
.eslintrc.js
.prettierrc
commitlint.config.ts
jest.config.ts
lint-staged.config.js
tsconfig.eslint.json
tsconfig.json
webpack.config.js
3 changes: 3 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"printWidth": 120
}
148 changes: 148 additions & 0 deletions README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
# Deploy to github-pages
[![NPM](https://nodei.co/npm/nvtsk-deploy-gh.png)](https://www.npmjs.com/package/nvtsk-deploy-gh)

[![Node.js Package](https://github.com/v-nvtsk/otus-jsbasic-dz50-nodejs/actions/workflows/npm-deploy.yml/badge.svg)](https://github.com/v-nvtsk/otus-jsbasic-dz50-nodejs/actions/workflows/npm-deploy.yml)
![NPM Version](https://img.shields.io/npm/v/nvtsk-deploy-gh)
![GitHub repo size](https://img.shields.io/github/repo-size/v-nvtsk/otus-jsbasic-dz50-nodejs)
![NPM Unpacked Size](https://img.shields.io/npm/unpacked-size/nvtsk-deploy-gh)

[![Lint and Test](https://github.com/v-nvtsk/otus-jsbasic-dz50-nodejs/actions/workflows/lint-test.yaml/badge.svg)](https://github.com/v-nvtsk/otus-jsbasic-dz50-nodejs/actions/workflows/lint-test.yaml)
![Endpoint Badge](https://img.shields.io/endpoint?url=https%3A%2F%2Fgist.githubusercontent.com%2Fv-nvtsk%2Ff9b687636482339cabd6a8c4b369f3eb%2Fraw%2F772fcddd8351230f0f3c307f37baf87361a66fc3%2Fotus-jsbasic-final-react-junit-tests.json)

---

> cli application for deploy to github-pages
## Usage

Allows to declare build command to build project and require directory name where built project will be.
If build is not need it will just use directory with ready build.

Run with dialog:

```sh
npx nvtsk-deploy-gh
```

![alt text](images/dialog.gif)

Run with command-line arguments

```sh
npx nvtsk-deploy-gh --build "npm run build" --dir dist
```

## npm package settings

`package.json`

```json
"name": "nvtsk-deploy-gh",
"version": "1.0.2",
"main": "./dist/index.js",
"bin": {
"nvtsk-deploy-gh": "dist/index.js"
},
"types": "./dist/index.d.ts",
"repository": {
"type": "git",
"url": "git+https://github.com/v-nvtsk/otus-jsbasic-dz50-nodejs.git"
},
```

Deploy to npmjs with github-action workflow.
Distributive entry-point file with bundle is prepended with a line with shebang which runs js file in node.js
```sh
#!/usr/bin/env -S node

/*! For license information please see index.js.LICENSE.txt */
(()=>{var e,t,r,n,i={36776:(e,t,r)=>{"use strict";var n=r(2203).Stream,i=r(88179);function o(e,t,r){var o=i(e||function(e){this.
...
```
## Used algorithm
_`./dist` is used here as an example path_
1. Make sure you are on the branch that contains the "dist/" directory you want to publish, or on the branch that is able to build:
2. Stash the contents of the "dist/" directory:
```sh
git add dist
git stash push --keep-index
```
3. If the gh-pages branch does not exist, create it:
```sh
git checkout --orphan gh-pages
git reset --hard
git commit --allow-empty -m "Initializing gh-pages branch"
git push -u origin gh-pages
```
1. Check out the gh-pages branch
```sh
git checkout gh-pages
```
5. Apply the stash that contains your "dist/" directory (this will restore the "dist/" directory):
```sh
git stash pop
```
6. Stage "dist/" directory and move the contents of the "dist/" directory to the root of the repository:
```sh
git add dist
git mv -f dist/* .
git reset HEAD -- dist
```
7. Add all the new files to the gh-pages branch, commit, and push to GitHub;
```sh
git commit -m "deploy"
git push origin gh-pages
```
## GIF made with `asciinema`
### Installation - asciinema docs
[asciinema docs](https://docs.asciinema.org/)
```sh
install asciinema
```
asciinema creates cast files from terminal.
agg is instrument to create gifs from cast files.
Visit [latest release](https://github.com/asciinema/agg/releases/latest) page, and download a binary appropriate for your system.
For 64-bit x86 system choose a file with `x86_64` in the name. For ARMv8 (64-bit, e.g. Apple Silicon) choose a file with `aarch64`. For ARMv7 (32-bit, e.g. Raspberry Pi) choose a file with `arm`.
Make it executable and put it somewhere in `$PATH`:
````sh
chmod a+x agg
sudo mv agg /usr/local/bin```
````
start rec to your_script_name.cast cast-file
```sh
asciinema rec ./your_script_name.cast
```
convert cast-file to gif your_gif_file.gif
```sh
agg ./your_script_name.cast ./your_gif_file.gif
```
1 change: 1 addition & 0 deletions commitlint.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default { extends: ["@commitlint/config-conventional"] };
Binary file added images/dialog.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 693e993

Please sign in to comment.