├── .babelrc ├── .eslintignore ├── .eslintrc.js ├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── build.js ├── dist └── index.js ├── package-lock.json ├── package.json └── test └── smoke.test.js /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | ["env", { 4 | "targets": { 5 | "node": "8", 6 | "browsers": "last 2 versions" 7 | }, 8 | "useBuiltIns": true 9 | }] 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | /.git 2 | /dist 3 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | "extends": "airbnb", 3 | "env": { 4 | "browser": true, 5 | "jest": true, 6 | "node": true 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Runtime data 7 | pids 8 | *.pid 9 | *.seed 10 | 11 | # Directory for instrumented libs generated by jscoverage/JSCover 12 | lib-cov 13 | 14 | # Coverage directory used by tools like istanbul 15 | coverage 16 | 17 | # nyc test coverage 18 | .nyc_output 19 | 20 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 21 | .grunt 22 | 23 | # node-waf configuration 24 | .lock-wscript 25 | 26 | # Compiled binary addons (http://nodejs.org/api/addons.html) 27 | build/Release 28 | 29 | # Dependency directories 30 | node_modules 31 | jspm_packages 32 | 33 | # Optional npm cache directory 34 | .npm 35 | 36 | # Optional REPL history 37 | .node_repl_history 38 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "8" 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Dan Kaplun 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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # hterm-umdjs [![Build Status](https://travis-ci.org/dbkaplun/hterm-umdjs.svg?branch=master)](https://travis-ci.org/dbkaplun/hterm-umdjs) 2 | Chromium's hterm, automatically packaged as a UMD module (CommonJS/AMD/globals) 3 | 4 | ## Installation 5 | 6 | ```sh 7 | $ npm install hterm-umdjs 8 | ``` 9 | 10 | ## Usage 11 | 12 | ```js 13 | import { hterm, lib } from 'hterm-umdjs'; 14 | // or 15 | const { hterm, lib } = require('hterm-umdjs'); 16 | 17 | hterm.defaultStorage = new lib.Storage.Memory(); 18 | const term = new hterm.Terminal(); 19 | ``` 20 | 21 | ## See also 22 | 23 | * Chromium's [hterm](https://chromium.googlesource.com/apps/libapps/+/HEAD/hterm) 24 | * [hterm-umd](https://www.npmjs.com/package/hterm-umd), another wrapper 25 | -------------------------------------------------------------------------------- /build.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env babel-node 2 | 3 | import { execSync } from 'child_process'; 4 | import fs from 'fs'; 5 | import path from 'path'; 6 | 7 | export const HTERM_REPO = 'https://chromium.googlesource.com/apps/libapps'; 8 | export const HTERM_BRANCH = 'master'; 9 | export const OUTFILE = 'dist/index.js'; 10 | export const TMPDIR = path.resolve(__dirname, 'tmp'); 11 | 12 | export function buildHterm(repo, branch, outfile, tmpdir = TMPDIR) { 13 | const gitargs = `--work-tree="${tmpdir}" --git-dir="${tmpdir}/.git"`; 14 | execSync(`mkdir -p ${tmpdir}`); 15 | execSync(`git clone ${repo} ${tmpdir}`); 16 | execSync(`git ${gitargs} checkout ${branch}`); 17 | execSync(`${tmpdir}/hterm/bin/mkdist.sh`); 18 | 19 | // modified version of https://github.com/umdjs/umd/blob/95563fd6b46f06bda0af143ff67292e7f6ede6b7/templates/returnExportsGlobal.js 20 | const htermEncoding = 'utf8'; 21 | fs.writeFileSync(path.join(__dirname, outfile), ` 22 | (function (root, factory) { 23 | var GLOBAL_NAME = '_htermExports'; 24 | if (typeof define === 'function' && define.amd) { 25 | // AMD. Register as an anonymous module. 26 | define(['exports'], function (exports) { 27 | root[GLOBAL_NAME] = factory(exports); 28 | }); 29 | } else if (typeof exports === 'object' && typeof exports.nodeName !== 'string') { 30 | // CommonJS 31 | factory(exports); 32 | } else { 33 | // Browser globals 34 | root[GLOBAL_NAME] = factory({}); 35 | } 36 | }(this, function (exports) { 37 | ${/* libdot */fs.readFileSync(`${tmpdir}/hterm/dist/js/hterm_all.js`, htermEncoding).replace('lib.ensureRuntimeDependencies_();', '')} 38 | exports.lib = lib; 39 | ${/* hterm */fs.readFileSync(`${tmpdir}/hterm/dist/js/hterm.js`, htermEncoding)} 40 | exports.hterm = hterm; 41 | })); 42 | `.replace(/^\s+/, '').replace(/\s+$/, '\n')); 43 | 44 | const [, htermVersion] = fs.readFileSync(`${tmpdir}/hterm/doc/ChangeLog.md`).toString().match(/([\d.]+)/) || []; 45 | const htermRev = execSync(`git ${gitargs} rev-parse HEAD`).toString().trim(); 46 | execSync(`rm -rf ${tmpdir}`); 47 | return { 48 | version: htermVersion, 49 | rev: htermRev, 50 | }; 51 | } 52 | 53 | export function updateVersion(packageJSONPath, htermVersion, htermRev) { 54 | const pkg = JSON.parse(fs.readFileSync(packageJSONPath)); 55 | pkg.version = `${pkg.version.replace(/\+.*$/, '')}+${htermVersion ? `${htermVersion}.sha.` : ''}${htermRev.slice(0, 7)}`; 56 | fs.writeFileSync(packageJSONPath, `${JSON.stringify(pkg, null, ' ')}\n`); 57 | return pkg.version; 58 | } 59 | 60 | if (require.main === module) { 61 | const hterm = buildHterm(HTERM_REPO, HTERM_BRANCH, OUTFILE); 62 | console.log(`built ${OUTFILE}`); // eslint-disable-line no-console 63 | const version = updateVersion('package.json', hterm.version, hterm.rev); 64 | console.log(version); // eslint-disable-line no-console 65 | } 66 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "hterm-umdjs", 3 | "version": "1.4.1", 4 | "description": "Chromium's hterm, automatically packaged as a UMD module (CommonJS/AMD/globals)", 5 | "homepage": "https://github.com/dbkaplun/hterm-umdjs#readme", 6 | "bugs": "https://github.com/dbkaplun/hterm-umdjs/issues", 7 | "main": "dist/index.js", 8 | "scripts": { 9 | "build": "babel-node build.js", 10 | "test": "npm run eslint && npm run jest", 11 | "hterm-version": "if [[ -z $(git status --porcelain) ]]; then version=\"$(npm run build | tail -n1)\" && npm test && git add . && git commit -m \"Version $version\" && git tag \"v$version\"; else echo 'Git working directory not clean.' && exit 1; fi", 12 | "shipit": "git push origin master --tags && npm publish", 13 | "eslint": "eslint .", 14 | "jest": "jest" 15 | }, 16 | "repository": { 17 | "type": "git", 18 | "url": "git+https://github.com/dbkaplun/hterm-umdjs.git" 19 | }, 20 | "dependencies": {}, 21 | "devDependencies": { 22 | "babel-cli": "6.26.0", 23 | "babel-jest": "22.4.4", 24 | "babel-preset-env": "1.7.0", 25 | "eslint": "4.19.1", 26 | "eslint-config-airbnb": "16.1.0", 27 | "eslint-plugin-import": "2.12.0", 28 | "eslint-plugin-jsx-a11y": "6.0.3", 29 | "eslint-plugin-react": "7.8.2", 30 | "jest": "22.4.4" 31 | }, 32 | "author": "Dan Kaplun ", 33 | "license": "MIT" 34 | } 35 | -------------------------------------------------------------------------------- /test/smoke.test.js: -------------------------------------------------------------------------------- 1 | import { hterm, lib } from '..'; 2 | 3 | describe('hterm-umdjs', () => { 4 | it('should work', () => { 5 | hterm.defaultStorage = new lib.Storage.Memory(); 6 | const term = new hterm.Terminal(); 7 | term.io.println('hterm-umdjs'); 8 | }); 9 | }); 10 | --------------------------------------------------------------------------------