Parcourir la source

add build scripts

mightyplow il y a 5 ans
Parent
commit
5c9b82ed71
5 fichiers modifiés avec 2325 ajouts et 53 suppressions
  1. 1 0
      .gitignore
  2. 0 11
      flags.js
  3. 0 23
      flags.ts
  4. 2295 9
      package-lock.json
  5. 29 10
      package.json

+ 1 - 0
.gitignore

@@ -1,2 +1,3 @@
 node_modules/
 .flags.js
+dist/

+ 0 - 11
flags.js

@@ -1,11 +0,0 @@
-const $isset = (flag, flags = 0) => (flags & flag) === flag;
-const $set = (flag, flags = 0) => flags | flag;
-const $unset = (flag, flags = 0) => flags ^ flag;
-const $toggle = (flag, flags = 0) => $isset(flag, flags) ? $unset(flag, flags) : $set(flag, flags);
-const combine = (...options) => options.reduce((flags, flag) => $set(flag, flags), 0);
-const createMultiFlagHandler = (fn) => (...options) => (flags = 0) => fn(combine(...options), flags);
-const set = createMultiFlagHandler($set);
-const unset = createMultiFlagHandler($unset);
-const toggle = createMultiFlagHandler($toggle);
-const isset = createMultiFlagHandler($isset);
-export { combine, set, unset, toggle, isset };

+ 0 - 23
flags.ts

@@ -1,23 +0,0 @@
-const $isset = (flag: number, flags = 0) => (flags & flag) === flag
-const $set = (flag: number, flags = 0) => flags | flag
-const $unset = (flag: number, flags = 0) => flags ^ flag
-const $toggle = (flag: number, flags = 0) => $isset(flag, flags) ? $unset(flag, flags) : $set(flag, flags)
-
-const combine = (...options: number[]) => options.reduce((flags, flag) => $set(flag, flags), 0)
-
-const createMultiFlagHandler = <T>(fn: (flag: number, flags: number) => T) => 
-    (...options: number[]) => 
-        (flags = 0): T => fn(combine(...options), flags) 
-
-const set = createMultiFlagHandler($set)
-const unset = createMultiFlagHandler($unset)
-const toggle = createMultiFlagHandler($toggle)
-const isset = createMultiFlagHandler($isset)
-
-export {
-    combine,
-    set,
-    unset,
-    toggle,
-    isset
-}

Fichier diff supprimé car celui-ci est trop grand
+ 2295 - 9
package-lock.json


+ 29 - 10
package.json

@@ -1,21 +1,40 @@
 {
-  "name": "flags",
+  "name": "@mightyplow/flags",
   "version": "1.0.0",
-  "description": "",
-  "main": "flags.js",
+  "description": "A utility to handle bitwise flags.",
+  "main": "./dist/es5/flags.js",
+  "module": "./dist/es6/flags.js",
+  "browser": "./dist/es5/flags.min.js",
+  "repository": {
+    "url": "ssh://git@git.mightyplow.net:30022/mightyplow/flags.git"
+  },
+  "files": [
+    "dist"
+  ],
   "scripts": {
-    "compile": "tsc flags.ts -d -t ESNext --removeComments --strict",
-    "uglify": "terser -cm -o flags.min.js --module -- flags.js",
-    "build": "npm run compile && npm run uglify",
-    "test": "echo \"Error: no test specified\" && exit 1"
+    "compile": "tsc ./src/flags.ts -d -t ESNext --strict --pretty --outDir ./dist/es6",
+    "compile-es5": "npm run compile -- -t ES5 --lib es6 --outDir ./dist/es5",
+    "uglify-es5": "terser -cm -o ./dist/es5/flags.min.js --source-map -- ./dist/es5/flags.js",
+    "build-es6": "npm run compile",
+    "build-es5": "npm run compile-es5",
+    "prebuild": "rm -rf dist",
+    "build": "npm run build-es6 && npm run build-es5 && npm run uglify-es5",
+    "prepublish": "npm run test",
+    "test": "mocha -r ts-node/register tests/**/*.test.ts"
   },
-  "keywords": [],
-  "author": "",
+  "keywords": ["flags", "bits"],
+  "author": "mightyplow@gmail.com",
   "license": "ISC",
   "dependencies": {},
   "devDependencies": {
+    "@types/chai": "^4.2.3",
+    "@types/mocha": "^5.2.7",
+    "chai": "^4.2.0",
     "dts-gen": "^0.5.8",
+    "mocha": "^6.2.2",
     "terser": "^4.3.9",
-    "typescript": "^3.6.4"
+    "ts-node": "^8.4.1",
+    "typescript": "^3.6.4",
+    "typings": "^2.1.1"
   }
 }