Skip to content

Commit

Permalink
feat: asasdasasd
Browse files Browse the repository at this point in the history
asasdasd
  • Loading branch information
luoxue committed Nov 18, 2019
1 parent ea12f9c commit 8f9515f
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 36 deletions.
Binary file added .DS_Store
Binary file not shown.
24 changes: 24 additions & 0 deletions aaa.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const prompt = require('prompt')

prompt.start();

//
// Get two properties from the user: username and password
//
prompt.get([{
name: 'username',
required: true
}, {
name: 'password',
hidden: true,
conform: function (value) {
return true;
}
}], function (err, result) {
//
// Log the results.
//
console.log('Command-line input received:');
console.log(' username: ' + result.username);
console.log(' password: ' + result.password);
});
78 changes: 43 additions & 35 deletions commit/lib/cz/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const filter = (array) => {
return x;
});
};

// 获取选择列表
const getList = (obj) => {
const objLeng = longest(Object.keys(obj)).length * 2 + 1;
Expand All @@ -21,25 +21,32 @@ const getList = (obj) => {
}));
};


module.exports = function (options) {
const typeList = getList(options.types);
const inquirer = require('inquirer')


return {
prompter(cz, commit) {
console.log(chalk.yellow('\n标题会在100个字符后进行裁剪。 主体内容每行会在100个字符后自动换行,手动换行请直接输入"\\n"。\n'));

cz.prompt([
{
type: 'list',
name: 'type',
message: '选择你提交的信息类型:',
choices: typeList
}, {
type: 'input',
type: 'string',
name: 'scope',
required: true,
pattern: /^\w+$/,
message: '本次提交的改变所影响的范围?',
// validate(str) {
// if (str.length > 1) {
// return str.length > 1
// } else {
// console.log('字符长度大于1')
// }
// },
message: '本次提交的改变所影响的范围?必填',
}, {
type: 'input',
name: 'subject',
Expand Down Expand Up @@ -73,44 +80,45 @@ module.exports = function (options) {
return answers.isIssueAffected;
}
}
]).then((answers) => {
const maxLineWidth = 100;
])
.then((answers) => {
const maxLineWidth = 100;

const wrapOptions = {
trim: true,
newline: '\n',
indent: '',
width: maxLineWidth
};
const wrapOptions = {
trim: true,
newline: '\n',
indent: '',
width: maxLineWidth
};

// 判断影响范围是否输入
const scope = answers.scope ? `(${answers.scope.trim()})` : '';
// 判断影响范围是否输入
const scope = answers.scope ? `(${answers.scope.trim()})` : '';

// 限制短描述为 100 个字符
console.log('**********')
console.log(answers.type)
console.log(scope)
console.log(answers.subject.trim())
console.log('**********')
const head = (`${answers.type + scope}: ${answers.subject.trim()}`).slice(0, maxLineWidth);
// 限制短描述为 100 个字符
console.log('**********')
console.log(answers.type)
console.log(scope)
console.log(answers.subject.trim())
console.log('**********')
const head = (`${answers.type + scope}: ${answers.subject.trim()}`).slice(0, maxLineWidth);

// 限制详细描述最长宽度为 100 个字符串
const body = wrap(answers.body, wrapOptions);
// 限制详细描述最长宽度为 100 个字符串
const body = wrap(answers.body, wrapOptions);

// Apply breaking change prefix, removing it if already present
let breaking = answers.breaking ? answers.breaking.trim() : '';
// Apply breaking change prefix, removing it if already present
let breaking = answers.breaking ? answers.breaking.trim() : '';

// 如果手动输入了 不兼容变更,则过滤掉,最后进行长度限制
breaking = breaking ? `不兼容变更: ${breaking.replace(/^不兼容变更: /, '')}` : '';
breaking = wrap(breaking, wrapOptions);
// 如果手动输入了 不兼容变更,则过滤掉,最后进行长度限制
breaking = breaking ? `不兼容变更: ${breaking.replace(/^不兼容变更: /, '')}` : '';
breaking = wrap(breaking, wrapOptions);

const issues = answers.issues ? wrap(answers.issues, wrapOptions) : '';
const issues = answers.issues ? wrap(answers.issues, wrapOptions) : '';

const footer = filter([breaking, issues]).join('\n\n');
const footer = filter([breaking, issues]).join('\n\n');

console.log('------222----',head, body, footer, '------222---------')
commit(`${head}\n\n${body}\n\n${footer}`);
});
console.log('------222----', head, body, footer, '------222---------')
commit(`${head}\n\n${body}\n\n${footer}`);
});
}
};
};
1 change: 0 additions & 1 deletion commit/lib/cz/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
'format cjs';

const engine = require('./engine');

module.exports = engine({
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
"homepage": "https://github.com/luoxue-victor/learn_webpack#readme",
"dependencies": {
"@commitlint/config-conventional": "^8.2.0",
"inquirer": "^7.0.0",
"jimi-web-changelog": "^0.1.7",
"prompt": "^1.0.0",
"webpack": "^4.41.2"
},
"devDependencies": {
Expand Down

0 comments on commit 8f9515f

Please sign in to comment.