diff --git a/packages/plugin-store/.babelrc b/packages/plugin-store/.babelrc new file mode 100644 index 0000000..633f93f --- /dev/null +++ b/packages/plugin-store/.babelrc @@ -0,0 +1,3 @@ +{ + "extends": "../../.babelrc" +} diff --git a/packages/plugin-store/.npmignore b/packages/plugin-store/.npmignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/packages/plugin-store/.npmignore @@ -0,0 +1 @@ +node_modules diff --git a/packages/plugin-store/README.md b/packages/plugin-store/README.md new file mode 100644 index 0000000..e69de29 diff --git a/packages/plugin-store/package.json b/packages/plugin-store/package.json new file mode 100644 index 0000000..e3ad12d --- /dev/null +++ b/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": { + } +} diff --git a/packages/plugin-store/rollup.config.js b/packages/plugin-store/rollup.config.js new file mode 100644 index 0000000..95d7542 --- /dev/null +++ b/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', + }, + ] +}); diff --git a/packages/plugin-store/scripts/prepublish.js b/packages/plugin-store/scripts/prepublish.js new file mode 100644 index 0000000..7dd2753 --- /dev/null +++ b/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, '../')); diff --git a/packages/plugin-store/src/index.ts b/packages/plugin-store/src/index.ts new file mode 100644 index 0000000..ccc8aef --- /dev/null +++ b/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; diff --git a/packages/plugin-store/tsconfig.json b/packages/plugin-store/tsconfig.json new file mode 100644 index 0000000..61ac029 --- /dev/null +++ b/packages/plugin-store/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../tsconfig", + "compilerOptions": { + "outDir": "dist/types" + }, + "include": ["./src", "./types"] +}