diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..d8e085a --- /dev/null +++ b/.editorconfig @@ -0,0 +1,10 @@ +root = true + +[*] +indent_style = space +indent_size = 2 +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true +end_of_line = lf +max_line_length = null diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md new file mode 100644 index 0000000..8876950 --- /dev/null +++ b/.github/CONTRIBUTING.md @@ -0,0 +1,142 @@ +# Contributing + +:tada: First off, thanks for taking the time to contribute! + +The following is a set of guidelines for contributing to the `piral-cli-vite6` packages, which is hosted in the smapiot organization on GitHub. These are mostly guidelines, not rules. Use your best judgment, and feel free to propose changes to this document in a pull request. + +When contributing to this repository, please first discuss the change you wish to make via issue, email, or any other method with the owners of this repository before making a change. + +## Code of Conduct + +This project and everyone participating in it is governed by the [Code of Conduct](../CODE_OF_CONDUCT.md). By participating, you are expected to uphold this code. Please report unacceptable behavior to the email specified there. + +## How Can I Contribute + +### Development Instructions + +Please find more information about how to setup your machine for developing the `piral-cli-vite6` packages in [the source documentation](../README.md). + +### Reporting Bugs + +Before creating bug report, please make sure that you first check the [existing issues](https://github.com/smapiot/piral-cli-vite6/issues?q=is%3Aopen+is%3Aissue+label%3Abug), as you might find that the issue is already reported. Fill out [the required template](https://github.com/smapiot/piral-cli-vite6/issues/new?template=bug_report.md), the information it asks for helps us resolve issues faster. + +Following these guidelines helps maintainers and the community understand your report :pencil:, reproduce the behavior :computer:, and find related reports :mag_right:. + +### Suggesting Enhancements + +This section guides you through submitting an enhancement suggestion for the `piral-cli-vite6` packages, including completely new features and minor improvements to existing functionality. + +Before creating enhancement suggestions, please make sure that you first check the [existing suggestions](https://github.com/smapiot/piral-cli-vite6/issues?q=is%3Aopen+is%3Aissue+label%3Aenhancement), as you might find that the enhancement has already been requested. Fill out [the template](https://github.com/smapiot/piral-cli-vite6/issues/new?template=feature_request.md), including the steps that you imagine you would take if the feature you're requesting existed. + +#### How Do I Submit a Suggestion + +Enhancements or general suggestions are tracked as [GitHub issues](https://guides.github.com/features/issues/). After you've determined that the enhancement is not already requested, go ahead and create an issue providing the following information: + +- **Use a clear and descriptive title** for the issue to identify the suggestion. +- **Provide a step-by-step description of the suggested enhancement** in as many details as possible. +- **Describe the current behavior** and **explain which behavior you expected to see instead** and why. +- **Include screenshots and animated GIFs** which help you demonstrate the steps or point out the part of the `piral-cli-vite6` packages which the suggestion is related to. *Note*: We usually live in code. Any code you can already show would be the best illustration. + +## Branching Model + +### Main Branches + +The central repository holds four main branches with an infinite lifetime: + +- **main** +- **develop** +- **experimental** +- **documentation** + +We consider `main` to be the main branch where the source code always reflects a production-ready state, and `develop` to be the main branch where the source code always reflects a state with the latest delivered changes for the next release. When the source code in the `develop` branch reaches a stable point and is ready to be released, all of the changes should be merged back into main. Therefore, each time when changes are merged back into main, this is a new production release. + +The **experimental** branch is a special branch for an upcoming release that is unclear in scope and functionality. Releases from this branch should be considered unstable and might never reach production. No hotfixes or minor updates will be first-pushed to this branch. Instead, only (experimental) new features are (potentially exclusively) added to this branch. + +The **documentation** branch is used for updates and fixes to the currently live (i.e., `main`-build) documentation. + +The following table gives an overview: + +| Branch Name | NPM Release / Tag | Version Suffix | +| ------------- | ----------------- | -------------- | +| main | latest | (none) | +| develop | next | beta | + +If you don't know what to do - use `develop` as target for pull requests. + +### Supporting Branches + +Next to the main branches `main` and `develop`, our development model uses a few of supporting branches to aid parallel development between team members, ease tracking of features and to assist in quickly fixing live production problems. Unlike the main branches, these branches always have a limited life time, since they will be removed eventually. + +The two main different types of branches we may use are: + +- **Feature branches**, i.e., `feature/*` +- **Hotfix branches**, i.e., `hotfix/*` + +#### Creating a Feature Branch + +Create a branch **from** `develop` which must merge back **into** `develop`. + +Naming convention: + +- anything except `main`, `develop`, `release/*`, or `hotfix/*` +- preferred `feature/{issue-id}-{issue-description}`, e.g., `feature/#123-add-foo` + +#### Creating a Hotfix Branch + +Create a branch **from** `main` which must merge back **into** either `main` and / or `develop`. While a *real* hotfix will apply to both immediately, a simple fix will just be applied to `develop`. + +Naming convention: + +- `hotfix/{new-patch-version}`, e.g., `hotfix/1.2.1` +- `hotfix/{issue-id}-{issue-description}`, e.g., `hotfix/#123-fixed-foo-undefined` + +Hotfix branches are normally created from the `main` branch (especially if they are applied to both `main` and `develop`, otherwise creating the branch from `develop` may be okay as well). For example, say version 1.2 is the current production release running live and causing troubles due to a severe bug. But changes on develop are yet unstable. + +## Pull Request Process + +Following is a short guide on how to make a valid Pull Request. + +1. Firstly you need a local fork of the the project, so go ahead and press the `fork` button in + GitHub. This will create a copy of the repository in your own GitHub account and you'll see a + note that it's been forked underneath the project name: `Forked from smapiot/piral-cli-vite6`. + Clone the newly forked repository locally and set up a new remote that points to the original + project so that you can grab any changes and bring them into your local copy. + + ```sh + git remote add upstream git@github.com:smapiot/piral-cli-vite6.git + ``` + + You now have two remotes for this project on disk: + + 1. `origin` which points to your GitHub fork of the project. + You can read and write to this remote. + 2. `upstream` which points to the main project's GitHub repository. + You can only read from this remote. + +2. Create the branch, following or [Branching Model](#branching-model). + +3. Do some work :) This is the fun part where you get to contribute to the `piral-cli-vite6` packages :rocket:. + +4. Before pushing your code, few more task that need to be preformed: + + - Make sure that the test and build scripts run successfully + + ```sh + npm test + lerna run build + ``` + + - Update the *CHANGELOG.md* following our convention + +5. Commit and push the code to the origin. + + ```sh + git commit -m "Description of my awesome new feature" + git push origin HEAD + ``` + +6. After the code is successfully pushed to the origin repository, navigate to + [`piral-cli-vite6` repository](https://github.com/smapiot/piral-cli-vite6/pulls) + and issue a new pull request. + +You may merge the Pull Request in once you have the sign-off of at least one other (core) developer, or if you do not have permission to do that, you may request the reviewer to merge it for you. diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..4779e1e --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,3 @@ +# These are supported funding model platforms + +github: [smapiot, FlorianRappl] diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md new file mode 100644 index 0000000..251eaa4 --- /dev/null +++ b/.github/ISSUE_TEMPLATE.md @@ -0,0 +1,8 @@ +# Issue Templates + +Please use one of the following templates to create your issue: + +- [Bug report](https://github.com/smapiot/piral-cli-vite6/issues/new?template=bug_report.md) +- [Feature proposal](https://github.com/smapiot/piral-cli-vite6/issues/new?template=feature_request.md) + +In case of questions please either use [our Gitter chat room](https://gitter.im/piral-io/community) or (preferably) [the Piral tag on StackOverflow](https://stackoverflow.com/questions/tagged/piral). diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..268e4d2 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,42 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: 'bug' +assignees: '' +--- + +# Bug Report + +For more information, see the `CONTRIBUTING` guide. + +## Prerequisites + +- [ ] Can you reproduce the problem in a [MWE](https://en.wikipedia.org/wiki/Minimal_working_example)? +- [ ] Are you running the latest version? +- [ ] Did you perform a search in the issues? + +## Environment Details and Version + +[Package Version, OS, Browser, ...] + +## Description + +[Description of the bug] + +## Steps to Reproduce + +1. [First Step] +2. [next step...] + +## Expected behavior + +[What you expected to happen] + +## Actual behavior + +[What actually happened] + +## Possible Origin / Solution + +[Optionally, share your idea to fix the issue] diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..0c2dd0e --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,23 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: 'enhancement' +assignees: '' +--- + +# New Feature Proposal + +For more information, see the `CONTRIBUTING` guide. + +## Description + +[Description of the proposed feature] + +## Background + +[Provide any additional background for the feature, e.g., why is the current solution insufficient, what problem will it solve, etc.] + +## Discussion + +[Optionally, outline any pros and cons you can currently think of to provide the basis for a solid discussion] diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..6820712 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,31 @@ +# New Pull Request + +For more information, see the `CONTRIBUTING` guide. + +## Prerequisites + +Please make sure you can check the following boxes: + +- [ ] I have read the **CONTRIBUTING** document +- [ ] My code follows the code style of this project +- [ ] All new and existing tests passed + +## Type(s) of Changes + +### Contribution Type + +What types of changes does your code introduce? Put an `x` in all the boxes that apply: + +- [ ] Bug fix (non-breaking change which fixes an issue, please reference the issue id) +- [ ] New feature (non-breaking change which adds functionality, make sure to open an associated issue first) +- [ ] Breaking change (fix or feature that would cause existing functionality to change) +- [ ] I have updated the documentation accordingly +- [ ] I have added tests to cover my changes + +### Description + +[Place a meaningful description here] + +### Remarks + +[Optionally place any follow-up comments, remarks, observations, or notes here for future reference] diff --git a/.github/stale.yml b/.github/stale.yml new file mode 100644 index 0000000..a061475 --- /dev/null +++ b/.github/stale.yml @@ -0,0 +1,21 @@ +# Number of days of inactivity before an issue becomes stale +daysUntilStale: 21 +# Number of days of inactivity before a stale issue is closed +daysUntilClose: 7 +# Issues with these labels will never be considered stale +exemptLabels: + - in-review + - in-testing + - in-implementation + - information + - spike + - help wanted +# Label to use when marking an issue as stale +staleLabel: wontfix +# Comment to post when marking an issue as stale. Set to `false` to disable +markComment: > + This issue has been automatically marked as stale because it has not had + recent activity. It will be closed if no further activity occurs. Thank you + for your contributions. +# Comment to post when closing a stale issue. Set to `false` to disable +closeComment: false \ No newline at end of file diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml new file mode 100644 index 0000000..d973fd2 --- /dev/null +++ b/.github/workflows/codeql-analysis.yml @@ -0,0 +1,67 @@ +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +# +# ******** NOTE ******** +# We have attempted to detect the languages in your repository. Please check +# the `language` matrix defined below to confirm you have the correct set of +# supported CodeQL languages. +# +name: "CodeQL" + +on: + push: + branches: [ develop, main ] + pull_request: + # The branches below must be a subset of the branches above + branches: [ develop ] + schedule: + - cron: '19 3 * * 1' + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + language: [ 'javascript' ] + # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ] + # Learn more: + # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v1 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + # queries: ./path/to/local/query, your-org/your-repo/queries@main + + # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@v1 + + # ℹī¸ Command-line programs to run using the OS shell. + # 📚 https://git.io/JvXDl + + # ✏ī¸ If the Autobuild fails above, remove it and uncomment the following three lines + # and modify them (or add more) to build your code if your project + # uses a compiled language + + #- run: | + # make bootstrap + # make release + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v1 diff --git a/.github/workflows/twitter-release.yml b/.github/workflows/twitter-release.yml new file mode 100644 index 0000000..f70bb93 --- /dev/null +++ b/.github/workflows/twitter-release.yml @@ -0,0 +1,25 @@ +name: tweet-release + +on: + release: + types: + - published + +jobs: + tweet: + runs-on: ubuntu-latest + steps: + - uses: smapiot/send-tweet-v2-action@v1 + name: Tweet new release + with: + status: "New ${{ github.event.repository.name }} release ${{ github.event.release.tag_name }}! ${{ github.event.release.html_url }} #microfrontends #piral #cli #vite6 #release" + consumer-key: ${{ secrets.TWITTER_CONSUMER_API_KEY }} + consumer-secret: ${{ secrets.TWITTER_CONSUMER_API_SECRET }} + access-token: ${{ secrets.TWITTER_ACCESS_TOKEN }} + access-token-secret: ${{ secrets.TWITTER_ACCESS_TOKEN_SECRET }} + - uses: smapiot/send-bluesky-post-action@v2 + name: Bluesky post new release + with: + status: "New ${{ github.event.repository.name }} release ${{ github.event.release.tag_name }}! ${{ github.event.release.html_url }} #microfrontends #piral #cli #vite6 #release" + bluesky-email: ${{ secrets.BLUESKY_EMAIL }} + bluesky-password: ${{ secrets.BLUESKY_PASSWORD }} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..40e22b5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,105 @@ +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* +packages/*/lib + +# Diagnostic reports (https://nodejs.org/api/report.html) +report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage +*.lcov + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# TypeScript v1 declaration files +typings/ + +# TypeScript cache +*.tsbuildinfo + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Microbundle cache +.rpt2_cache/ +.rts2_cache_cjs/ +.rts2_cache_es/ +.rts2_cache_umd/ + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env +.env.test + +# parcel-bundler cache (https://parceljs.org/) +.cache + +# Next.js build output +.next + +# Nuxt.js build / generate output +.nuxt +dist + +# Gatsby files +.cache/ +# 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 + +# Serverless directories +.serverless/ + +# FuseBox cache +.fusebox/ + +# DynamoDB Local files +.dynamodb/ + +# TernJS port file +.tern-port diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..13f05f4 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,4 @@ +package.json +package-lock.json +src/**/node_modules +src/**/lib diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..9724b30 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,5 @@ +# Changelog + +## 1.0.0 (tbd) + +- Initial release diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..5f828a6 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,47 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery and unwelcome sexual attention or advances +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a professional setting + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. + +## Scope + +This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at **contact@piral.io**. All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html. + +[homepage]: https://www.contributor-covenant.org + +For answers to common questions about this code of conduct, see https://www.contributor-covenant.org/faq. diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..7f4e972 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 - 2024 smapiot + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..7e0d96a --- /dev/null +++ b/README.md @@ -0,0 +1,45 @@ +[![Piral Logo](https://github.com/smapiot/piral/raw/main/docs/assets/logo.png)](https://piral.io) + +# piral-cli-vite6 · [![Build Status](https://smapiot.visualstudio.com/piral-pipelines/_apis/build/status/smapiot.piral-cli-vite6?branchName=develop)](https://smapiot.visualstudio.com/piral-pipelines/_build/latest?definitionId=122&branchName=develop) ![GitHub License](https://img.shields.io/badge/license-MIT-blue.svg) + +The `piral-cli` plugin for using `vite` (**version 6**) as bundler. For version 4 of `vite` use [`piral-cli-vite`](https://github.com/smapiot/piral-cli-vite). For version 5 of `vite` use [`piral-cli-vite5`](https://github.com/smapiot/piral-cli-vite5). + +## Important Links + +* đŸ“ĸ **[We are hiring!](https://smapiot.com/jobs)** - work with us on Piral, its ecosystem and our users +* 🌍 [Website](https://piral.io/) - learn more about Piral +* 📖 [Documentation](https://docs.piral.io/) - everything to get started and master micro frontends +* 🉐 **Help translating Piral!** - making PRs in the [documentation branch](https://github.com/smapiot/piral/tree/documentation) +* 🐞 [Issue Tracker](https://github.com/smapiot/piral/issues) - report bugs or suggest new features +* 🗨 [Forums](https://stackoverflow.com/questions/tagged/piral) - use the community support on StackOverflow +* đŸ‘Ē [Community Chat](https://gitter.im/piral-io/community) - ask questions and provide answers in our Gitter room + +## Status + +* [x] Pilets (tested / working) + * [x] Codegen + * [x] Bundle Splitting + * [x] ESM output + * [x] CSS / SASS + * [x] Importmap references + * [x] Importmap bundles + * [ ] v0 format (not implemented) + * [ ] v1 format (not implemented) + * [x] v2 format + * [x] v3 format + * [x] tsconfig changes + * [x] Building + * [x] Debugging + * [x] Reloading +* [x] Piral instances (tested / working) + * [x] Codegen + * [x] HTML entry point + * [x] Emulator build + * [x] Release build + * [x] tsconfig changes + * [x] Debugging + * [x] Reloading + +## License + +This code is released using the MIT license. For more information see the [LICENSE file](LICENSE). diff --git a/azure-pipelines.yml b/azure-pipelines.yml new file mode 100644 index 0000000..77c7bc6 --- /dev/null +++ b/azure-pipelines.yml @@ -0,0 +1,215 @@ +trigger: + branches: + include: + - main + - develop + - experimental + +variables: +- group: piral-deployment-variables +- name: previewId + value: $(Build.BuildId) +- name: agentName + value: 'ubuntu-latest' +- name: releaseBranch + value: 'main' +- name: previewBranch + value: 'develop' +- name: canaryBranch + value: 'experimental' +- name: nodeVersion + value: '22.5.1' + +stages: +- stage: Build + displayName: Process Code + + jobs: + - job: BuildCode + displayName: Verify and Build Code + pool: + vmImage: $(agentName) + steps: + - task: NodeTool@0 + displayName: Use Node $(nodeVersion) + inputs: + versionSpec: $(nodeVersion) + - task: YarnInstaller@2 + displayName: Install Yarn + inputs: + checkLatest: true + - task: Yarn@2 + displayName: Install Dependencies + inputs: + Arguments: install + - task: Yarn@2 + displayName: Test Code + inputs: + Arguments: test + +- stage: CanaryRelease + + displayName: Release Packages (Alpha) + dependsOn: Build + condition: and(succeeded(), eq(variables['Build.SourceBranchName'], variables['canaryBranch'])) + + jobs: + - deployment: CanaryReleasePackages + displayName: CanaryRelease Piral Packages + condition: eq(variables['Build.SourceBranchName'], variables['canaryBranch']) + pool: + vmImage: $(agentName) + environment: 'registry-npmjs-org' + strategy: + runOnce: + deploy: + steps: + - checkout: self + - task: NodeTool@0 + displayName: Use Node $(nodeVersion) + inputs: + versionSpec: $(nodeVersion) + - task: YarnInstaller@2 + displayName: Install Yarn + inputs: + checkLatest: true + - task: Yarn@2 + displayName: Install Dependencies + inputs: + Arguments: install + - task: npmAuthenticate@0 + inputs: + workingFile: .npmrc + customEndpoint: DefaultNpmConnection + - task: Bash@3 + displayName: Configure Git + inputs: + targetType: inline + script: >- + git config --global user.email "releases@piral.io" + + git config --global user.name "Piral Release Bot" + + git checkout $(canaryBranch) + + git checkout -- . + - task: Yarn@2 + displayName: Canary Packages + inputs: + Arguments: ci:canary + customEndpoint: DefaultNpmConnection + +- stage: PreviewRelease + + displayName: Release Packages (Beta) + dependsOn: Build + condition: and(succeeded(), eq(variables['Build.SourceBranchName'], variables['previewBranch'])) + + jobs: + - deployment: PreReleasePackages + displayName: PreRelease Piral Packages + condition: eq(variables['Build.SourceBranchName'], variables['previewBranch']) + pool: + vmImage: $(agentName) + environment: 'registry-npmjs-org' + strategy: + runOnce: + deploy: + steps: + - checkout: self + - task: NodeTool@0 + displayName: Use Node $(nodeVersion) + inputs: + versionSpec: $(nodeVersion) + - task: YarnInstaller@2 + displayName: Install Yarn + inputs: + checkLatest: true + - task: Yarn@2 + displayName: Install Dependencies + inputs: + Arguments: install + - task: npmAuthenticate@0 + inputs: + workingFile: .npmrc + customEndpoint: DefaultNpmConnection + - task: Bash@3 + displayName: Configure Git + inputs: + targetType: inline + script: >- + git config --global user.email "releases@piral.io" + + git config --global user.name "Piral Release Bot" + + git checkout $(previewBranch) + + git checkout -- . + - task: Yarn@2 + displayName: Prerelease Packages + inputs: + Arguments: ci:prerelease + customEndpoint: DefaultNpmConnection + +- stage: Release + + displayName: Release Packages + dependsOn: Build + condition: and(succeeded(), eq(variables['Build.SourceBranchName'], variables['releaseBranch'])) + + jobs: + - deployment: ReleasePackages + displayName: Release Piral Packages + condition: eq(variables['Build.SourceBranchName'], variables['releaseBranch']) + pool: + vmImage: $(agentName) + environment: 'registry-npmjs-org' + strategy: + runOnce: + deploy: + steps: + - checkout: self + - task: NodeTool@0 + displayName: Use Node $(nodeVersion) + inputs: + versionSpec: $(nodeVersion) + - task: YarnInstaller@2 + displayName: Install Yarn + inputs: + checkLatest: true + - task: Yarn@2 + displayName: Install Dependencies + inputs: + Arguments: install + - task: npmAuthenticate@0 + inputs: + workingFile: .npmrc + customEndpoint: DefaultNpmConnection + - task: Bash@3 + displayName: Configure Git + inputs: + targetType: inline + script: >- + git config --global user.email "releases@piral.io" + + git config --global user.name "Piral Release Bot" + + git remote rm origin + + git remote add origin https://$(githubPersonalAccessToken)@github.com/smapiot/piral-cli-vite6.git + + git fetch origin + + git checkout $(releaseBranch) + + git checkout -- . + - task: Yarn@2 + displayName: Update Release Date + inputs: + Arguments: ci:version-update + customEndpoint: DefaultNpmConnection + - task: Yarn@2 + displayName: Release Packages + inputs: + Arguments: ci:release + customEndpoint: DefaultNpmConnection diff --git a/jest.config.js b/jest.config.js new file mode 100644 index 0000000..3d5e22a --- /dev/null +++ b/jest.config.js @@ -0,0 +1,19 @@ +module.exports = { + collectCoverage: true, + setupFiles: [], + roots: ['packages/'], + transform: { + '^.+\\.tsx?$': 'ts-jest', + '^.+\\.jsx?$': 'babel-jest', + }, + testRegex: '(/__tests__/.*|\\.(test|spec))\\.(jsx?|tsx?)$', + moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'], + globals: { + NODE_ENV: 'test', + 'ts-jest': { + diagnostics: false, + }, + }, + testURL: 'http://localhost', + verbose: true, +}; diff --git a/lerna.json b/lerna.json new file mode 100644 index 0000000..c823e9d --- /dev/null +++ b/lerna.json @@ -0,0 +1,4 @@ +{ + "npmClient": "yarn", + "version": "1.0.0" +} \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..ea58a0d --- /dev/null +++ b/package.json @@ -0,0 +1,33 @@ +{ + "name": "piral-cli-vite6-packages", + "private": true, + "workspaces": [ + "packages/*" + ], + "scripts": { + "build": "lerna run build", + "lint": "tslint -c tslint.json 'src/**/*.{ts,tsx}' --project tsconfig.json", + "prettify": "prettier --config prettier.config.js --write \"src/**/*.{ts,tsx}\"", + "test": "jest --forceExit --passWithNoTests", + "prepublish": "yarn build", + "release": "lerna publish", + "ci:version": "node tools/changelog-version.js", + "ci:version-update": "yarn ci:version --update && git add CHANGELOG.md && git commit -m UpdateReleaseDate", + "ci:canary": "lerna publish $(yarn --silent ci:version)-alpha.$BUILD_BUILDID --exact --yes --force-publish --no-git-tag-version --no-push --dist-tag canary && git checkout -- .", + "ci:prerelease": "lerna publish $(yarn --silent ci:version)-beta.$BUILD_BUILDID --exact --yes --force-publish --no-git-tag-version --no-push --dist-tag next && git checkout -- .", + "ci:release": "lerna publish $(yarn --silent ci:version) --yes --force-publish --message '[skip ci] publish %s'" + }, + "devDependencies": { + "@types/node": "^22", + "@types/yargs": "^17", + "jest": "^29", + "jest-cli": "^29", + "lerna": "^8", + "prettier": "^3", + "ts-jest": "^29", + "tslint": "^6", + "tslint-config-prettier": "^1", + "tslint-plugin-prettier": "^2", + "typescript": "^5" + } +} diff --git a/packages/piral-cli-vite5/LICENSE b/packages/piral-cli-vite5/LICENSE new file mode 100644 index 0000000..7f4e972 --- /dev/null +++ b/packages/piral-cli-vite5/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 - 2024 smapiot + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/packages/piral-cli-vite5/README.md b/packages/piral-cli-vite5/README.md new file mode 100644 index 0000000..57b12f0 --- /dev/null +++ b/packages/piral-cli-vite5/README.md @@ -0,0 +1,100 @@ +[![Piral Logo](https://github.com/smapiot/piral/raw/main/docs/assets/logo.png)](https://piral.io) + +# [Piral CLI Vite 6](https://piral.io) · [![GitHub License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/smapiot/piral-cli-vite6/blob/main/LICENSE) [![npm version](https://img.shields.io/npm/v/piral-cli-vite6.svg?style=flat)](https://www.npmjs.com/package/piral-cli-vite6) [![tested with jest](https://img.shields.io/badge/tested_with-jest-99424f.svg)](https://jestjs.io) [![Gitter Chat](https://badges.gitter.im/gitterHQ/gitter.png)](https://gitter.im/piral-io/community) + +This plugin enables using [Vite 6](https://vitejs.dev/) as the bundler for Piral instances and pilets. + +## Installation + +Use your favorite npm client for the installation: + +```sh +npm i piral-cli-vite6 --save-dev +``` + +**Note**: If you don't install any bundler for use in `piral-cli` then `piral-cli-vite6` will be automatically installed for you. + +## Using + +There is nothing to do. Standard commands such as `piral build` or `pilet debug` will now work with Vite 6 as the bundler. + +This plugin comes with batteries included. You don't need to install or specify your Vite version. + +### What's Inside + +Right now it includes: + +- `vite-plugin-codegen` +- `vite-plugin-environment` + +Additionally, most known referenced assets are handled as files. + +As such it should be prepared to include assets (images, videos, ...), stylesheets (CSS and SASS), and work with TypeScript. + +### Public Folder + +By default the source folder (e.g., `/src`) is set as root. Therefore, the `src/public` folder (if available) will be used for the public assets. If you want to change this you can use a custom Vite config as explained below, e.g.: + +```js +import { resolve } from 'path'; + +export default { + publicDir: resolve(__dirname, 'public'), +} +``` + +### Referencing Scripts + +Vite uses all scripts with `type=module` to be entry points in the *index.html* file. However, as you might just have scaffolded a solution or are more used to simply have ` +``` + +to + +```html + + + + + + +``` + +### Customizing + +If you want to customize the given config (e.g., to add more plugins) then create a file *vite.config.js* (or anything else accepted by Vite, e.g., *vite.config.ts*) in your root directory. + +In the most trivial version the file looks as follows: + +```js +import { defineConfig } from 'vite'; + +export default defineConfig({ + // Your config additions here +}); +``` + +If you want to add some plugin you could do: + +```js +import { defineConfig } from "vite"; +import legacy from "@vitejs/plugin-legacy"; + +export default defineConfig({ + plugins: [ + legacy({ + targets: ['defaults', 'not IE 11'], + }), + ], +}); +``` + +The configuration works with all formats that Vite supports. + +## License + +Piral is released using the MIT license. For more information see the [license file](./LICENSE). diff --git a/packages/piral-cli-vite5/package.json b/packages/piral-cli-vite5/package.json new file mode 100644 index 0000000..12894e5 --- /dev/null +++ b/packages/piral-cli-vite5/package.json @@ -0,0 +1,52 @@ +{ + "name": "piral-cli-vite6", + "version": "1.0.0", + "description": "Provides debug and build capabilities for pilets and Piral instances using Vite v6.", + "keywords": [ + "piral-cli", + "piral", + "plugin", + "vite", + "vite6", + "build", + "debug", + "bundle" + ], + "author": "smapiot", + "homepage": "https://piral.io", + "license": "MIT", + "main": "lib/index.js", + "typings": "lib/index.d.ts", + "engines": { + "node": ">=20.0" + }, + "files": [ + "lib", + "src" + ], + "funding": { + "type": "github", + "url": "https://github.com/sponsors/smapiot" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/smapiot/piral-cli-vite6.git" + }, + "bugs": { + "url": "https://github.com/smapiot/piral-cli-vite6/issues" + }, + "scripts": { + "build": "tsc", + "test": "echo \"Error: run tests from root\" && exit 1" + }, + "devDependencies": { + "piral-cli": "^1" + }, + "dependencies": { + "sass": "^1", + "vite": "^6", + "vite-plugin-codegen": "^1", + "vite-plugin-environment": "^1", + "vite-plugin-pilet": "^1" + } +} diff --git a/packages/piral-cli-vite5/src/actions.ts b/packages/piral-cli-vite5/src/actions.ts new file mode 100644 index 0000000..27a32de --- /dev/null +++ b/packages/piral-cli-vite5/src/actions.ts @@ -0,0 +1,28 @@ +import { resolve } from 'path'; +import type { + DebugPiletBundlerDefinition, + DebugPiralBundlerDefinition, + BuildPiletBundlerDefinition, + BuildPiralBundlerDefinition, + WatchPiralBundlerDefinition, +} from 'piral-cli'; + +export const debugPiral: DebugPiralBundlerDefinition = { + path: resolve(__dirname, 'vite6', 'piral.js'), +}; + +export const watchPiral: WatchPiralBundlerDefinition = { + path: resolve(__dirname, 'vite6', 'piral.js'), +}; + +export const buildPiral: BuildPiralBundlerDefinition = { + path: resolve(__dirname, 'vite6', 'piral.js'), +}; + +export const debugPilet: DebugPiletBundlerDefinition = { + path: resolve(__dirname, 'vite6', 'pilet.js'), +}; + +export const buildPilet: BuildPiletBundlerDefinition = { + path: resolve(__dirname, 'vite6', 'pilet.js'), +}; diff --git a/packages/piral-cli-vite5/src/index.ts b/packages/piral-cli-vite5/src/index.ts new file mode 100644 index 0000000..29ddc05 --- /dev/null +++ b/packages/piral-cli-vite5/src/index.ts @@ -0,0 +1,8 @@ +import * as actions from './actions'; +import type { CliPlugin } from 'piral-cli'; + +const plugin: CliPlugin = (cli) => { + cli.withBundler('vite6', actions); +}; + +module.exports = plugin; diff --git a/packages/piral-cli-vite5/src/vite6/bundler-run.ts b/packages/piral-cli-vite5/src/vite6/bundler-run.ts new file mode 100644 index 0000000..fecf725 --- /dev/null +++ b/packages/piral-cli-vite5/src/vite6/bundler-run.ts @@ -0,0 +1,54 @@ +import { EventEmitter } from 'events'; +import { InlineConfig, build } from 'vite'; + +interface ViteConfig extends InlineConfig { + debug: boolean; + outFile: string; + requireRef?: string; +} + +export function runVite(options: ViteConfig) { + const { debug, outFile, requireRef, ...config } = options; + const eventEmitter = new EventEmitter(); + const bundle = { + outFile: `/${outFile}`, + outDir: config.build.outDir, + name: outFile, + requireRef, + }; + + return Promise.resolve({ + async bundle() { + if (debug) { + config.build.watch = {}; + } + + const watcher = await build(config); + + if (debug && 'on' in watcher) { + watcher.on('event', (event) => { + if (event.code === 'ERROR') { + console.error(event); + } else if (event.code === 'BUNDLE_START') { + console.info('Bundling ...'); + } else if (event.code === 'BUNDLE_END') { + event.result.close(); + console.info('Bundled!'); + } else if (event.code === 'END') { + eventEmitter.emit('end', bundle); + } + }); + + eventEmitter.emit('start', bundle); + } + + return bundle; + }, + onStart(cb) { + eventEmitter.on('start', cb); + }, + onEnd(cb) { + eventEmitter.on('end', cb); + }, + }); +} diff --git a/packages/piral-cli-vite5/src/vite6/common.ts b/packages/piral-cli-vite5/src/vite6/common.ts new file mode 100644 index 0000000..c02dd78 --- /dev/null +++ b/packages/piral-cli-vite5/src/vite6/common.ts @@ -0,0 +1,38 @@ +import type { InlineConfig } from 'vite'; +import codegen from 'vite-plugin-codegen'; +import environment from 'vite-plugin-environment'; + +export function createCommonConfig( + root: string, + outDir: string, + develop = true, + sourcemap = true, + minify = true, + variables: Record = {}, +): InlineConfig { + const varKeys = Object.keys({ + BUILD_PCKG_NAME: process.env.BUILD_PCKG_NAME, + BUILD_PCKG_VERSION: process.env.BUILD_PCKG_VERSION, + BUILD_TIME_FULL: process.env.BUILD_TIME_FULL, + PIRAL_CLI_VERSION: process.env.PIRAL_CLI_VERSION, + NODE_ENV: process.env.NODE_ENV, + ...variables, + }); + return { + root, + build: { + outDir, + sourcemap, + emptyOutDir: false, + minify, + rollupOptions: { + output: { + assetFileNames: '[name].[hash][extname]', + chunkFileNames: '[name].[hash].js', + entryFileNames: '[name].[hash].js', + }, + }, + }, + plugins: [environment(varKeys), codegen({ outDir, rootDir: root })], + }; +} diff --git a/packages/piral-cli-vite5/src/vite6/pilet.ts b/packages/piral-cli-vite5/src/vite6/pilet.ts new file mode 100644 index 0000000..788978a --- /dev/null +++ b/packages/piral-cli-vite5/src/vite6/pilet.ts @@ -0,0 +1,106 @@ +import pilet from 'vite-plugin-pilet'; +import type { PiletBuildHandler } from 'piral-cli'; +import { createCommonConfig } from './common'; +import { runVite } from './bundler-run'; + +function nameOf(path: string) { + return path.replace(/\.js$/, ''); +} + +function getPackageName() { + return process.env.BUILD_PCKG_NAME; +} + +function getRequireRef() { + const name = getPackageName(); + return `rolluppr_${name.replace(/\W/gi, '')}`; +} + +const supportedSchemas = ['v2', 'v3']; + +function checkSupported(schema: string): asserts schema is 'v2' | 'v3' { + if (!supportedSchemas.includes(schema)) { + throw new Error( + `The provided schema version is not supported. This version supports: ${supportedSchemas.join(', ')}.`, + ); + } +} + +const handler: PiletBuildHandler = { + create(options) { + const schema = options.version; + const piletName = getPackageName(); + const requireRef = getRequireRef(); + const external: Array = []; + const id = nameOf(options.outFile); + const input = { + [id]: options.entryModule, + }; + + // first populate with global externals + options.externals.forEach((name) => { + external.push(name); + }); + + // then populate with distributed externals + options.importmap.forEach((dep) => { + external.push(dep.name); + }); + + // finally add the local importmap entries to the bundler entry points + options.importmap.forEach((dep) => { + if (dep.type === 'local') { + input[nameOf(dep.ref)] = dep.entry; + } + }); + + checkSupported(schema); + + const config = createCommonConfig('', options.outDir, options.develop, options.sourceMaps, options.minify, {}); + + return runVite({ + ...config, + build: { + ...config.build, + lib: { + entry: options.entryModule, + fileName: () => options.outFile, + formats: ['system' as any], + }, + rollupOptions: { + ...config.build.rollupOptions, + input, + output: { + ...config.build.rollupOptions.output, + assetFileNames(assetInfo) { + // keep name of combined stylesheet + if (assetInfo.name === 'style.css') { + return assetInfo.name; + } + + return '[name].[hash][extname]'; + }, + entryFileNames: '[name].js', + }, + external, + }, + }, + plugins: [ + ...config.plugins, + pilet({ + id, + schema, + piletName, + requireRef, + importmap: options.importmap, + debug: options.develop, + }), + ], + debug: options.watch, + outFile: options.outFile, + requireRef, + }); + }, +}; + +export const create = handler.create; diff --git a/packages/piral-cli-vite5/src/vite6/piral.ts b/packages/piral-cli-vite5/src/vite6/piral.ts new file mode 100644 index 0000000..30150a2 --- /dev/null +++ b/packages/piral-cli-vite5/src/vite6/piral.ts @@ -0,0 +1,70 @@ +import type { PiralBuildHandler } from 'piral-cli'; +import type { Plugin } from 'vite'; +import { dirname, resolve } from 'path'; +import { createCommonConfig } from './common'; +import { runVite } from './bundler-run'; +import { readFileSync, readdirSync, writeFileSync } from 'fs'; + +function transformIndexHtml(html: string) { + return html + .replace(//gm, '