UNPKG

1.55 kBJavaScriptView Raw
1/**
2 * @file project-path.js
3 * @author clark-t (clarktanglei@163.com)
4 */
5
6const path = require('path')
7
8function componentsDir (dir) {
9 return path.resolve(dir, 'components')
10}
11
12// function possibleComponentPaths(dir, id) {
13// let compDir = componentsDir(dir);
14// return [
15// path.resolve(compDir, id + '.vue'),
16// path.resolve(compDir, id, id + '.vue')
17// ];
18// }
19
20// function componentPath (dir, id) {
21// let compDir = componentsDir(dir)
22// return path.resolve(compDir, id, id + '.vue')
23// }
24
25function testDir (dir) {
26 return path.resolve(dir, 'example')
27}
28
29function componentTestDir (dir, component) {
30 return path.resolve(dir, component, 'example')
31}
32
33// function storeDir (dir) {
34// return path.resolve(dir, 'store')
35// }
36
37function isComponentPath (rootDir, pathname) {
38 // let basename = path.basename(pathname)
39 // 非入口文件的增减则不做任何处理
40 if (!/(mip-[\w-]+)\/\1\.(vue|js|ts)$/.test(pathname)) {
41 return false
42 }
43
44 let basename = path.basename(pathname)
45
46 return path.resolve(
47 componentsDir(rootDir),
48 path.basename(basename, path.extname(basename)),
49 basename
50 ) === path.resolve(pathname)
51}
52
53// function packageJson (rootDir) {
54// return path.resolve(dir, 'package.json')
55// }
56
57// function config (rootDir) {
58// return
59// }
60
61module.exports = {
62 components: componentsDir,
63 // componentPath: componentPath,
64 componentTestDir: componentTestDir,
65 // possibleComponents: possibleComponentPaths,
66 test: testDir,
67 // store: storeDir,
68 isComponentPath
69}