1 |
|
2 | var ArrayConcat = Array.prototype.concat;
|
3 | var fs = require("fs");
|
4 |
|
5 | function mkdir(path)
|
6 | {
|
7 | return wrap(function (callback)
|
8 | {
|
9 | return fs.mkdir(path, callback);
|
10 | });
|
11 | }
|
12 | module.exports.mkdir = mkdir;
|
13 |
|
14 | module.exports.cd = process.chdir;
|
15 |
|
16 | function ls(path)
|
17 | {
|
18 | return new Promise(function (resolve, reject)
|
19 | {
|
20 | fs.readdir(path, function (err, result)
|
21 | {
|
22 | if (err)
|
23 | return reject(err);
|
24 |
|
25 | console.log(result.join("\n"));
|
26 |
|
27 | resolve(result);
|
28 | });
|
29 | });
|
30 | }
|
31 | module.exports.ls = ls;
|
32 |
|
33 | function cat(path)
|
34 | {
|
35 | return wrap(function (callback)
|
36 | {
|
37 | fs.readFile(path, "utf-8", callback);
|
38 | });
|
39 | }
|
40 | module.exports.cat = cat;
|
41 |
|
42 | function wrap(aFunction)
|
43 | {
|
44 | return new Promise(function (resolve, reject)
|
45 | {
|
46 | aFunction(function (err, result)
|
47 | {
|
48 | if (err)
|
49 | return reject(err);
|
50 |
|
51 | resolve(result);
|
52 | });
|
53 | });
|
54 | }
|
55 |
|
56 | var spawn = require("@runkit/tolmasky/spawn/1.0.0");
|
57 | var ArraySlice = Array.prototype.slice;
|
58 | var ArrayConcat = Array.prototype.concat;
|
59 |
|
60 | function yarn()
|
61 | {
|
62 |
|
63 | return spawn("node", ArrayConcat.call([require.resolve("yarn/bin/yarn.js")], ArraySlice.apply(arguments), "--no-progress"), { displayCommand: "yarn", displayArguments: [].concat(arguments) }));
|
64 | }
|
65 | module.exports.yarn = yarn;
|
66 |
|
67 |
|
68 | var childProcess = require("child_process");
|
69 |
|
70 | function spawnAsync(command, args, opts) {
|
71 | if (typeof args === 'undefined') {
|
72 | args = [];
|
73 | }
|
74 | if (typeof opts === 'undefined') {
|
75 | opts = {};
|
76 | }
|
77 | return new Promise(function(resolve, reject){
|
78 | var stdoutString = '';
|
79 | var stderrString = '';
|
80 |
|
81 | var child = childProcess.spawn(command, args, opts);
|
82 |
|
83 | child.stdout.on('data', function(data){
|
84 | stdoutString += data.toString();
|
85 | console.log(data.toString());
|
86 | });
|
87 | child.stderr.on('data', function(data){
|
88 | stderrString += data.toString();
|
89 | console.log(data.toString());
|
90 | });
|
91 | child.on('close', function(exitCode) {
|
92 |
|
93 | var result = {
|
94 | command: command,
|
95 | args: args,
|
96 | opts: opts,
|
97 | code: exitCode,
|
98 | stdout: stdoutString,
|
99 | stderr: stderrString,
|
100 | };
|
101 | if (exitCode === 0 || opts.ignoreExitCode) {
|
102 | if (typeof opts.resolveValue === 'undefined') {
|
103 | resolve(result);
|
104 | } else {
|
105 | resolve(opts.resolveValue);
|
106 | }
|
107 | } else {
|
108 | reject(result);
|
109 | }
|
110 | });
|
111 | });
|
112 | }; |
\ | No newline at end of file |