UNPKG

1.99 kBJavaScriptView Raw
1// these prompts are used if the plugin is late-installed into an existing
2// project and invoked by `vue invoke`.
3
4const inquirer = require('inquirer');
5const chalk = require('chalk');
6const { execSync } = require('child_process');
7const { hasStylelintConfig } = require('./utils');
8
9let git;
10function hasGit() {
11 if (git != null) {
12 return git;
13 }
14 try {
15 execSync('git --version', { stdio: 'ignore' });
16 git = true;
17 } catch (e) {
18 git = false;
19 }
20 return git;
21}
22
23const questions = [
24 {
25 name: 'config',
26 type: 'list',
27 message: 'Pick a stylelint config:',
28 default: 0,
29 when: ({ overwriteConfig }) => (overwriteConfig ? overwriteConfig !== 'abort' : true),
30 choices: [
31 {
32 name: 'Standard',
33 value: 'stylelint-config-standard',
34 short: 'Standard',
35 }, {
36 name: 'Primer',
37 value: 'stylelint-config-primer',
38 short: 'Primer',
39 },
40 new inquirer.Separator(),
41 {
42 name: 'Kanbaru',
43 value: '@ascendancyy/stylelint-config-kanbaru',
44 short: 'Kanbaru',
45 },
46 ],
47 }, {
48 name: 'lintStyleOn',
49 type: 'checkbox',
50 message: 'Pick additional stylelint features:',
51 when: ({ overwriteConfig }) => (overwriteConfig ? overwriteConfig !== 'abort' : true),
52 choices: [
53 {
54 name: 'Lint on build',
55 value: 'build',
56 }, {
57 name: `Lint and fix on commit ${hasGit() ? '' : chalk`{red (requires Git)}`}`,
58 value: 'commit',
59 },
60 ],
61 },
62];
63
64const cwd = process.cwd();
65if (hasStylelintConfig(cwd)) {
66 questions.unshift({
67 name: 'overwriteConfig',
68 type: 'expand',
69 message: 'Existing stylelint config found:',
70 choices: [
71 {
72 key: 'y',
73 name: 'Overwrite',
74 value: 'overwrite',
75 }, {
76 key: 'x',
77 name: 'Cancel setup (Plugin generator will be invoked, but will not make changes)',
78 value: 'abort',
79 },
80 ],
81 });
82}
83
84module.exports = questions;