@initx-plugin/core 0.0.19 → 0.0.20
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/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.mjs +22 -24
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -82,7 +82,7 @@ declare abstract class InitxPlugin<TConfig extends PluginConfig = PluginConfig>
|
|
|
82
82
|
private executeHandle;
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
declare function createStore(
|
|
86
|
-
declare function writeStore(
|
|
85
|
+
declare function createStore({ name }: PackageInfo, defaultStore?: Record<string, any>): any;
|
|
86
|
+
declare function writeStore({ name }: PackageInfo): void;
|
|
87
87
|
|
|
88
88
|
export { type HandlerInfo, type InitxBaseContext, type InitxContext, InitxPlugin, type InitxPluginInfo, type MatchedPlugin, type PackageInfo, createStore, loadPlugins, matchPlugins, writeStore };
|
package/dist/index.d.ts
CHANGED
|
@@ -82,7 +82,7 @@ declare abstract class InitxPlugin<TConfig extends PluginConfig = PluginConfig>
|
|
|
82
82
|
private executeHandle;
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
declare function createStore(
|
|
86
|
-
declare function writeStore(
|
|
85
|
+
declare function createStore({ name }: PackageInfo, defaultStore?: Record<string, any>): any;
|
|
86
|
+
declare function writeStore({ name }: PackageInfo): void;
|
|
87
87
|
|
|
88
88
|
export { type HandlerInfo, type InitxBaseContext, type InitxContext, InitxPlugin, type InitxPluginInfo, type MatchedPlugin, type PackageInfo, createStore, loadPlugins, matchPlugins, writeStore };
|
package/dist/index.mjs
CHANGED
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
+
import { homedir } from 'node:os';
|
|
2
3
|
import fs from 'fs-extra';
|
|
3
4
|
import { defu } from 'defu';
|
|
4
5
|
import { c } from '@initx-plugin/utils';
|
|
5
6
|
|
|
7
|
+
const INITX_DIR = path.resolve(homedir(), ".initx");
|
|
6
8
|
const STORE_FILE_NAME = "store.json";
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
const REWRITED_FILE_NAME = ".rewrited";
|
|
10
|
+
const resolveStore = (name) => path.resolve(INITX_DIR, name, STORE_FILE_NAME);
|
|
11
|
+
const resolveRewrited = (name) => path.resolve(INITX_DIR, name, REWRITED_FILE_NAME);
|
|
12
|
+
function createStore({ name }, defaultStore = {}) {
|
|
13
|
+
fs.ensureDirSync(path.resolve(INITX_DIR, name));
|
|
14
|
+
const storePath = resolveStore(name);
|
|
10
15
|
const generateResult = (resultData) => {
|
|
11
16
|
writeJson(storePath, resultData);
|
|
12
|
-
return useProxy(
|
|
17
|
+
return useProxy(name, resultData);
|
|
13
18
|
};
|
|
14
19
|
if (!fs.existsSync(storePath)) {
|
|
15
20
|
return generateResult(defaultStore);
|
|
@@ -23,27 +28,21 @@ function createStore(root, defaultStore = {}) {
|
|
|
23
28
|
}
|
|
24
29
|
return generateResult(json);
|
|
25
30
|
}
|
|
26
|
-
function writeStore(
|
|
27
|
-
const
|
|
28
|
-
if (!
|
|
31
|
+
function writeStore({ name }) {
|
|
32
|
+
const rewritedPath = resolveRewrited(name);
|
|
33
|
+
if (!fs.existsSync(rewritedPath)) {
|
|
29
34
|
return;
|
|
30
35
|
}
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
36
|
+
const rewrited = fs.readJsonSync(rewritedPath);
|
|
37
|
+
writeJson(resolveStore(name), rewrited);
|
|
38
|
+
fs.removeSync(rewritedPath);
|
|
35
39
|
}
|
|
36
40
|
function writeJson(path2, data) {
|
|
37
41
|
fs.writeJsonSync(path2, data, {
|
|
38
42
|
spaces: 2
|
|
39
43
|
});
|
|
40
44
|
}
|
|
41
|
-
function useProxy(
|
|
42
|
-
if (!stores.has(root)) {
|
|
43
|
-
stores.set(root, {
|
|
44
|
-
rewrited: false
|
|
45
|
-
});
|
|
46
|
-
}
|
|
45
|
+
function useProxy(name, obj = {}) {
|
|
47
46
|
const isPlainObject = (value) => {
|
|
48
47
|
return Object.prototype.toString.call(value) === "[object Object]";
|
|
49
48
|
};
|
|
@@ -57,14 +56,13 @@ function useProxy(root, obj = {}) {
|
|
|
57
56
|
return value;
|
|
58
57
|
},
|
|
59
58
|
set(target2, key, value) {
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
const success = Reflect.set(target2, key, value);
|
|
60
|
+
fs.writeJsonSync(resolveRewrited(name), target2);
|
|
61
|
+
return success;
|
|
62
62
|
}
|
|
63
63
|
});
|
|
64
64
|
};
|
|
65
|
-
|
|
66
|
-
stores.get(root).data = store;
|
|
67
|
-
return store;
|
|
65
|
+
return createDeepProxy(obj);
|
|
68
66
|
}
|
|
69
67
|
|
|
70
68
|
var __defProp = Object.defineProperty;
|
|
@@ -151,7 +149,7 @@ class InitxPlugin {
|
|
|
151
149
|
}
|
|
152
150
|
async executeHandle(context, ...others) {
|
|
153
151
|
await this.handle(context, ...others);
|
|
154
|
-
writeStore(context.packageInfo
|
|
152
|
+
writeStore(context.packageInfo);
|
|
155
153
|
}
|
|
156
154
|
}
|
|
157
155
|
|
|
@@ -194,7 +192,7 @@ function matchPlugins(plugins, { key, cliOptions }, ...others) {
|
|
|
194
192
|
const matchedHandlers = [];
|
|
195
193
|
for (const plugin of plugins) {
|
|
196
194
|
const { instance, packageInfo } = plugin;
|
|
197
|
-
const store = createStore(packageInfo
|
|
195
|
+
const store = createStore(packageInfo, instance.defaultConfig);
|
|
198
196
|
const matched = instance.run({
|
|
199
197
|
key,
|
|
200
198
|
store,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@initx-plugin/core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.20",
|
|
5
5
|
"description": "core module for initx plugins",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://github.com/initx-collective/initx#readme",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"defu": "^6.1.4",
|
|
26
26
|
"fs-extra": "^11.2.0",
|
|
27
27
|
"importx": "^0.5.0",
|
|
28
|
-
"@initx-plugin/utils": "0.0.
|
|
28
|
+
"@initx-plugin/utils": "0.0.20"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@types/fs-extra": "^11.0.4"
|