diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..e97bbd7 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,30 @@ +name: CI + +on: + push: + branches: ['main'] + pull_request: + branches: ['main'] + +jobs: + ci: + if: github.repository == 'skirtles-code/create-vue-lib' + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Install pnpm + uses: pnpm/action-setup@v4 + - name: Set up Node + uses: actions/setup-node@v4 + with: + node-version: 20 + cache: 'pnpm' + - name: Install dependencies + run: pnpm install + - name: Lint + run: pnpm run lint + - name: Type check + run: pnpm run type-check + - name: Build + run: pnpm run build diff --git a/packages/create-vue-lib/src/index.ts b/packages/create-vue-lib/src/index.ts index 37b7904..5d773bb 100644 --- a/packages/create-vue-lib/src/index.ts +++ b/packages/create-vue-lib/src/index.ts @@ -83,6 +83,7 @@ type Config = { includeEsLint: boolean includeEsLintStylistic: boolean includeVitest: boolean + includeGithubCi: boolean includeAtAliases: boolean includeTestVariable: boolean } @@ -268,6 +269,7 @@ async function init() { const includeDocs = await togglePrompt('Include VitePress for documentation?', true) const includeGithubPages = includeDocs && await togglePrompt('Include GitHub Pages config for documentation?') const includePlayground = await togglePrompt('Include playground application for development?', true) + const includeGithubCi = await togglePrompt('Include GitHub CI configuration?', !!githubPath) const includeExamples = await togglePromptIf(extended, 'Include example code?', true, 'Yes', 'No, just configs') const includeAtAliases = await togglePromptIf(extended, 'Configure @ as an alias for src?') const includeTestVariable = await togglePromptIf(extended, 'Configure global __TEST__ variable?') @@ -334,6 +336,7 @@ async function init() { includeEsLint, includeEsLintStylistic, includeVitest, + includeGithubCi, includeAtAliases, includeTestVariable } @@ -360,6 +363,10 @@ async function init() { copyTemplate('vitest', config) } + if (config.includeGithubCi) { + copyTemplate('ci', config) + } + console.log() console.log(`${bgGreen(bold(black('DONE')))} Project created`) console.log() diff --git a/packages/create-vue-lib/src/template/ci/config/.github/workflows/ci.yml.ejs b/packages/create-vue-lib/src/template/ci/config/.github/workflows/ci.yml.ejs new file mode 100644 index 0000000..9af5437 --- /dev/null +++ b/packages/create-vue-lib/src/template/ci/config/.github/workflows/ci.yml.ejs @@ -0,0 +1,38 @@ +name: CI + +on: + push: + branches: ['main'] + pull_request: + branches: ['main'] + +jobs: + ci: +<%_ if (config.githubPath) { _%> + if: github.repository == '<%- config.githubPath %>' +<%_ } _%> + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Install pnpm + uses: pnpm/action-setup@v4 + - name: Set up Node + uses: actions/setup-node@v4 + with: + node-version: 20 + cache: 'pnpm' + - name: Install dependencies + run: pnpm install +<%_ if (config.includeEsLint) { _%> + - name: Lint + run: pnpm run lint +<%_ } _%> + - name: Type check + run: pnpm run type-check + - name: Build + run: pnpm run build +<%_ if (config.includeVitest) { _%> + - name: Test + run: pnpm run test:unit +<%_ } _%> diff --git a/packages/docs/src/questions.md b/packages/docs/src/questions.md index 35c8a28..b826b93 100644 --- a/packages/docs/src/questions.md +++ b/packages/docs/src/questions.md @@ -50,6 +50,7 @@ Include VitePress for documentation? … No / Yes Include GitHub Pages config for documentation? … No / Yes Include playground application for development? … No / Yes + Include GitHub CI configuration? … No / Yes Include example code? … No, just configs / Yes Configure @ as an alias for src? … No / Yes Configure global __TEST__ variable? @@ -191,6 +192,14 @@ This isn't a playground in the same sense as the official Vue playground. Instea The playground application will use your library direct from the source code, without needing to build the library separately. This is usually beneficial, as it allows for quicker development and immediate feedback on changes. But it does make the playground slightly less representative of a real consuming application, as it isn't using the built files. +## Include GitHub CI configuration?{#include-github-ci} + +Continuous Integration (CI) is used to help catch problems as soon as they occur. + +This option will include a GitHub Actions configuration for a CI workflow. It will run the `lint`, `type-check`, `build` and `test:unit` targets from the `scripts` section of the root `package.json`. The workflow is triggered by any PRs opened against the `main` branch, as well as when changes are pushed to `main`. + +If a [GitHub path](#github-path) has been provided, the job will be configured so that it only runs for that specific fork. + ## Include example code?{#include-examples} :::info NOTE