保誠-保戶業務員媒合平台
HelenHuang
2022-06-09 9bdb95c9e34cef640534e5e5a1e2225a80442000
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
'use strict';
 
const fs = require('fs');
const path = require('upath');
const chokidar = require('chokidar');
const consola = require('consola');
const chalk = require('chalk');
const semver = require('semver');
const globby = require('globby');
const scule = require('scule');
 
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
 
const fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
const path__default = /*#__PURE__*/_interopDefaultLegacy(path);
const chokidar__default = /*#__PURE__*/_interopDefaultLegacy(chokidar);
const consola__default = /*#__PURE__*/_interopDefaultLegacy(consola);
const chalk__default = /*#__PURE__*/_interopDefaultLegacy(chalk);
const semver__default = /*#__PURE__*/_interopDefaultLegacy(semver);
const globby__default = /*#__PURE__*/_interopDefaultLegacy(globby);
 
function requireNuxtVersion(currentVersion, requiredVersion) {
  const pkgName = require("../package.json").name;
  if (!currentVersion || !requireNuxtVersion) {
    return;
  }
  const _currentVersion = semver__default['default'].coerce(currentVersion);
  const _requiredVersion = semver__default['default'].coerce(requiredVersion);
  if (semver__default['default'].lt(_currentVersion, _requiredVersion)) {
    throw new Error(`
 
      ${chalk__default['default'].cyan(pkgName)} is not compatible with your current Nuxt version : ${chalk__default['default'].yellow("v" + currentVersion)}
 
      Required: ${chalk__default['default'].green("v" + requiredVersion)} or ${chalk__default['default'].cyan("higher")}
    `);
  }
}
 
function sortDirsByPathLength({ path: pathA }, { path: pathB }) {
  return pathB.split(/[\\/]/).filter(Boolean).length - pathA.split(/[\\/]/).filter(Boolean).length;
}
function hyphenate(str) {
  return str.replace(/\B([A-Z])/g, "-$1").toLowerCase();
}
async function scanComponents(dirs, srcDir) {
  const components = [];
  const filePaths = new Set();
  const scannedPaths = [];
  for (const { path: path$1, pattern, ignore = [], prefix, extendComponent, pathPrefix, level, prefetch = false, preload = false, isAsync: dirIsAsync } of dirs.sort(sortDirsByPathLength)) {
    const resolvedNames = new Map();
    for (const _file of await globby__default['default'](pattern, { cwd: path$1, ignore })) {
      const filePath = path.join(path$1, _file);
      if (scannedPaths.find((d) => filePath.startsWith(d))) {
        continue;
      }
      if (filePaths.has(filePath)) {
        continue;
      }
      filePaths.add(filePath);
      const prefixParts = [].concat(prefix ? scule.splitByCase(prefix) : [], pathPrefix !== false ? scule.splitByCase(path.relative(path$1, path.dirname(filePath))) : []);
      let fileName = path.basename(filePath, path.extname(filePath));
      if (fileName.toLowerCase() === "index") {
        fileName = pathPrefix === false ? path.basename(path.dirname(filePath)) : "";
      }
      const isAsync = (fileName.endsWith(".async") ? true : dirIsAsync) || null;
      fileName = fileName.replace(/\.async$/, "");
      const fileNameParts = scule.splitByCase(fileName);
      const componentNameParts = [];
      while (prefixParts.length && (prefixParts[0] || "").toLowerCase() !== (fileNameParts[0] || "").toLowerCase()) {
        componentNameParts.push(prefixParts.shift());
      }
      const componentName = scule.pascalCase(componentNameParts).replace(/^\d+/, "") + scule.pascalCase(fileNameParts).replace(/^\d+/, "");
      if (resolvedNames.has(componentName)) {
        console.warn(`Two component files resolving to the same name \`${componentName}\`:
 
 - ${filePath}
 - ${resolvedNames.get(componentName)}`);
        continue;
      }
      resolvedNames.set(componentName, filePath);
      const pascalName = scule.pascalCase(componentName);
      const kebabName = hyphenate(componentName);
      const shortPath = path.relative(srcDir, filePath);
      const chunkName = "components/" + kebabName;
      let component = {
        filePath,
        pascalName,
        kebabName,
        chunkName,
        shortPath,
        isAsync,
        import: "",
        asyncImport: "",
        export: "default",
        global: Boolean(global),
        level: Number(level),
        prefetch: Boolean(prefetch),
        preload: Boolean(preload)
      };
      if (typeof extendComponent === "function") {
        component = await extendComponent(component) || component;
      }
      component.import = component.import || `require('${component.filePath}').${component.export}`;
      component.asyncImport = component.asyncImport || `function () { return import('${component.filePath}' /* webpackChunkName: "${component.chunkName}" */).then(function(m) { return m['${component.export}'] || m }) }`;
      const definedComponent = components.find((c) => c.pascalName === component.pascalName);
      if (definedComponent && component.level < definedComponent.level) {
        Object.assign(definedComponent, component);
      } else if (!definedComponent) {
        components.push(component);
      }
    }
    scannedPaths.push(path$1);
  }
  return components;
}
 
const isPureObjectOrString = (val) => !Array.isArray(val) && typeof val === "object" || typeof val === "string";
const getDir = (p) => fs__default['default'].statSync(p).isDirectory() ? p : path__default['default'].dirname(p);
const componentsModule = function() {
  var _a;
  const { nuxt } = this;
  const { components } = nuxt.options;
  if (!components) {
    return;
  }
  requireNuxtVersion((_a = nuxt == null ? void 0 : nuxt.constructor) == null ? void 0 : _a.version, "2.10");
  const options = {
    dirs: ["~/components"],
    loader: !nuxt.options.dev,
    ...Array.isArray(components) ? { dirs: components } : components
  };
  nuxt.hook("build:before", async (builder) => {
    const nuxtIgnorePatterns = builder.ignore.ignore ? builder.ignore.ignore._rules.map((rule) => rule.pattern) : [];
    await nuxt.callHook("components:dirs", options.dirs);
    const resolvePath = (dir) => nuxt.resolver.resolvePath(dir);
    try {
      const globalDir = getDir(resolvePath("~/components/global"));
      if (!options.dirs.find((dir) => resolvePath(dir) === globalDir)) {
        options.dirs.push({
          path: globalDir
        });
      }
    } catch (err) {
      nuxt.options.watch.push(path__default['default'].resolve(nuxt.options.srcDir, "components", "global"));
    }
    const componentDirs = options.dirs.filter(isPureObjectOrString).map((dir) => {
      const dirOptions = typeof dir === "object" ? dir : { path: dir };
      let dirPath = dirOptions.path;
      try {
        dirPath = getDir(nuxt.resolver.resolvePath(dirOptions.path));
      } catch (err) {
      }
      const transpile = typeof dirOptions.transpile === "boolean" ? dirOptions.transpile : "auto";
      dirOptions.level = Number(dirOptions.level || 0);
      const enabled = fs__default['default'].existsSync(dirPath);
      if (!enabled && dirOptions.path !== "~/components") {
        console.warn("Components directory not found: `" + dirPath + "`");
      }
      const extensions = dirOptions.extensions || builder.supportedExtensions;
      return {
        ...dirOptions,
        enabled,
        path: dirPath,
        extensions,
        pattern: dirOptions.pattern || `**/*.{${extensions.join(",")},}`,
        isAsync: dirOptions.isAsync,
        ignore: [
          "**/*.stories.{js,ts,jsx,tsx}",
          "**/*{M,.m,-m}ixin.{js,ts,jsx,tsx}",
          "**/*.d.ts",
          ...nuxtIgnorePatterns,
          ...dirOptions.ignore || []
        ],
        transpile: transpile === "auto" ? dirPath.includes("node_modules") : transpile
      };
    }).filter((d) => d.enabled);
    nuxt.options.build.transpile.push(...componentDirs.filter((dir) => dir.transpile).map((dir) => dir.path));
    let components2 = await scanComponents(componentDirs, nuxt.options.srcDir);
    await nuxt.callHook("components:extend", components2);
    if (options.loader) {
      consola__default['default'].info("Using components loader to optimize imports");
      this.extendBuild((config) => {
        var _a2;
        const vueRule = (_a2 = config.module) == null ? void 0 : _a2.rules.find((rule) => {
          var _a3;
          return (_a3 = rule.test) == null ? void 0 : _a3.toString().includes(".vue");
        });
        if (!vueRule) {
          throw new Error("Cannot find vue loader");
        }
        if (!vueRule.use) {
          vueRule.use = [{
            loader: vueRule.loader.toString(),
            options: vueRule.options
          }];
          delete vueRule.loader;
          delete vueRule.options;
        }
        if (!Array.isArray(vueRule.use)) {
          vueRule.use = [vueRule.use];
        }
        vueRule.use.unshift({
          loader: require.resolve("./loader"),
          options: {
            getComponents: () => components2
          }
        });
      });
      nuxt.hook("webpack:config", (configs) => {
        for (const config of configs.filter((c) => ["client", "modern", "server"].includes(c.name))) {
          config.entry.app.unshift(path__default['default'].resolve(__dirname, "../lib/installComponents.js"));
        }
      });
    }
    if (nuxt.options.dev && componentDirs.some((dir) => dir.watch !== false)) {
      const watcher = chokidar__default['default'].watch(componentDirs.filter((dir) => dir.watch !== false).map((dir) => dir.path), nuxt.options.watchers.chokidar);
      watcher.on("all", async (eventName) => {
        if (!["add", "unlink"].includes(eventName)) {
          return;
        }
        components2 = await scanComponents(componentDirs, nuxt.options.srcDir);
        await nuxt.callHook("components:extend", components2);
        await builder.generateRoutesAndFiles();
      });
      nuxt.hook("close", () => {
        watcher.close();
      });
    }
    const getComponents = () => components2;
    const templates = [
      "components/index.js",
      "components/plugin.js",
      "components/readme_md",
      "vetur/tags.json"
    ];
    for (const t of templates) {
      this[t.includes("plugin") ? "addPlugin" : "addTemplate"]({
        src: path__default['default'].resolve(__dirname, "../templates", t),
        fileName: t.replace("_", "."),
        options: { getComponents }
      });
    }
    const componentsListFile = path__default['default'].resolve(nuxt.options.buildDir, "components/readme.md");
    consola__default['default'].info("Discovered Components:", path__default['default'].relative(process.cwd(), componentsListFile));
  });
};
componentsModule.meta = { name: "@nuxt/components" };
 
module.exports = componentsModule;