diff --git a/package.json b/package.json index 0ad85f4..4abfa89 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,7 @@ "tslint": "tslint 'src/**/*.{js,jsx,ts,tsx}' -t verbose --project .", "clean": "rimraf lib es6 es2019 es2020 esm typedocs coverage gh-pages yarn-error.log", "build": "tsc --project tsconfig.build.json --module commonjs", + "build:commands": "ts-node scripts/build-commands.ts", "jest": "node -r ts-node/register ./node_modules/.bin/jest", "test": "jest --maxWorkers 7", "coverage": "yarn test --collectCoverage", @@ -55,7 +56,8 @@ "tslib": "^2.6.2", "tslint": "^6.1.3", "tslint-config-common": "^1.6.2", - "typescript": "^5.3.3" + "typescript": "^5.3.3", + "commands": "https://github.com/streamich/commands#4321d5d40473c48fadf49fd99662032eac9b855b" }, "jest": { "verbose": true, diff --git a/scripts/build-commands.ts b/scripts/build-commands.ts new file mode 100644 index 0000000..38c59f1 --- /dev/null +++ b/scripts/build-commands.ts @@ -0,0 +1,24 @@ +import * as fs from 'fs'; +const defs = require('commands/lib/commands.json'); + +let ts = `// This file is generated by "yarn build:commands". + +// Set of commands that are writable. +export const write = new Set([ +`; + +const commands = Object.keys(defs); +for (const command of commands) { + const cmd = command.toUpperCase(); + const def = defs[command]; + const isWritable = Array.isArray(def.flags) && def.flags.includes('write'); + if (isWritable) ts += ` '${cmd}',\n`; +} +ts += `]); +`; + +const dir = 'src/generated'; +fs.mkdirSync(dir, {recursive: true}); +const filename = dir + '/commands.ts'; +fs.writeFileSync(filename, ts); +console.log('Wrote', filename); diff --git a/src/generated/commands.ts b/src/generated/commands.ts new file mode 100644 index 0000000..57983f9 --- /dev/null +++ b/src/generated/commands.ts @@ -0,0 +1,104 @@ +// This file is generated by "yarn build:commands". + +// Set of commands that are writable. +export const write = new Set([ + 'APPEND', + 'BITFIELD', + 'BITOP', + 'BLMOVE', + 'BLMPOP', + 'BLPOP', + 'BRPOP', + 'BRPOPLPUSH', + 'BZMPOP', + 'BZPOPMAX', + 'BZPOPMIN', + 'COPY', + 'DECR', + 'DECRBY', + 'DEL', + 'EXPIRE', + 'EXPIREAT', + 'FLUSHALL', + 'FLUSHDB', + 'GEOADD', + 'GEORADIUS', + 'GEORADIUSBYMEMBER', + 'GEOSEARCHSTORE', + 'GETDEL', + 'GETEX', + 'GETSET', + 'HDEL', + 'HINCRBY', + 'HINCRBYFLOAT', + 'HMSET', + 'HSET', + 'HSETNX', + 'INCR', + 'INCRBY', + 'INCRBYFLOAT', + 'LINSERT', + 'LMOVE', + 'LMPOP', + 'LPOP', + 'LPUSH', + 'LPUSHX', + 'LREM', + 'LSET', + 'LTRIM', + 'MIGRATE', + 'MOVE', + 'MSET', + 'MSETNX', + 'PERSIST', + 'PEXPIRE', + 'PEXPIREAT', + 'PFADD', + 'PFDEBUG', + 'PFMERGE', + 'PSETEX', + 'RENAME', + 'RENAMENX', + 'RESTORE', + 'RESTORE-ASKING', + 'RPOP', + 'RPOPLPUSH', + 'RPUSH', + 'RPUSHX', + 'SADD', + 'SDIFFSTORE', + 'SET', + 'SETBIT', + 'SETEX', + 'SETNX', + 'SETRANGE', + 'SINTERSTORE', + 'SMOVE', + 'SORT', + 'SPOP', + 'SREM', + 'SUNIONSTORE', + 'SWAPDB', + 'UNLINK', + 'XACK', + 'XADD', + 'XAUTOCLAIM', + 'XCLAIM', + 'XDEL', + 'XREADGROUP', + 'XSETID', + 'XTRIM', + 'ZADD', + 'ZDIFFSTORE', + 'ZINCRBY', + 'ZINTERSTORE', + 'ZMPOP', + 'ZPOPMAX', + 'ZPOPMIN', + 'ZRANGESTORE', + 'ZREM', + 'ZREMRANGEBYLEX', + 'ZREMRANGEBYRANK', + 'ZREMRANGEBYSCORE', + 'ZUNIONSTORE', +]); diff --git a/yarn.lock b/yarn.lock index b578365..8c22c96 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1024,6 +1024,10 @@ commander@^2.12.1: resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33" integrity sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ== +"commands@https://github.com/streamich/commands#4321d5d40473c48fadf49fd99662032eac9b855b": + version "0.2.0" + resolved "https://github.com/streamich/commands#4321d5d40473c48fadf49fd99662032eac9b855b" + concat-map@0.0.1: version "0.0.1" resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"