Browse Source

add npm release

bugtaker 5 years ago
parent
commit
d73da35b55
4 changed files with 93 additions and 0 deletions
  1. 2 0
      .gitignore
  2. 12 0
      cli/giter.js
  3. 43 0
      cli/install.js
  4. 36 0
      package.json

+ 2 - 0
.gitignore

@@ -23,3 +23,5 @@ vendor/
 giter
 dist/
 bin/
+node_modules/
+package-lock.json

+ 12 - 0
cli/giter.js

@@ -0,0 +1,12 @@
+#!/usr/bin/env node
+'use strict';
+
+const path = require('path');
+const cp = require('child_process');
+
+const binPath = path.join(__dirname, '../bin/giter');
+
+cp.spawn(binPath, process.argv.slice(2), {
+  cwd: process.cwd(),
+  stdio: ['inherit', 'inherit', 'inherit']
+});

+ 43 - 0
cli/install.js

@@ -0,0 +1,43 @@
+const download = require('download');
+const ora = require('ora');
+const pkg = require('../package.json');
+
+const PLATFORM = {
+  'darwin': 'darwin',
+  'freebsd': 'freebsd',
+  'linux': 'linux',
+  'openbsd': 'openbsd',
+  'win32': 'windows'
+};
+const ARCH = {
+  'ia32': '386',
+  'x64': 'amd64',
+  'x32': '386'
+};
+
+function install() {
+  if (!(process.arch in ARCH)) {
+    console.error('Installation is not supported for this architecture: ' + process.arch);
+    return;
+  }
+
+  if (!(process.platform in PLATFORM)) {
+    console.error('Installation is not supported for this platform: ' + process.platform);
+    return;
+  }
+  const platform = PLATFORM[process.platform];
+  const arch = ARCH[process.arch];
+  const ghURL = `https://github.com/jsmartx/giter/releases/download/v${pkg.version}/`;
+  const url = `${ghURL}${pkg.name}_${pkg.version}_${platform}_${arch}.tar.gz`;
+
+  const spinner = ora(`Downloading ${url}`).start();
+  download(url, 'bin', {
+    extract: true
+  }).then(() => {
+    spinner.succeed();
+  }).catch(() => {
+    spinner.fail();
+  });
+}
+
+install();

+ 36 - 0
package.json

@@ -0,0 +1,36 @@
+{
+  "name": "giter",
+  "version": "0.0.5",
+  "description": "Git users manager",
+  "main": "cli/giter.js",
+  "bin": {
+    "giter": "cli/giter.js"
+  },
+  "scripts": {
+    "postinstall": "node ./cli/install.js"
+  },
+  "files": [
+    "cli/"
+  ],
+  "repository": {
+    "type": "git",
+    "url": "git+https://github.com/jsmartx/giter.git"
+  },
+  "keywords": [
+    "git",
+    "users",
+    "config",
+    "manager",
+    "ssh"
+  ],
+  "author": "jsmartx.com",
+  "license": "MIT",
+  "bugs": {
+    "url": "https://github.com/jsmartx/giter/issues"
+  },
+  "homepage": "https://github.com/jsmartx/giter#readme",
+  "dependencies": {
+    "download": "^7.1.0",
+    "ora": "^3.0.0"
+  }
+}