Skip to content

Commit

Permalink
fix: format
Browse files Browse the repository at this point in the history
  • Loading branch information
whizbz11 committed Aug 17, 2020
1 parent 5e30a1b commit 7c502ba
Show file tree
Hide file tree
Showing 17 changed files with 48 additions and 32,220 deletions.
49 changes: 48 additions & 1 deletion src/cli/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@
*/
const inquirer = require('inquirer')
const path = require('path')
const rp = require('request-promise');
const fse = require('fs-extra')
const { pascalCase } = require('change-case')
const compressing = require('compressing')
const chalk = require('chalk')
// const shell = require('shelljs')
const codeMode = ['js', 'ts']
const deviceType = ['mobile', 'PC']

const templateTempFile = 'yonui-template-temp.tgz'
const init = async () => {
// 输入相关的配置参数
const ans = await inquirer.prompt([
Expand Down Expand Up @@ -45,18 +49,61 @@ const init = async () => {
const create = async (ans = { codeMode: 'ts', device: 'PC', author: 'Hyj', project: 'xx' }) => {
const filepath = path.resolve(ans.project)
const libraryName = pascalCase(ans.project)
console.log();
console.log(chalk.green('\t\t⏳ yonui cloud transfer to local machine ⏳'));
console.log();
// console.log(chalk.green(`⏳🔊📢⚠️🇺🇿🌍☁️`));
console.log(chalk.cyan.bold('[Info] : 🚀 Start downloading yonui project to the current directory 🎁'));
console.log(chalk.cyan.bold(`Path:${filepath} 🏠`));
console.log();

// const filepath = '.'
const libraConfigPath = path.resolve(filepath, 'config.json')
const packagePath = path.resolve(filepath, 'package.json')
const manifestPath = path.resolve(filepath, 'manifest.json')
compressing.tgz.uncompress(path.join(__dirname, '../../templates/project.tgz'), filepath).then(() => {
await getRemoteTemplate(filepath)
compressing.tgz.uncompress(path.resolve(filepath, templateTempFile), filepath).then(() => {
const packageJson = require(packagePath)
const libraConfig = require(libraConfigPath)
const manifestJson = require(manifestPath)
fse.outputJSONSync(libraConfigPath, { ...libraConfig, type: ans.codeMode, device: ans.device }, { replacer: null, spaces: 2 })
fse.outputJSONSync(packagePath, { ...packageJson, author: ans.author, name: ans.project }, { replacer: null, spaces: 2 })
fse.outputJSONSync(manifestPath, { ...manifestJson, name: libraryName }, { replacer: null, spaces: 2 })
fse.remove(path.resolve(filepath, templateTempFile));
console.log(chalk.cyan(`[Tips] : Project has inited ! 🏆 cd ${ans.project} && ynpm install && ynpm start`));
})
}

const download = async function (options, filename, cb) {
let opts = {
method: 'get',
headers: {
Accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3',
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,zh-TW;q=0.7',
Connection: 'keep-alive',
'Upgrade-Insecure-Requests': 1
}
}
opts = { ...opts, ...options };
// 获得文件夹路径
const fileFolder = path.dirname(filename);
// 创建文件夹
fse.ensureDirSync(fileFolder);
// 开始下载无需返回
rp(opts).pipe(fse.createWriteStream(filename)).on('close', cb);
}

/**
* 下载zip压缩包包含路径文件名
*/
const getRemoteTemplate = (filepath) => {
const url = 'http://iuap-design-cdn.oss-cn-beijing.aliyuncs.com/static/yonui/templates/project.tgz'
return new Promise((resolve, reject) => {
download({ url }, path.resolve(filepath, templateTempFile), () => {
resolve({ success: true });
});
});
}

module.exports = init
8 changes: 0 additions & 8 deletions templates/Project/.eslintignore

This file was deleted.

20 changes: 0 additions & 20 deletions templates/Project/.eslintrc.js

This file was deleted.

7 changes: 0 additions & 7 deletions templates/Project/.gitignore

This file was deleted.

5 changes: 0 additions & 5 deletions templates/Project/README.md

This file was deleted.

Empty file removed templates/Project/api.md
Empty file.
3 changes: 0 additions & 3 deletions templates/Project/commitlint.config.js

This file was deleted.

7 changes: 0 additions & 7 deletions templates/Project/components/_style/index.less

This file was deleted.

Empty file.
36 changes: 0 additions & 36 deletions templates/Project/config.json

This file was deleted.

9 changes: 0 additions & 9 deletions templates/Project/manifest.json

This file was deleted.

59 changes: 0 additions & 59 deletions templates/Project/package.json

This file was deleted.

Loading

0 comments on commit 7c502ba

Please sign in to comment.