@workplane/adapter-shell 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +10 -0
- package/dist/index.js +40 -0
- package/dist/index.js.map +1 -0
- package/package.json +34 -0
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { join } from "path";
|
|
3
|
+
import { writeFile } from "fs/promises";
|
|
4
|
+
var shellAdapter = {
|
|
5
|
+
name: "shell",
|
|
6
|
+
kind: "shell.exec",
|
|
7
|
+
async run(context, payload) {
|
|
8
|
+
const renderedCommand = payload.args && payload.args.length > 0 ? `${payload.command} ${payload.args.join(" ")}` : payload.command;
|
|
9
|
+
const commandCwd = payload.cwd ? payload.cwd.startsWith("/") ? payload.cwd : join(context.workspacePath, payload.cwd) : context.workspacePath;
|
|
10
|
+
const result = await context.exec("/bin/sh", ["-lc", renderedCommand], { cwd: commandCwd });
|
|
11
|
+
const artifactsDir = await context.ensureWorkspace("artifacts");
|
|
12
|
+
const resultPath = join(artifactsDir, "shell-result.json");
|
|
13
|
+
await writeFile(
|
|
14
|
+
resultPath,
|
|
15
|
+
JSON.stringify(
|
|
16
|
+
{
|
|
17
|
+
command: renderedCommand,
|
|
18
|
+
cwd: commandCwd,
|
|
19
|
+
exitCode: result.exitCode
|
|
20
|
+
},
|
|
21
|
+
null,
|
|
22
|
+
2
|
|
23
|
+
),
|
|
24
|
+
"utf8"
|
|
25
|
+
);
|
|
26
|
+
await context.emitArtifact({
|
|
27
|
+
type: "shell.result",
|
|
28
|
+
name: "shell-result.json",
|
|
29
|
+
path: resultPath,
|
|
30
|
+
metadata: { exitCode: result.exitCode }
|
|
31
|
+
});
|
|
32
|
+
if (result.exitCode !== 0) {
|
|
33
|
+
throw new Error(`shell command failed with exit code ${result.exitCode}`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
export {
|
|
38
|
+
shellAdapter
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { WorkAdapter } from \"@workplane/adapter-sdk\";\nimport { join } from \"node:path\";\nimport { writeFile } from \"node:fs/promises\";\n\ninterface ShellPayload {\n command: string;\n args?: string[];\n cwd?: string;\n}\n\nexport const shellAdapter: WorkAdapter<ShellPayload> = {\n name: \"shell\",\n kind: \"shell.exec\",\n async run(context, payload) {\n const renderedCommand = payload.args && payload.args.length > 0 ? `${payload.command} ${payload.args.join(\" \")}` : payload.command;\n const commandCwd = payload.cwd\n ? payload.cwd.startsWith(\"/\")\n ? payload.cwd\n : join(context.workspacePath, payload.cwd)\n : context.workspacePath;\n const result = await context.exec(\"/bin/sh\", [\"-lc\", renderedCommand], { cwd: commandCwd });\n const artifactsDir = await context.ensureWorkspace(\"artifacts\");\n const resultPath = join(artifactsDir, \"shell-result.json\");\n await writeFile(\n resultPath,\n JSON.stringify(\n {\n command: renderedCommand,\n cwd: commandCwd,\n exitCode: result.exitCode,\n },\n null,\n 2,\n ),\n \"utf8\",\n );\n await context.emitArtifact({\n type: \"shell.result\",\n name: \"shell-result.json\",\n path: resultPath,\n metadata: { exitCode: result.exitCode },\n });\n if (result.exitCode !== 0) {\n throw new Error(`shell command failed with exit code ${result.exitCode}`);\n }\n },\n};\n"],"mappings":";AACA,SAAS,YAAY;AACrB,SAAS,iBAAiB;AAQnB,IAAM,eAA0C;AAAA,EACrD,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM,IAAI,SAAS,SAAS;AAC1B,UAAM,kBAAkB,QAAQ,QAAQ,QAAQ,KAAK,SAAS,IAAI,GAAG,QAAQ,OAAO,IAAI,QAAQ,KAAK,KAAK,GAAG,CAAC,KAAK,QAAQ;AAC3H,UAAM,aAAa,QAAQ,MACvB,QAAQ,IAAI,WAAW,GAAG,IACxB,QAAQ,MACR,KAAK,QAAQ,eAAe,QAAQ,GAAG,IACzC,QAAQ;AACZ,UAAM,SAAS,MAAM,QAAQ,KAAK,WAAW,CAAC,OAAO,eAAe,GAAG,EAAE,KAAK,WAAW,CAAC;AAC1F,UAAM,eAAe,MAAM,QAAQ,gBAAgB,WAAW;AAC9D,UAAM,aAAa,KAAK,cAAc,mBAAmB;AACzD,UAAM;AAAA,MACJ;AAAA,MACA,KAAK;AAAA,QACH;AAAA,UACE,SAAS;AAAA,UACT,KAAK;AAAA,UACL,UAAU,OAAO;AAAA,QACnB;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,MACA;AAAA,IACF;AACA,UAAM,QAAQ,aAAa;AAAA,MACzB,MAAM;AAAA,MACN,MAAM;AAAA,MACN,MAAM;AAAA,MACN,UAAU,EAAE,UAAU,OAAO,SAAS;AAAA,IACxC,CAAC;AACD,QAAI,OAAO,aAAa,GAAG;AACzB,YAAM,IAAI,MAAM,uCAAuC,OAAO,QAAQ,EAAE;AAAA,IAC1E;AAAA,EACF;AACF;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@workplane/adapter-shell",
|
|
3
|
+
"version": "0.3.1",
|
|
4
|
+
"private": false,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/MindStaq/workplane.git"
|
|
10
|
+
},
|
|
11
|
+
"main": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"import": "./dist/index.js",
|
|
16
|
+
"types": "./dist/index.d.ts"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist",
|
|
21
|
+
"README.md"
|
|
22
|
+
],
|
|
23
|
+
"sideEffects": false,
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public",
|
|
26
|
+
"registry": "https://registry.npmjs.org/"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@workplane/adapter-sdk": "0.3.1"
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "tsup"
|
|
33
|
+
}
|
|
34
|
+
}
|