diff --git a/.github/workflows/delete_development.yml b/.github/workflows/delete_development.yml new file mode 100644 index 0000000..637078b --- /dev/null +++ b/.github/workflows/delete_development.yml @@ -0,0 +1,19 @@ +name: delete_development +on: + workflow_dispatch: +env: + COMPONENT_NAME: ${{ github.event.repository.name }} +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Configure AWS Credentials + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-access-key-id: ${{ vars.TOOLKIT_AWS_ACCESS_KEY }} + aws-secret-access-key: ${{ secrets.TOOLKIT_AWS_ACCESS_SECRET }} + aws-region: us-east-2 + - name: Delete S3 bucket + run: aws s3 rm s3://dev.toolkit.illinois.edu/content/$COMPONENT_NAME --recursive + - name: Invalidate Cloudfront cache + run: aws cloudfront create-invalidation --distribution-id ${{ vars.TOOLKIT_AWS_CLOUDFRONT_DEV }} --paths "/$COMPONENT_NAME*" \ No newline at end of file diff --git a/.github/workflows/deploy_development.yml b/.github/workflows/deploy_development.yml new file mode 100644 index 0000000..00660b9 --- /dev/null +++ b/.github/workflows/deploy_development.yml @@ -0,0 +1,38 @@ +name: deploy_development +on: + workflow_dispatch: + inputs: + version: + description: 'Version number' + required: true + default: '' + type: string +env: + MAJORVERSION: '' + COMPONENT_NAME: ${{ github.event.repository.name }} +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: 'Checkout GitHub Action' + uses: actions/checkout@v4 + - name: Get version from input + run: echo "VERSION=${GITHUB_BRANCH}" >> $GITHUB_ENV + env: + GITHUB_BRANCH: ${{ github.event.inputs.version }} + - name: Display version install + run: echo "Installing dev version ${VERSION}" + + - run: npm install + - run: npm rebuild + - run: npm run-script build + - name: Configure AWS Credentials + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-access-key-id: ${{ vars.TOOLKIT_AWS_ACCESS_KEY }} + aws-secret-access-key: ${{ secrets.TOOLKIT_AWS_ACCESS_SECRET }} + aws-region: us-east-2 + - name: Deploy toolbox to S3 bucket + run: aws s3 sync ./dist/ s3://dev.toolkit.illinois.edu/content/$COMPONENT_NAME/$VERSION --delete --acl bucket-owner-full-control + - name: Invalidate Cloudfront cache + run: aws cloudfront create-invalidation --distribution-id ${{ vars.TOOLKIT_AWS_CLOUDFRONT_DEV }} --paths "/$COMPONENT_NAME/$VERSION*" \ No newline at end of file diff --git a/.github/workflows/deploy_production.yml b/.github/workflows/deploy_production.yml new file mode 100644 index 0000000..167dd2b --- /dev/null +++ b/.github/workflows/deploy_production.yml @@ -0,0 +1,64 @@ +name: deploy_production +on: + push: + tags: [ '**' ] +env: + MAJORVERSION: '' + MINORVERSION: '' + FULLVERSION: '' + COMPONENT_NAME: ${{ github.event.repository.name }} +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: 'Checkout GitHub Action' + uses: actions/checkout@v4 + - name: 'Get Version' + id: get_version + uses: battila7/get-version-action@v2 + + - name: 'Check for correct naming convention' + if: ${{ !steps.get_version.outputs.is-semver }} + run: exit 1 + - name: 'Get major version from tag' + run: echo "MAJORVERSION=${GITHUB_BRANCH}" >> $GITHUB_ENV + env: + GITHUB_BRANCH: ${{ steps.get_version.outputs.major }} + - name: 'Get minor version from tag' + run: echo "MINORVERSION=${GITHUB_BRANCH}.${GITHUB_BRANCH_MINOR}" >> $GITHUB_ENV + env: + GITHUB_BRANCH: ${{ steps.get_version.outputs.major }} + GITHUB_BRANCH_MINOR: ${{ steps.get_version.outputs.minor }} + - name: Get patch (full) version from tag + run: echo "FULLVERSION=${GITHUB_BRANCH}" >> $GITHUB_ENV + env: + GITHUB_BRANCH: ${{ steps.get_version.outputs.version-without-v }} + - name: Display major version install + run: echo "Installing major version ${MAJORVERSION}" + - name: Display minor version install + run: echo "Installing minor version ${MINORVERSION}" + - name: Display patch (full) version install + run: echo "Installing patch (full) version ${FULLVERSION}" + + - run: npm install + - run: npm rebuild + - run: npm run-script build + - name: Configure AWS Credentials + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-access-key-id: ${{ vars.TOOLKIT_AWS_ACCESS_KEY }} + aws-secret-access-key: ${{ secrets.TOOLKIT_AWS_ACCESS_SECRET }} + aws-region: us-east-2 + + - name: Deploy toolbox to S3 bucket for major version + run: aws s3 sync ./dist/ s3://cdn.toolkit.illinois.edu/content/$COMPONENT_NAME/$MAJORVERSION --delete --acl bucket-owner-full-control + - name: Invalidate Cloudfront cache for major version + run: aws cloudfront create-invalidation --distribution-id ${{ vars.TOOLKIT_AWS_CLOUDFRONT }} --paths "/$COMPONENT_NAME/$MAJORVERSION*" + - name: Deploy toolbox to S3 bucket for minor version + run: aws s3 sync ./dist/ s3://cdn.toolkit.illinois.edu/content/$COMPONENT_NAME/$MINORVERSION --delete --acl bucket-owner-full-control + - name: Invalidate Cloudfront cache for minor version + run: aws cloudfront create-invalidation --distribution-id ${{ vars.TOOLKIT_AWS_CLOUDFRONT }} --paths "/$COMPONENT_NAME/$MINORVERSION*" + - name: Deploy toolbox to S3 bucket for patch (full) version + run: aws s3 sync ./dist/ s3://cdn.toolkit.illinois.edu/content/$COMPONENT_NAME/$FULLVERSION --delete --acl bucket-owner-full-control + - name: Invalidate Cloudfront cache for patch (full) version + run: aws cloudfront create-invalidation --distribution-id ${{ vars.TOOLKIT_AWS_CLOUDFRONT }} --paths "/$COMPONENT_NAME/$FULLVERSION*" \ No newline at end of file diff --git a/.github/workflows/deploy_production_manual.yml b/.github/workflows/deploy_production_manual.yml new file mode 100644 index 0000000..252cdca --- /dev/null +++ b/.github/workflows/deploy_production_manual.yml @@ -0,0 +1,41 @@ +name: deploy_production_manual +on: + workflow_dispatch: + inputs: + version: + description: 'Version number' + required: true + default: '' + type: string +env: + MAJORVERSION: '' + MINORVERSION: '' + FULLVERSION: '' + COMPONENT_NAME: ${{ github.event.repository.name }} +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: 'Checkout GitHub Action' + uses: actions/checkout@v4 + - name: Get version from input + run: echo "VERSION=${GITHUB_BRANCH}" >> $GITHUB_ENV + env: + GITHUB_BRANCH: ${{ github.event.inputs.version }} + - name: Display version install + run: echo "Installing production version ${VERSION}" + + - run: npm install + - run: npm rebuild + - run: npm run-script build + - name: Configure AWS Credentials + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-access-key-id: ${{ vars.TOOLKIT_AWS_ACCESS_KEY }} + aws-secret-access-key: ${{ secrets.TOOLKIT_AWS_ACCESS_SECRET }} + aws-region: us-east-2 + + - name: Deploy toolbox to S3 bucket for version + run: aws s3 sync ./dist/ s3://cdn.toolkit.illinois.edu/content/$COMPONENT_NAME/$VERSION --delete --acl bucket-owner-full-control + - name: Invalidate Cloudfront cache for version + run: aws cloudfront create-invalidation --distribution-id ${{ vars.TOOLKIT_AWS_CLOUDFRONT }} --paths "/$COMPONENT_NAME/$VERSION*" diff --git a/.github/workflows/templating.yml b/.github/workflows/templating.yml new file mode 100644 index 0000000..d3dd39c --- /dev/null +++ b/.github/workflows/templating.yml @@ -0,0 +1,31 @@ +name: Apply caz templating + +on: [push] + +jobs: + run-caz: + # Avoid running more than once + if: ${{ github.repository != 'web-illinois/toolkit-template' && github.repository != 'marvel-uiuc/template-ilw' && github.run_number == 1 }} + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + ref: ${{ github.head_ref }} + - uses: actions/setup-node@v4 + with: + node-version: 20 + - name: Apply caz template + run: npx -y caz ./ output --name ${{ github.event.repository.name }} --repository ${{ github.repository }} + - name: Commit template changes + run: | + git config user.name 'github-actions[bot]' + git config user.email 'github-actions[bot]@users.noreply.github.com' + rm -rf template index.js .gitignore package-lock.json README.md + cp -rT output . + rm -rf output + git add -A + git commit -a -m "chore: init template" + git push --force \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6f50b0d --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.idea/ +/package-lock.json \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..3c1a82d --- /dev/null +++ b/README.md @@ -0,0 +1,55 @@ +# Toolkit Template + +Repository template for creating a new Web Component, specifically +tailored to be part of the +[Web at Illinois](https://github.com/web-illinois) Web Implementation +Guidelines Group (WIGG) [Toolkit](https://github.com/web-illinois/toolkit-management). + +## How To Use + +> [!IMPORTANT] +> Follow the [steps in the toolkit-management documentation](https://github.com/web-illinois/toolkit-management/blob/main/documentation/README.md) +> to contribute a component to the toolkit. + +## How this template works + +The content that will be in the resulting repository is templated under +the [`template`](./template) directory. The templating is configured +in [`index.js`](./index.js), and uses a simple scaffolding tool called +[CAZ](https://github.com/zce/caz). + +There is a [templating GitHub Workflow](./.github/workflows/templating.yml) in this +repository that's configured to run only once when the template is used. +That workflow executes CAZ to scaffold the repository to the proper contents +with the naming determined by the new repository's name. + +CAZ accepts input using "prompts", which can be specified in the command +line invocation of the tool. The workflow specifies the values to those +prompts, and CAZ takes care of the rest. + +Finally, the workflow commits the changes to the new repository. This usually +takes less than 10 seconds. Once done, the repository is ready to be worked on. + +## Developing this template + +### Adding files + +New files can be added to the [`template`](./template) directory, and they +are automatically picked up. + +- Substitutions in file names happen with curly braces, `{variable}` +- Inside files, [lodash](https://lodash.com/docs#template) templates are used, + which uses `<%= variable %>` as delimiters. + +> [!NOTE] +> GitHub Workflows cannot be templated, and so must be entirely dynamic +> and contained in the main [`.github/workflows`](./.github/workflows) directory. + +### Adding Variables + +If additional variables are needed, they must be added in two locations: + +1. In [`index.js`](./index.js) as prompts. +2. In the [workflow](./.github/workflows/templating.yml), they need to be + given values as arguments for the `caz` command. + diff --git a/index.js b/index.js new file mode 100644 index 0000000..189d9d2 --- /dev/null +++ b/index.js @@ -0,0 +1,27 @@ +const path = require("path"); + +const date = new Date(); + +/** @type {import('caz').Template} */ +module.exports = { + name: "template-ilw", + metadata: { + year: date.getFullYear(), + month: String(date.getMonth() + 1).padStart(2, "0"), + day: String(date.getDate()).padStart(2, "0"), + }, + prompts: [ + { + name: "name", + type: "text", + message: "Project name", + }, + { + name: "repository", + type: "text", + message: "Repository", + }, + ], + init: false, + install: false +}; diff --git a/template/.gitignore b/template/.gitignore new file mode 100644 index 0000000..54f07af --- /dev/null +++ b/template/.gitignore @@ -0,0 +1,24 @@ +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +pnpm-debug.log* +lerna-debug.log* + +node_modules +dist +dist-ssr +*.local + +# Editor directories and files +.vscode/* +!.vscode/extensions.json +.idea +.DS_Store +*.suo +*.ntvs* +*.njsproj +*.sln +*.sw? \ No newline at end of file diff --git a/template/README.md b/template/README.md new file mode 100644 index 0000000..11e9ccf --- /dev/null +++ b/template/README.md @@ -0,0 +1,28 @@ +# <%= name %> + +Links: **[<%= name %> in Builder](https://builder3.toolkit.illinois.edu/component/<%= name %>/index.html)** | +[Illinois Web Theme](https://webtheme.illinois.edu/) | +[Toolkit Development](https://github.com/web-illinois/toolkit-management) + +## Overview + +A 1-3 paragraph explanation of what the component does and how it presents. + +## Code Examples + +```html +<<%= name %>>> +``` + +## Accessibility Notes and Use + +Consider accessibility, both for building the component and for its use: + +- Is there sufficient color contrast? +- Can the component be fully understood without colors? +- Does the component need alt text or ARIA roles? +- Can the component be navigated with a keyboard? Is the tab order correct? +- Are focusable elements interactive, and interactive elements focusable? +- Are form fields, figures, fieldsets and other interactive elements labelled? + +## External References diff --git a/template/builder/versions/{name}.1.0.0-alpha.json b/template/builder/versions/{name}.1.0.0-alpha.json new file mode 100644 index 0000000..571a59e --- /dev/null +++ b/template/builder/versions/{name}.1.0.0-alpha.json @@ -0,0 +1,41 @@ +{ + "title": "<%= _.startCase(name.slice(4)) %>", + "tag": "<%= name %>", + "github": "https://github.com/web-illinois/<%= name %>/", + "type": "web component", + "element-name": "<%= name %>", + "description": "Description for builder.", + "version": "1.0.0-alpha", + "date": "<%= month %>/<%= day %>/<%= year %>", + "css": "https://dev.toolkit.illinois.edu/<%= name %>/1.0.0-alpha/<%= name %>.css", + "js": "https://dev.toolkit.illinois.edu/<%= name %>/1.0.0-alpha/<%= name %>.js", + "production": false, + "notes": "", + "parent-style": "", + "samples": [ + { + "name": "default", + "description": "Default information", + "text": "

Lorem ipsum

" + } + ], + "attributes-fixed": [], + "attributes-text": [], + "attributes": [ + { + "name": "theme", + "description": "Color theme used", + "depreciated": false, + "values": [ + "", + "blue", + "orange", + "white" + ] + } + ], + "classes-fixed": [], + "classes": [], + "css-variables": [ + ] +} diff --git a/template/builder/{name}.json b/template/builder/{name}.json new file mode 100644 index 0000000..04ac2a1 --- /dev/null +++ b/template/builder/{name}.json @@ -0,0 +1,11 @@ +{ + "title": "<%= _.startCase(name.slice(4)) %>", + "tag": "<%= name %>", + "github": "https://github.com/web-illinois/<%= name %>/", + "type": "web component", + "element-name": "<%= name %>", + "description": "Description for builder.", + "toolkit-version": "", + "production-version": "", + "development-version": "1.0.0-alpha" +} \ No newline at end of file diff --git a/template/package.json b/template/package.json new file mode 100644 index 0000000..4b56ac2 --- /dev/null +++ b/template/package.json @@ -0,0 +1,24 @@ +{ + "name": "@illinois-toolkit/<%= name %>", + "description": "One paragraph description of the component.", + "repository": "github:<%= repository %>", + "private": false, + "version": "0.0.1", + "type": "module", + "exports": { + ".": { + "import": "./src/<%= name %>.js" + } + }, + "scripts": { + "dev": "vite", + "build": "vite build --config vite.build.config.js --emptyOutDir", + "preview": "vite preview" + }, + "dependencies": { + "lit": "3.1.3" + }, + "devDependencies": { + "vite": "^5.2.0" + } +} \ No newline at end of file diff --git a/template/samples/index.html b/template/samples/index.html new file mode 100644 index 0000000..11ecae5 --- /dev/null +++ b/template/samples/index.html @@ -0,0 +1,17 @@ + + + + + + + <%= _.startCase(name.slice(4)) %> Component + + + + + + +<<%= name %>>> + + + diff --git a/template/src/{name}.css b/template/src/{name}.css new file mode 100644 index 0000000..e69de29 diff --git a/template/src/{name}.js b/template/src/{name}.js new file mode 100644 index 0000000..cf2edb5 --- /dev/null +++ b/template/src/{name}.js @@ -0,0 +1,35 @@ +import { LitElement, html } from 'lit'; +import styles from './<%= name %>.styles'; +import './<%= name %>.css'; + +class <%= _.upperFirst(_.camelCase(name.slice(4))) %> extends LitElement { + + static get properties() { + return { + theme: { type: String, attribute: true } + }; + } + + static get styles() { + return styles; + } + + constructor() { + super(); + this.align = ''; + this.focus = ''; + this.shadow = false; + this.collapse = false; + this.theme = ''; + } + + render() { + return html` +
+ +
+ `; + } +} + +customElements.define('<%= name %>', <%= _.upperFirst(_.camelCase(name.slice(4))) %>); \ No newline at end of file diff --git a/template/src/{name}.styles.js b/template/src/{name}.styles.js new file mode 100644 index 0000000..9b256ee --- /dev/null +++ b/template/src/{name}.styles.js @@ -0,0 +1,5 @@ +import { css } from 'lit'; + +export default css` + +`; \ No newline at end of file diff --git a/template/vite.build.config.js b/template/vite.build.config.js new file mode 100644 index 0000000..fe1d4dd --- /dev/null +++ b/template/vite.build.config.js @@ -0,0 +1,25 @@ +import { defineConfig } from "vite"; + +// https://vitejs.dev/config/ +export default defineConfig({ + root: "src", + build: { + outDir: "../dist", + lib: { + name: "<%= name %>", + entry: "<%= name %>.js", + fileName: "<%= name %>", + formats: ["es", "cjs", "umd"], + }, + rollupOptions: { + output: { + assetFileNames: (chunkInfo) => { + if (chunkInfo.name === "style.css") return "<%= name %>.css"; + }, + }, + }, + }, + server: { + hmr: false, + }, +});