├── .gitignore ├── .editorconfig ├── example.png ├── package.json ├── README.md ├── LICENSE ├── templates └── page.html ├── index.js └── .eslintrc /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | partkeepr-labels 3 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | [*] 2 | indent_style = tab 3 | indent_size = 4 4 | -------------------------------------------------------------------------------- /example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vlad-ivanov-name/partkeepr-label-gen/HEAD/example.png -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "partkeepr-label-gen", 3 | "version": "0.0.1", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "Vlad Ivanov ", 10 | "license": "MIT", 11 | "dependencies": { 12 | "yargs": "~4.3.2", 13 | "swig": "~1.4.2", 14 | "mkdirp": "~0.5.1" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## partkeepr-label-gen 2 | 3 | This tool generates a page with labels and barcodes from PartKeepr CSV export. 4 | It is meant to be used in an environment where each part has its own storage 5 | location. 6 | 7 | Usage: 8 | 9 | 1. Clone and run `npm install` 10 | 1. Install zint 11 | 1. Open PartKeepr parts view 12 | 1. Click “Custom Export”. Add columns `name` and `storageLocation.name`. Save exported data. 13 | 1. Feed the resulting csv to the script: 14 | 15 | ``` 16 | ./index.js -i input.csv -o output_folder_name 17 | ``` 18 | 19 | 1. Open `output_folder_name/index.html` and print it. 20 | 1. Optionally, edit `template/page.html` to adjust the layout 21 | 22 | Here is how it looks (parts from PartKeepr demo): 23 | 24 | 25 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Vlad Ivanov 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /templates/page.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 85 | 86 |
87 | {% for label in labels %} 88 |
89 | {{ label.storageLocation }} 90 | {{ label.partName }} 91 | 92 |
93 | {% endfor %} 94 |
95 | 96 | 97 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | (function() { 4 | 'use strict'; 5 | 6 | const 7 | DEFAULT_FOLDER_NAME = 'partkeepr-labels'; 8 | 9 | const 10 | argv = require('yargs') 11 | .alias('i', 'input') 12 | .alias('o', 'output') 13 | .alias('p', 'part-number') 14 | .demand(['i']) 15 | .default('o', DEFAULT_FOLDER_NAME) 16 | .argv, 17 | fs = require('fs'), 18 | mkdirp = require('mkdirp'), 19 | child_process = require('child_process'), 20 | swig = require('swig'); 21 | 22 | let 23 | input, 24 | records = []; 25 | 26 | function readInput() { 27 | input = fs.readFileSync(argv.input); 28 | } 29 | 30 | function parseInput() { 31 | const 32 | STATE_START = 0, 33 | STATE_STRING = 1, 34 | STATE_QUOTED_STRING = 2, 35 | STATE_QUOTE_ESCAPE = 3; 36 | 37 | const 38 | separator = ','; 39 | 40 | let 41 | lines = input.toString().split('\n'), 42 | buffer, 43 | record, 44 | line, 45 | state = STATE_START; 46 | 47 | // I swear there are tons of libraries that 48 | // do fancy streamed/piped processing and 49 | // can process gigabytes of data using multiple 50 | // threads but I haven't found a single working 51 | // synchronous parser 52 | for (let i = 0; i < lines.length; i++) { 53 | line = lines[i]; 54 | 55 | if (line.trim() === '') { 56 | continue; 57 | } 58 | 59 | record = []; 60 | buffer = ''; 61 | state = STATE_START; 62 | 63 | for (let j = 0; j < line.length; j++) { 64 | switch (state) { 65 | case STATE_START: 66 | if (line[j] === separator) { 67 | record.push(buffer); 68 | } else if (line[j] === '"') { 69 | state = STATE_QUOTED_STRING; 70 | } else { 71 | state = STATE_STRING; 72 | buffer += line[j]; 73 | } 74 | break; 75 | case STATE_STRING: 76 | if (line[j] === '"') { 77 | state = STATE_QUOTE_ESCAPE; 78 | } else if (line[j] === separator) { 79 | state = STATE_START; 80 | 81 | record.push(buffer); 82 | buffer = ''; 83 | } else { 84 | buffer += line[j]; 85 | } 86 | break; 87 | case STATE_QUOTE_ESCAPE: 88 | if (line[j] === '"') { 89 | buffer += '"'; 90 | state = STATE_QUOTED_STRING; 91 | } else if (line[j] === separator) { 92 | state = STATE_START; 93 | 94 | record.push(buffer); 95 | buffer = ''; 96 | } 97 | break; 98 | case STATE_QUOTED_STRING: 99 | if (line[j] === '"') { 100 | state = STATE_QUOTE_ESCAPE; 101 | } else { 102 | buffer += line[j]; 103 | } 104 | break; 105 | } 106 | } 107 | 108 | record.push(buffer); 109 | records.push(record); 110 | } 111 | } 112 | 113 | function saveHTML() { 114 | let 115 | labels = []; 116 | const 117 | nameIndex = records[0].indexOf('name'), 118 | locationIndex = records[0].indexOf('storageLocation.name'); 119 | 120 | for (let i = records.length - 1; i > 0; i--) { 121 | labels.push({ 122 | partName: records[i][nameIndex], 123 | storageLocation: records[i][locationIndex], 124 | barcode: i + '.svg' 125 | }); 126 | } 127 | 128 | const 129 | result = swig.renderFile('./templates/page.html', { 130 | labels: labels 131 | }); 132 | 133 | mkdirp.sync(argv.output + '/images'); 134 | fs.writeFileSync(argv.output + '/index.html', result); 135 | 136 | const 137 | escape = (str) => { 138 | return '\'' + str 139 | .replace(/\\/g, '\\\\') 140 | .replace(/"/g, '\\"') + '\''; 141 | }; 142 | 143 | for (let i = records.length - 1; i > 0; i--) { 144 | let 145 | svg = child_process.execSync( 146 | 'zint --notext --directsvg -d ' + 147 | escape(records[i][locationIndex]) 148 | ).toString(); 149 | 150 | svg = svg.replace( 151 | 'version="1.1"', 152 | 'version="1.1" preserveAspectRatio="xMidYMid slice"' 153 | ); 154 | 155 | fs.writeFileSync(argv.output + '/images/' + i + '.svg', svg); 156 | } 157 | } 158 | 159 | function main() { 160 | try { 161 | readInput(); 162 | parseInput(); 163 | saveHTML(); 164 | } catch (e) { 165 | console.error('Error: ' + e.message); 166 | console.log(e.stack); 167 | } 168 | } 169 | 170 | main(); 171 | })(); 172 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "parserOptions": { 3 | "ecmaVersion": 6, 4 | }, 5 | "env": { 6 | "node": true 7 | }, 8 | "ecmaFeatures": {}, 9 | "rules": { 10 | "no-alert": 0, 11 | "no-array-constructor": 0, 12 | "no-bitwise": 0, 13 | "no-caller": 0, 14 | "no-catch-shadow": 0, 15 | "no-class-assign": 0, 16 | "no-cond-assign": 2, 17 | "no-console": 0, 18 | "no-const-assign": 0, 19 | "no-constant-condition": 2, 20 | "no-continue": 0, 21 | "no-control-regex": 2, 22 | "no-debugger": 2, 23 | "no-delete-var": 2, 24 | "no-div-regex": 0, 25 | "no-dupe-keys": 2, 26 | "no-dupe-args": 2, 27 | "no-duplicate-case": 2, 28 | "no-else-return": 0, 29 | "no-empty": 2, 30 | "no-empty-character-class": 2, 31 | "no-empty-label": 0, 32 | "no-eq-null": 0, 33 | "no-eval": 2, 34 | "no-ex-assign": 2, 35 | "no-extend-native": 0, 36 | "no-extra-bind": 0, 37 | "no-extra-boolean-cast": 2, 38 | "no-extra-parens": 0, 39 | "no-extra-semi": 2, 40 | "no-fallthrough": 2, 41 | "no-floating-decimal": 0, 42 | "no-func-assign": 2, 43 | "no-implicit-coercion": 0, 44 | "no-implied-eval": 0, 45 | "no-inline-comments": 0, 46 | "no-inner-declarations": [2, "functions"], 47 | "no-invalid-regexp": 2, 48 | "no-invalid-this": 0, 49 | "no-irregular-whitespace": 2, 50 | "no-iterator": 0, 51 | "no-label-var": 0, 52 | "no-labels": 0, 53 | "no-lone-blocks": 0, 54 | "no-lonely-if": 0, 55 | "no-loop-func": 0, 56 | "no-mixed-requires": [0, false], 57 | "no-mixed-spaces-and-tabs": [2, false], 58 | "linebreak-style": [0, "unix"], 59 | "no-multi-spaces": 0, 60 | "no-multi-str": 0, 61 | "no-multiple-empty-lines": [0, {"max": 2}], 62 | "no-native-reassign": 0, 63 | "no-negated-in-lhs": 2, 64 | "no-nested-ternary": 0, 65 | "no-new": 0, 66 | "no-new-func": 0, 67 | "no-new-object": 0, 68 | "no-new-require": 0, 69 | "no-new-wrappers": 0, 70 | "no-obj-calls": 2, 71 | "no-octal": 2, 72 | "no-octal-escape": 0, 73 | "no-param-reassign": 0, 74 | "no-path-concat": 0, 75 | "no-plusplus": 0, 76 | "no-process-env": 0, 77 | "no-process-exit": 0, 78 | "no-proto": 0, 79 | "no-redeclare": 2, 80 | "no-regex-spaces": 2, 81 | "no-restricted-modules": 0, 82 | "no-return-assign": 0, 83 | "no-script-url": 0, 84 | "no-self-compare": 0, 85 | "no-sequences": 2, 86 | "no-shadow": 0, 87 | "no-shadow-restricted-names": 0, 88 | "no-spaced-func": 0, 89 | "no-sparse-arrays": 2, 90 | "no-sync": 0, 91 | "no-ternary": 0, 92 | "no-trailing-spaces": 2, 93 | "no-this-before-super": 0, 94 | "no-throw-literal": 0, 95 | "no-undef": 2, 96 | "no-undef-init": 0, 97 | "no-undefined": 0, 98 | "no-unexpected-multiline": 0, 99 | "no-underscore-dangle": 2, 100 | "no-unneeded-ternary": 0, 101 | "no-unreachable": 2, 102 | "no-unused-expressions": 0, 103 | "no-unused-vars": [2, {"vars": "all", "args": "after-used"}], 104 | "no-use-before-define": 2, 105 | "no-useless-call": 0, 106 | "no-void": 0, 107 | "no-var": 2, 108 | "no-warning-comments": [0, { "terms": ["todo", "fixme", "xxx"], "location": "start" }], 109 | "no-with": 0, 110 | "array-bracket-spacing": [0, "never"], 111 | "arrow-parens": 0, 112 | "arrow-spacing": 0, 113 | "accessor-pairs": 0, 114 | "block-scoped-var": 0, 115 | "brace-style": [0, "1tbs"], 116 | "callback-return": 0, 117 | "camelcase": 0, 118 | "comma-dangle": [2, "never"], 119 | "comma-spacing": 0, 120 | "comma-style": 0, 121 | "complexity": [0, 11], 122 | "computed-property-spacing": [0, "never"], 123 | "consistent-return": 0, 124 | "consistent-this": [0, "that"], 125 | "constructor-super": 0, 126 | "curly": [0, "all"], 127 | "default-case": 0, 128 | "dot-location": 0, 129 | "dot-notation": [0, { "allowKeywords": true }], 130 | "eol-last": 0, 131 | "eqeqeq": 2, 132 | "func-names": 0, 133 | "func-style": [0, "declaration"], 134 | "generator-star-spacing": 0, 135 | "guard-for-in": 0, 136 | "handle-callback-err": 0, 137 | "id-length": 0, 138 | "indent": 0, 139 | "init-declarations": 0, 140 | "key-spacing": [0, { "beforeColon": false, "afterColon": true }], 141 | "lines-around-comment": 0, 142 | "max-depth": [0, 4], 143 | "max-len": [0, 80, 4], 144 | "max-nested-callbacks": [0, 2], 145 | "max-params": [0, 3], 146 | "max-statements": [0, 10], 147 | "new-cap": 0, 148 | "new-parens": 0, 149 | "newline-after-var": 0, 150 | "object-curly-spacing": [0, "never"], 151 | "object-shorthand": 0, 152 | "one-var": 0, 153 | "operator-assignment": [0, "always"], 154 | "operator-linebreak": 0, 155 | "padded-blocks": 0, 156 | "prefer-const": 0, 157 | "prefer-spread": 0, 158 | "prefer-reflect": 0, 159 | "quote-props": 0, 160 | "quotes": [2, "single"], 161 | "radix": 2, 162 | "id-match": 0, 163 | "require-yield": 0, 164 | "semi": 2, 165 | "semi-spacing": [0, {"before": false, "after": true}], 166 | "sort-vars": 0, 167 | "space-after-keywords": [0, "always"], 168 | "space-before-blocks": [0, "always"], 169 | "space-before-function-paren": [0, "always"], 170 | "space-in-parens": [0, "never"], 171 | "space-infix-ops": 0, 172 | "space-return-throw-case": 0, 173 | "space-unary-ops": [0, { "words": true, "nonwords": false }], 174 | "spaced-comment": 0, 175 | "strict": 0, 176 | "use-isnan": 2, 177 | "valid-jsdoc": 0, 178 | "valid-typeof": 2, 179 | "vars-on-top": 0, 180 | "wrap-iife": 0, 181 | "wrap-regex": 0, 182 | "yoda": [0, "never"] 183 | } 184 | } 185 | --------------------------------------------------------------------------------