Skip to content

Commit

Permalink
fix: 修复数据存储模版相关
Browse files Browse the repository at this point in the history
1. 完善模版变量
2. 完善url存储
3. email、url报错中增加传入的值
4. 完善数据获取
  • Loading branch information
eliassama committed Dec 15, 2021
1 parent 4be9346 commit 9b34b62
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/commands/config/author/email.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function execute(data: string) {
}
console.log(
chalk.bold.red(
"Failed to set author's email because the set email is not valid",
`Failed to set author's email ${data}, because the set email is not valid`,
),
);
}
6 changes: 5 additions & 1 deletion src/commands/config/author/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import * as LocalStorage from '../../../utils/local-storage';
const chalk = require('chalk');

export function execute(data: string) {
if (data[data.length - 1] === "/"){
data = data.substring(0, data.length - 1)
}

if (
/^(?:(http|https|ftp):\/\/)?((|[\w-]+\.)+[a-z0-9]+)(?:(\/[^/?#]+)*)?(\?[^#]+)?(#.+)?$/i.test(
data,
Expand All @@ -15,7 +19,7 @@ export function execute(data: string) {
}
console.log(
chalk.bold.red(
"Failed to set author's url because the set url is not valid",
`Failed to set author's url ${data}, because the set url is not valid`,
),
);
}
2 changes: 1 addition & 1 deletion src/template/ts-package/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ${project.name}
[![standard-readme compliant](https://img.shields.io/badge/${project.name}-v${project.version}-green.svg?style=flat-square)](${project.repository})
[![standard-readme compliant](https://img.shields.io/badge/${project.name-badge}-v0.0.0--alpha.1-green.svg?style=flat-square)](${project.repository})

${project.description}

Expand Down
2 changes: 1 addition & 1 deletion src/template/ts-package/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
},
"repository": {
"type": "git",
"url": "git+${project.repository}"
"url": "git+${project.repository}.git"
},
"author": "${author.name} <${author.email}> (${author.url})",
"license": "MIT",
Expand Down
6 changes: 3 additions & 3 deletions src/utils/local-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ export function read(target?: string) {
try {
const ReadData = JSON.parse(fs.readFileSync(LocalStorageFile, 'utf-8'));
if (target) {
return new Function('ReadData', `return ReadData.${target}`)(ReadData);
return new Function('ReadData', 'DefaultData', `return Object.assign(DefaultData.${target},ReadData.${target})`)(ReadData, DefaultData);
}
return ReadData;
return ReadData || DefaultData;
} catch (e) {
if (target) {
return '';
return new Function( 'DefaultData', `return DefaultData.${target}`)(DefaultData);
}
return DefaultData;
}
Expand Down

0 comments on commit 9b34b62

Please sign in to comment.