Skip to content

Commit

Permalink
Merge branch 'release/1.0.33' into v1
Browse files Browse the repository at this point in the history
  • Loading branch information
khalwat committed Jan 30, 2024
2 parents b9cb389 + 2585c34 commit a3f35c8
Show file tree
Hide file tree
Showing 21 changed files with 3,174 additions and 1,759 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/build-and-deploy-docs.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Build and Deploy Docs
env:
DOCS_DEST_DIR: /vite/
DOCS_DEST_DIR: /vite/v1/
on:
push:
branches:
Expand All @@ -22,11 +22,11 @@ jobs:
strategy:
fail-fast: true
matrix:
node-version: [14.x]
node-version: [20.x]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
Expand Down
34 changes: 34 additions & 0 deletions .github/workflows/code-analysis.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Code Analysis

on:
pull_request: null
push:
branches:
- develop
workflow_dispatch:
permissions:
contents: read
jobs:
code_analysis:
strategy:
fail-fast: false
matrix:
actions:
-
name: 'PHPStan'
run: composer phpstan
-
name: 'Coding Standards'
run: composer fix-cs
name: ${{ matrix.actions.name }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
# see https://github.com/shivammathur/setup-php
- uses: shivammathur/setup-php@v2
with:
php-version: 8.2
coverage: none
# composer install cache - https://github.com/ramsey/composer-install
- uses: "ramsey/composer-install@v2"
- run: ${{ matrix.actions.run }}
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

All notable changes to this project will be documented in this file.

## 1.0.33 - 2024.01.30
### Added
* If the `devServer` is running, the `ViteService::fetch()` method will try to use the `devServerInternal` URL first, falling back on the `devServerPublic` so that `craft.vite.inline()` can pull from the `devServer` if it is running ([#22](https://github.com/nystudio107/craft-plugin-vite/issues/22))
* Add `phpstan` and `ecs` code linting
* Add `code-analysis.yaml` GitHub action

### Changed
* Updated docs to use node 20 & a new sitemap plugin
* PHPstan code cleanup
* ECS code cleanup

## 1.0.32 - 2023.12.08
### Fixed
* Fixed a type error if you passed an array of entries into the `errorEntry` config ([#76](https://github.com/nystudio107/craft-vite/issues/76))
Expand Down
4 changes: 2 additions & 2 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
The MIT License (MIT)

Copyright (c) 2021 nystudio107
Copyright (c) nystudio107

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.
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.
14 changes: 12 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "nystudio107/craft-vite",
"description": "Allows the use of the Vite.js next generation frontend tooling with Craft CMS",
"type": "craft-plugin",
"version": "1.0.32",
"version": "1.0.33",
"keywords": [
"craft",
"cms",
Expand All @@ -23,7 +23,17 @@
],
"require": {
"craftcms/cms": "^3.0.0",
"nystudio107/craft-plugin-vite": "^1.0.32"
"nystudio107/craft-plugin-vite": "^1.0.33"
},
"require-dev": {
"craftcms/ecs": "dev-main",
"craftcms/phpstan": "dev-main",
"craftcms/rector": "dev-main"
},
"scripts": {
"phpstan": "vendor/bin/phpstan --ansi --memory-limit=1G",
"check-cs": "ecs check --ansi",
"fix-cs": "ecs check --fix --ansi"
},
"config": {
"allow-plugins": {
Expand Down
6 changes: 4 additions & 2 deletions docs/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
ARG TAG=14-alpine
FROM nystudio107/node-dev-base:$TAG
ARG TAG=20-alpine
FROM node:$TAG

RUN npm install -g npm@^10.0.0

WORKDIR /app/

Expand Down
82 changes: 38 additions & 44 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -1,53 +1,47 @@
TAG?=14-alpine
CONTAINER?=$(shell basename $(dir $(CURDIR)))-docs
DOCKERRUN=docker container run \
--name ${CONTAINER} \
--rm \
-p 3002:3002 \
-t \
-v `pwd`:/app \
${CONTAINER}:${TAG}
DOCSDEST?=../../../sites/nystudio107/web/docs/vite
MAJOR_VERSION?=1
TAG?=20-alpine
CONTAINER?=$(shell basename $(dir $(CURDIR)))-v${MAJOR_VERSION}-docs
DOCS_DEV_PORT?=400${MAJOR_VERSION}
DOCS_DEST?=../../../sites/nystudio107/web/docs/vite/v1
IMAGE_INFO=$(shell docker image inspect $(CONTAINER):$(TAG))
IMAGE_NAME=${CONTAINER}:${TAG}
DOCKER_RUN=docker container run --rm -it -v "${CURDIR}":/app

.PHONY: docker build dev fix install lint clean npm
.PHONY: build clean dev fix image-build image-check lint npm ssh

# Start the Docker container
docker:
docker build \
. \
-t ${CONTAINER}:${TAG} \
--build-arg TAG=${TAG} \
--no-cache
# Build the production docs
build: docker install
${DOCKERRUN} \
run docs:build
rm -rf ${DOCSDEST}
mv ./docs/.vitepress/dist ${DOCSDEST}
# Start up the dev server
dev: docker install
${DOCKERRUN} \
run docs:dev
# Fix the docs via textlint
fix: docker install
${DOCKERRUN} \
run docs:fix
# Run an npm install
install: docker
${DOCKERRUN} \
install
# Lint the docs via textlint
lint: docker install
${DOCKERRUN} \
run docs:lint
# Remove node_modules/* & package-lock.json
# Perform a dist build via npm run docs:build
build: image-check
${DOCKER_RUN} --name ${CONTAINER}-$@ ${IMAGE_NAME} run docs:build
rm -rf ${DOCS_DEST}
mv ./docs/.vitepress/dist ${DOCS_DEST}
# Remove node_modules/ & package-lock.json
clean:
rm -rf node_modules/
rm -f package-lock.json
# Run the development server via npm run docs:dev
dev: image-check
${DOCKER_RUN} --name ${CONTAINER}-$@ -e DOCS_DEV_PORT="${DOCS_DEV_PORT}" -p ${DOCS_DEV_PORT}:${DOCS_DEV_PORT} ${IMAGE_NAME} run docs:dev
# Fix the docs with textlint via npm run docs:fix
fix: image-check
${DOCKER_RUN} --name ${CONTAINER}-$@ ${IMAGE_NAME} run docs:fix
# Build the Docker image & run npm install
image-build:
docker build . -t ${IMAGE_NAME} --build-arg TAG=${TAG} --no-cache
${DOCKER_RUN} --name ${CONTAINER}-$@ ${IMAGE_NAME} install
# Ensure the image has been created
image-check:
ifeq ($(IMAGE_INFO), [])
image-check: image-build
endif
# Lint the docs with textlint via npm run docs:lint
lint: image-check
${DOCKER_RUN} --name ${CONTAINER}-$@ ${IMAGE_NAME} run docs:lint
# Run the passed in npm command
npm: docker
${DOCKERRUN} \
$(filter-out $@,$(MAKECMDGOALS)) $(MAKEFLAGS)
npm: image-check
${DOCKER_RUN} --name ${CONTAINER}-$@ ${IMAGE_NAME} $(filter-out $@,$(MAKECMDGOALS)) $(MAKEFLAGS)
# Open a shell inside of the container
ssh: image-check
${DOCKER_RUN} --name ${CONTAINER}-$@ --entrypoint=/bin/sh ${IMAGE_NAME}
%:
@:
# ref: https://stackoverflow.com/questions/6273608/how-to-pass-argument-to-makefile-from-command-line
74 changes: 74 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# `vite` docs

This buildchain is a self-contained build system for the `vite` documentation.

## Overview

The buildchain uses [VitePress](https://vitepress.dev/) via a Docker container to facilitate writing the docs as [markdown](https://vitepress.dev/guide/markdown), linting them via [textlint](https://textlint.github.io/), building them as HTML files with bundled assets, and publishing them automatically via a [GitHub action](https://docs.github.com/en/actions).

It also uses a [Rollup](https://rollupjs.org/) [sitemap plugin](https://github.com/aminnairi/rollup-plugin-sitemap) to generate a `sitemap.xml` for the generated docs.

The markdown sources for the docs and assets are in the `docs/docs/` directory.

The built distribution docs are created via the `build-and-deploy-docs.yaml`

## Prerequisites

To run the buildchain for development purposes:

- You must have [Docker Desktop](https://www.docker.com/products/docker-desktop/) (or the equivalent) installed

## Commands

This buildchain uses `make` as an interface to the buildchain. The following commands are available from the `buildchain/` directory:

- `make image-build` - Build the Docker image & run `npm install`. This command must be run once before using the Docker container.
- `make dev` - Start Vite HMR dev server while writing/editing the docs. Click on the link displayed in the terminal to open the docs up
- `make lint` - Run `textlint` on the docs, reporting on any errors and warnings
- `make fix` - Run `textlint` on the docs, automatically fixing any errors, and reporting any warnings
- `make clean` - Remove `node_modules/` and `package-lock.json` to start clean (need to run `make image-build` after doing this, see below)
- `make npm XXX` - Run an `npm` command inside the container, e.g.: `make npm run lint` or `make npm install`
- `make ssh` - Open up a shell session into the buildchain Docker container
- `make build` - Do a local distribution build of the docs; normally not needed since they are built & deployed via GitHub action

## Docs versioning

Each major version of the plugin corresponds to a major version of Craft.

Each major version of the plugin has separate documentation that needs to be updated when changes span plugin versions.

The latest version of the docs that correspond to the latest version of the plugin is always the root of the docs tree, with older versions appearing in sub-directories:

```
│ index.html
├── v4
│ └── index.html
├── v3
│ └── index.html
```

The docs are entirely separate, but linked to eachother via a version menu, configured in the `docs/docs/.vitepress/config.ts` file.

## Algolia Docsearch

The docs uses [Algolia Docsearch](https://docsearch.algolia.com/) to index them, and allow for easy searching via a search field with auto-complete.

Algolia Docsearch is configured in the `docs/docs/.vitepress/config.ts` file.

## textlint

The buildchain uses [textlint](https://textlint.github.io/) to automatically fix errors on build, and also issue writing style warnings.

`textlint` automatically uses any rules added to the `docs/package.json` file, which can be overridden or customized via the `docs/.textlintrc.js` file.

See the [textlint docs](https://textlint.github.io/docs/getting-started.html) for details.

## Overriding environment variables

The `Makefile` contains sane defaults for most things, but you can override them via environment variables if you need to.

For instance, if you want to change the `DOCS_DEST` environment variable to change where `make build` builds the docs locally, you can set it before running any buildchain `make` commands:
```bash
env DOCS_DEST=../path/to/some/dir make build
```
...or use any other method for [setting environment variables](https://www.twilio.com/blog/how-to-set-environment-variables.html). This environment variable needs to be set in the shell where you run the buildchain's various `make` commands from, so setting it in your project's `.env` file won't work.
9 changes: 8 additions & 1 deletion docs/docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {defineConfig} from 'vitepress'
export default defineConfig({
title: 'Vite Plugin',
description: 'Documentation for the Vite plugin',
base: '/docs/vite/',
base: '/docs/vite/v1/',
lang: 'en-US',
head: [
['meta', {content: 'https://github.com/nystudio107', property: 'og:see_also',}],
Expand Down Expand Up @@ -33,6 +33,13 @@ export default defineConfig({
{text: 'Store', link: 'https://plugins.craftcms.com/vite'},
{text: 'Changelog', link: 'https://nystudio107.com/plugins/vite/changelog'},
{text: 'Issues', link: 'https://github.com/nystudio107/craft-vite/issues'},
{
text: 'v1', items: [
{text: 'v5', link: 'https://nystudio107.com/docs/vite/'},
{text: 'v4', link: 'https://nystudio107.com/docs/vite/v4/'},
{text: 'v1', link: '/'},
],
},
]
},
});
21 changes: 16 additions & 5 deletions docs/docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Article: [Vite.js Next Generation Frontend Tooling + Craft CMS](https://nystudio

## Requirements

This plugin requires Craft CMS 3.0.0 or later, or Craft CMS 4.0.0 or later.
This plugin requires Craft CMS 3.0.0 or later

## Installation

Expand All @@ -32,6 +32,8 @@ To install the plugin, follow these instructions.

3. In the Control Panel, go to Settings → Plugins and click the “Install” button for Vite.

4. Install Vite. Vite's *[Getting Started Guide](https://vitejs.dev/guide/)* provides various installation options.

Check warning on line 35 in docs/docs/index.md

View workflow job for this annotation

GitHub Actions / build (20.x)

"various" is a weasel word

## Vite Overview

Vite is a bridge between Craft CMS/Twig and the next generation frontend build tool [Vite.js](https://vitejs.dev/)

Check warning on line 39 in docs/docs/index.md

View workflow job for this annotation

GitHub Actions / build (20.x)

Avoid using “next generation”
Expand Down Expand Up @@ -126,6 +128,15 @@ hosted on a CDN or such.

### Configuring Vite.js

### Vite 5.0 or later

As of Vite 5.0 or later, there's been a [change to where the `manifest.json`](https://vitejs.dev/guide/migration#manifest-files-are-now-generated-in-vite-directory-by-default) is generated by default.

It is now placed inside a `.vite/` directory by default. You can accomodate this in either of the following ways:

* Change the `manifest` setting in your `vite.config.js` file to `manifest.json` (it can not either be a `bool` or a file path `string`)
* Change the `manifestPath` setting in your `config/vite.php` file to `'@webroot/dist/.vite/manifest.json'`

#### Basic Config

Here’s a basic `vite.config.js` for use as a [Vite config](https://vitejs.dev/config/):
Expand All @@ -138,7 +149,7 @@ export default ({command}) => ({
outDir: '../cms/web/dist/',
rollupOptions: {
input: {
app: './src/js/app.ts',
app: 'src/js/app.ts',
}
},
},
Expand Down Expand Up @@ -168,7 +179,7 @@ export default ({command}) => ({
outDir: '../cms/web/dist/',
rollupOptions: {
input: {
app: './src/js/app.ts',
app: 'src/js/app.ts',
}
},
},
Expand Down Expand Up @@ -202,7 +213,7 @@ export default ({command}) => ({
outDir: '../cms/web/dist/',
rollupOptions: {
input: {
app: './src/js/app.ts',
app: 'src/js/app.ts',
}
},
},
Expand Down Expand Up @@ -254,7 +265,7 @@ export default ({command}) => ({
outDir: '../cms/web/dist/',
rollupOptions: {
input: {
app: './src/js/app.ts',
app: 'src/js/app.ts',
}
},
},
Expand Down
Loading

0 comments on commit a3f35c8

Please sign in to comment.