JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 482
  • Score
    100M100P100Q96714F

Simple Perforce API

Package Exports

  • p4api

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (p4api) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

p4api

Perforce API using marchal syntax and promise

Syntax

var p4 = require('p4api/p4');

p4.cmd(p4Cmd, input).then(function(out){
    ...
});

Where :

  • p4Cmd is the Perforce command (string) with options separated with space.
  • input is a optional string for input value (like password for login command).

p4.cmd() return a promise wich is resolved with the marchal result of the command as an object (out).

out has the following structure :

  • prompt : string printed by perforce before the result (else empty string)
  • stat : if exists, list of all result with code=stat
  • info : if exists, list of all result with code=info
  • error : if exists, list of all result with code=error

Examples

List of depots

var p4 = require('p4api');

p4.cmd("depots").then(function(out){console.log(out);});

Result is like :

{
  "prompt": "",
  "stat": [
    {
      "code": "stat",
      "name": "CM",
      "time": "1314373478",
      "type": "local",
      "map": "/perforce/Data/CM/...",
      "desc": "Created by xxxx. ..."
    },
    {
      "code": "stat",
      "name": "depot",
      "time": "1314374519",
      "type": "local",
      "map": "/perforce/Data/depot/...",
      "desc": "Created by xxxx. ..."
    }
  ]
}

Command Error

...
p4.cmd("mistake")
...

Result is :

{
  "prompt": "",
  "error": [
    {
      "code": "error",
      "data": "Unknown command.  Try 'p4 help' for info.\n",
      "severity": 3,
      "generic": 1
    }
  ]
}       

Login (commande with prompt and input)

...
p4.cmd("login", "myGoodPasswd")
...

Result is like :

{
  "prompt": "Enter password: ↵",
  "info": [
    {
      "code": "info",
      "data": "Success:  Password verified.",
      "level": 5
    },
    {
      "code": "info",
      "data": "User toto logged in.",
      "level": 0
    }
  ]
}       

Check Login (commande with param)

...
p4.cmd("login -s")
...

Result is like :

{
  "prompt": "",
  "stat": [
    {
      "code": "stat",
      "TicketExpiration": "85062",
      "user": "xxxx"
    }
  ]
}       

Clear viewpathes of the current Client

function clearViewPathes() {
    return p4.cmd('client -o')
    .then(function(out) {
        client = out.stat[0];
        for (var i = 0;; i++) {
            if (client['View' + i] === undefined) break;
            delete client['View' + i];
        }

        return p4.cmd('client -i', client);
    })
    .then(function(out) {
        return p4.cmd('sync -f');
    })
}