Commit 224a64b2 authored by 郭铭瑶's avatar 郭铭瑶 🤘

嵌入前端页面以供选择生成模板

parent 70c16226
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
"ignorePatterns": [ "ignorePatterns": [
"out", "out",
"dist", "dist",
"**/*.d.ts" "**/*.d.ts",
"front-view"
] ]
} }
...@@ -9,5 +9,6 @@ ...@@ -9,5 +9,6 @@
"dist": true // set this to false to include "dist" folder in search results "dist": true // set this to false to include "dist" folder in search results
}, },
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts // Turn off tsc task auto detection since we have the necessary tasks as npm scripts
"typescript.tsc.autoDetect": "off" "typescript.tsc.autoDetect": "off",
"quickcli.workspace": "/Users/MrGuo/Playground"
} }
\ No newline at end of file
module.exports = {
env: {
browser: true,
es2021: true,
},
extends: ['plugin:vue/vue3-recommended', 'plugin:prettier/recommended'],
parserOptions: {
parser: 'babel-eslint',
},
rules: {
'vue/no-multiple-template-root': 'off',
'vue/max-attributes-per-line': 'off',
'vue/html-self-closing': 'off',
'vue/singleline-html-element-content-newline': 'off',
'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0, // 生产环境禁止debugger
'no-console': process.env.NODE_ENV === 'production' ? 2 : 0, // 生产环境禁止console
'no-alert': process.env.NODE_ENV === 'production' ? 2 : 0, // 生产环境禁止alert
'no-shadow-restricted-names': 2, // 禁用关键字及保留字等
'dot-notation': 1, // 尽可能使用 . 来访问对象属性
'no-multi-spaces': 1, // 禁止使用多个空格
'brace-style': 1, // 大括号风格 - one true brace style
'no-var': 1, // 禁用var声明
'no-new-object': 1, // 禁止new Object
'no-array-constructor': 1, // 禁止new Array
'prefer-const': 1, // 要求使用 const 声明那些声明后不再被修改的变量
'prefer-destructuring': 1, // 优先使用数组和对象解构
'no-param-reassign': 1, // 禁止在函数中对函数参数重新赋值
'no-extra-semi': 1, // 禁用不必要的分号
// "no-unused-vars": 1, // 禁止已声明但未使用的变量
// "indent": [1, 2], // 使用2个空格缩进
'no-multiple-empty-lines': [1, { max: 1 }], // 禁止连续出现2个及以上空行
'default-case': 1, // 要求switch语句必须有default分支
'key-spacing': [1, { beforeColon: false, afterColon: true }], // 冒号前不要空格,后需要空格
'comma-spacing': [1, { before: false, after: true }], // 逗号前不要空格,后需要空格
'arrow-spacing': [1, { before: true, after: true }], // 箭头函数中的箭头前后需要留空格
quotes: [1, 'single'], // 字符串使用单引号
semi: [1, 'never'], // 禁止使用分号
},
}
node_modules
.DS_Store
dist
dist-ssr
*.local
\ No newline at end of file
module.exports = {
tabWidth: 2,
useTabs: false,
singleQuote: true,
semi: false,
}
\ No newline at end of file
MIT License
Copyright (c) 2021 Max Kwok
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.
# my-vite-app
vite + vue 项目自用模板
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>My Cli</title>
</head>
<body>
<div id="app"></div>
<script>
const vscode = acquireVsCodeApi();
</script>
<script type="module" src="/src/main.js"></script>
</body>
</html>
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
{
"name": "front-view",
"version": "0.0.0",
"scripts": {
"dev": "vite",
"start": "node node_modules/esbuild/install.js && npm run dev",
"build": "vite build"
},
"dependencies": {
"vue": "^3.0.5"
},
"devDependencies": {
"@vitejs/plugin-vue": "^1.1.5",
"@vue/compiler-sfc": "^3.0.5",
"babel-eslint": "^10.1.0",
"eslint": "^7.17.0",
"eslint-config-prettier": "^7.1.0",
"eslint-plugin-prettier": "^3.3.1",
"eslint-plugin-vue": "^7.4.1",
"prettier": "^2.2.1",
"stylus": "^0.54.8",
"vite": "^2.1.0"
},
"description": "插件前端展示页面",
"author": "Guo"
}
import{r as e,o as t,a as l,p as a,b as n,c as s,d as i,w as o,v as c,e as u,F as r,f as d,g as m,h as p,t as v,i as b,j as y}from"./vendor.049267cb.js";const g={name:"Main",setup(){const a=e(null),n=e(1),s=e(null),i=e(null),o=e([{title:"Vue3版大屏",desc:"Vue3.0 + TypeScript + Vite2.0大屏用",url:"gitee:guomingyao/my-view"},{title:"Vue2大屏",desc:"Vue2.0大屏用",url:"gitee:guomingyao/monitor-template"},{title:"Vite App",desc:"Vue3.0 + Vite2.0 普通项目用",url:"gitee:guomingyao/my-vite-app"},{title:"微前端",desc:"微前端父项目模板",url:"gitee:guomingyao/micfrontend-template"}]),c=e(null),u=e(null),r=e=>{const{command:t,data:l}=e.data;switch(t){case"DIRECTORY":u.value=l.text}};t((()=>{window.addEventListener("message",r)})),l((()=>{window.removeEventListener("message",r)}));return{fileRef:a,step:n,curIndex:s,curData:i,templates:o,filename:c,directory:u,onClick:(e,t)=>{i.value=e,s.value=t},selectDirectory:()=>{vscode.postMessage({command:"SELECT_FOLDER"})},toStep:e=>{n.value=e},submit:()=>{vscode.postMessage({command:"FETCH_PROJECT",data:{url:i.value.url,filePath:u.value,filename:c.value}})}}}},f=p();a("data-v-54631bd4");const C=u("h2",null,"选择模板",-1),k={class:"wrapper"},V=u("h2",null,"选择目录",-1),h={class:"item"},w={class:"item directory"};n();const E=f(((e,t,l,a,n,p)=>(s(),i("main",null,[o(u("section",null,[C,u("div",k,[(s(!0),i(r,null,d(a.templates,((e,t)=>(s(),i("div",{key:e.title},[u("div",{class:["inner",{on:a.curIndex===t}],onClick:l=>a.onClick(e,t)},[u("h3",null,v(e.title),1),u("span",null,v(e.desc),1)],10,["onClick"])])))),128))]),u("button",{onClick:t[1]||(t[1]=e=>a.toStep(2)),class:""+(a.curData?"btn":"disable-btn")},"下一步",2)],512),[[c,1===a.step]]),o(u("section",null,[V,u("div",h,[o(u("input",{type:"text","onUpdate:modelValue":t[2]||(t[2]=e=>a.filename=e),title:a.filename,placeholder:"请输入项目名称"},null,8,["title"]),[[m,a.filename]])]),u("div",w,[u("input",{value:a.directory,title:a.directory,type:"text",placeholder:"请选择项目存放路径",readonly:""},null,8,["value","title"]),u("button",{class:"btn",onClick:t[3]||(t[3]=(...e)=>a.selectDirectory&&a.selectDirectory(...e))},"选择")]),u("button",{onClick:t[4]||(t[4]=(...e)=>a.submit&&a.submit(...e)),class:""+(a.filename&&a.directory?"btn":"disable-btn")},"完成",2),u("button",{onClick:t[5]||(t[5]=e=>a.toStep(1)),class:"btn"},"上一步")],512),[[c,2===a.step]])]))));g.render=E,g.__scopeId="data-v-54631bd4";const D={name:"App",components:{Main:g}};D.render=function(e,t,l,a,n,o){const c=b("Main");return s(),i(c)};y(D).mount("#app");
h2[data-v-54631bd4]{padding:0 12px}.wrapper[data-v-54631bd4]{display:flex;flex-wrap:wrap}.wrapper>div[data-v-54631bd4]{width:25%;padding:10px;box-sizing:border-box}.wrapper>div .inner[data-v-54631bd4]{background:#3b3b47;height:140px;padding:10px 20px;cursor:pointer;transition:border .2s ease-in-out;border:1px solid transparent;box-sizing:border-box;position:relative}.wrapper>div .inner span[data-v-54631bd4]{color:#ccc;font-size:12px}.wrapper>div .inner.on[data-v-54631bd4],.wrapper>div .inner[data-v-54631bd4]:hover{border:1px solid #2f86ee}.wrapper>div .inner.on[data-v-54631bd4]:before{content:'';display:inline-block;position:absolute;top:2px;right:2px;width:0;height:0;border:10px solid transparent;border-top-color:inherit;border-right-color:inherit}.item[data-v-54631bd4]{width:40%;margin:40px auto;display:flex;height:34px}.item .btn[data-v-54631bd4]{float:none;margin:0;width:100px;margin-left:10px}.item input[data-v-54631bd4]{display:block;flex:1;border:none;outline:0;font-size:14px;padding:0 14px;line-height:34px;color:#2c3e50;overflow:hidden;white-space:nowrap;text-overflow:ellipsis}html{background:#1e2127}#app{font-family:Avenir,Helvetica,Arial,sans-serif;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;color:#eee;padding:0 10px}/*! normalize.css v8.0.1 | MIT License | github.com/necolas/normalize.css */html{line-height:1.15;-webkit-text-size-adjust:100%}body{margin:0}main{display:block}h1{font-size:2em;margin:.67em 0}hr{box-sizing:content-box;height:0;overflow:visible}pre{font-family:monospace,monospace;font-size:1em}a{background-color:transparent}abbr[title]{border-bottom:none;text-decoration:underline;text-decoration:underline dotted}b,strong{font-weight:bolder}code,kbd,samp{font-family:monospace,monospace;font-size:1em}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}img{border-style:none}button,input,optgroup,select,textarea{font-family:inherit;font-size:100%;line-height:1.15;margin:0}button,input{overflow:visible}button,select{text-transform:none}[type=button],[type=reset],[type=submit],button{-webkit-appearance:button}[type=button]::-moz-focus-inner,[type=reset]::-moz-focus-inner,[type=submit]::-moz-focus-inner,button::-moz-focus-inner{border-style:none;padding:0}[type=button]:-moz-focusring,[type=reset]:-moz-focusring,[type=submit]:-moz-focusring,button:-moz-focusring{outline:1px dotted ButtonText}fieldset{padding:.35em .75em .625em}legend{box-sizing:border-box;color:inherit;display:table;max-width:100%;padding:0;white-space:normal}progress{vertical-align:baseline}textarea{overflow:auto}[type=checkbox],[type=radio]{box-sizing:border-box;padding:0}[type=number]::-webkit-inner-spin-button,[type=number]::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}[type=search]::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}details{display:block}summary{display:list-item}template{display:none}[hidden]{display:none}.btn{z-index:1;position:relative;font-size:inherit;font-family:inherit;color:#fff;padding:.5em 1em;outline:0;border:none;background-color:#3b3b47;overflow:hidden;transition:color .4s ease-in-out;float:right;margin:10px 10px 0 0}.disable-btn{z-index:1;position:relative;font-size:inherit;font-family:inherit;color:#fff;padding:.5em 1em;outline:0;border:none;background-color:#3b3b47;overflow:hidden;transition:color .4s ease-in-out;float:right;margin:10px 10px 0 0;opacity:.5;cursor:not-allowed;pointer-events:all!important}.btn::before{content:'';z-index:-1;position:absolute;top:50%;left:50%;width:1em;height:1em;border-radius:50%;background-color:#2f86ee;transform-origin:center;transform:translate3d(-50%,-50%,0) scale3d(0,0,0);transition:transform .45s ease-in-out}.btn:hover{cursor:pointer;color:#161616}.btn:hover::before{transform:translate3d(-50%,-50%,0) scale3d(15,15,15)}
\ No newline at end of file
This diff is collapsed.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>My Cli</title>
<script type="module" crossorigin src="./assets/index.0626f78d.js"></script>
<link rel="modulepreload" href="./assets/vendor.049267cb.js">
<link rel="stylesheet" href="./assets/index.7c40afb3.css">
</head>
<body>
<div id="app"></div>
<script>
const vscode = acquireVsCodeApi();
</script>
</body>
</html>
\ No newline at end of file
<template>
<Main />
</template>
<script>
import Main from './components/main.vue'
export default {
name: 'App',
components: { Main },
}
</script>
<style lang="stylus">
html
background #1e2127
#app
font-family Avenir, Helvetica, Arial, sans-serif
-webkit-font-smoothing antialiased
-moz-osx-font-smoothing grayscale
color #eee
padding 0 10px
</style>
/*! normalize.css v8.0.1 | MIT License | github.com/necolas/normalize.css */
/* Document
========================================================================== */
/**
* 1. Correct the line height in all browsers.
* 2. Prevent adjustments of font size after orientation changes in iOS.
*/
html {
line-height: 1.15; /* 1 */
-webkit-text-size-adjust: 100%; /* 2 */
}
/* Sections
========================================================================== */
/**
* Remove the margin in all browsers.
*/
body {
margin: 0;
}
/**
* Render the `main` element consistently in IE.
*/
main {
display: block;
}
/**
* Correct the font size and margin on `h1` elements within `section` and
* `article` contexts in Chrome, Firefox, and Safari.
*/
h1 {
font-size: 2em;
margin: 0.67em 0;
}
/* Grouping content
========================================================================== */
/**
* 1. Add the correct box sizing in Firefox.
* 2. Show the overflow in Edge and IE.
*/
hr {
box-sizing: content-box; /* 1 */
height: 0; /* 1 */
overflow: visible; /* 2 */
}
/**
* 1. Correct the inheritance and scaling of font size in all browsers.
* 2. Correct the odd `em` font sizing in all browsers.
*/
pre {
font-family: monospace, monospace; /* 1 */
font-size: 1em; /* 2 */
}
/* Text-level semantics
========================================================================== */
/**
* Remove the gray background on active links in IE 10.
*/
a {
background-color: transparent;
}
/**
* 1. Remove the bottom border in Chrome 57-
* 2. Add the correct text decoration in Chrome, Edge, IE, Opera, and Safari.
*/
abbr[title] {
border-bottom: none; /* 1 */
text-decoration: underline; /* 2 */
text-decoration: underline dotted; /* 2 */
}
/**
* Add the correct font weight in Chrome, Edge, and Safari.
*/
b,
strong {
font-weight: bolder;
}
/**
* 1. Correct the inheritance and scaling of font size in all browsers.
* 2. Correct the odd `em` font sizing in all browsers.
*/
code,
kbd,
samp {
font-family: monospace, monospace; /* 1 */
font-size: 1em; /* 2 */
}
/**
* Add the correct font size in all browsers.
*/
small {
font-size: 80%;
}
/**
* Prevent `sub` and `sup` elements from affecting the line height in
* all browsers.
*/
sub,
sup {
font-size: 75%;
line-height: 0;
position: relative;
vertical-align: baseline;
}
sub {
bottom: -0.25em;
}
sup {
top: -0.5em;
}
/* Embedded content
========================================================================== */
/**
* Remove the border on images inside links in IE 10.
*/
img {
border-style: none;
}
/* Forms
========================================================================== */
/**
* 1. Change the font styles in all browsers.
* 2. Remove the margin in Firefox and Safari.
*/
button,
input,
optgroup,
select,
textarea {
font-family: inherit; /* 1 */
font-size: 100%; /* 1 */
line-height: 1.15; /* 1 */
margin: 0; /* 2 */
}
/**
* Show the overflow in IE.
* 1. Show the overflow in Edge.
*/
button,
input {
/* 1 */
overflow: visible;
}
/**
* Remove the inheritance of text transform in Edge, Firefox, and IE.
* 1. Remove the inheritance of text transform in Firefox.
*/
button,
select {
/* 1 */
text-transform: none;
}
/**
* Correct the inability to style clickable types in iOS and Safari.
*/
button,
[type='button'],
[type='reset'],
[type='submit'] {
-webkit-appearance: button;
}
/**
* Remove the inner border and padding in Firefox.
*/
button::-moz-focus-inner,
[type='button']::-moz-focus-inner,
[type='reset']::-moz-focus-inner,
[type='submit']::-moz-focus-inner {
border-style: none;
padding: 0;
}
/**
* Restore the focus styles unset by the previous rule.
*/
button:-moz-focusring,
[type='button']:-moz-focusring,
[type='reset']:-moz-focusring,
[type='submit']:-moz-focusring {
outline: 1px dotted ButtonText;
}
/**
* Correct the padding in Firefox.
*/
fieldset {
padding: 0.35em 0.75em 0.625em;
}
/**
* 1. Correct the text wrapping in Edge and IE.
* 2. Correct the color inheritance from `fieldset` elements in IE.
* 3. Remove the padding so developers are not caught out when they zero out
* `fieldset` elements in all browsers.
*/
legend {
box-sizing: border-box; /* 1 */
color: inherit; /* 2 */
display: table; /* 1 */
max-width: 100%; /* 1 */
padding: 0; /* 3 */
white-space: normal; /* 1 */
}
/**
* Add the correct vertical alignment in Chrome, Firefox, and Opera.
*/
progress {
vertical-align: baseline;
}
/**
* Remove the default vertical scrollbar in IE 10+.
*/
textarea {
overflow: auto;
}
/**
* 1. Add the correct box sizing in IE 10.
* 2. Remove the padding in IE 10.
*/
[type='checkbox'],
[type='radio'] {
box-sizing: border-box; /* 1 */
padding: 0; /* 2 */
}
/**
* Correct the cursor style of increment and decrement buttons in Chrome.
*/
[type='number']::-webkit-inner-spin-button,
[type='number']::-webkit-outer-spin-button {
height: auto;
}
/**
* 1. Correct the odd appearance in Chrome and Safari.
* 2. Correct the outline style in Safari.
*/
[type='search'] {
-webkit-appearance: textfield; /* 1 */
outline-offset: -2px; /* 2 */
}
/**
* Remove the inner padding in Chrome and Safari on macOS.
*/
[type='search']::-webkit-search-decoration {
-webkit-appearance: none;
}
/**
* 1. Correct the inability to style clickable types in iOS and Safari.
* 2. Change font properties to `inherit` in Safari.
*/
::-webkit-file-upload-button {
-webkit-appearance: button; /* 1 */
font: inherit; /* 2 */
}
/* Interactive
========================================================================== */
/*
* Add the correct display in Edge, IE 10+, and Firefox.
*/
details {
display: block;
}
/*
* Add the correct display in all browsers.
*/
summary {
display: list-item;
}
/* Misc
========================================================================== */
/**
* Add the correct display in IE 10+.
*/
template {
display: none;
}
/**
* Add the correct display in IE 10.
*/
[hidden] {
display: none;
}
$btn()
z-index: 1;
position: relative;
font-size: inherit;
font-family: inherit;
color: white;
padding: 10px 20px;
outline: none;
border: none;
background-color: #3b3b47;
overflow: hidden;
transition: color 0.4s ease-in-out;
float right
margin 10px 10px 0 0
.btn {
$btn()
}
.disable-btn {
$btn()
opacity 0.5
cursor not-allowed
pointer-events all !important
}
.btn::before {
content: '';
z-index: -1;
position: absolute;
top: 50%;
left: 50%;
width: 1em;
height: 1em;
border-radius: 50%;
background-color: #2F86EE;
transform-origin: center;
transform: translate3d(-50%, -50%, 0) scale3d(0, 0, 0);
transition: transform 0.45s ease-in-out;
}
.btn:hover {
cursor: pointer;
color: #161616;
}
.btn:hover::before {
transform: translate3d(-50%, -50%, 0) scale3d(15, 15, 15);
}
\ No newline at end of file
<template>
<main>
<section v-show="step === 1">
<h2>选择模板</h2>
<div class="wrapper">
<div v-for="(item, i) in templates" :key="item.title">
<div class="inner" :class="{on: curIndex === i}" @click="onClick(item, i)">
<h3>{{item.title}}</h3>
<span>{{item.desc}}</span>
</div>
</div>
</div>
<button @click="toStep(2)" :class="`${curData ? 'btn' : 'disable-btn'}`">下一步</button>
</section>
<section v-show="step === 2">
<h2>选择目录</h2>
<div class="item">
<input type="text" v-model="filename" :title="filename" placeholder="请输入项目名称"/>
</div>
<div class="item directory">
<input :value="directory" :title="directory" type="text" placeholder="请选择项目存放路径" readonly/>
<button class="btn" @click="selectDirectory">选择</button>
</div>
<button @click="submit" :class="`${(filename && directory) ? 'btn' : 'disable-btn'}`">完成</button>
<button @click="toStep(1)" class='btn'>上一步</button>
</section>
</main>
</template>
<script>
import {onBeforeUnmount, onMounted, ref} from 'vue'
export default {
name: 'Main',
setup() {
const fileRef = ref(null)
const step = ref(1)
const curIndex = ref(null)
const curData = ref(null)
const templates = ref([
{
title: 'Vue3版大屏',
desc: 'Vue3.0 + TypeScript + Vite2.0大屏用',
url: 'gitee:guomingyao/my-view',
},
{
title: 'Vue2大屏',
desc: 'Vue2.0大屏用',
url: 'gitee:guomingyao/monitor-template',
},
{
title: 'Vite App',
desc: 'Vue3.0 + Vite2.0 普通项目用',
url: 'gitee:guomingyao/my-vite-app',
},
{
title: '微前端',
desc: '微前端父项目模板',
url: 'gitee:guomingyao/micfrontend-template',
},
])
const filename = ref(null)
const directory = ref(null)
const onClick = (data, i) => {
curData.value = data
curIndex.value = i
}
const cb = event => {
const {command, data} = event.data
switch (command) {
case 'DIRECTORY':
directory.value = data.text
break;
default:
break;
}
}
onMounted(() => {
window.addEventListener('message', cb)
})
onBeforeUnmount(() => {
window.removeEventListener('message', cb)
})
const selectDirectory = () => {
vscode.postMessage({
command: 'SELECT_FOLDER',
})
}
const toStep = (val) => {
step.value = val
}
const submit = () => {
vscode.postMessage({
command: 'FETCH_PROJECT',
data: {
url: curData.value.url,
filePath: directory.value,
filename: filename.value,
}
})
}
return {
fileRef,
step,
curIndex,
curData,
templates,
filename,
directory,
onClick,
selectDirectory,
toStep,
submit,
}
}
}
</script>
<style lang="stylus" scoped>
h2
padding 0 12px
.wrapper
display flex
flex-wrap wrap
>div
width 25%
padding 10px
box-sizing border-box
.inner
background #3b3b47
height 140px
padding 10px 20px
cursor pointer
transition border .2s ease-in-out
border 1px solid transparent
box-sizing border-box
position relative
span
color #ccc
font-size 12px
&:hover,
&.on
border 1px solid #2F86EE
&.on
&:before
content ''
display inline-block
position absolute
top 2px
right @top
width 0
height 0
border 10px solid transparent
border-top-color inherit
border-right-color inherit
.item
width 40%
margin 40px auto
display flex
height 34px
.btn
float none
margin 0
width 100px
margin-left 10px
input
display block
flex 1
border none
outline none
font-size 14px
padding 0 @font-size
line-height 34px
color #2c3e50
overflow hidden
white-space nowrap
text-overflow ellipsis
</style>
\ No newline at end of file
import { createApp } from 'vue'
import App from './App.vue'
import './assets/css/normalize.css'
import './assets/css/style.styl'
createApp(App).mount('#app')
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'
// https://vitejs.dev/config/
export default defineConfig({
base: './',
build: {
outDir: resolve(__dirname, './public'),
},
plugins: [vue()],
resolve: {
alias: {
'@': resolve(__dirname, './src'),
'@images': resolve(__dirname, './src/assets/images'),
},
},
})
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -10,14 +10,14 @@ ...@@ -10,14 +10,14 @@
"Other" "Other"
], ],
"activationEvents": [ "activationEvents": [
"onCommand:my-cli.helloWorld" "onCommand:my-cli.my-cli"
], ],
"main": "./dist/extension.js", "main": "./dist/extension.js",
"contributes": { "contributes": {
"commands": [ "commands": [
{ {
"command": "my-cli.helloWorld", "command": "my-cli.my-cli",
"title": "Hello World" "title": "My Cli"
} }
] ]
}, },
...@@ -47,5 +47,8 @@ ...@@ -47,5 +47,8 @@
"vscode-test": "^1.5.2", "vscode-test": "^1.5.2",
"webpack": "^5.38.1", "webpack": "^5.38.1",
"webpack-cli": "^4.7.0" "webpack-cli": "^4.7.0"
},
"dependencies": {
"npm-gitee-lw": "^1.0.3"
} }
} }
// The module 'vscode' contains the VS Code extensibility API // The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below // Import the module and reference it with the alias vscode in your code below
import * as vscode from 'vscode'; import * as vscode from 'vscode';
import { getWebViewContent, fetchProject } from './util';
// this method is called when your extension is activated // this method is called when your extension is activated
// your extension is activated the very first time the command is executed // your extension is activated the very first time the command is executed
...@@ -8,15 +9,47 @@ export function activate(context: vscode.ExtensionContext) { ...@@ -8,15 +9,47 @@ export function activate(context: vscode.ExtensionContext) {
// Use the console to output diagnostic information (console.log) and errors (console.error) // Use the console to output diagnostic information (console.log) and errors (console.error)
// This line of code will only be executed once when your extension is activated // This line of code will only be executed once when your extension is activated
console.log('Congratulations, your extension "my-cli" is now active!'); // console.log('Congratulations, your extension "my-cli" is now active!');
// The command has been defined in the package.json file // The command has been defined in the package.json file
// Now provide the implementation of the command with registerCommand // Now provide the implementation of the command with registerCommand
// The commandId parameter must match the command field in package.json // The commandId parameter must match the command field in package.json
let disposable = vscode.commands.registerCommand('my-cli.helloWorld', () => { let disposable = vscode.commands.registerCommand('my-cli.my-cli', () => {
// The code you place here will be executed every time your command is executed const panel = vscode.window.createWebviewPanel(
// Display a message box to the user 'my-cli',
vscode.window.showInformationMessage('Hello World from my-cli!'); '创建前端项目',
vscode.ViewColumn.One,
{
enableScripts: true,
retainContextWhenHidden: true,
}
);
panel.webview.html = getWebViewContent('../front-view/public/index.html');
panel.webview.onDidReceiveMessage(msg => {
console.log('====> ', msg);
const {command, data} = msg;
switch (command) {
case 'FETCH_PROJECT':
const {url, filePath, filename} = data;
fetchProject({url, filePath, filename});
break;
case 'SELECT_FOLDER':
vscode.window.showOpenDialog({
canSelectFolders: true,
canSelectFiles: false
}).then(folders => {
panel.webview.postMessage({
command: 'DIRECTORY',
data: {
text: folders?.[0]?.path
}
});
});
break;
default:
break;
}
}, undefined, context.subscriptions);
}); });
context.subscriptions.push(disposable); context.subscriptions.push(disposable);
......
import * as vscode from 'vscode';
import path = require('path');
import fs = require('fs');
const download = require('npm-gitee-lw');
export const getWebViewContent = (filePath: string) => {
const dirname = path.dirname(filePath);
const resourcePath = path.join(__dirname, dirname);
const filename = path.basename(filePath);
const html = fs.readFileSync(path.join(resourcePath, filename), 'utf-8');
// vscode不支持直接加载本地资源,需要替换成其专有路径格式,这里只是简单的将样式和JS的路径替换
return html.replace(/(<link.+?href="|<script.+?src="|<img.+?src=")(.+?)"/g, (m, $1, $2) => {
return $1 + vscode.Uri.file(path.resolve(resourcePath, $2)).with({ scheme: 'vscode-resource' }).toString() + '"';
});
};
export const isDirExist = (path:string) => {
try {
fs.accessSync(path, fs.constants.R_OK | fs.constants.W_OK);
return true;
} catch (err) {
return false;
}
};
export interface FileConfig {
url:string
filePath:string
filename: string
}
export const fetchProject = ({url, filePath, filename}: FileConfig) => {
const projectPath = `${filePath}/${filename}`;
const start = () => {
download(url, projectPath, {clone: true}, async (err:Error) => {
if (err) {
vscode.window.showErrorMessage(err.message);
throw new Error(err.message);
}
vscode.window.showInformationMessage(`'${filename}' 项目创建成功!`);
await vscode.commands.executeCommand('vscode.openFolder', vscode.Uri.file(projectPath), true);
});
};
if (isDirExist(projectPath)) {
vscode.window.showErrorMessage('该路径下已存在同名项目文件夹!');
return;
}
start();
};
\ No newline at end of file
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
}, },
"exclude": [ "exclude": [
"node_modules", "node_modules",
".vscode-test" ".vscode-test",
"front-view"
] ]
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment