Skip to content

Commit e201fbc

Browse files
authored
Merge pull request #58 from FEMessage/dev
release
2 parents d1458c6 + 29cf1c4 commit e201fbc

File tree

7 files changed

+62
-16
lines changed

7 files changed

+62
-16
lines changed

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,17 @@ yarn build
4646

4747
### `-u, --upgrade`
4848

49-
更新当前组件配置
49+
更新当前项目基本配置
50+
51+
### `--files`
52+
53+
- Type: `string`
54+
55+
额外更新的文件, 以更新组件为例:
56+
57+
```sh
58+
npx vue-sfc-cli --upgrade --files package.json
59+
```
5060

5161
## Notice
5262

init.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@ const fs = require('fs-extra')
1111
const argv = parseArgs(process.argv.slice(2))
1212

1313
let pkg = {}
14+
let pkgName = ''
1415
/**
1516
* Prompt user for input to populate template files
1617
*/
17-
let npmName
18-
let ownerName
19-
const OWNER_NAME = 'femessage'
18+
let npmName = argv.get('npm')
19+
let ownerName = argv.get('owner')
20+
const OWNER_NAME = 'FEMessage'
2021

2122
function isUpgrade() {
2223
return argv.has('u') || argv.has('upgrade')
@@ -25,8 +26,7 @@ function isUpgrade() {
2526
if (isUpgrade()) {
2627
try {
2728
pkg = require(path.join(process.cwd(), 'package.json'))
28-
npmName = pkg.name.replace(/^@[\w-]*\//, '')
29-
ownerName = pkg.name.replace(/^@([\w-]*)\/[\w-]*/, '$1')
29+
pkgName = pkg.name.replace(/^@[\w-]*\//, '')
3030
} catch {}
3131
}
3232

@@ -36,14 +36,17 @@ if (argv.has('test')) {
3636
}
3737

3838
const promptAngle = kleur.dim('> ')
39+
3940
if (!npmName) {
4041
console.log(
41-
'The component name:'
42+
`The component name: ${pkgName ? kleur.dim(`(${pkgName})`) : ''}`
4243
)
4344
npmName = readline.prompt({
45+
defaultInput: pkgName,
4446
prompt: promptAngle
4547
})
4648
}
49+
4750
if (!ownerName) {
4851
console.log(
4952
`The owner: ${kleur.dim(`(${OWNER_NAME})`)}`

lib/fileActions.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,24 +84,29 @@ module.exports = class FileActions {
8484
this.opts,
8585
{
8686
source: fs.readFileSync(path.join(this.opts.templatesDir, 'package-json'), 'utf8'),
87+
includePkg: files.includes('package.json')
8788
}
8889
)
8990
)
9091
}
9192
}
9293

93-
function upgradePackageJson({ pkg, source, componentName, ownerName }) {
94+
function upgradePackageJson({ pkg, source, componentName, ownerName, includePkg }) {
9495
const properties = ['scripts', 'devDependencies']
9596
const cliVersion = require('../package.json').version
9697

9798
const templatePkg = JSON.parse(parseContent(source, { componentName, ownerName }))
9899
const currentPkg = pkg
99100

100-
properties.forEach(key => {
101-
currentPkg[key] = Object.assign(pkg[key], templatePkg[key])
102-
})
101+
if (currentPkg['vue-sfc-cli']) {
102+
currentPkg['vue-sfc-cli'] = cliVersion
103+
}
103104

104-
currentPkg['vue-sfc-cli'] = cliVersion
105+
if (includePkg) {
106+
properties.forEach(key => {
107+
currentPkg[key] = Object.assign(pkg[key], templatePkg[key])
108+
})
109+
}
105110

106111
fs.outputJSONSync(path.join(process.cwd(), 'package.json'), currentPkg, {
107112
spaces: 2

templates/.all-contributorsrc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"projectName": "{{componentName}}",
3+
"projectOwner": "{{ownerName}}",
4+
"repoType": "github",
5+
"repoHost": "https://github.com",
6+
"files": [
7+
"README.md"
8+
],
9+
"imageSize": 100,
10+
"commit": false,
11+
"commitConvention": "angular",
12+
"contributors": [],
13+
"contributorsPerLine": 7
14+
}

templates/README.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# {{componentName}}
22

33
[![Build Status](https://travis-ci.com/{{ownerName}}/{{componentName}}.svg?branch=master)](https://travis-ci.com/{{ownerName}}/{{componentName}})
4-
[![NPM Download](https://img.shields.io/npm/dm/@{{ownerName}}/{{componentName}}.svg)](https://www.npmjs.com/package/@{{ownerName}}/{{componentName}})
5-
[![NPM Version](https://img.shields.io/npm/v/@{{ownerName}}/{{componentName}}.svg)](https://www.npmjs.com/package/@{{ownerName}}/{{componentName}})
6-
[![NPM License](https://img.shields.io/npm/l/@{{ownerName}}/{{componentName}}.svg)](https://github.com/{{ownerName}}/{{componentName}}/blob/master/LICENSE)
4+
[![NPM Download](https://img.shields.io/npm/dm/@{{ownerNameLowerCase}}/{{componentName}}.svg)](https://www.npmjs.com/package/@{{ownerNameLowerCase}}/{{componentName}})
5+
[![NPM Version](https://img.shields.io/npm/v/@{{ownerNameLowerCase}}/{{componentName}}.svg)](https://www.npmjs.com/package/@{{ownerNameLowerCase}}/{{componentName}})
6+
[![NPM License](https://img.shields.io/npm/l/@{{ownerNameLowerCase}}/{{componentName}}.svg)](https://github.com/{{ownerName}}/{{componentName}}/blob/master/LICENSE)
77
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/{{ownerName}}/{{componentName}}/pulls)
88
[![Automated Release Notes by gren](https://img.shields.io/badge/%F0%9F%A4%96-release%20notes-00B2EE.svg)](https://github-tools.github.io/github-release-notes/)
99

@@ -17,6 +17,7 @@
1717
- [Install](#install)
1818
- [Example](#example)
1919
- [Reference](#reference)
20+
- [Contributors](#contributors)
2021
- [License](#license)
2122

2223
## Introduction
@@ -45,6 +46,18 @@
4546

4647
[⬆ Back to Top](#table-of-contents)
4748

49+
## Contributors
50+
51+
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
52+
53+
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
54+
<!-- prettier-ignore -->
55+
<!-- ALL-CONTRIBUTORS-LIST:END -->
56+
57+
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
58+
59+
[⬆ Back to Top](#table-of-contents)
60+
4861
## License
4962

5063
[MIT](./LICENSE)

templates/package-json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "@{{ownerName}}/{{componentName}}",
2+
"name": "@{{ownerNameLowerCase}}/{{componentName}}",
33
"version": "1.0.0",
44
"description": "",
55
"author": "https://github.com/{{ownerName}}",

utils/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ exports.parseContent = (content, { componentName, ownerName }) => {
1111
.replace(createRegExp('componentNamePascal'), pascalify(componentName))
1212
.replace(createRegExp('componentName'), kebabcasify(componentName))
1313
.replace(createRegExp('ownerName'), ownerName)
14+
.replace(createRegExp('ownerNameLowerCase'), ownerName.toLowerCase())
1415
.replace(createRegExp('cliVersion'), require('../package.json').version)
1516
.replace(createRegExp('licenseYear'), new Date().getFullYear())
1617
}

0 commit comments

Comments
 (0)