diff --git a/config/default.json b/config/default.json index 39c28fa..21863dd 100644 --- a/config/default.json +++ b/config/default.json @@ -182,7 +182,7 @@ "$ref": "#/files/paths/tests" }, { - "$ref": "#/files/paths/vitestconfig" + "$ref": "#/files/paths/vitestconfigts" }, { "$ref": "#/files/paths/changelog" @@ -270,6 +270,15 @@ }, { "$ref": "#/files/paths/releaserc" + }, + { + "$ref": "#/files/paths/tests" + }, + { + "$ref": "#/files/paths/eslintrc" + }, + { + "$ref": "#/files/paths/vitestconfigjs" } ] }, @@ -752,10 +761,14 @@ "from": "scripts", "to": "scripts" }, - "vitestconfig": { + "vitestconfigts": { "from": "vitest.config.ts", "to": "vitest.config.ts" }, + "vitestconfigjs": { + "from": "vitest.config.js", + "to": "vitest.config.js" + }, "aliveserver": { "from": "alive-server.json", "to": ".alive-server.json" diff --git a/templates/javascript/changelogrc.json b/templates/javascript/changelogrc.json index 2ce8bc1..5ea4b6a 100644 --- a/templates/javascript/changelogrc.json +++ b/templates/javascript/changelogrc.json @@ -1,13 +1,51 @@ { "header": "Changelog", "types": [ - { "type": "feat", "section": "๐ŸŒŸ Features" }, - { "type": "fix", "section": "๐Ÿ› Bug Fixes" }, - { "type": "chore", "hidden": true }, - { "type": "docs", "section": "๐Ÿ“– Documentation" }, - { "type": "style", "hidden": true }, - { "type": "refactor", "hidden": true }, - { "type": "perf", "section": "๐Ÿš€ Performance" }, - { "type": "test", "hidden": true } + { + "type": "feat", + "section": "๐ŸŒŸ Features", + "hidden": false + }, + { + "type": "fix", + "section": "๐Ÿ› Bug Fixes", + "hidden": false + }, + { + "type": "chore", + "section": "๐Ÿงฐ Chores", + "hidden": false + }, + { + "type": "docs", + "section": "๐Ÿ“– Documentation", + "hidden": false + }, + { + "type": "style", + "section": "๐Ÿ’… Style", + "hidden": false + }, + { + "type": "refactor", + "section": "โœจ Refactor", + "hidden": false + }, + { + "type": "perf", + "section": "๐Ÿš€ Performance", + "hidden": false + }, + { + "type": "test", + "section": "๐Ÿงช Tests", + "hidden": false + }, + { + "type": "build", + "section": "๐Ÿ› ๏ธ Build", + "hidden": false + }, + { "type": "ci", "section": "๐Ÿค– CI", "hidden": false } ] } diff --git a/templates/javascript/eslintrc.json b/templates/javascript/eslintrc.json new file mode 100644 index 0000000..c309d11 --- /dev/null +++ b/templates/javascript/eslintrc.json @@ -0,0 +1,12 @@ +{ + "root": true, + "env": { + "node": true, + "browser": true + }, + "extends": ["eslint:recommended", "prettier"], + "parserOptions": { + "ecmaVersion": "latest", + "sourceType": "module" + } +} diff --git a/templates/javascript/gitattributes b/templates/javascript/gitattributes index 176a458..996deab 100644 --- a/templates/javascript/gitattributes +++ b/templates/javascript/gitattributes @@ -1 +1,217 @@ -* text=auto +## GITATTRIBUTES FOR WEB PROJECTS +# +# These settings are for any web project. +# +# Details per file setting: +# text These files should be normalized (i.e. convert CRLF to LF). +# binary These files are binary and should be left untouched. +# +# Note that binary is a macro for -text -diff. +###################################################################### + +# Auto detect +## Handle line endings automatically for files detected as +## text and leave all files detected as binary untouched. +## This will handle all files NOT defined below. +* text=auto + +# Source code +*.bash text eol=lf +*.bat text eol=crlf +*.cmd text eol=crlf +*.coffee text +*.css text diff=css +*.htm text diff=html +*.html text diff=html +*.inc text +*.ini text +*.js text +*.mjs text +*.cjs text +*.json text +*.jsx text +*.less text +*.ls text +*.map text -diff +*.od text +*.onlydata text +*.php text diff=php +*.pl text +*.ps1 text eol=crlf +*.py text diff=python +*.rb text diff=ruby +*.sass text +*.scm text +*.scss text diff=css +*.sh text eol=lf +.husky/* text eol=lf +*.sql text +*.styl text +*.tag text +*.ts text +*.tsx text +*.xml text +*.xhtml text diff=html + +# Docker +Dockerfile text + +# Documentation +*.ipynb text eol=lf +*.markdown text diff=markdown +*.md text diff=markdown +*.mdwn text diff=markdown +*.mdown text diff=markdown +*.mkd text diff=markdown +*.mkdn text diff=markdown +*.mdtxt text +*.mdtext text +*.txt text +AUTHORS text +CHANGELOG text +CHANGES text +CONTRIBUTING text +COPYING text +copyright text +*COPYRIGHT* text +INSTALL text +license text +LICENSE text +NEWS text +readme text +*README* text +TODO text + +# Templates +*.dot text +*.ejs text +*.erb text +*.haml text +*.handlebars text +*.hbs text +*.hbt text +*.jade text +*.latte text +*.mustache text +*.njk text +*.phtml text +*.svelte text +*.tmpl text +*.tpl text +*.twig text +*.vue text + +# Configs +*.cnf text +*.conf text +*.config text +.editorconfig text +.env text +.gitattributes text +.gitconfig text +.htaccess text +*.lock text -diff +package.json text eol=lf +package-lock.json text eol=lf -diff +pnpm-lock.yaml text eol=lf -diff +.prettierrc text +yarn.lock text -diff +*.toml text +*.yaml text +*.yml text +browserslist text +Makefile text +makefile text +# Fixes syntax highlighting on GitHub to allow comments +tsconfig.json linguist-language=JSON-with-Comments + +# Heroku +Procfile text + +# Graphics +*.ai binary +*.bmp binary +*.eps binary +*.gif binary +*.gifv binary +*.ico binary +*.jng binary +*.jp2 binary +*.jpg binary +*.jpeg binary +*.jpx binary +*.jxr binary +*.pdf binary +*.png binary +*.psb binary +*.psd binary +# SVG treated as an asset (binary) by default. +*.svg text +# If you want to treat it as binary, +# use the following line instead. +# *.svg binary +*.svgz binary +*.tif binary +*.tiff binary +*.wbmp binary +*.webp binary + +# Audio +*.kar binary +*.m4a binary +*.mid binary +*.midi binary +*.mp3 binary +*.ogg binary +*.ra binary + +# Video +*.3gpp binary +*.3gp binary +*.as binary +*.asf binary +*.asx binary +*.avi binary +*.fla binary +*.flv binary +*.m4v binary +*.mng binary +*.mov binary +*.mp4 binary +*.mpeg binary +*.mpg binary +*.ogv binary +*.swc binary +*.swf binary +*.webm binary + +# Archives +*.7z binary +*.gz binary +*.jar binary +*.rar binary +*.tar binary +*.zip binary + +# Fonts +*.ttf binary +*.eot binary +*.otf binary +*.woff binary +*.woff2 binary + +# Executables +*.exe binary +*.pyc binary +# Prevents massive diffs caused by vendored, minified files +**/.yarn/releases/** binary +**/.yarn/plugins/** binary + +# RC files (like .babelrc or .eslintrc) +*.*rc text + +# Ignore files (like .npmignore or .gitignore) +*.*ignore text + +# Prevents massive diffs from built files +dist/* binary diff --git a/templates/javascript/github/workflows/main.yml b/templates/javascript/github/workflows/main.yml index d0e2387..d7bf402 100644 --- a/templates/javascript/github/workflows/main.yml +++ b/templates/javascript/github/workflows/main.yml @@ -1,17 +1,83 @@ name: CI -on: [push] +on: + push: + branches: [master] + + pull_request: + branches: [master] + + workflow_dispatch: jobs: build: - name: Build on ${{ matrix.os }} + name: Build on ${{ matrix.os }} and Node.js ${{ matrix.node-version }} runs-on: ${{ matrix.os }} strategy: matrix: os: [ubuntu-latest, macOS-latest, windows-latest] + node-version: ["18.x", "20.x"] + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + persist-credentials: false + + - name: Setup PNPM + uses: pnpm/action-setup@v3 + with: + version: 8 + + - name: Setup Node.js + uses: actions/setup-node@v2 + with: + node-version: ${{ matrix.node-version }} + cache: "pnpm" + + - name: Install + run: pnpm install + + - name: Lint + run: pnpm lint + + - name: Test + run: pnpm test + + release: + name: Release + + if: github.ref == 'refs/heads/master' + + needs: [build] + + runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 + with: + fetch-depth: 0 + persist-credentials: false + + - name: Setup PNPM + uses: pnpm/action-setup@v3 + with: + version: 8 + + - name: Setup Node.js + uses: actions/setup-node@v2 + with: + node-version-file: .nvmrc + cache: "pnpm" + + - name: Install + run: pnpm install + + - name: Release + run: pnpm semantic-release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/templates/javascript/gitignore b/templates/javascript/gitignore index f8d4024..7ee40ba 100644 --- a/templates/javascript/gitignore +++ b/templates/javascript/gitignore @@ -5,6 +5,7 @@ npm-debug.log* yarn-debug.log* yarn-error.log* lerna-debug.log* +.pnpm-debug.log* # Diagnostic reports (https://nodejs.org/api/report.html) report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json @@ -41,8 +42,8 @@ build/Release node_modules/ jspm_packages/ -# TypeScript v1 declaration files -typings/ +# Snowpack dependency directory (https://snowpack.dev/) +web_modules/ # TypeScript cache *.tsbuildinfo @@ -53,6 +54,9 @@ typings/ # Optional eslint cache .eslintcache +# Optional stylelint cache +.stylelintcache + # Microbundle cache .rpt2_cache/ .rts2_cache_cjs/ @@ -68,15 +72,20 @@ typings/ # Yarn Integrity file .yarn-integrity -# dotenv environment variables file +# dotenv environment variable files .env -.env.test +.env.development.local +.env.test.local +.env.production.local +.env.local # parcel-bundler cache (https://parceljs.org/) .cache +.parcel-cache # Next.js build output .next +out # Nuxt.js build / generate output .nuxt @@ -84,13 +93,20 @@ dist # Gatsby files .cache/ -# Comment in the public line in if your project uses Gatsby and *not* Next.js +# Comment in the public line in if your project uses Gatsby and not Next.js # https://nextjs.org/blog/next-9-1#public-directory-support # public # vuepress build output .vuepress/dist +# vuepress v2.x temp and cache directory +.temp +.cache + +# Docusaurus cache and generated files +.docusaurus + # Serverless directories .serverless/ @@ -103,5 +119,14 @@ dist # TernJS port file .tern-port -# Local history +# Stores VSCode versions used for testing VSCode extensions +.vscode-test + +# yarn v2 +.yarn/cache +.yarn/unplugged +.yarn/build-state.yml +.yarn/install-state.gz +.pnp.* + .history/ diff --git a/templates/javascript/lintstagedrc.json b/templates/javascript/lintstagedrc.json index 81340b7..737f65a 100644 --- a/templates/javascript/lintstagedrc.json +++ b/templates/javascript/lintstagedrc.json @@ -1,4 +1,4 @@ { - "*?(test|spec).{js,jsx,ts,tsx}": ["prettier --write"], + "*?(test|spec).{js,jsx,ts,tsx}": ["eslint --fix", "prettier --write"], "*.{css,scss,md,html,json,yml,yaml}": ["prettier --write"] } diff --git a/templates/javascript/package.json.ejs b/templates/javascript/package.json.ejs index 816795a..174d91b 100644 --- a/templates/javascript/package.json.ejs +++ b/templates/javascript/package.json.ejs @@ -15,6 +15,7 @@ }, "scripts": { "commit": "git-cz", + "lint": "eslint . --fix", "pretty:fix": "prettier --write .", "start": "cross-env NODE_ENV=production node src/app.js", "dev": "nodemon src/app.js", @@ -38,6 +39,8 @@ <%- node.getDevDependency("cross-env") %>, <%- node.getDevDependency("cz-conventional-changelog") %>, <%- node.getDevDependency("doctoc") %>, + <%- node.getDevDependency("eslint") %>, + <%- node.getDevDependency("eslint-config-prettier") %>, <%- node.getDevDependency("husky") %>, <%- node.getDevDependency("lint-staged") %>, <%- node.getDevDependency("nodemon") %>, diff --git a/templates/javascript/releaserc.json b/templates/javascript/releaserc.json index c70cd9b..38b6d68 100644 --- a/templates/javascript/releaserc.json +++ b/templates/javascript/releaserc.json @@ -32,14 +32,52 @@ "presetConfig": { "header": "Changelog", "types": [ - { "type": "feat", "section": "๐ŸŒŸ Features" }, - { "type": "fix", "section": "๐Ÿ› Bug Fixes" }, - { "type": "chore", "hidden": true }, - { "type": "docs", "section": "๐Ÿ“– Documentation" }, - { "type": "style", "hidden": true }, - { "type": "refactor", "section": "โœจ Refactor" }, - { "type": "perf", "section": "๐Ÿš€ Performance" }, - { "type": "test", "hidden": true } + { + "type": "feat", + "section": "๐ŸŒŸ Features", + "hidden": false + }, + { + "type": "fix", + "section": "๐Ÿ› Bug Fixes", + "hidden": false + }, + { + "type": "chore", + "section": "๐Ÿงฐ Chores", + "hidden": false + }, + { + "type": "docs", + "section": "๐Ÿ“– Documentation", + "hidden": false + }, + { + "type": "style", + "section": "๐Ÿ’… Style", + "hidden": false + }, + { + "type": "refactor", + "section": "โœจ Refactor", + "hidden": false + }, + { + "type": "perf", + "section": "๐Ÿš€ Performance", + "hidden": false + }, + { + "type": "test", + "section": "๐Ÿงช Tests", + "hidden": false + }, + { + "type": "build", + "section": "๐Ÿ› ๏ธ Build", + "hidden": false + }, + { "type": "ci", "section": "๐Ÿค– CI", "hidden": false } ] } } @@ -50,7 +88,12 @@ "changelogTitle": "# Changelog" } ], - "@semantic-release/npm", + [ + "@semantic-release/npm", + { + "npmPublish": false + } + ], [ "@semantic-release/git", { diff --git a/templates/javascript/src/app.js b/templates/javascript/src/app.js index 8b4947b..8d01919 100644 --- a/templates/javascript/src/app.js +++ b/templates/javascript/src/app.js @@ -1,3 +1,7 @@ import "dotenv/config"; -console.log("Hello, World!"); +export function helloWorld() { + return "Hello, World!"; +} + +console.log(helloWorld()); diff --git a/templates/javascript/tests/app.test.js b/templates/javascript/tests/app.test.js new file mode 100644 index 0000000..9b2505b --- /dev/null +++ b/templates/javascript/tests/app.test.js @@ -0,0 +1,12 @@ +import { describe, it, expect } from "vitest"; +import { helloWorld } from "../src/app.js"; + +describe("app", () => { + it("should return 'Hello, World!'", () => { + expect(helloWorld()).toBe("Hello, World!"); + }); + + it("should always pass", () => { + expect(true).toBe(true); + }); +}); diff --git a/templates/javascript/vitest.config.js b/templates/javascript/vitest.config.js new file mode 100644 index 0000000..90d7a00 --- /dev/null +++ b/templates/javascript/vitest.config.js @@ -0,0 +1,12 @@ +import { defineConfig } from "vitest/config"; + +export default defineConfig({ + test: { + environment: "node", + testTimeout: 60000, + resolveSnapshotPath(path, extension) { + return path + extension; + }, + include: ["tests/**/*.test.js"], + }, +}); diff --git a/templates/javascript/vscode/extensions.json b/templates/javascript/vscode/extensions.json index 7d0492d..4078e5f 100644 --- a/templates/javascript/vscode/extensions.json +++ b/templates/javascript/vscode/extensions.json @@ -1,3 +1,9 @@ { - "recommendations": ["editorconfig.editorconfig", "esbenp.prettier-vscode"] + "recommendations": [ + "editorconfig.editorconfig", + "dbaeumer.vscode-eslint", + "esbenp.prettier-vscode", + "github.vscode-github-actions", + "vitest.explorer" + ] } diff --git a/templates/javascript/vscode/launch.json b/templates/javascript/vscode/launch.json new file mode 100644 index 0000000..5aa959f --- /dev/null +++ b/templates/javascript/vscode/launch.json @@ -0,0 +1,15 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "launch", + "name": "Launch Program", + "skipFiles": ["/**"], + "program": "${workspaceFolder}/src/app.js" + } + ] +} diff --git a/tests/javascript.test.ts b/tests/javascript.test.ts index 782af02..8b3c205 100644 --- a/tests/javascript.test.ts +++ b/tests/javascript.test.ts @@ -32,6 +32,8 @@ const devDependencies = [ "cross-env", "cz-conventional-changelog", "doctoc", + "eslint", + "eslint-config-prettier", "husky", "lint-staged", "nodemon", @@ -47,13 +49,16 @@ const files = [ ".husky/commit-msg", ".husky/pre-commit", ".vscode/extensions.json", + ".vscode/launch.json", ".vscode/settings.json", "src/app.js", + "tests/app.test.js", ".all-contributorsrc", ".changelogrc.json", ".commitlintrc.json", ".czrc", ".editorconfig", + ".eslintrc.json", ".gitattributes", ".gitignore", ".lintstagedrc.json", @@ -69,6 +74,7 @@ const files = [ "LICENSE", "package.json", "README.md", + "vitest.config.js", ]; describe("generator-norgate-av:javascript", () => {