@cabloy/module-info 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
File without changes
@@ -0,0 +1,9 @@
1
+ import { IModuleInfo } from './interface.js';
2
+ export * from './interface.js';
3
+ export declare const ParseModuleNameLevelInit = 1;
4
+ export declare function parseModuleName(level?: number): string | undefined;
5
+ export declare function parseModuleInfo(level?: number): IModuleInfo | undefined;
6
+ export declare function parseInfoFromPath(pathName: string): IModuleInfo | undefined;
7
+ export declare function parseInfo(moduleName: any, type?: string): IModuleInfo | undefined;
8
+ export declare function parseName(moduleUrl: any): any;
9
+ //# sourceMappingURL=index.d.ts.map
package/dist/index.js ADDED
@@ -0,0 +1,135 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ var __importDefault = (this && this.__importDefault) || function (mod) {
17
+ return (mod && mod.__esModule) ? mod : { "default": mod };
18
+ };
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.parseName = exports.parseInfo = exports.parseInfoFromPath = exports.parseModuleInfo = exports.parseModuleName = exports.ParseModuleNameLevelInit = void 0;
21
+ const stack_utils_1 = __importDefault(require("stack-utils"));
22
+ __exportStar(require("./interface.js"), exports);
23
+ exports.ParseModuleNameLevelInit = 1;
24
+ function parseModuleName(level = exports.ParseModuleNameLevelInit) {
25
+ const info = parseModuleInfo(level + 1);
26
+ if (!info)
27
+ return;
28
+ return info.relativeName;
29
+ }
30
+ exports.parseModuleName = parseModuleName;
31
+ function parseModuleInfo(level = exports.ParseModuleNameLevelInit) {
32
+ const stackUtils = new stack_utils_1.default();
33
+ const traces = stackUtils.capture(level);
34
+ const trace = traces[level - 1];
35
+ const fileName = trace.getFileName();
36
+ return parseInfoFromPath(fileName);
37
+ }
38
+ exports.parseModuleInfo = parseModuleInfo;
39
+ function parseInfoFromPath(pathName) {
40
+ pathName = pathName.replace(/\\/gi, '/');
41
+ const parts = pathName.split('/');
42
+ for (let i = parts.length - 1; i >= 0; i--) {
43
+ const part = parts[i];
44
+ if (part.indexOf('-') === -1)
45
+ continue;
46
+ const info = parseInfo(part);
47
+ if (!info)
48
+ continue;
49
+ return info;
50
+ }
51
+ }
52
+ exports.parseInfoFromPath = parseInfoFromPath;
53
+ const PREFIX_A = '/api/';
54
+ const PREFIX_B = 'cabloy-module-api-';
55
+ const PREFIX_C = './cabloy-module-api-';
56
+ const PREFIX_D = './';
57
+ // aa-hello aa/hello
58
+ // first check / then -
59
+ function parseInfo(moduleName, type = 'module') {
60
+ if (!moduleName)
61
+ return;
62
+ if (moduleName.indexOf('://') > -1)
63
+ return;
64
+ if (moduleName.charAt(0) === '/')
65
+ moduleName = moduleName.substr(1);
66
+ let parts = moduleName.split('/').filter(item => item);
67
+ if (parts.length < 2) {
68
+ parts = moduleName.split('-').filter(item => item);
69
+ if (parts.length < 2)
70
+ return;
71
+ if (parts.length >= 5)
72
+ parts = parts.slice(3);
73
+ }
74
+ if (type === 'suite') {
75
+ return {
76
+ pid: parts[0],
77
+ name: parts[1],
78
+ fullName: `cabloy-suite-api-${parts[0]}-${parts[1]}`,
79
+ relativeName: `${parts[0]}-${parts[1]}`,
80
+ url: '',
81
+ originalName: '',
82
+ };
83
+ }
84
+ return {
85
+ pid: parts[0],
86
+ name: parts[1],
87
+ fullName: `cabloy-module-api-${parts[0]}-${parts[1]}`,
88
+ relativeName: `${parts[0]}-${parts[1]}`,
89
+ url: `${parts[0]}/${parts[1]}`,
90
+ sync: parts[2] === 'sync',
91
+ monkey: parts[2] === 'monkey',
92
+ originalName: '',
93
+ };
94
+ }
95
+ exports.parseInfo = parseInfo;
96
+ // /api/aa/hello/home/index
97
+ // cabloy-module-api-aa-hello
98
+ // ./aa-hello/
99
+ // ./cabloy-module-api-aa-hello/
100
+ function parseName(moduleUrl) {
101
+ if (!moduleUrl)
102
+ return null;
103
+ if (moduleUrl.indexOf('/api/static/') === 0) {
104
+ moduleUrl = '/api/' + moduleUrl.substring('/api/static/'.length);
105
+ }
106
+ if (moduleUrl.indexOf(PREFIX_A) === 0) {
107
+ const posA = PREFIX_A.length;
108
+ const posB = moduleUrl.indexOf('/', posA) + 1;
109
+ if (posB === -1)
110
+ return null;
111
+ const posC = moduleUrl.indexOf('/', posB);
112
+ if (posC === -1)
113
+ return null;
114
+ return moduleUrl.substring(posA, posC);
115
+ }
116
+ else if (moduleUrl.indexOf(PREFIX_B) === 0) {
117
+ return _parseName(moduleUrl, PREFIX_B);
118
+ }
119
+ else if (moduleUrl.indexOf(PREFIX_C) === 0) {
120
+ return _parseName(moduleUrl, PREFIX_C);
121
+ }
122
+ else if (moduleUrl.indexOf(PREFIX_D) === 0) {
123
+ return _parseName(moduleUrl, PREFIX_D);
124
+ }
125
+ return null;
126
+ }
127
+ exports.parseName = parseName;
128
+ function _parseName(moduleUrl, prefix) {
129
+ const posA = prefix.length;
130
+ let posB = moduleUrl.indexOf('/', posA);
131
+ if (posB === -1)
132
+ posB = moduleUrl.length;
133
+ return moduleUrl.substring(posA, posB);
134
+ }
135
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,42 @@
1
+ export interface IModuleInfo {
2
+ pid: string;
3
+ name: string;
4
+ fullName: string;
5
+ relativeName: string;
6
+ url: string;
7
+ sync?: boolean;
8
+ monkey?: boolean;
9
+ vendor?: boolean;
10
+ source?: boolean;
11
+ node_modules?: boolean;
12
+ originalName: string;
13
+ }
14
+ export interface ISuiteModuleBase {
15
+ name: string;
16
+ info: IModuleInfo;
17
+ root: string;
18
+ pkg: string;
19
+ package: IModulePackage;
20
+ }
21
+ export interface ISuite extends ISuiteModuleBase {
22
+ modules: string[];
23
+ }
24
+ export interface IModule extends ISuiteModuleBase {
25
+ suite?: string;
26
+ }
27
+ export interface IModulePackage {
28
+ name: string;
29
+ version: string;
30
+ eggBornModule: {
31
+ fileVersion: number;
32
+ dependencies: Record<string, string>;
33
+ theme: object;
34
+ icon: string;
35
+ locale: string;
36
+ };
37
+ title: string;
38
+ description: string;
39
+ author: string;
40
+ dependencies: string;
41
+ }
42
+ //# sourceMappingURL=interface.d.ts.map
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=interface.js.map
package/package.json CHANGED
@@ -1,19 +1,26 @@
1
1
  {
2
2
  "name": "@cabloy/module-info",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "cabloy module-info",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
8
- "main": "./dist/index.js",
9
- "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": [
11
+ "./src/index.ts",
12
+ "./dist/index.d.ts"
13
+ ],
14
+ "import": "./dist/index.js",
15
+ "require": "./dist/index.js",
16
+ "default": "./src/index.ts"
17
+ },
18
+ "./package.json": "./package.json"
19
+ },
10
20
  "files": [
11
21
  "dist/**/*.js",
12
22
  "dist/**/*.d.ts"
13
23
  ],
14
- "scripts": {
15
- "lint": "eslint ."
16
- },
17
24
  "keywords": [
18
25
  "egg",
19
26
  "egg-born",
@@ -21,6 +28,10 @@
21
28
  "cabloy"
22
29
  ],
23
30
  "author": "zhennann",
24
- "license": "MIT",
25
- "dependencies": {}
26
- }
31
+ "dependencies": {
32
+ "stack-utils": "^2.0.6"
33
+ },
34
+ "scripts": {
35
+ "lint": "eslint ."
36
+ }
37
+ }