Skip to content

Commit c54c5c3

Browse files
popomonpopomon
authored andcommitted
ci: Added script for project initialization
Summary: 1. Added commit hook 2. Added node version scripts (nvm, npm, yarn) 3. Added code formatting scripts (typescript, eslint, prettier, husky, lint-staged) Referenced: 6b54142
1 parent d4b93f0 commit c54c5c3

23 files changed

+607
-1
lines changed

.bin/_init.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
3+
# Clear project
4+
rm -rf node_modules
5+
rm -rf yarn.lock
6+
rm -rf dist
7+
rm -rf .husky
8+
rm -rf .lintstagedrc.json
9+
rm -rf .eslintignore
10+
rm -rf .eslintrc.js
11+
rm -rf .prettierrc
12+
rm -rf .prettierignore
13+
rm -rf .npmrc
14+
rm -rf .nvmrc
15+
rm -rf .yarnrc
16+
rm -rf tsconfig.json
17+
rm -rf tsconfig.path.json
18+
rm -rf package.json
19+
rm -rf package.jsone
20+
rm -rf package-lock.json
21+
rm -rf yarn-error.log
22+
23+
# Initialize project
24+
yarn init -y
25+
26+
# Add engines attribute
27+
IS_ENGINES=$(sed -n '/engines/p' package.json)
28+
if [[ ! -n "$IS_ENGINES" ]] ; then
29+
license=$(sed -n '/"license": "[.a-zA-Z0-9]*"/p' package.json)
30+
sed -ie "s/ \"license\": \"[.a-zA-Z0-9]*\"/$license,\n \"engines\": {\n \"node\": \"\"\n }/g" package.json
31+
fi

.bin/_set_config.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
3+
# Set environment
4+
source ./.bin/set_node_version/index.sh
5+
source ./.bin/set_code_formatting/index.sh
6+
7+

.bin/set_code_formatting/_eslint.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
3+
# Install eslint
4+
yarn add eslint
5+
6+
# Install prettier related packages
7+
yarn add eslint-config-prettier
8+
yarn add eslint-plugin-prettier
9+
10+
# Install eslint typescript packages
11+
yarn add -D @typescript-eslint/eslint-plugin
12+
yarn add -D @typescript-eslint/parser
13+
14+
# Create eslint config file
15+
echo "module.exports = {" > .eslintrc.js
16+
echo " parser: \"@typescript-eslint/parser\"," >> .eslintrc.js
17+
echo " extends: [" >> .eslintrc.js
18+
echo " \"plugin:@typescript-eslint/recommended\"," >> .eslintrc.js
19+
echo " \"plugin:prettier/recommended\"" >> .eslintrc.js
20+
echo " ]," >> .eslintrc.js
21+
echo " rules: {" >> .eslintrc.js
22+
echo " \"prettier/prettier\": 0," >> .eslintrc.js
23+
echo " \"comma-dangle\": [\"error\", \"never\"]" >> .eslintrc.js
24+
echo " }" >> .eslintrc.js
25+
echo "};" >> .eslintrc.js
26+
27+
# Create eslint ignore file
28+
echo "node_modules/*" > .eslintignore
29+
echo "dist/*" >> .eslintignore
30+
echo "asset/*" >> .eslintignore

.bin/set_code_formatting/_husky.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
# Install
4+
yarn add husky
5+
6+
# Create husky config files
7+
mkdir .husky
8+
touch .husky/pre-commit
9+
chmod 755 .husky/pre-commit
10+
echo '#!/bin/sh' > .husky/pre-commit
11+
echo '. "$(dirname "$0")/_/husky.sh"' >> .husky/pre-commit
12+
echo '' >> .husky/pre-commit
13+
echo 'yarn lint-staged && echo \"[Husky] pre-commit\"' >> .husky/pre-commit
14+
15+
# Enable husky pre-commit hook
16+
git config advice.ignoredHook false
17+
18+
# Install git hook
19+
./node_modules/husky/lib/bin.js install .husky
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
# Install
4+
yarn add lint-staged
5+
6+
# Create husky config files
7+
echo "{" > .lintstagedrc.json
8+
echo " \"**/*.{js,jsx,ts,tsx}\": [\"eslint --fix .\", \"prettier -c .\"]" >> .lintstagedrc.json
9+
echo "}" >> .lintstagedrc.json
10+

.bin/set_code_formatting/_prettier.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
3+
# Install prettier
4+
yarn add prettier
5+
6+
# Create prettier config file
7+
echo '{' > .prettierrc
8+
echo ' "arrowParens": "always",' >> .prettierrc
9+
echo ' "bracketSpacing": true,' >> .prettierrc
10+
echo ' "embeddedLanguageFormatting": "auto",' >> .prettierrc
11+
echo ' "endOfLine": "lf",' >> .prettierrc
12+
echo ' "htmlWhitespaceSensitivity": "css",' >> .prettierrc
13+
echo ' "insertPragma": false,' >> .prettierrc
14+
echo ' "jsxBracketSameLine": false,' >> .prettierrc
15+
echo ' "jsxSingleQuote": false,' >> .prettierrc
16+
echo ' "printWidth": 80,' >> .prettierrc
17+
echo ' "proseWrap": "preserve",' >> .prettierrc
18+
echo ' "quoteProps": "as-needed",' >> .prettierrc
19+
echo ' "requirePragma": false,' >> .prettierrc
20+
echo ' "semi": true,' >> .prettierrc
21+
echo ' "singleQuote": false,' >> .prettierrc
22+
echo ' "tabWidth": 2,' >> .prettierrc
23+
echo ' "trailingComma": "none",' >> .prettierrc
24+
echo ' "useTabs": false,' >> .prettierrc
25+
echo ' "vueIndentScriptAndStyle": false' >> .prettierrc
26+
echo '}' >> .prettierrc
27+
28+
# Create prettier ignore file
29+
echo '.husky' > .prettierignore
30+
echo 'dist' >> .prettierignore
31+
echo 'node_modules' >> .prettierignore
32+
echo 'yarn.lock' >> .prettierignore
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
3+
# Install typescript
4+
yarn add -D typescript
5+
6+
# Create typescript path configuration file - tsconfig.path.json
7+
echo "{" > ./tsconfig.path.json
8+
echo " \"compilerOptions\": {" >> ./tsconfig.path.json
9+
echo " \"baseUrl\": \".\"," >> ./tsconfig.path.json
10+
echo " \"paths\": {" >> ./tsconfig.path.json
11+
echo " \"@src/*\": [\"src/*\"]" >> ./tsconfig.path.json
12+
echo " // Add folder" >> ./tsconfig.path.json
13+
echo " // \"@xxx/*\": [\"src/xxx/*\"]," >> ./tsconfig.path.json
14+
echo " }" >> ./tsconfig.path.json
15+
echo " }" >> ./tsconfig.path.json
16+
echo "}" >> ./tsconfig.path.json
17+
18+
# Create typescript configuration file - tsconfig.json
19+
echo "{" > ./tsconfig.json
20+
echo " \"extends\": \"./tsconfig.path.json\"," >> ./tsconfig.json
21+
echo " \"compilerOptions\": {" >> ./tsconfig.json
22+
echo " \"target\": \"es2016\"," >> ./tsconfig.json
23+
echo " \"module\": \"commonjs\"," >> ./tsconfig.json
24+
echo " \"esModuleInterop\": true," >> ./tsconfig.json
25+
echo " \"forceConsistentCasingInFileNames\": true," >> ./tsconfig.json
26+
echo " \"strict\": true," >> ./tsconfig.json
27+
echo " \"skipLibCheck\": true," >> ./tsconfig.json
28+
echo " \"outDir\": \"./dist\"" >> ./tsconfig.json
29+
echo " }," >> ./tsconfig.json
30+
echo " \"include\": [\"src\"]," >> ./tsconfig.json
31+
echo " \"exclude\": [\"node_modules\", \"dist\"]" >> ./tsconfig.json
32+
echo "}" >> ./tsconfig.json

.bin/set_code_formatting/index.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
3+
source ./.bin/set_code_formatting/_typescript.sh
4+
source ./.bin/set_code_formatting/_prettier.sh
5+
source ./.bin/set_code_formatting/_eslint.sh
6+
source ./.bin/set_code_formatting/_husky.sh
7+
source ./.bin/set_code_formatting/_lint-staged.sh
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
# Declare node version
4+
NODE_VERSION="v18.12.1"
5+
6+
# Set node version to package.json
7+
function set_attribute() {
8+
sed -ie "s/\"$2\": \"[.a-zA-Z0-9]*\"/\"$2\": \"$3\"/g" $1
9+
}
10+
set_attribute package.json node $NODE_VERSION

.bin/set_node_version/_npm.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
echo 'engine-strict=true' > .npmrc

.bin/set_node_version/_nvm.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
3+
# Create nvm config file
4+
echo "$NODE_VERSION" > .nvmrc
5+
6+
# Set nvm path
7+
unset PREFIX
8+
. ~/.nvm/nvm.sh
9+
10+
# Set node version
11+
nvm install $NODE_VERSION
12+
nvm use

.bin/set_node_version/_yarn.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
echo '--install.ignore-engines false' > .yarnrc

.bin/set_node_version/index.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
source ./.bin/set_node_version/_node_version.sh
4+
source ./.bin/set_node_version/_npm.sh
5+
source ./.bin/set_node_version/_yarn.sh
6+
source ./.bin/set_node_version/_nvm.sh

0 commit comments

Comments
 (0)