Browse Source

feat: add imove plugin store

master
smallstonesk 4 years ago
parent
commit
f558c21787
  1. 3
      packages/plugin-store/.babelrc
  2. 1
      packages/plugin-store/.npmignore
  3. 0
      packages/plugin-store/README.md
  4. 45
      packages/plugin-store/package.json
  5. 17
      packages/plugin-store/rollup.config.js
  6. 6
      packages/plugin-store/scripts/prepublish.js
  7. 24
      packages/plugin-store/src/index.ts
  8. 7
      packages/plugin-store/tsconfig.json

3
packages/plugin-store/.babelrc

@ -0,0 +1,3 @@
{
"extends": "../../.babelrc"
}

1
packages/plugin-store/.npmignore

@ -0,0 +1 @@
node_modules

0
packages/plugin-store/README.md

45
packages/plugin-store/package.json

@ -0,0 +1,45 @@
{
"name": "@imove/plugin-store",
"version": "0.0.1",
"description": "iMove plugin that supports persisting data",
"keywords": [
"imove",
"plugin",
"store"
],
"author": "smallstonesk <575913857@qq.com>",
"homepage": "https://github.com/suanmei/iMove#readme",
"license": "MIT",
"main": "dist/core.common.js",
"module": "dist/core.esm.js",
"types": "dist/types/index.d.ts",
"directories": {
"dist": "dist"
},
"files": [
"dist"
],
"publishConfig": {
"access": "public",
"registry": "http://registry.npmjs.org/"
},
"repository": {
"type": "git",
"url": "git+https://github.com/suanmei/iMove.git"
},
"scripts": {
"prepublishOnly": "node scripts/prepublish.js",
"declare-type": "tsc --emitDeclarationOnly",
"build": "rollup -c & npm run declare-type",
"watch": "watch 'npm run build' ./src"
},
"bugs": {
"url": "https://github.com/suanmei/iMove/issues"
},
"devDependencies": {
"rollup": "^2.7.3",
"watch": "^1.0.2"
},
"dependencies": {
}
}

17
packages/plugin-store/rollup.config.js

@ -0,0 +1,17 @@
import path from 'path';
import rollupBaseConfig from '../../rollup.config';
import pkg from './package.json';
export default Object.assign(rollupBaseConfig, {
input: path.join(__dirname, './src/index.ts'),
output: [
{
file: pkg.main,
format: 'cjs',
},
{
file: pkg.module,
format: 'es',
},
]
});

6
packages/plugin-store/scripts/prepublish.js

@ -0,0 +1,6 @@
#!/usr/bin/env node
const path = require('path');
const prePublish = require('../../../scripts/prepublish');
prePublish('@imove/plugin-store', path.join(__dirname, '../'));

24
packages/plugin-store/src/index.ts

@ -0,0 +1,24 @@
const storeSymbol = Symbol('store');
const plugin = (logic: any) => {
return {
ctxCreated(ctx: { [key: string]: any }) {
if (!logic[storeSymbol]) {
logic[storeSymbol] = {};
}
ctx.store = {
set(key: string, val: any) {
logic[storeSymbol][key] = val;
},
get(key: string) {
return logic[storeSymbol][key];
},
remove(key: string) {
delete logic[storeSymbol][key];
}
};
}
};
};
export default plugin;

7
packages/plugin-store/tsconfig.json

@ -0,0 +1,7 @@
{
"extends": "../../tsconfig",
"compilerOptions": {
"outDir": "dist/types"
},
"include": ["./src", "./types"]
}
Loading…
Cancel
Save