执行过npm install命令的vue-element-admin源码
康凯
2022-05-20 aa4c235a8ca67ea8b731f90c951a465e92c0a865
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
'use strict';
 
const chalk = require('chalk');
const nodePlop = require('node-plop');
const fs = require('fs');
 
const defaultChoosingMessage = chalk.blue('[PLOP]') + ' Please choose a generator.';
 
module.exports = (function () {
 
    function getHelpMessage(generator) {
        const maxLen = Math.max(...generator.prompts.map(prompt => prompt.name.length));
        console.log([
            '',
            chalk.bold('Options:'),
            ...generator.prompts.map(prompt =>
                '  --' + prompt.name +
                ' '.repeat(maxLen - prompt.name.length + 2) +
                chalk.dim(prompt.help ? prompt.help : prompt.message)
            )
        ].join('\n'));
    }
 
    function chooseOptionFromList(plopList, message) {
        const plop = nodePlop();
        const generator = plop.setGenerator('choose', {
            prompts: [{
                type: 'list',
                name: 'generator',
                message: message || defaultChoosingMessage,
                choices: plopList.map(function (p) {
                    return {
                        name: p.name + chalk.gray(!!p.description ? ' - ' + p.description : ''),
                        value: p.name
                    };
                })
            }]
        });
        return generator.runPrompts().then(results => results.generator);
    }
 
    function displayHelpScreen() {
        console.log([
            '',
            chalk.bold('Usage:'),
            '  $ plop                 ' + chalk.dim('Select from a list of available generators'),
            '  $ plop <name>          ' + chalk.dim('Run a generator registered under that name'),
            '  $ plop <name> [input]  ' + chalk.dim('Run the generator with input data to bypass prompts'),
            '',
            chalk.bold('Options:'),
            '  -h, --help             ' + chalk.dim('Show this help display'),
            '  -t, --show-type-names  ' + chalk.dim('Show type names instead of abbreviations'),
            '  -i, --init             ' + chalk.dim('Generate a basic plopfile.js'),
            '  -v, --version          ' + chalk.dim('Print current version'),
            '  -f, --force            ' + chalk.dim('Run the generator forcefully'),
            '  --plopfile             ' + chalk.dim('Path to the plopfile'),
            '  --cwd                  ' + chalk.dim('Directory from which relative paths are calculated against'),
            '  --require              ' + chalk.dim('String or array of modules to require before running plop'),
            '',
            chalk.bold('Examples:'),
            '  $ ' + chalk.blue('plop'),
            '  $ ' + chalk.blue('plop component'),
            '  $ ' + chalk.blue('plop component "name of component"'),
            '',
        ].join('\n'));
    }
 
    function createInitPlopfile(cwd, callback){
        var initString = 'module.exports = function (plop) {\n\n' +
            '\tplop.setGenerator(\'basics\', {\n' +
            '\t\tdescription: \'this is a skeleton plopfile\',\n' +
            '\t\tprompts: [],\n' +
            '\t\tactions: []\n' +
            '\t});\n\n' +
            '};';
 
        fs.writeFile(cwd + '/plopfile.js', initString, callback);
    }
 
    const typeDisplay = {
        'function': chalk.yellow('->'),
        'add': chalk.green('++'),
        'addMany': chalk.green('+!'),
        'modify': `${chalk.green('+')}${chalk.red('-')}`,
        'append': chalk.green('_+')
    };
    const typeMap = (name, noMap) => {
        const dimType = chalk.dim(name);
        return (noMap ? dimType : typeDisplay[name] || dimType);
    };
 
    return {
        chooseOptionFromList,
        displayHelpScreen,
        createInitPlopfile,
        typeMap,
        getHelpMessage
    };
})();