- Edit
- components/HelloWorld.vue
to test HMR
-
- Check out - create-vue, the official Vue + Vite starter -
-- Install - Volar - in your IDE for a better DX -
-- Click on the Vite and Vue logos to learn more -
-This is an HTML email body.
', // HTML 格式的邮件正文(可选) - - // 附件(可选) - // attachments: [ - // { - // filename: 'example.txt', - // path: './path/to/example.txt', - // }, - // { - // filename: 'image.png', - // path: './path/to/image.png', - // cid: 'unique-image-id', // Content-Id for inline embedding - // }, - // ], -}; - -// 发送邮件 -transporter.sendMail(mailOptions, (error, info) => { - if (error) { - console.error('Failed to send email:', error); - } else { - console.log('Email sent successfully. Response:', info); - } -}); diff --git a/packages-demos/others/package.json b/packages-demos/others/package.json deleted file mode 100644 index cc9858d..0000000 --- a/packages-demos/others/package.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "name": "others", - "version": "1.0.0", - "description": "", - "main": "index.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "keywords": [], - "author": "", - "license": "ISC", - "dependencies": { - "express": "^4.19.2", - "fs-extra": "^11.2.0", - "nodemailer": "^6.9.13" - }, - "devDependencies": { - "axios": "^1.6.8" - } -} diff --git a/packages/create-cocos-plugin/README.md b/packages/create-cocos-plugin/README.md new file mode 100644 index 0000000..f83a592 --- /dev/null +++ b/packages/create-cocos-plugin/README.md @@ -0,0 +1,59 @@ +# create-cocos-plugin + +## Scaffolding Your First COCOS-plugin Project + +> **Compatibility Note:** +> create-cocos-plugin dependens on Vite. Vite requires [Node.js](https://nodejs.org/en/) version 18+, 20+. However, some templates require a higher Node.js version to work, please upgrade if your package manager warns about it. + +With NPM: + +```bash +$ npm create cocos-plugin@latest +``` + +With Yarn: + +```bash +$ yarn create cocos-plugin +``` + +With PNPM: + +```bash +$ pnpm create cocos-plugin +``` + +With Bun: + +```bash +$ bun create cocos-plugin +``` + +Then follow the prompts! + +You can also directly specify the project name and the template you want to use via additional command line options. For example, to scaffold a cocos-plugin + Vue project, run: + +```bash +# npm 7+, extra double-dash is needed: +npm create cocos-plugin@latest my-cocos-plugin -- --template vue + +# yarn +yarn create cocos-plugin my-cocos-plugin --template vue + +# pnpm +pnpm create cocos-plugin my-cocos-plugin --template vue + +# Bun +bun create cocos-plugin my-cocos-plugin --template vue +``` + +Currently supported template presets include: + +- `vanilla` +- `vanilla-ts` +- `vue` +- `vue-ts` +- `react` +- `react-ts` + +You can use `.` for the project name to scaffold in the current directory. diff --git a/packages/create-cocos-plugin/__tests__/cli.spec.ts b/packages/create-cocos-plugin/__tests__/cli.spec.ts new file mode 100644 index 0000000..db22dfd --- /dev/null +++ b/packages/create-cocos-plugin/__tests__/cli.spec.ts @@ -0,0 +1,112 @@ +import fs from 'node:fs'; +import path from 'node:path'; +import type { SyncOptions, SyncResult } from 'execa'; +import { execaCommandSync } from 'execa'; +import { afterEach, beforeAll, expect, test } from 'vitest'; + +const CLI_PATH = path.join(__dirname, '..'); + +const projectName = 'test-app'; +const genPath = path.join(__dirname, projectName); + +const run =
+ Edit src/App.tsx
and save to test HMR
+
+ Click on the Vite and React logos to learn more +
+ > + ) +} + +export default App diff --git a/packages/create-cocos-plugin/templates/react-ts/src/assets/react.svg b/packages/create-cocos-plugin/templates/react-ts/src/assets/react.svg new file mode 100644 index 0000000..6c87de9 --- /dev/null +++ b/packages/create-cocos-plugin/templates/react-ts/src/assets/react.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/packages/create-cocos-plugin/templates/react-ts/src/index.css b/packages/create-cocos-plugin/templates/react-ts/src/index.css new file mode 100644 index 0000000..6119ad9 --- /dev/null +++ b/packages/create-cocos-plugin/templates/react-ts/src/index.css @@ -0,0 +1,68 @@ +:root { + font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif; + line-height: 1.5; + font-weight: 400; + + color-scheme: light dark; + color: rgba(255, 255, 255, 0.87); + background-color: #242424; + + font-synthesis: none; + text-rendering: optimizeLegibility; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; +} + +a { + font-weight: 500; + color: #646cff; + text-decoration: inherit; +} +a:hover { + color: #535bf2; +} + +body { + margin: 0; + display: flex; + place-items: center; + min-width: 320px; + min-height: 100vh; +} + +h1 { + font-size: 3.2em; + line-height: 1.1; +} + +button { + border-radius: 8px; + border: 1px solid transparent; + padding: 0.6em 1.2em; + font-size: 1em; + font-weight: 500; + font-family: inherit; + background-color: #1a1a1a; + cursor: pointer; + transition: border-color 0.25s; +} +button:hover { + border-color: #646cff; +} +button:focus, +button:focus-visible { + outline: 4px auto -webkit-focus-ring-color; +} + +@media (prefers-color-scheme: light) { + :root { + color: #213547; + background-color: #ffffff; + } + a:hover { + color: #747bff; + } + button { + background-color: #f9f9f9; + } +} diff --git a/packages/create-cocos-plugin/templates/react-ts/src/main.tsx b/packages/create-cocos-plugin/templates/react-ts/src/main.tsx new file mode 100644 index 0000000..6f4ac9b --- /dev/null +++ b/packages/create-cocos-plugin/templates/react-ts/src/main.tsx @@ -0,0 +1,10 @@ +import { StrictMode } from 'react' +import { createRoot } from 'react-dom/client' +import App from './App.tsx' +import './index.css' + +createRoot(document.getElementById('root')!).render( +
+ Edit src/App.jsx
and save to test HMR
+
+ Click on the Vite and React logos to learn more +
+ > + ) +} + +export default App diff --git a/packages/create-cocos-plugin/templates/react/src/assets/react.svg b/packages/create-cocos-plugin/templates/react/src/assets/react.svg new file mode 100644 index 0000000..6c87de9 --- /dev/null +++ b/packages/create-cocos-plugin/templates/react/src/assets/react.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/packages/create-cocos-plugin/templates/react/src/index.css b/packages/create-cocos-plugin/templates/react/src/index.css new file mode 100644 index 0000000..6119ad9 --- /dev/null +++ b/packages/create-cocos-plugin/templates/react/src/index.css @@ -0,0 +1,68 @@ +:root { + font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif; + line-height: 1.5; + font-weight: 400; + + color-scheme: light dark; + color: rgba(255, 255, 255, 0.87); + background-color: #242424; + + font-synthesis: none; + text-rendering: optimizeLegibility; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; +} + +a { + font-weight: 500; + color: #646cff; + text-decoration: inherit; +} +a:hover { + color: #535bf2; +} + +body { + margin: 0; + display: flex; + place-items: center; + min-width: 320px; + min-height: 100vh; +} + +h1 { + font-size: 3.2em; + line-height: 1.1; +} + +button { + border-radius: 8px; + border: 1px solid transparent; + padding: 0.6em 1.2em; + font-size: 1em; + font-weight: 500; + font-family: inherit; + background-color: #1a1a1a; + cursor: pointer; + transition: border-color 0.25s; +} +button:hover { + border-color: #646cff; +} +button:focus, +button:focus-visible { + outline: 4px auto -webkit-focus-ring-color; +} + +@media (prefers-color-scheme: light) { + :root { + color: #213547; + background-color: #ffffff; + } + a:hover { + color: #747bff; + } + button { + background-color: #f9f9f9; + } +} diff --git a/packages/create-cocos-plugin/templates/react/src/main.jsx b/packages/create-cocos-plugin/templates/react/src/main.jsx new file mode 100644 index 0000000..89f91e5 --- /dev/null +++ b/packages/create-cocos-plugin/templates/react/src/main.jsx @@ -0,0 +1,10 @@ +import { StrictMode } from 'react' +import { createRoot } from 'react-dom/client' +import App from './App.jsx' +import './index.css' + +createRoot(document.getElementById('root')).render( +
+ Edit
+ components/HelloWorld.vue
to test HMR
+
+ Check out + create-vue, the official Vue + Vite starter +
++ Learn more about IDE Support for Vue in the + Vue Docs Scaling up Guide. +
+Click on the Vite and Vue logos to learn more
+ + + diff --git a/packages-demos/cocos-plugin-vue3/source/panel.ts b/packages/create-cocos-plugin/templates/vue-ts/src/panel.ts similarity index 73% rename from packages-demos/cocos-plugin-vue3/source/panel.ts rename to packages/create-cocos-plugin/templates/vue-ts/src/panel.ts index 99105b5..1c6e73e 100644 --- a/packages-demos/cocos-plugin-vue3/source/panel.ts +++ b/packages/create-cocos-plugin/templates/vue-ts/src/panel.ts @@ -1,11 +1,12 @@ -import { join } from 'path'; -import { readFileSync } from 'fs'; +import { join } from 'node:path'; +import { readFileSync } from 'node:fs'; import App from './App.vue'; import { createApp } from 'vue'; +import './style.css'; const weakMap = new WeakMap(); -export const template = ''; // 只留一个 div 用于 vue 的 mount +export const template = '