• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

MicroAppJS / plugin-vuepress / 7004622455

27 Nov 2023 11:56AM UTC coverage: 43.081%. Remained the same
7004622455

push

github

zyao89
feat: update deploy

41 of 139 branches covered (0.0%)

Branch coverage included in aggregate %.

124 of 244 relevant lines covered (50.82%)

1.45 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

60.23
/src/commands/createConfig.js
1
'use strict';
2

3
module.exports = function createConfig(api, args, opts) {
1✔
4
    const { _, smartMerge } = require('@micro-app/shared-utils');
3✔
5
    const path = require('path');
3✔
6

7
    const vuepressConfig = api.vuepressConfig;
3✔
8
    const sourceDir = args._ && args._[1] || vuepressConfig.sourceDir || '.';
3!
9
    const root = vuepressConfig.root;
3✔
10
    vuepressConfig.sourceDir = path.resolve(root, sourceDir);
3✔
11

12
    const loadConfig = require('@vuepress/core/lib/node/loadConfig');
3✔
13

14
    // const vuepressDir = api.resolveWorkspace('.vuepress'); // 不能使用,vuepress内部代码太乱
15
    const vuepressDir = path.resolve(vuepressConfig.sourceDir, '.vuepress');
3✔
16
    const siteConfig = loadConfig(vuepressDir) || {};
3!
17

18
    const customConfig = require('../config');
3✔
19
    const config = smartMerge({}, customConfig, siteConfig, vuepressConfig, opts, _.pick(args, [ 'base' ]));
3✔
20
    config.root = root;
3✔
21
    // reset vuepressDir
22
    config.vuepressDir = vuepressDir;
3✔
23
    config.cacheDir = path.resolve(api.tempDir, '.cache');
3✔
24
    // reset dest
25
    config.dest = path.resolve(vuepressConfig.sourceDir, config.dest);
3✔
26

27
    const options = api.config || {};
3!
28
    const resolveAlias = options.resolveAlias || {};
3!
29
    const resolveShared = options.resolveShared || {};
3!
30
    const nodeModulesPaths = options.nodeModulesPaths || [];
3✔
31

32
    api.logger.debug('resolveAlias: ', JSON.stringify(resolveAlias, false, 4));
3✔
33
    api.logger.debug('resolveShared: ', JSON.stringify(resolveShared, false, 4));
3✔
34

35
    if (config.chainWebpack && _.isFunction(config.chainWebpack)) {
3!
36
        const orginalChainWebpack = config.chainWebpack;
×
37
        config.chainWebpack = function(_config, isServer) {
×
38
            if (isServer) {
×
39
                orginalChainWebpack(injectWebpackAlias(_config, resolveShared, nodeModulesPaths), isServer);
×
40
            } else {
41
                orginalChainWebpack(injectWebpackAlias(_config, resolveAlias, nodeModulesPaths), isServer);
×
42
            }
43
            // if (api.hasKey('resolveWebpackChain')) {
44
            //     api.resolveWebpackChain(_config, isServer);
45
            // }
46
        };
47
    } else {
48
        config.chainWebpack = function(_config, isServer) {
3✔
49
            if (isServer) {
×
50
                injectWebpackAlias(_config, resolveShared, nodeModulesPaths);
×
51
            } else {
52
                injectWebpackAlias(_config, resolveAlias, nodeModulesPaths);
×
53
            }
54
            // if (api.hasKey('resolveWebpackChain')) {
55
            //     api.resolveWebpackChain(_config, isServer);
56
            // }
57
        };
58
    }
59

60
    if (config.configureWebpack && _.isFunction(config.configureWebpack)) {
3!
61
        const orginalConfigWebpack = config.configureWebpack;
×
62
        config.configureWebpack = function(config, isServer) {
×
63
            if (api.hasKey('resolveWebpackConfig')) {
×
64
                api.resolveWebpackConfig(config, isServer);
×
65
            }
66
            return orginalConfigWebpack(config, isServer);
×
67
        };
68
    } else {
69
        config.chainWebpack = function(config, isServer) {
3✔
70
            if (api.hasKey('resolveWebpackConfig')) {
×
71
                return api.resolveWebpackConfig(config, isServer);
×
72
            }
73
            return config;
×
74
        };
75
    }
76

77
    // watcher
78
    config.extraWatchFiles = (config.extraWatchFiles || []).concat(
3✔
79
        require('../constants').FILENAMES.map(filename => path.resolve(api.root, filename))
27✔
80
    );
81

82
    // blog
83
    const blogConfig = config.themeConfig && config.themeConfig.blogConfig || {};
3✔
84
    const postsDir = blogConfig.postsDir || 'posts';
3✔
85
    config.extraWatchFiles.push(postsDir); // add watcher files
3✔
86

87
    api.logger.debug('vuepressConfig: ', JSON.stringify(config, false, 4));
3✔
88
    return config;
3✔
89
};
90

91
function injectWebpackAlias(config, alias, nodeModulesPaths) {
92
    config.resolve
×
93
        .modules
94
        .merge(nodeModulesPaths)
95
        .end()
96
        .alias
97
        .merge(alias);
98
    return config;
×
99
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc