Last active
November 26, 2025 16:51
-
-
Save VictorQueiroz/bde7fc01fc645bb98d0159306f25cb16 to your computer and use it in GitHub Desktop.
Script to create a TypeScript project with predefined subprojects.
This file contains hidden or 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
| #!/bin/bash | |
| create_indentation_files(){ | |
| echo '{' >> .prettierrc | |
| echo ' "tabWidth": 2,' >> .prettierrc | |
| echo ' "objectWrap": "collapse",' >> .prettierrc | |
| echo ' "proseWrap": "always",' >> .prettierrc | |
| echo ' "semi": true,' >> .prettierrc | |
| echo ' "printWidth": 70,' >> .prettierrc | |
| echo ' "trailingComma": "none",' >> .prettierrc | |
| echo ' "singleQuote": false,' >> .prettierrc | |
| echo ' "arrowParens": "avoid",' >> .prettierrc | |
| echo ' "quoteProps": "consistent",' >> .prettierrc | |
| echo ' "useTabs": false' >> .prettierrc | |
| echo '}' >> .prettierrc | |
| echo 'root = true' >> .editorconfig | |
| echo '' >> .editorconfig | |
| echo '[*]' >> .editorconfig | |
| echo 'indent_style = space' >> .editorconfig | |
| echo 'indent_size = 2' >> .editorconfig | |
| echo 'end_of_line = lf' >> .editorconfig | |
| echo 'charset = utf-8' >> .editorconfig | |
| echo 'trim_trailing_whitespace = true' >> .editorconfig | |
| echo 'insert_final_newline = true' >> .editorconfig | |
| } | |
| main() { | |
| # Create `.nvmrc` folder | |
| node --version > .nvmrc || exit 1 | |
| # Create `.gitignore` folder | |
| echo '/node_modules' >> .gitignore | |
| echo '*.js' >> .gitignore | |
| echo '*.map' >> .gitignore | |
| echo '*.d.ts' >> .gitignore | |
| echo 'tsconfig.tsbuildinfo' >> .gitignore | |
| # TypeScript projects since the root folder | |
| local -a typescript_projects | |
| typescript_projects=( | |
| src | |
| test | |
| ) | |
| local -a development_dependencies | |
| development_dependencies=( | |
| semver | |
| tsx | |
| typescript | |
| eslint | |
| prettier | |
| ) | |
| local base_tsconfig_path | |
| base_tsconfig_path="tsconfig.base.json" | |
| # Install development dependencies | |
| npm install --save-dev "${development_dependencies[@]}" | |
| local get_current_node_major_version_args | |
| get_current_node_major_version_args=( | |
| -p 'require("semver").parse(process.argv[1]).major' | |
| "$(node --version)" | |
| ) | |
| local node_major_version | |
| node_major_version="$(node "${get_current_node_major_version_args[@]}" || exit 1)" | |
| # Install type definitions for Node.js | |
| npm install -D '@types/node@'"^${node_major_version}" | |
| # Create `tsconfig.json` | |
| npx tsc --init || exit 1 | |
| # Rename `tsconfig.json` to `tsconfig.defaults.json` | |
| mv --verbose tsconfig.json tsconfig.defaults.json | |
| # Create `tsconfig.base.json` | |
| echo '{ "compilerOptions": { "incremental": true, "composite": true, "allowJs": false, "checkJs": false, "types": [], "lib": [], "strict": true }, "include": [], "exclude": [] }' > "${base_tsconfig_path}" | |
| for project_folder in "${typescript_projects[@]}"; do | |
| mkdir --parents --verbose "${project_folder}" | |
| local project_relative_base_tsconfig_path | |
| project_relative_base_tsconfig_path="$(realpath --canonicalize-existing --relative-to "${project_folder}" "${base_tsconfig_path}")" | |
| # Create tsconfig.json | |
| echo "{ \"extends\": \"${project_relative_base_tsconfig_path}\" }" > "${project_folder}/tsconfig.json" | |
| # Create `index.ts` | |
| echo 'export default 1;' > "${project_folder}/index.ts" | |
| done | |
| # Install production dependencies | |
| npm install --save "$@" | |
| # Set up `.prettierrc` and `.editorconfig` file | |
| create_indentation_files || exit 1 | |
| } | |
| main "$@" || exit 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment