@tomjs/create-app 5.0.0 → 5.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
- package/templates/config/hbuilderx/extension/index.ts +22 -0
- package/templates/config/hbuilderx/extension/webview.ts +71 -0
- package/templates/config/hbuilderx/package.json +96 -0
- package/templates/config/hbuilderx/tsconfig.node.json +15 -0
- package/templates/config/package.json +10 -7
- package/templates/hbuilderx-base/README.md +20 -0
- package/templates/hbuilderx-base/package.json +52 -0
- package/templates/hbuilderx-base/src/env.d.ts +1 -0
- package/templates/hbuilderx-base/src/index.ts +17 -0
- package/templates/hbuilderx-base/tsconfig.json +7 -0
- package/templates/hbuilderx-base/tsdown.config.ts +13 -0
- package/templates/hbuilderx-react/README.md +25 -0
- package/templates/hbuilderx-react/index.html +13 -0
- package/templates/hbuilderx-react/package.json +12 -0
- package/templates/hbuilderx-react/pnpm-workspace.yaml +5 -0
- package/templates/hbuilderx-react/src/App.css +45 -0
- package/templates/hbuilderx-react/src/App.tsx +41 -0
- package/templates/hbuilderx-react/src/assets/react.svg +1 -0
- package/templates/hbuilderx-react/src/assets/vite.svg +1 -0
- package/templates/hbuilderx-react/src/index.css +73 -0
- package/templates/hbuilderx-react/src/main.tsx +10 -0
- package/templates/hbuilderx-react/tsconfig.app.json +18 -0
- package/templates/hbuilderx-react/vite.config.ts +19 -0
- package/templates/hbuilderx-vue/README.md +26 -0
- package/templates/hbuilderx-vue/index.html +13 -0
- package/templates/hbuilderx-vue/package.json +12 -0
- package/templates/hbuilderx-vue/pnpm-workspace.yaml +4 -0
- package/templates/hbuilderx-vue/src/App.vue +32 -0
- package/templates/hbuilderx-vue/src/assets/vite.svg +1 -0
- package/templates/hbuilderx-vue/src/assets/vue.svg +1 -0
- package/templates/hbuilderx-vue/src/components/HelloWorld.vue +29 -0
- package/templates/hbuilderx-vue/src/main.ts +5 -0
- package/templates/hbuilderx-vue/src/style.css +68 -0
- package/templates/hbuilderx-vue/tsconfig.app.json +18 -0
- package/templates/hbuilderx-vue/vite.config.ts +17 -0
- package/templates/vscode-react/package.json +1 -1
- package/templates/vscode-vue/package.json +1 -1
- package/templates/vscode-vue/tsconfig.app.json +0 -1
- package/templates/web-react/tsconfig.app.json +0 -1
- package/templates/web-vue/tsconfig.app.json +0 -1
- package/templates/vscode-vue/tsconfig.node.json +0 -8
- /package/templates/{vscode-react → config/hbuilderx}/tsconfig.json +0 -0
- /package/templates/{vscode-vue → config/vscode}/tsconfig.json +0 -0
- /package/templates/{vscode-react → config/vscode}/tsconfig.node.json +0 -0
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import e from"meow";import t from"node:fs";import n,{readdir as r}from"node:fs/promises";import i from"node:os";import a from"node:path";import{fileURLToPath as o}from"node:url";import*as s from"@clack/prompts";import{copy as c,mkdir as l,mkdirp as u,readFile as d,readJson as f,readJsonSync as p,rm as m,rmSync as h,writeFile as g,writeJson as _}from"@tomjs/node";import{camelCase as v,merge as y,upperFirst as b}from"lodash-es";import{glob as x}from"tinyglobby";import S from"chalk";import{$ as C}from"execa";import w from"@tomjs/logger";const T=o(new URL(`..`,import.meta.url)),ee=[`vue`,`react`],E=[{name:`node`,display:`Node`,color:S.green,children:[{name:`node-base`,display:`Base`,color:S.green,public:`npm`},{name:`node-cli`,display:`CLI`,color:S.green,public:`npm`},{name:`node-vite`,display:`Vite Plugin`,value:`vite-plugin-xxx`,color:S.blue,hasStyle:!0,public:`npm`}]},{name:`web`,display:`Web`,color:S.magenta,children:[{name:`web-vue`,display:`Vue`,color:S.green,hasStyle:!0},{name:`web-react`,display:`React`,color:S.blue,hasStyle:!0}]},{name:`vscode`,display:`VSCode`,color:S.blue,children:[{name:`vscode-base`,display:`Base`,color:S.yellow,public:`public`},{name:`vscode-vue`,display:`Vue`,color:S.green,commonTemplates:[`vscode`],hasStyle:!0,public:`public`},{name:`vscode-react`,display:`React`,color:S.blue,commonTemplates:[`vscode`],hasStyle:!0,public:`public`}]},{name:`electron`,display:`Electron`,color:S.cyan,children:[{name:`electron-vue`,display:`Vue`,color:S.green,commonTemplates:[`electron`],hasStyle:!0},{name:`electron-react`,display:`React`,color:S.blue,commonTemplates:[`electron`],hasStyle:!0}]}],D=[{id:`github`,name:`Github`,url:`https://github.com`},{id:`gitcode`,name:`GitCode`,url:`https://gitcode.com`},{id:`gitee`,name:`码云`,url:`https://gitee.com`}],O=`publisher.name.displayName.type.version.private.packageManager.description.author.contributors.license.funding.homepage.repository.publishConfig.bugs.keywords.categories.sideEffects.imports.exports.main.module.unpkg.jsdelivr.types.typesVersions.bin.icon.files.engines.activationEvents.contributes.scripts.peerDependencies.peerDependenciesMeta.dependencies.optionalDependencies.devDependencies.pnpm.overrides.resolutions.husky.simple-git-hooks.lint-staged.eslintConfig`.split(`.`),k=[`dev`,`dev:`,`debug`,`debug:`,`start`,`build`,`build:`,`preview`,`release`,`release:`,`clean`,`clean:`,`test`,`lint`,`lint:`],A=new w({directory:`create-app/logs`}),te=process.platform===`win32`;let j={};function ne(e){j=e}function M(){return j}async function N(e,t){let{trim:n,...r}=Object.assign({stdio:`pipe`,shell:!0},t);Array.isArray(e)&&(e=e.join(` `));let i=e=>{M().verbose?A.debug(e):A.write(e)};i(`$ ${e}`);try{let t=(await C(r)`${e}`).stdout;return i(t),n?t.trim().replace(/\n|\r/g,``):t.trim()}catch(e){let t=e.stderr||e.message;throw i(t),Error(t)}}function P(e){if(e===`C`)return`en-US`;let t=``;try{t=Intl.getCanonicalLocales(e)[0]}catch(t){console.log(`${t.toString()}, invalid language tag: "${e}"\n`)}switch(t){case`zh-TW`:case`zh-HK`:case`zh-MO`:case`zh-CN`:case`zh-SG`:t=`zh-CN`;break;default:t=e}return t}function F(){return P((process.env.LC_ALL||process.env.LC_MESSAGES||process.env.LANG||Intl.DateTimeFormat().resolvedOptions().locale||`en-US`).split(`.`)[0].replace(`_`,`-`))}async function I(e){return await t.promises.readFile(e,`utf-8`).then(e=>JSON.parse(e)||{})}async function L(e){let n=F(),r=a.resolve(e,`${n}.json`),i=a.resolve(e,`en-US.json`);return t.existsSync(r)?await I(r):await I(i)}const R=await L(a.join(T,`locales`));function z(...e){if(e.length===0||!R)return``;let[t,...n]=e,r=R[t]??``;if(n[0]===null||n[0]===void 0||n[0]===``)return r;let i=typeof n[0]==`object`?n[0]:n;return r.replace(/\{([^}]+)\}/g,(e,t)=>i[t]??e)}const B=a.join(o(import.meta.url),`../../`),V=a.join(B,`templates`),H=()=>s.cancel(z(`prompt.cancel`));async function U(e){ne(e);let t=await W(e);t&&(await G(t),e.package&&await ue(t),t.template===`node-vite`&&await de(t.targetDir,t.packageName),e.package||await N(`git init`,{cwd:t.targetDir}))}async function W(e){let n=async function(){let e=await s.select({message:z(`prompt.templateType.message`),options:E.map(e=>({label:e.color(e.display||e.name),value:e.name}))});if(s.isCancel(e))return H();let t=E.find(t=>t.name===e),r=await s.select({message:z(`prompt.template.message`),options:t.children.map(e=>({label:e.color(e.display||e.name),value:e.name})).concat({label:z(`prompt.template.back`),value:`back`})});return s.isCancel(r)?H():r===`back`?await n():{template:r,templateOptions:t.children.find(e=>e.name===r)}},r=await n();if(!r)return;let o=``;await q(`user.email`)===`tom@tomgao.cc`&&(o=`tomjs`);let{template:c,templateOptions:l}=r,u=c.startsWith(`node-`),d=e.packageName;d||(d=l.value||c,o&&u&&(d=`@${o}/${d}`));let f=await s.text({message:z(`prompt.package.message`),initialValue:d,defaultValue:d,placeholder:d,validate:e=>e.length===0||ae(e)?void 0:z(`prompt.package.invalid`)});if(s.isCancel(f))return H();d=f;let p=K(d),m=await s.text({message:z(`prompt.project.message`),defaultValue:p,initialValue:p,placeholder:p,validate:e=>e.length===0||e.length>0?void 0:z(`prompt.project.invalid`)});if(s.isCancel(m))return H();if(p=a.resolve(p===`~`&&!te?i.homedir():e.cwd||process.cwd(),m),t.existsSync(p)&&!re(p)){let t=e.overwrite;if(!t){let e=await s.select({message:z(`prompt.exist.message`,p),options:[{label:z(`prompt.exist.option.no`),value:`no`},{label:z(`prompt.exist.option.yes`),value:`yes`},{label:z(`prompt.exist.option.ignore`),value:`ignore`}]});if(s.isCancel(e))return H();t=e}switch(t){case`yes`:ie(p);break;case`no`:H();return}}let h;if(e.private!==!0&&l.public){let e=await s.confirm({message:z(`prompt.public.message`),active:z(`prompt.confirm.yes`),inactive:z(`prompt.confirm.no`),initialValue:!0});if(s.isCancel(e))return H();h=e}let g;if(h){let e=await s.select({message:z(`prompt.gitUrl.message`),options:D.map(e=>({label:`${e.name} (${e.url})`,value:e.id}))});if(s.isCancel(e))return H();g=D.find(t=>t.id===e)?.url}let _;if(h){o=se(d)||o;let e=await s.text({message:z(`prompt.orgName.message`),defaultValue:o,placeholder:o,validate:e=>o&&!e||oe(e)?void 0:z(`prompt.orgName.invalid`)});if(s.isCancel(e))return H();_=e}return delete l.color,{targetDir:p,orgName:_,packageName:d,template:c,templateOptions:l,isPublic:h,gitUrl:g}}async function G(e){A.debug(`projectOptions:`,e);let{targetDir:t,packageName:o,template:s,isPublic:p,gitUrl:h,orgName:v,templateOptions:b}=e;await l(t);let S=s.includes(`vscode`),C={},w=a.join(t,`.temp`);if(await u(w),await J(C,`base`,w),b.hasStyle&&(await J(C,`style`,w),!s.includes(`vue`))){function e(e){return e.replaceAll(`vue,`,``).replaceAll(`,vue`,``)}let t=await r(a.join(V,`config/style`));for(let n of t){if(n===`package.json`){C.scripts&&Object.keys(C.scripts).forEach(t=>{C.scripts[t].includes(`vue`)&&(C.scripts[t]=e(C.scripts[t]))});continue}let t=a.join(w,n),r=await d(t);r.includes(`vue`)&&g(t,e(r))}}p&&b.public&&await J(C,b.public,w);let T=ee.find(e=>s.includes(`-${e}`));T&&await J(C,T,w);let E=b.commonTemplates;if(Array.isArray(E)&&E.length>0)for(let e of E)await J(C,e,w);if(await c(w,t),await m(w),await c(a.join(V,s),t),y(C,await f(a.join(a.join(V,s),`package.json`))),C.name=o,p){delete C.private,C.name=o,C.license=`MIT`;let e=await q(`user.name`)||i.userInfo().username,n=await q(`user.email`);e&&n?C.author={name:e,email:n}:e&&(C.author=e);let r=`${h}/${v}/${a.basename(t)}`;S&&(C.publisher=v,C.homepage=`${r}/blob/main/README.md`,C.bugs={url:`${r}/issues`},delete C.publishConfig),C.repository={type:`git`,url:`${r}.git`,directory:M().package?`packages/${a.basename(t)}`:void 0}}else C.private=!0,delete C.publishConfig,C.devDependencies&&delete C.devDependencies.publint;if(await _(a.join(t,`package.json`),X(C)),await le(t),p){let{author:e}=C,r=``;e&&(typeof e==`string`?r=e:typeof e==`object`&&(e.name&&e.email?r=`${e.name}<${e.email}>`:e.name?r=e.name:e.email&&(r=e.email)));let i={pkgName:o,dateYear:new Date().getFullYear(),gitUserName:r},s=(await n.readdir(t)).filter(e=>[`README.md`,`README.zh_CN.md`,`LICENSE`].includes(e));for(let e of s){let n=await d(a.join(t,e));Object.keys(i).forEach(e=>{n=n.replace(RegExp(`{{${e}}}`,`g`),i[e])}),await g(a.join(t,e),n)}}let D=await x(`**/_*`,{ignore:[`**/node_modules/**`,`**/.*`],cwd:t});for(let e of D){let r=e.split(`/`);r[r.length-1]=r[r.length-1].substring(1),await n.rename(a.join(t,e),a.join(t,r.join(`/`)))}}function K(e){return(e||``).trim().replace(/^@[^/]+\//,``)}function re(e){return t.readdirSync(e).length===0}function ie(e){t.existsSync(e)&&h(e)}function ae(e){return/^(?:@[a-z\d\-*~][a-z\d\-*._~]*\/)?[a-z\d\-~][a-z\d\-._~]*$/.test(e)}function oe(e){return/^[a-z][a-z\d\-._]*$/.test(e)}async function q(e){return N(`git config --get ${e}`,{trim:!0})}function se(e){if(e.startsWith(`@`))return e.split(`/`)[0].substring(1)}async function J(e,r,i){let o=a.join(V,`config/${r}`);if(!t.existsSync(o))return;let s=await n.readdir(o);for(let t of s)[`node_modules`,`.git`].includes(t)||(t===`package.json`?y(e,await f(a.join(o,`package.json`))):await c(a.join(o,t),a.join(i,t)))}function Y(e,t){if(!e)return e;let n={};return Array.isArray(t)&&t.length>0?(t.filter(t=>t in e).forEach(t=>{n[t]=e[t]}),Object.keys(e).filter(e=>!t.includes(e)).sort().forEach(t=>{n[t]=e[t]})):Object.keys(e).sort().forEach(t=>{n[t]=e[t]}),n}function ce(e,t,n){let r={},i=Object.keys(e);{let e=i.filter(e=>e.includes(`:`));i=i.filter(e=>!e.includes(`:`)).sort().concat(e)}let a=s(t),o=s(n);return a.concat(i.filter(e=>!a.includes(e)&&!o.includes(e))).concat(o).forEach(t=>{r[t]=e[t]}),r;function s(e){let t=Array.isArray(e)?e:[];return t.length>0&&(t=t.reduce((e,t)=>{if(t.endsWith(`:`)){let n=i.filter(n=>!e.includes(n)&&n.startsWith(t));return e.concat(n)}return i.includes(t)?e.concat(t):e},[])),t}}function X(e){return e=Y(e,O),e.scripts&&=ce(e.scripts,k,[`prepare`,`prepublishOnly`]),[`dependencies`,`devDependencies`,`peerDependencies`].forEach(t=>{e[t]&&(e[t]=Y(e[t]))}),e}async function le(e){let t=p(a.join(V,`config/package.json`))?.dependencies||{},n=await x(`**/package.json`,{ignore:[`**/node_modules/**`,`**/.*`],cwd:e});for(let r of n){let n=a.join(e,r),i=await f(n);[`dependencies`,`devDependencies`].forEach(e=>{let n=i[e];n&&Object.keys(n).forEach(e=>{n[e]=t[e]||n[e]})}),_(n,X(i))}}async function ue(e){let n=e.templateOptions.hasStyle,r=[`.editorconfig`,`.gitignore`,`.gitattributes`,`commitlint.config.mjs`,`simple-git-hooks.mjs`,`pnpm-workspace.yaml`];n||r.push(`lint-staged.config.mjs`),[`vscode`,`electron`].find(t=>e.template.startsWith(t))||r.push(`.vscode`),r.forEach(n=>{let r=a.join(e.targetDir,n);t.existsSync(r)&&h(r)});let i=await f(a.join(e.targetDir,`package.json`));if(i.scripts&&delete i.scripts.prepare,!n)delete i.devDependencies;else if(i.devDependencies){let e=await f(a.join(V,`config/style/package.json`)),t=Object.keys(e.devDependencies||{});Object.keys(i.devDependencies).forEach(e=>{t.includes(e)||delete i.devDependencies[e]})}await _(a.join(e.targetDir,`package.json`),i)}async function de(e,t){let n=v((t.split(`/`).pop()||``).replace(`vite-plugin`,``)||`xxx`),r=await x([`src/**/*.ts`,`examples/*/vite.config.ts`,`examples/*/package.json`],{ignore:[`**/node_modules/**`,`**/.*`],cwd:e});for(let t of r){let r=a.join(e,t);await g(r,(await d(r)).replaceAll(`xxx`,n).replaceAll(`Xxx`,b(n)))}}const Z=e(`
|
|
1
|
+
import e from"meow";import t from"node:fs";import n,{readdir as r}from"node:fs/promises";import i from"node:os";import a from"node:path";import{fileURLToPath as o}from"node:url";import*as s from"@clack/prompts";import{copy as c,mkdir as l,mkdirp as u,readFile as d,readJson as f,readJsonSync as p,rm as m,rmSync as h,writeFile as g,writeJson as _}from"@tomjs/node";import{camelCase as v,merge as y,upperFirst as b}from"lodash-es";import{glob as x}from"tinyglobby";import S from"chalk";import{$ as C}from"execa";import w from"@tomjs/logger";const T=o(new URL(`..`,import.meta.url)),ee=[`vue`,`react`],E=[{name:`node`,display:`Node`,color:S.green,children:[{name:`node-base`,display:`Base`,color:S.green,public:`npm`},{name:`node-cli`,display:`CLI`,color:S.green,public:`npm`},{name:`node-vite`,display:`Vite Plugin`,value:`vite-plugin-xxx`,color:S.blue,hasStyle:!0,public:`npm`}]},{name:`web`,display:`Web`,color:S.magenta,children:[{name:`web-vue`,display:`Vue`,color:S.green,hasStyle:!0},{name:`web-react`,display:`React`,color:S.blue,hasStyle:!0}]},{name:`vscode`,display:`VSCode`,color:S.blue,children:[{name:`vscode-base`,display:`Base`,color:S.yellow,public:`public`},{name:`vscode-vue`,display:`Vue`,color:S.green,commonTemplates:[`vscode`],hasStyle:!0,public:`public`},{name:`vscode-react`,display:`React`,color:S.blue,commonTemplates:[`vscode`],hasStyle:!0,public:`public`}]},{name:`electron`,display:`Electron`,color:S.cyan,children:[{name:`electron-vue`,display:`Vue`,color:S.green,commonTemplates:[`electron`],hasStyle:!0},{name:`electron-react`,display:`React`,color:S.blue,commonTemplates:[`electron`],hasStyle:!0}]},{name:`hbuilderx`,display:`HBuilderX`,color:S.yellow,children:[{name:`hbuilderx-base`,display:`Base`,color:S.yellow,public:`public`},{name:`hbuilderx-vue`,display:`Vue`,color:S.green,commonTemplates:[`hbuilderx`],hasStyle:!0,public:`public`},{name:`hbuilderx-react`,display:`React`,color:S.blue,commonTemplates:[`hbuilderx`],hasStyle:!0,public:`public`}]}],D=[{id:`github`,name:`Github`,url:`https://github.com`},{id:`gitcode`,name:`GitCode`,url:`https://gitcode.com`},{id:`gitee`,name:`码云`,url:`https://gitee.com`}],O=`publisher.name.displayName.type.version.private.packageManager.description.author.contributors.license.funding.homepage.repository.publishConfig.bugs.keywords.categories.sideEffects.imports.exports.main.module.unpkg.jsdelivr.types.typesVersions.bin.icon.files.engines.activationEvents.contributes.scripts.peerDependencies.peerDependenciesMeta.dependencies.optionalDependencies.devDependencies.pnpm.overrides.resolutions.husky.simple-git-hooks.lint-staged.eslintConfig`.split(`.`),k=[`dev`,`dev:`,`debug`,`debug:`,`start`,`build`,`build:`,`preview`,`release`,`release:`,`clean`,`clean:`,`test`,`lint`,`lint:`],A=new w({directory:`create-app/logs`}),te=process.platform===`win32`;let j={};function ne(e){j=e}function M(){return j}async function N(e,t){let{trim:n,...r}=Object.assign({stdio:`pipe`,shell:!0},t);Array.isArray(e)&&(e=e.join(` `));let i=e=>{M().verbose?A.debug(e):A.write(e)};i(`$ ${e}`);try{let t=(await C(r)`${e}`).stdout;return i(t),n?t.trim().replace(/\n|\r/g,``):t.trim()}catch(e){let t=e.stderr||e.message;throw i(t),Error(t)}}function P(e){if(e===`C`)return`en-US`;let t=``;try{t=Intl.getCanonicalLocales(e)[0]}catch(t){console.log(`${t.toString()}, invalid language tag: "${e}"\n`)}switch(t){case`zh-TW`:case`zh-HK`:case`zh-MO`:case`zh-CN`:case`zh-SG`:t=`zh-CN`;break;default:t=e}return t}function F(){return P((process.env.LC_ALL||process.env.LC_MESSAGES||process.env.LANG||Intl.DateTimeFormat().resolvedOptions().locale||`en-US`).split(`.`)[0].replace(`_`,`-`))}async function I(e){return await t.promises.readFile(e,`utf-8`).then(e=>JSON.parse(e)||{})}async function L(e){let n=F(),r=a.resolve(e,`${n}.json`),i=a.resolve(e,`en-US.json`);return t.existsSync(r)?await I(r):await I(i)}const R=await L(a.join(T,`locales`));function z(...e){if(e.length===0||!R)return``;let[t,...n]=e,r=R[t]??``;if(n[0]===null||n[0]===void 0||n[0]===``)return r;let i=typeof n[0]==`object`?n[0]:n;return r.replace(/\{([^}]+)\}/g,(e,t)=>i[t]??e)}const B=a.join(o(import.meta.url),`../../`),V=a.join(B,`templates`),H=()=>s.cancel(z(`prompt.cancel`));async function U(e){ne(e);let t=await W(e);t&&(await G(t),e.package&&await ue(t),t.template===`node-vite`&&await de(t.targetDir,t.packageName),e.package||await N(`git init`,{cwd:t.targetDir}))}async function W(e){let n=async function(){let e=await s.select({message:z(`prompt.templateType.message`),options:E.map(e=>({label:e.color(e.display||e.name),value:e.name}))});if(s.isCancel(e))return H();let t=E.find(t=>t.name===e),r=await s.select({message:z(`prompt.template.message`),options:t.children.map(e=>({label:e.color(e.display||e.name),value:e.name})).concat({label:z(`prompt.template.back`),value:`back`})});return s.isCancel(r)?H():r===`back`?await n():{template:r,templateOptions:t.children.find(e=>e.name===r)}},r=await n();if(!r)return;let o=``;await q(`user.email`)===`tom@tomgao.cc`&&(o=`tomjs`);let{template:c,templateOptions:l}=r,u=c.startsWith(`node-`),d=e.packageName;d||(d=l.value||c,o&&u&&(d=`@${o}/${d}`));let f=await s.text({message:z(`prompt.package.message`),initialValue:d,defaultValue:d,placeholder:d,validate:e=>e.length===0||ae(e)?void 0:z(`prompt.package.invalid`)});if(s.isCancel(f))return H();d=f;let p=K(d),m=await s.text({message:z(`prompt.project.message`),defaultValue:p,initialValue:p,placeholder:p,validate:e=>e.length===0||e.length>0?void 0:z(`prompt.project.invalid`)});if(s.isCancel(m))return H();if(p=a.resolve(p===`~`&&!te?i.homedir():e.cwd||process.cwd(),m),t.existsSync(p)&&!re(p)){let t=e.overwrite;if(!t){let e=await s.select({message:z(`prompt.exist.message`,p),options:[{label:z(`prompt.exist.option.no`),value:`no`},{label:z(`prompt.exist.option.yes`),value:`yes`},{label:z(`prompt.exist.option.ignore`),value:`ignore`}]});if(s.isCancel(e))return H();t=e}switch(t){case`yes`:ie(p);break;case`no`:H();return}}let h;if(e.private!==!0&&l.public){let e=await s.confirm({message:z(`prompt.public.message`),active:z(`prompt.confirm.yes`),inactive:z(`prompt.confirm.no`),initialValue:!0});if(s.isCancel(e))return H();h=e}let g;if(h){let e=await s.select({message:z(`prompt.gitUrl.message`),options:D.map(e=>({label:`${e.name} (${e.url})`,value:e.id}))});if(s.isCancel(e))return H();g=D.find(t=>t.id===e)?.url}let _;if(h){o=se(d)||o;let e=await s.text({message:z(`prompt.orgName.message`),defaultValue:o,placeholder:o,validate:e=>o&&!e||oe(e)?void 0:z(`prompt.orgName.invalid`)});if(s.isCancel(e))return H();_=e}return delete l.color,{targetDir:p,orgName:_,packageName:d,template:c,templateOptions:l,isPublic:h,gitUrl:g}}async function G(e){A.debug(`projectOptions:`,e);let{targetDir:t,packageName:o,template:s,isPublic:p,gitUrl:h,orgName:v,templateOptions:b}=e;await l(t);let S=s.includes(`vscode`),C={},w=a.join(t,`.temp`);if(await u(w),await J(C,`base`,w),b.hasStyle&&(await J(C,`style`,w),!s.includes(`vue`))){function e(e){return e.replaceAll(`vue,`,``).replaceAll(`,vue`,``)}let t=await r(a.join(V,`config/style`));for(let n of t){if(n===`package.json`){C.scripts&&Object.keys(C.scripts).forEach(t=>{C.scripts[t].includes(`vue`)&&(C.scripts[t]=e(C.scripts[t]))});continue}let t=a.join(w,n),r=await d(t);r.includes(`vue`)&&g(t,e(r))}}p&&b.public&&await J(C,b.public,w);let T=ee.find(e=>s.includes(`-${e}`));T&&await J(C,T,w);let E=b.commonTemplates;if(Array.isArray(E)&&E.length>0)for(let e of E)await J(C,e,w);if(await c(w,t),await m(w),await c(a.join(V,s),t),y(C,await f(a.join(a.join(V,s),`package.json`))),C.name=o,p){delete C.private,C.name=o,C.license=`MIT`;let e=await q(`user.name`)||i.userInfo().username,n=await q(`user.email`);e&&n?C.author={name:e,email:n}:e&&(C.author=e);let r=`${h}/${v}/${a.basename(t)}`;S&&(C.publisher=v,C.homepage=`${r}/blob/main/README.md`,C.bugs={url:`${r}/issues`},delete C.publishConfig),C.repository={type:`git`,url:`${r}.git`,directory:M().package?`packages/${a.basename(t)}`:void 0}}else C.private=!0,delete C.publishConfig,C.devDependencies&&delete C.devDependencies.publint;if(await _(a.join(t,`package.json`),X(C)),await le(t),p){let{author:e}=C,r=``;e&&(typeof e==`string`?r=e:typeof e==`object`&&(e.name&&e.email?r=`${e.name}<${e.email}>`:e.name?r=e.name:e.email&&(r=e.email)));let i={pkgName:o,dateYear:new Date().getFullYear(),gitUserName:r},s=(await n.readdir(t)).filter(e=>[`README.md`,`README.zh_CN.md`,`LICENSE`].includes(e));for(let e of s){let n=await d(a.join(t,e));Object.keys(i).forEach(e=>{n=n.replace(RegExp(`{{${e}}}`,`g`),i[e])}),await g(a.join(t,e),n)}}let D=await x(`**/_*`,{ignore:[`**/node_modules/**`,`**/.*`],cwd:t});for(let e of D){let r=e.split(`/`);r[r.length-1]=r[r.length-1].substring(1),await n.rename(a.join(t,e),a.join(t,r.join(`/`)))}}function K(e){return(e||``).trim().replace(/^@[^/]+\//,``)}function re(e){return t.readdirSync(e).length===0}function ie(e){t.existsSync(e)&&h(e)}function ae(e){return/^(?:@[a-z\d\-*~][a-z\d\-*._~]*\/)?[a-z\d\-~][a-z\d\-._~]*$/.test(e)}function oe(e){return/^[a-z][a-z\d\-._]*$/.test(e)}async function q(e){return N(`git config --get ${e}`,{trim:!0})}function se(e){if(e.startsWith(`@`))return e.split(`/`)[0].substring(1)}async function J(e,r,i){let o=a.join(V,`config/${r}`);if(!t.existsSync(o))return;let s=await n.readdir(o);for(let t of s)[`node_modules`,`.git`].includes(t)||(t===`package.json`?y(e,await f(a.join(o,`package.json`))):await c(a.join(o,t),a.join(i,t)))}function Y(e,t){if(!e)return e;let n={};return Array.isArray(t)&&t.length>0?(t.filter(t=>t in e).forEach(t=>{n[t]=e[t]}),Object.keys(e).filter(e=>!t.includes(e)).sort().forEach(t=>{n[t]=e[t]})):Object.keys(e).sort().forEach(t=>{n[t]=e[t]}),n}function ce(e,t,n){let r={},i=Object.keys(e);{let e=i.filter(e=>e.includes(`:`));i=i.filter(e=>!e.includes(`:`)).sort().concat(e)}let a=s(t),o=s(n);return a.concat(i.filter(e=>!a.includes(e)&&!o.includes(e))).concat(o).forEach(t=>{r[t]=e[t]}),r;function s(e){let t=Array.isArray(e)?e:[];return t.length>0&&(t=t.reduce((e,t)=>{if(t.endsWith(`:`)){let n=i.filter(n=>!e.includes(n)&&n.startsWith(t));return e.concat(n)}return i.includes(t)?e.concat(t):e},[])),t}}function X(e){return e=Y(e,O),e.scripts&&=ce(e.scripts,k,[`prepare`,`prepublishOnly`]),[`dependencies`,`devDependencies`,`peerDependencies`].forEach(t=>{e[t]&&(e[t]=Y(e[t]))}),e}async function le(e){let t=p(a.join(V,`config/package.json`))?.dependencies||{},n=await x(`**/package.json`,{ignore:[`**/node_modules/**`,`**/.*`],cwd:e});for(let r of n){let n=a.join(e,r),i=await f(n);[`dependencies`,`devDependencies`].forEach(e=>{let n=i[e];n&&Object.keys(n).forEach(e=>{n[e]=t[e]||n[e]})}),_(n,X(i))}}async function ue(e){let n=e.templateOptions.hasStyle,r=[`.editorconfig`,`.gitignore`,`.gitattributes`,`commitlint.config.mjs`,`simple-git-hooks.mjs`,`pnpm-workspace.yaml`];n||r.push(`lint-staged.config.mjs`),[`vscode`,`electron`].find(t=>e.template.startsWith(t))||r.push(`.vscode`),r.forEach(n=>{let r=a.join(e.targetDir,n);t.existsSync(r)&&h(r)});let i=await f(a.join(e.targetDir,`package.json`));if(i.scripts&&delete i.scripts.prepare,!n)delete i.devDependencies;else if(i.devDependencies){let e=await f(a.join(V,`config/style/package.json`)),t=Object.keys(e.devDependencies||{});Object.keys(i.devDependencies).forEach(e=>{t.includes(e)||delete i.devDependencies[e]})}await _(a.join(e.targetDir,`package.json`),i)}async function de(e,t){let n=v((t.split(`/`).pop()||``).replace(`vite-plugin`,``)||`xxx`),r=await x([`src/**/*.ts`,`examples/*/vite.config.ts`,`examples/*/package.json`],{ignore:[`**/node_modules/**`,`**/.*`],cwd:e});for(let t of r){let r=a.join(e,t);await g(r,(await d(r)).replaceAll(`xxx`,n).replaceAll(`Xxx`,b(n)))}}const Z=e(`
|
|
2
2
|
Usage
|
|
3
3
|
$ create-app [options] <package-name>
|
|
4
4
|
|
package/package.json
CHANGED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ExtensionContext } from 'hbuilderx';
|
|
2
|
+
import { setContext } from '@tomjs/hbuilderx';
|
|
3
|
+
import { commands } from 'hbuilderx';
|
|
4
|
+
import { createDialogWebview, createLeftWebview, createRightWebview } from './webview';
|
|
5
|
+
|
|
6
|
+
export function activate(context: ExtensionContext) {
|
|
7
|
+
setContext(context);
|
|
8
|
+
|
|
9
|
+
context.subscriptions.push(
|
|
10
|
+
commands.registerCommand('tomjs.ext.showLeftWebview', async () => {
|
|
11
|
+
createLeftWebview();
|
|
12
|
+
}),
|
|
13
|
+
commands.registerCommand('tomjs.ext.showRightWebview', async () => {
|
|
14
|
+
createRightWebview();
|
|
15
|
+
}),
|
|
16
|
+
commands.registerCommand('tomjs.ext.showWebviewDialog', async () => {
|
|
17
|
+
createDialogWebview();
|
|
18
|
+
}),
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function deactivate() { }
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { WebViewDialog, WebViewPanel } from 'hbuilderx';
|
|
2
|
+
import { getContext } from '@tomjs/hbuilderx';
|
|
3
|
+
import { window } from 'hbuilderx';
|
|
4
|
+
import { getWebviewHtml } from 'virtual:hbuilderx';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @description 显示webview
|
|
8
|
+
*/
|
|
9
|
+
function showWebView(webviewPanel: WebViewPanel | WebViewDialog) {
|
|
10
|
+
const webview = webviewPanel.webView;
|
|
11
|
+
|
|
12
|
+
webview.html = getWebviewHtml({
|
|
13
|
+
// dev server
|
|
14
|
+
serverUrl: process.env.VITE_DEV_SERVER_URL,
|
|
15
|
+
// build
|
|
16
|
+
context: getContext(),
|
|
17
|
+
injectCode: `<script>window.__FLAG1__=666;window.__FLAG2__=888;console.log(window.__FLAG1__);</script>`,
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
// 插件接收webview发送的消息(可以被JSON化的数据)
|
|
21
|
+
webview.onDidReceiveMessage((msg) => {
|
|
22
|
+
console.log('extension msg:', msg);
|
|
23
|
+
if (msg.command === 'alert') {
|
|
24
|
+
window.showInformationMessage(msg.text);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
let leftWebviewPanel: WebViewPanel;
|
|
30
|
+
export function createLeftWebview() {
|
|
31
|
+
if (!leftWebviewPanel) {
|
|
32
|
+
leftWebviewPanel = window.createWebView('tomjs.webview.left', {
|
|
33
|
+
enableScripts: true,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
showWebView(leftWebviewPanel);
|
|
38
|
+
|
|
39
|
+
window.showView({
|
|
40
|
+
containerId: 'tomjsActivitybar',
|
|
41
|
+
viewId: 'tomjs.webview.left',
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
let rightWebviewPanel: WebViewPanel;
|
|
46
|
+
export function createRightWebview() {
|
|
47
|
+
if (!rightWebviewPanel) {
|
|
48
|
+
rightWebviewPanel = window.createWebView('tomjs.webview.right', {
|
|
49
|
+
enableScripts: true,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
showWebView(rightWebviewPanel);
|
|
54
|
+
|
|
55
|
+
window.showView({
|
|
56
|
+
containerId: 'tomjsRightSide',
|
|
57
|
+
viewId: 'tomjs.webview.right',
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export function createDialogWebview() {
|
|
62
|
+
const dialogWebviewPanel = window.createWebViewDialog({
|
|
63
|
+
title: 'Dialog Webview',
|
|
64
|
+
}, {
|
|
65
|
+
enableScripts: true,
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
showWebView(dialogWebviewPanel);
|
|
69
|
+
|
|
70
|
+
dialogWebviewPanel.show();
|
|
71
|
+
};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
{
|
|
2
|
+
"keywords": [
|
|
3
|
+
"HBuilderX"
|
|
4
|
+
],
|
|
5
|
+
"categories": [
|
|
6
|
+
"Other"
|
|
7
|
+
],
|
|
8
|
+
"engines": {
|
|
9
|
+
"node": ">=16.17.0",
|
|
10
|
+
"HBuilderX": "^2.7.0"
|
|
11
|
+
},
|
|
12
|
+
"activationEvents": [],
|
|
13
|
+
"contributes": {
|
|
14
|
+
"commands": [
|
|
15
|
+
{
|
|
16
|
+
"command": "tomjs.ext.showLeftWebview",
|
|
17
|
+
"title": "触发左侧视图"
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"command": "tomjs.ext.showRightWebview",
|
|
21
|
+
"title": "触发右侧视图"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"command": "tomjs.ext.showWebviewDialog",
|
|
25
|
+
"title": "触发弹框视图"
|
|
26
|
+
}
|
|
27
|
+
],
|
|
28
|
+
"menus": {
|
|
29
|
+
"editor/context": [
|
|
30
|
+
{
|
|
31
|
+
"command": "tomjs.ext.showLeftWebview",
|
|
32
|
+
"group": "z_commands",
|
|
33
|
+
"when": "editorTextFocus"
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"command": "tomjs.ext.showRightWebview",
|
|
37
|
+
"group": "z_commands",
|
|
38
|
+
"when": "editorTextFocus"
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"command": "tomjs.ext.showWebviewDialog",
|
|
42
|
+
"group": "z_commands",
|
|
43
|
+
"when": "editorTextFocus"
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
"command": "tomjs.ext.showCustomEditor",
|
|
47
|
+
"group": "z_commands",
|
|
48
|
+
"when": "editorTextFocus"
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"group": "z_commands"
|
|
52
|
+
}
|
|
53
|
+
]
|
|
54
|
+
},
|
|
55
|
+
"viewsContainers": {
|
|
56
|
+
"activitybar": [
|
|
57
|
+
{
|
|
58
|
+
"id": "tomjsActivitybar",
|
|
59
|
+
"title": "左侧webview展示"
|
|
60
|
+
}
|
|
61
|
+
],
|
|
62
|
+
"rightside": [
|
|
63
|
+
{
|
|
64
|
+
"id": "tomjsRightSide",
|
|
65
|
+
"title": "右侧webview展示"
|
|
66
|
+
}
|
|
67
|
+
]
|
|
68
|
+
},
|
|
69
|
+
"views": {
|
|
70
|
+
"tomjsActivitybar": [
|
|
71
|
+
{
|
|
72
|
+
"id": "tomjs.webview.left",
|
|
73
|
+
"title": "webview - 展示"
|
|
74
|
+
}
|
|
75
|
+
],
|
|
76
|
+
"tomjsRightSide": [
|
|
77
|
+
{
|
|
78
|
+
"id": "tomjs.webview.right",
|
|
79
|
+
"title": "webview - 展示"
|
|
80
|
+
}
|
|
81
|
+
]
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
"scripts": {
|
|
85
|
+
"dev": "run-p dev:*",
|
|
86
|
+
"dev:vite": "vite",
|
|
87
|
+
"dev:cli": "hx-cli --watch"
|
|
88
|
+
},
|
|
89
|
+
"dependencies": {
|
|
90
|
+
"@tomjs/hbuilderx": "^1.2.0"
|
|
91
|
+
},
|
|
92
|
+
"devDependencies": {
|
|
93
|
+
"@tomjs/hbuilderx-cli": "^1.3.1",
|
|
94
|
+
"@tomjs/vite-plugin-hbuilderx": "^1.2.0"
|
|
95
|
+
}
|
|
96
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "@tomjs/tsconfig/node.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
|
|
5
|
+
"types": [
|
|
6
|
+
"@tomjs/hbuilderx/types",
|
|
7
|
+
"@tomjs/vite-plugin-hbuilderx/types"
|
|
8
|
+
]
|
|
9
|
+
},
|
|
10
|
+
"include": [
|
|
11
|
+
"hbuilderx.d.ts",
|
|
12
|
+
"extension",
|
|
13
|
+
"vite.config.ts"
|
|
14
|
+
]
|
|
15
|
+
}
|
|
@@ -3,14 +3,17 @@
|
|
|
3
3
|
"@antfu/eslint-config": "^6.7.3",
|
|
4
4
|
"@clack/prompts": "^0.11.0",
|
|
5
5
|
"@commitlint/cli": "^20.3.0",
|
|
6
|
-
"@eslint-react/eslint-plugin": "^2.5.
|
|
6
|
+
"@eslint-react/eslint-plugin": "^2.5.1",
|
|
7
7
|
"@tomjs/commitlint": "^5.0.0",
|
|
8
|
-
"@tomjs/eslint": "^6.
|
|
9
|
-
"@tomjs/
|
|
8
|
+
"@tomjs/eslint": "^6.5.0",
|
|
9
|
+
"@tomjs/hbuilderx": "^1.2.0",
|
|
10
|
+
"@tomjs/hbuilderx-cli": "^1.3.1",
|
|
11
|
+
"@tomjs/logger": "^3.0.0",
|
|
10
12
|
"@tomjs/node": "^2.2.3",
|
|
11
13
|
"@tomjs/stylelint": "^7.0.0",
|
|
12
|
-
"@tomjs/tsconfig": "^3.0
|
|
13
|
-
"@tomjs/vite-plugin-electron": "^2.
|
|
14
|
+
"@tomjs/tsconfig": "^3.2.0",
|
|
15
|
+
"@tomjs/vite-plugin-electron": "^2.3.0",
|
|
16
|
+
"@tomjs/vite-plugin-hbuilderx": "^1.2.0",
|
|
14
17
|
"@tomjs/vite-plugin-vscode": "^6.1.0",
|
|
15
18
|
"@tomjs/vscode": "^2.5.0",
|
|
16
19
|
"@tomjs/vscode-dev": "^3.1.2",
|
|
@@ -41,7 +44,7 @@
|
|
|
41
44
|
"publint": "0.3.16",
|
|
42
45
|
"react": "^19.2.3",
|
|
43
46
|
"react-dom": "^19.2.3",
|
|
44
|
-
"sass": "^1.97.
|
|
47
|
+
"sass": "^1.97.2",
|
|
45
48
|
"simple-git-hooks": "^2.13.1",
|
|
46
49
|
"stylelint": "^16.26.1",
|
|
47
50
|
"tsdown": "^0.18.4",
|
|
@@ -52,6 +55,6 @@
|
|
|
52
55
|
"vite-plugin-vue-devtools": "^8.0.5",
|
|
53
56
|
"vue": "^3.5.26",
|
|
54
57
|
"vue-i18n": "^11.2.8",
|
|
55
|
-
"vue-tsc": "^3.2.
|
|
58
|
+
"vue-tsc": "^3.2.2"
|
|
56
59
|
}
|
|
57
60
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# hbuilderx-base
|
|
2
|
+
|
|
3
|
+
简单命令弹框插件
|
|
4
|
+
|
|
5
|
+
## 使用
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# 开发模式,不压缩代码
|
|
9
|
+
pnpm dev
|
|
10
|
+
# 生产模式,压缩代码
|
|
11
|
+
pnpm build
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## 调试
|
|
15
|
+
|
|
16
|
+
根据以下步骤调试插件,具体参考官方[插件教程](https://hx.dcloud.net.cn/ExtensionTutorial/firstExtension)
|
|
17
|
+
|
|
18
|
+
- 将当前项目 `hbuilderx-base` 拖拽到 `HBuilderX` 中
|
|
19
|
+
- 点击左上 `运行` 图标,选择点击 `运行插件-[hbuilderx-base]` 或 `调试插件-[hbuilderx-base]`,会打开的 `HBuilderX` 窗口调试插件。
|
|
20
|
+
- 在调试导入或创建任意项目,打开任意文件,在文件编辑器中点击鼠标右唤出菜单,选择 `Hello World` 选项, 会在右下角弹出提示框。
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"publisher": "tomjs",
|
|
3
|
+
"name": "ext-simple",
|
|
4
|
+
"displayName": "简单插件",
|
|
5
|
+
"type": "commonjs",
|
|
6
|
+
"version": "0.0.0",
|
|
7
|
+
"description": "简单插件",
|
|
8
|
+
"keywords": [
|
|
9
|
+
"HBuilderX"
|
|
10
|
+
],
|
|
11
|
+
"categories": [
|
|
12
|
+
"Other"
|
|
13
|
+
],
|
|
14
|
+
"main": "./dist/index.js",
|
|
15
|
+
"engines": {
|
|
16
|
+
"node": ">=16.17.0",
|
|
17
|
+
"HBuilderX": "^2.7.0"
|
|
18
|
+
},
|
|
19
|
+
"activationEvents": [],
|
|
20
|
+
"contributes": {
|
|
21
|
+
"commands": [
|
|
22
|
+
{
|
|
23
|
+
"command": "tomjs.xxx.showHello",
|
|
24
|
+
"title": "Hello World"
|
|
25
|
+
}
|
|
26
|
+
],
|
|
27
|
+
"menus": {
|
|
28
|
+
"editor/context": [
|
|
29
|
+
{
|
|
30
|
+
"command": "tomjs.xxx.showHello",
|
|
31
|
+
"group": "z_commands",
|
|
32
|
+
"when": "editorTextFocus"
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"group": "z_commands"
|
|
36
|
+
}
|
|
37
|
+
]
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"scripts": {
|
|
41
|
+
"dev": "tsdown --watch",
|
|
42
|
+
"build": "tsdown",
|
|
43
|
+
"lint": "eslint --fix"
|
|
44
|
+
},
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"@tomjs/hbuilderx": "^1.2.0"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@types/node": "^20.19.27",
|
|
50
|
+
"tsdown": "^0.18.4"
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/// <reference types="@tomjs/hbuilderx/types" />
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ExtensionContext } from 'hbuilderx';
|
|
2
|
+
import { isAlphaVersion, setContext } from '@tomjs/hbuilderx';
|
|
3
|
+
import { commands, window } from 'hbuilderx';
|
|
4
|
+
|
|
5
|
+
export function activate(context: ExtensionContext) {
|
|
6
|
+
setContext(context);
|
|
7
|
+
|
|
8
|
+
context.subscriptions.push(
|
|
9
|
+
commands.registerCommand('tomjs.xxx.showHello', async () => {
|
|
10
|
+
window.showInformationMessage(`Hello World!这是 ${isAlphaVersion ? '测试' : '正式'}版本的 HBuilderX。`, ['确定1', '取消2']).then((result) => {
|
|
11
|
+
window.showInformationMessage(`你点击了${result}`);
|
|
12
|
+
});
|
|
13
|
+
}),
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function deactivate() { }
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { defineConfig } from 'tsdown';
|
|
2
|
+
import pkg from './package.json';
|
|
3
|
+
|
|
4
|
+
export default defineConfig((cfg) => {
|
|
5
|
+
return {
|
|
6
|
+
entry: 'src/index.ts',
|
|
7
|
+
target: 'node16.17',
|
|
8
|
+
format: 'cjs',
|
|
9
|
+
external: ['hbuilderx'],
|
|
10
|
+
noExternal: cfg.watch ? [] : Object.keys(pkg.dependencies || {}),
|
|
11
|
+
fixedExtension: false,
|
|
12
|
+
};
|
|
13
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# hbuilderx-react
|
|
2
|
+
|
|
3
|
+
`window.createWebView` 或 `window.createWebViewDialog` 创建 `react` 网页视图
|
|
4
|
+
|
|
5
|
+
## 使用
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# 开发模式,不压缩代码
|
|
9
|
+
pnpm dev
|
|
10
|
+
# 生产模式,压缩代码
|
|
11
|
+
pnpm build
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## 调试
|
|
15
|
+
|
|
16
|
+
根据以下步骤调试插件,具体参考官方[插件教程](https://hx.dcloud.net.cn/ExtensionTutorial/firstExtension)
|
|
17
|
+
|
|
18
|
+
- 将当前项目 `hbuilderx-react` 拖拽到 `HBuilderX` 中
|
|
19
|
+
- 点击左上 `运行` 图标,选择点击 `运行插件-[hbuilderx-react]` 或 `调试插件-[hbuilderx-react]`,会打开的 `HBuilderX` 窗口调试插件。
|
|
20
|
+
- 在调试导入或创建任意项目,打开任意文件,在文件编辑器中点击鼠标右唤出菜单,选择 `触发左侧视图`、`触发右侧视图`、`触发弹框视图`,会分别打开或弹出视图。
|
|
21
|
+
|
|
22
|
+
网页调试
|
|
23
|
+
|
|
24
|
+
- 可以使用 [react-devtools](https://www.npmjs.com/package/react-devtools) 这个独立应用调试 `webview`
|
|
25
|
+
- 可以使用 `Google Chrome`,在地址栏输入 `chrome://inspect/#devices` 访问。如果 `Remote Target` 不显示,打开 `HBuilderX` 调试插件的控制台,查看会看到 `DevTools listening on ws://127.0.0.1:9500/devtools/browser/e964a967-04da-48f2-8656-9ba933f39e59`, 配置 `Discover network targets` 对应的 `localhost:9500` 即可。
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<title>vite+react</title>
|
|
7
|
+
</head>
|
|
8
|
+
|
|
9
|
+
<body>
|
|
10
|
+
<div id="root"></div>
|
|
11
|
+
<script type="module" src="/src/main.tsx"></script>
|
|
12
|
+
</body>
|
|
13
|
+
</html>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"publisher": "tomjs",
|
|
3
|
+
"name": "hbuilderx-react",
|
|
4
|
+
"displayName": "hbuilderx react插件",
|
|
5
|
+
"type": "commonjs",
|
|
6
|
+
"version": "0.0.0",
|
|
7
|
+
"description": "hbuilderx react插件",
|
|
8
|
+
"main": "dist/extension/index.js",
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "tsc -b && vite build"
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
#root {
|
|
2
|
+
max-width: 1280px;
|
|
3
|
+
padding: 2rem;
|
|
4
|
+
margin: 0 auto;
|
|
5
|
+
text-align: center;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.logo {
|
|
9
|
+
height: 6em;
|
|
10
|
+
padding: 1.5em;
|
|
11
|
+
transition: filter 300ms;
|
|
12
|
+
will-change: filter;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.logo:hover {
|
|
16
|
+
filter: drop-shadow(0 0 2em #646cffaa);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.logo.react:hover {
|
|
20
|
+
filter: drop-shadow(0 0 2em #61dafbaa);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@keyframes logo-spin {
|
|
24
|
+
from {
|
|
25
|
+
transform: rotate(0deg);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
to {
|
|
29
|
+
transform: rotate(360deg);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@media (prefers-reduced-motion: no-preference) {
|
|
34
|
+
a:nth-of-type(2) .logo {
|
|
35
|
+
animation: logo-spin infinite 20s linear;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.card {
|
|
40
|
+
padding: 2em;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.read-the-docs {
|
|
44
|
+
color: #888;
|
|
45
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import reactLogo from '@/assets/react.svg';
|
|
3
|
+
import viteLogo from '@/assets/vite.svg';
|
|
4
|
+
import './App.css';
|
|
5
|
+
|
|
6
|
+
function App() {
|
|
7
|
+
const [count, setCount] = useState(0);
|
|
8
|
+
|
|
9
|
+
function onPostMessage() {
|
|
10
|
+
hbuilderx.postMessage({
|
|
11
|
+
command: 'alert',
|
|
12
|
+
text: `HelloWorld-${Date.now()}`,
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return (
|
|
17
|
+
<>
|
|
18
|
+
<div>
|
|
19
|
+
<a href="https://vite.dev" target="_blank">
|
|
20
|
+
<img src={viteLogo} className="logo" alt="Vite logo" />
|
|
21
|
+
</a>
|
|
22
|
+
<a href="https://react.dev" target="_blank">
|
|
23
|
+
<img src={reactLogo} className="logo react" alt="React logo" />
|
|
24
|
+
</a>
|
|
25
|
+
</div>
|
|
26
|
+
<h1>Vite + React</h1>
|
|
27
|
+
<div className="card">
|
|
28
|
+
<button onClick={() => setCount(count => count + 1)}>
|
|
29
|
+
count is
|
|
30
|
+
{' '}
|
|
31
|
+
{count}
|
|
32
|
+
</button>
|
|
33
|
+
<button style={{ marginLeft: 12 }} onClick={onPostMessage}>
|
|
34
|
+
发送消息
|
|
35
|
+
</button>
|
|
36
|
+
</div>
|
|
37
|
+
</>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export default App;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="35.93" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 228"><path fill="#00D8FF" d="M210.483 73.824a171.49 171.49 0 0 0-8.24-2.597c.465-1.9.893-3.777 1.273-5.621c6.238-30.281 2.16-54.676-11.769-62.708c-13.355-7.7-35.196.329-57.254 19.526a171.23 171.23 0 0 0-6.375 5.848a155.866 155.866 0 0 0-4.241-3.917C100.759 3.829 77.587-4.822 63.673 3.233C50.33 10.957 46.379 33.89 51.995 62.588a170.974 170.974 0 0 0 1.892 8.48c-3.28.932-6.445 1.924-9.474 2.98C17.309 83.498 0 98.307 0 113.668c0 15.865 18.582 31.778 46.812 41.427a145.52 145.52 0 0 0 6.921 2.165a167.467 167.467 0 0 0-2.01 9.138c-5.354 28.2-1.173 50.591 12.134 58.266c13.744 7.926 36.812-.22 59.273-19.855a145.567 145.567 0 0 0 5.342-4.923a168.064 168.064 0 0 0 6.92 6.314c21.758 18.722 43.246 26.282 56.54 18.586c13.731-7.949 18.194-32.003 12.4-61.268a145.016 145.016 0 0 0-1.535-6.842c1.62-.48 3.21-.974 4.76-1.488c29.348-9.723 48.443-25.443 48.443-41.52c0-15.417-17.868-30.326-45.517-39.844Zm-6.365 70.984c-1.4.463-2.836.91-4.3 1.345c-3.24-10.257-7.612-21.163-12.963-32.432c5.106-11 9.31-21.767 12.459-31.957c2.619.758 5.16 1.557 7.61 2.4c23.69 8.156 38.14 20.213 38.14 29.504c0 9.896-15.606 22.743-40.946 31.14Zm-10.514 20.834c2.562 12.94 2.927 24.64 1.23 33.787c-1.524 8.219-4.59 13.698-8.382 15.893c-8.067 4.67-25.32-1.4-43.927-17.412a156.726 156.726 0 0 1-6.437-5.87c7.214-7.889 14.423-17.06 21.459-27.246c12.376-1.098 24.068-2.894 34.671-5.345a134.17 134.17 0 0 1 1.386 6.193ZM87.276 214.515c-7.882 2.783-14.16 2.863-17.955.675c-8.075-4.657-11.432-22.636-6.853-46.752a156.923 156.923 0 0 1 1.869-8.499c10.486 2.32 22.093 3.988 34.498 4.994c7.084 9.967 14.501 19.128 21.976 27.15a134.668 134.668 0 0 1-4.877 4.492c-9.933 8.682-19.886 14.842-28.658 17.94ZM50.35 144.747c-12.483-4.267-22.792-9.812-29.858-15.863c-6.35-5.437-9.555-10.836-9.555-15.216c0-9.322 13.897-21.212 37.076-29.293c2.813-.98 5.757-1.905 8.812-2.773c3.204 10.42 7.406 21.315 12.477 32.332c-5.137 11.18-9.399 22.249-12.634 32.792a134.718 134.718 0 0 1-6.318-1.979Zm12.378-84.26c-4.811-24.587-1.616-43.134 6.425-47.789c8.564-4.958 27.502 2.111 47.463 19.835a144.318 144.318 0 0 1 3.841 3.545c-7.438 7.987-14.787 17.08-21.808 26.988c-12.04 1.116-23.565 2.908-34.161 5.309a160.342 160.342 0 0 1-1.76-7.887Zm110.427 27.268a347.8 347.8 0 0 0-7.785-12.803c8.168 1.033 15.994 2.404 23.343 4.08c-2.206 7.072-4.956 14.465-8.193 22.045a381.151 381.151 0 0 0-7.365-13.322Zm-45.032-43.861c5.044 5.465 10.096 11.566 15.065 18.186a322.04 322.04 0 0 0-30.257-.006c4.974-6.559 10.069-12.652 15.192-18.18ZM82.802 87.83a323.167 323.167 0 0 0-7.227 13.238c-3.184-7.553-5.909-14.98-8.134-22.152c7.304-1.634 15.093-2.97 23.209-3.984a321.524 321.524 0 0 0-7.848 12.897Zm8.081 65.352c-8.385-.936-16.291-2.203-23.593-3.793c2.26-7.3 5.045-14.885 8.298-22.6a321.187 321.187 0 0 0 7.257 13.246c2.594 4.48 5.28 8.868 8.038 13.147Zm37.542 31.03c-5.184-5.592-10.354-11.779-15.403-18.433c4.902.192 9.899.29 14.978.29c5.218 0 10.376-.117 15.453-.343c-4.985 6.774-10.018 12.97-15.028 18.486Zm52.198-57.817c3.422 7.8 6.306 15.345 8.596 22.52c-7.422 1.694-15.436 3.058-23.88 4.071a382.417 382.417 0 0 0 7.859-13.026a347.403 347.403 0 0 0 7.425-13.565Zm-16.898 8.101a358.557 358.557 0 0 1-12.281 19.815a329.4 329.4 0 0 1-23.444.823c-7.967 0-15.716-.248-23.178-.732a310.202 310.202 0 0 1-12.513-19.846h.001a307.41 307.41 0 0 1-10.923-20.627a310.278 310.278 0 0 1 10.89-20.637l-.001.001a307.318 307.318 0 0 1 12.413-19.761c7.613-.576 15.42-.876 23.31-.876H128c7.926 0 15.743.303 23.354.883a329.357 329.357 0 0 1 12.335 19.695a358.489 358.489 0 0 1 11.036 20.54a329.472 329.472 0 0 1-11 20.722Zm22.56-122.124c8.572 4.944 11.906 24.881 6.52 51.026c-.344 1.668-.73 3.367-1.15 5.09c-10.622-2.452-22.155-4.275-34.23-5.408c-7.034-10.017-14.323-19.124-21.64-27.008a160.789 160.789 0 0 1 5.888-5.4c18.9-16.447 36.564-22.941 44.612-18.3ZM128 90.808c12.625 0 22.86 10.235 22.86 22.86s-10.235 22.86-22.86 22.86s-22.86-10.235-22.86-22.86s10.235-22.86 22.86-22.86Z"></path></svg>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
:root {
|
|
2
|
+
font-family: system-ui, Avenir, Helvetica, Arial, sans-serif;
|
|
3
|
+
font-weight: 400;
|
|
4
|
+
|
|
5
|
+
font-synthesis: none;
|
|
6
|
+
line-height: 1.5;
|
|
7
|
+
color: rgba(255, 255, 255, 0.87);
|
|
8
|
+
|
|
9
|
+
color-scheme: light dark;
|
|
10
|
+
background-color: #242424;
|
|
11
|
+
text-rendering: optimizeLegibility;
|
|
12
|
+
-webkit-font-smoothing: antialiased;
|
|
13
|
+
-moz-osx-font-smoothing: grayscale;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
a {
|
|
17
|
+
font-weight: 500;
|
|
18
|
+
color: #646cff;
|
|
19
|
+
text-decoration: inherit;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
a:hover {
|
|
23
|
+
color: #535bf2;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
body {
|
|
27
|
+
display: flex;
|
|
28
|
+
place-items: center;
|
|
29
|
+
min-width: 320px;
|
|
30
|
+
min-height: 100vh;
|
|
31
|
+
margin: 0;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
h1 {
|
|
35
|
+
font-size: 3.2em;
|
|
36
|
+
line-height: 1.1;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
button {
|
|
40
|
+
padding: 0.6em 1.2em;
|
|
41
|
+
font-family: inherit;
|
|
42
|
+
font-size: 1em;
|
|
43
|
+
font-weight: 500;
|
|
44
|
+
cursor: pointer;
|
|
45
|
+
background-color: #1a1a1a;
|
|
46
|
+
border: 1px solid transparent;
|
|
47
|
+
border-radius: 8px;
|
|
48
|
+
transition: border-color 0.25s;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
button:hover {
|
|
52
|
+
border-color: #646cff;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
button:focus,
|
|
56
|
+
button:focus-visible {
|
|
57
|
+
outline: 4px auto -webkit-focus-ring-color;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
@media (prefers-color-scheme: light) {
|
|
61
|
+
:root {
|
|
62
|
+
color: #213547;
|
|
63
|
+
background-color: #ffffff;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
a:hover {
|
|
67
|
+
color: #747bff;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
button {
|
|
71
|
+
background-color: #f9f9f9;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "@tomjs/tsconfig/react.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
|
|
5
|
+
"paths": {
|
|
6
|
+
"@/*": [
|
|
7
|
+
"./src/*"
|
|
8
|
+
]
|
|
9
|
+
},
|
|
10
|
+
"types": [
|
|
11
|
+
"vite/client",
|
|
12
|
+
"@tomjs/hbuilderx/client"
|
|
13
|
+
]
|
|
14
|
+
},
|
|
15
|
+
"include": [
|
|
16
|
+
"src"
|
|
17
|
+
]
|
|
18
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import hbuilderx from '@tomjs/vite-plugin-hbuilderx';
|
|
3
|
+
import react from '@vitejs/plugin-react-swc';
|
|
4
|
+
import { defineConfig } from 'vite';
|
|
5
|
+
|
|
6
|
+
// https://vite.dev/config/
|
|
7
|
+
export default defineConfig({
|
|
8
|
+
resolve: {
|
|
9
|
+
alias: {
|
|
10
|
+
// https://github.com/facebook/react/issues/24928#issuecomment-2267624188
|
|
11
|
+
'react': path.resolve(process.cwd(), 'node_modules/react'),
|
|
12
|
+
'@': '/src',
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
build: {
|
|
16
|
+
assetsInlineLimit: 1024 * 100,
|
|
17
|
+
},
|
|
18
|
+
plugins: [react(), hbuilderx({ devtools: true })],
|
|
19
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# hbuilderx-vue
|
|
2
|
+
|
|
3
|
+
`window.createWebView` 或 `window.createWebViewDialog` 创建 `vue` 网页视图
|
|
4
|
+
|
|
5
|
+
## 使用
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# 开发模式,不压缩代码
|
|
9
|
+
pnpm dev
|
|
10
|
+
# 生产模式,压缩代码
|
|
11
|
+
pnpm build
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## 调试
|
|
15
|
+
|
|
16
|
+
根据以下步骤调试插件,具体参考官方[插件教程](https://hx.dcloud.net.cn/ExtensionTutorial/firstExtension)
|
|
17
|
+
|
|
18
|
+
- 将当前项目 `hbuilderx-vue` 拖拽到 `HBuilderX` 中
|
|
19
|
+
- 点击左上 `运行` 图标,选择点击 `运行插件-[hbuilderx-vue]` 或 `调试插件-[hbuilderx-vue]`,会打开的 `HBuilderX` 窗口调试插件。
|
|
20
|
+
- 在调试导入或创建任意项目,打开任意文件,在文件编辑器中点击鼠标右唤出菜单,选择 `触发左侧视图`、`触发右侧视图`、`触发弹框视图`,会分别打开或弹出视图。
|
|
21
|
+
|
|
22
|
+
网页调试
|
|
23
|
+
|
|
24
|
+
- 可以使用 [vite-plugin-vue-devtools](https://devtools.vuejs.org/guide/vite-plugin) 这个 `vite` 插件直接在页面调试
|
|
25
|
+
- 可以使用 [vue-devtools](https://devtools.vuejs.org/guide/standalone) 这个独立应用调试 `webview`
|
|
26
|
+
- 可以使用 `Google Chrome`,在地址栏输入 `chrome://inspect/#devices` 访问。如果 `Remote Target` 不显示,打开 `HBuilderX` 调试插件的控制台,查看会看到 `DevTools listening on ws://127.0.0.1:9500/devtools/browser/e964a967-04da-48f2-8656-9ba933f39e59`, 配置 `Discover network targets` 对应的 `localhost:9500` 即可。
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<title>vite+vue</title>
|
|
7
|
+
</head>
|
|
8
|
+
|
|
9
|
+
<body>
|
|
10
|
+
<div id="app"></div>
|
|
11
|
+
<script type="module" src="/src/main.ts"></script>
|
|
12
|
+
</body>
|
|
13
|
+
</html>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"publisher": "tomjs",
|
|
3
|
+
"name": "hbuilderx-vue",
|
|
4
|
+
"displayName": "hbuilderx vue插件",
|
|
5
|
+
"type": "commonjs",
|
|
6
|
+
"version": "0.0.0",
|
|
7
|
+
"description": "hbuilderx vue插件",
|
|
8
|
+
"main": "dist/extension/index.js",
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "vue-tsc --noEmit && vite build"
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import HelloWorld from '@/components/HelloWorld.vue';
|
|
3
|
+
</script>
|
|
4
|
+
|
|
5
|
+
<template>
|
|
6
|
+
<div>
|
|
7
|
+
<a href="https://vite.dev" target="_blank">
|
|
8
|
+
<img src="@/assets/vite.svg" class="logo" alt="Vite logo">
|
|
9
|
+
</a>
|
|
10
|
+
<a href="https://vuejs.org/" target="_blank">
|
|
11
|
+
<img src="@/assets/vue.svg" class="logo vue" alt="Vue logo">
|
|
12
|
+
</a>
|
|
13
|
+
</div>
|
|
14
|
+
<HelloWorld msg="Vite + Vue" />
|
|
15
|
+
</template>
|
|
16
|
+
|
|
17
|
+
<style scoped>
|
|
18
|
+
.logo {
|
|
19
|
+
height: 6em;
|
|
20
|
+
padding: 1.5em;
|
|
21
|
+
transition: filter 300ms;
|
|
22
|
+
will-change: filter;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.logo:hover {
|
|
26
|
+
filter: drop-shadow(0 0 2em #646cffaa);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.logo.vue:hover {
|
|
30
|
+
filter: drop-shadow(0 0 2em #42b883aa);
|
|
31
|
+
}
|
|
32
|
+
</style>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="37.07" height="36" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 198"><path fill="#41B883" d="M204.8 0H256L128 220.8L0 0h97.92L128 51.2L157.44 0h47.36Z"></path><path fill="#41B883" d="m0 0l128 220.8L256 0h-51.2L128 132.48L50.56 0H0Z"></path><path fill="#35495E" d="M50.56 0L128 133.12L204.8 0h-47.36L128 51.2L97.92 0H50.56Z"></path></svg>
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { ref } from 'vue';
|
|
3
|
+
|
|
4
|
+
defineProps<{ msg: string }>();
|
|
5
|
+
|
|
6
|
+
const count = ref(0);
|
|
7
|
+
|
|
8
|
+
function onPostMessage() {
|
|
9
|
+
hbuilderx.postMessage({
|
|
10
|
+
command: 'alert',
|
|
11
|
+
text: `HelloWorld-${Date.now()}`,
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
</script>
|
|
15
|
+
|
|
16
|
+
<template>
|
|
17
|
+
<h1>{{ msg }}</h1>
|
|
18
|
+
|
|
19
|
+
<div class="card">
|
|
20
|
+
<button type="button" @click="count++">
|
|
21
|
+
count is {{ count }}
|
|
22
|
+
</button>
|
|
23
|
+
<button type="button" style="margin-left: 12px;" @click="onPostMessage">
|
|
24
|
+
发送消息
|
|
25
|
+
</button>
|
|
26
|
+
</div>
|
|
27
|
+
</template>
|
|
28
|
+
|
|
29
|
+
<style scoped></style>
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
:root {
|
|
2
|
+
font-family: system-ui, Avenir, Helvetica, Arial, sans-serif;
|
|
3
|
+
font-weight: 400;
|
|
4
|
+
|
|
5
|
+
font-synthesis: none;
|
|
6
|
+
line-height: 1.5;
|
|
7
|
+
color: #213547;
|
|
8
|
+
|
|
9
|
+
color-scheme: light dark;
|
|
10
|
+
text-rendering: optimizeLegibility;
|
|
11
|
+
-webkit-font-smoothing: antialiased;
|
|
12
|
+
-moz-osx-font-smoothing: grayscale;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
a {
|
|
16
|
+
font-weight: 500;
|
|
17
|
+
color: #646cff;
|
|
18
|
+
text-decoration: inherit;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
a:hover {
|
|
22
|
+
color: #747bff;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
body {
|
|
26
|
+
display: flex;
|
|
27
|
+
place-items: center;
|
|
28
|
+
min-width: 320px;
|
|
29
|
+
min-height: 100vh;
|
|
30
|
+
margin: 0;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
h1 {
|
|
34
|
+
font-size: 3.2em;
|
|
35
|
+
line-height: 1.1;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
button {
|
|
39
|
+
padding: 0.6em 1.2em;
|
|
40
|
+
font-family: inherit;
|
|
41
|
+
font-size: 1em;
|
|
42
|
+
font-weight: 500;
|
|
43
|
+
cursor: pointer;
|
|
44
|
+
background-color: #f9f9f9;
|
|
45
|
+
border: 1px solid transparent;
|
|
46
|
+
border-radius: 8px;
|
|
47
|
+
transition: border-color 0.25s;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
button:hover {
|
|
51
|
+
border-color: #646cff;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
button:focus,
|
|
55
|
+
button:focus-visible {
|
|
56
|
+
outline: 4px auto -webkit-focus-ring-color;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.card {
|
|
60
|
+
padding: 2em;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
#app {
|
|
64
|
+
max-width: 1280px;
|
|
65
|
+
padding: 2rem;
|
|
66
|
+
margin: 0 auto;
|
|
67
|
+
text-align: center;
|
|
68
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "@tomjs/tsconfig/vue-dom.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
|
|
5
|
+
"paths": {
|
|
6
|
+
"@/*": ["./src/*"]
|
|
7
|
+
},
|
|
8
|
+
"types": [
|
|
9
|
+
"vite/client",
|
|
10
|
+
"@tomjs/hbuilderx/client"
|
|
11
|
+
]
|
|
12
|
+
},
|
|
13
|
+
"include": [
|
|
14
|
+
"src/**/*.ts",
|
|
15
|
+
"src/**/*.d.ts",
|
|
16
|
+
"src/**/*.vue"
|
|
17
|
+
]
|
|
18
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import hbuilderx from '@tomjs/vite-plugin-hbuilderx';
|
|
2
|
+
import vue from '@vitejs/plugin-vue';
|
|
3
|
+
import { defineConfig } from 'vite';
|
|
4
|
+
import devtools from 'vite-plugin-vue-devtools';
|
|
5
|
+
|
|
6
|
+
// https://vite.dev/config/
|
|
7
|
+
export default defineConfig({
|
|
8
|
+
resolve: {
|
|
9
|
+
alias: {
|
|
10
|
+
'@': '/src',
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
build: {
|
|
14
|
+
assetsInlineLimit: 1024 * 100,
|
|
15
|
+
},
|
|
16
|
+
plugins: [vue(), hbuilderx(), devtools()],
|
|
17
|
+
});
|
|
File without changes
|
|
File without changes
|
|
File without changes
|