diff --git a/LICENSE b/LICENSE old mode 100644 new mode 100755 index 77f865d..4e467aa --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ -MIT License +The MIT License (MIT) -Copyright (c) 2018 DCloud +Copyright (c) 2017-present, Yuxi (Evan) You Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -9,13 +9,13 @@ 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 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. +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/README.md b/README.md index 4bcbdb0..a9bc2e8 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,3 @@ -# uni-preset-vue -uni-app preset for vue +# @uni-app/vue-cli-preset-uni-app + +> uni-app plugin for vue-cli \ No newline at end of file diff --git a/generator.js b/generator.js new file mode 100644 index 0000000..9d3cc60 --- /dev/null +++ b/generator.js @@ -0,0 +1,90 @@ +const fs = require('fs') +const path = require('path') + + +async function generate(dir, files, base = '') { + + const globby = require('globby') + + const _files = await globby(['**/*'], { + cwd: dir + }) + + for (const rawPath of _files) { + files[path.join(base, rawPath)] = fs.readFileSync(path.resolve(dir, rawPath), 'utf-8') + } +} + +module.exports = (api, options, rootOptions) => { + + api.render(async function(files) { + + api.extendPackage({ + dependencies: { + '@dcloudio/uni-h5': '^0.0.1' + }, + devDependencies: { + '@dcloudio/vue-cli-plugin-uni': '^0.0.1' + }, + babel: { + presets: [ + ['@vue/app', { + useBuiltIns: 'entry' + }] + ] + }, + browserslist: [ + 'last 3 versions', + 'Android >= 4.4', + 'ios >= 8' + ], + vue: { + baseUrl: '/', + assetsDir: 'static' + }, + vuePlugins: { + service: [path.resolve(__dirname, '../vue-cli-plugin-uni-app')] + } + }) + + Object.keys(files).forEach(name => { + delete files[name] + }) + + const template = options.repo || options.template + + const base = 'src' + + if (template === 'default') { + await generate(path.resolve(__dirname, './template/default'), files, base) + } else { + const ora = require('ora') + const home = require('user-home') + const download = require('download-git-repo') + + const spinner = ora('模板下载中...') + spinner.start() + + const tmp = path.join(home, '.uni-app/templates', template.replace(/[\/:]/g, '-'), 'src') + + if (fs.existsSync(tmp)) { + require('rimraf').sync.rm(tmp) + } + + await new Promise((resolve, reject) => { + download(template, tmp, err => { + spinner.stop() + if (err) { + return reject(err) + } + resolve() + }) + }) + + await generate(tmp, files, base) + } + + await generate(path.resolve(__dirname, './template/common'), files) + + }) +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..cd5d9d2 --- /dev/null +++ b/package.json @@ -0,0 +1,18 @@ +{ + "name": "uni-preset-vue", + "version": "0.0.1", + "description": "uni-app preset for vue-cli", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "fxy060608", + "license": "MIT", + "dependencies": { + "download-git-repo": "^1.1.0", + "globby": "^8.0.1", + "ora": "^3.0.0", + "rimraf": "^2.6.2", + "user-home": "^2.0.0" + } +} diff --git a/preset.json b/preset.json new file mode 100644 index 0000000..8e25c56 --- /dev/null +++ b/preset.json @@ -0,0 +1,12 @@ +{ + "useConfigFiles": false, + "plugins": { + "@vue/cli-plugin-babel": { + "presets": [ + ["@vue/app", { + "useBuiltIns": "entry" + }] + ] + } + } +} diff --git a/prompts.js b/prompts.js new file mode 100644 index 0000000..42e5d69 --- /dev/null +++ b/prompts.js @@ -0,0 +1,43 @@ +module.exports = [{ + type: 'list', + name: 'template', + message: '请选择 uni-app 模板', + choices: [{ + name: '默认模板', + value: 'default' + }, + { + name: 'Hello uni-app', + value: 'direct:https://www.inkercloud.com/masterkong/hello-uniapp.zip' + }, + { + name: '登录模板', + value: 'hello uni-app' + }, + { + name: '看图模板', + value: 'hello uni-app' + }, + { + name: '自定义模板', + value: 'custom' + } + ], + default: 'None', + }, + { + when: answers => answers.template === 'custom', + type: 'input', + name: 'repo', + message: '请输入自定义 uni-app 模板地址', + filter(input) { + return new Promise(function(resolve, reject) { + if (input) { + resolve(input) + } else { + reject('uni-app 模板地址不能为空') + } + }) + } + } +] diff --git a/template/common/postcss.config.js b/template/common/postcss.config.js new file mode 100644 index 0000000..26229ec --- /dev/null +++ b/template/common/postcss.config.js @@ -0,0 +1,9 @@ +const pkg = require('./package.json') +module.exports = { + plugins: [ + require("autoprefixer")({ + browsers: pkg.browserslist + }), + // require("./packages/@uni-app/postcss") + ] +} diff --git a/template/common/public/index.html b/template/common/public/index.html new file mode 100644 index 0000000..fc58adc --- /dev/null +++ b/template/common/public/index.html @@ -0,0 +1,27 @@ + + + +
+ + + +