Skip to content

Instantly share code, notes, and snippets.

@VictorQueiroz
Last active January 25, 2026 20:59
Show Gist options
  • Select an option

  • Save VictorQueiroz/bde7fc01fc645bb98d0159306f25cb16 to your computer and use it in GitHub Desktop.

Select an option

Save VictorQueiroz/bde7fc01fc645bb98d0159306f25cb16 to your computer and use it in GitHub Desktop.
Script to create a TypeScript project with predefined subprojects.
root = true
[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
/node_modules
*.js
*.map
*.d.ts
tsconfig.tsbuildinfo
{
"tabWidth": 2,
"objectWrap": "collapse",
"proseWrap": "always",
"semi": true,
"printWidth": 70,
"trailingComma": "none",
"singleQuote": false,
"arrowParens": "avoid",
"quoteProps": "consistent",
"useTabs": false
}

Create TypeScript project

Run the script

gh gist view bde7fc01fc645bb98d0159306f25cb16 --filename create-typescript-project.sh --raw | bash
#!/bin/bash
gist_id=bde7fc01fc645bb98d0159306f25cb16
read_file() {
gh gist view "$gist_id" --filename "$1"
}
copy_gist_file(){
local file_name
file_name="$1"
if [[ -f "${file_name}" ]]; then
echo "${file_name} already exists. Skipping."
return 0
fi
read_file "${file_name}" > "${file_name}" || return 1
echo "Created ${file_name} from Gist ${gist_id}"
}
copy_files(){
copy_gist_file .prettierrc
copy_gist_file .editorconfig
copy_gist_file .gitignore
copy_gist_file tsconfig.base.json
}
main() {
# Create `.nvmrc` folder
node --version > .nvmrc || exit 1
# Set up `.prettierrc` and `.editorconfig` file
copy_files || exit 1
# 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
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 "$@"
}
main "$@" || exit 1
{
"compilerOptions": {
"incremental": true,
"composite": true,
"allowJs": false,
"checkJs": false,
"types": [],
"lib": [],
"strict": true,
"target": "esnext",
"module": "nodenext",
"moduleResolution": "nodenext",
"declaration": true,
"declarationMap": true,
"sourceMap": true,
},
"include": [],
"exclude": []
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment