Skip to content
This repository has been archived by the owner on Nov 19, 2021. It is now read-only.

Commit

Permalink
Fix docker command argument quotes
Browse files Browse the repository at this point in the history
Signed-off-by: Stéphane MORI <stephane.mori@gmail.com>
  • Loading branch information
stephane-mori committed Sep 30, 2021
1 parent a1593d8 commit 8fc7384
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 55 deletions.
5 changes: 5 additions & 0 deletions .changeset/slimy-elephants-return.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@techdocs/cli': patch
---

Allow to execute techdocs-cli serve using docker techdocs-container on Windows
72 changes: 36 additions & 36 deletions packages/techdocs-cli/src/lib/mkdocsServer.test.ts
Original file line number Diff line number Diff line change
@@ -1,73 +1,73 @@
import { runMkdocsServer } from "./mkdocsServer";
import { run } from "./run";
import { runMkdocsServer } from './mkdocsServer';
import { run } from './run';

jest.mock("./run", () => {
jest.mock('./run', () => {
return {
run: jest.fn()
run: jest.fn(),
};
});

describe("runMkdocsServer", () => {
describe('runMkdocsServer', () => {
beforeEach(() => {
jest.resetAllMocks();
});

describe("docker", () => {
it("should run docker directly by default", async () => {
describe('docker', () => {
it('should run docker directly by default', async () => {
await runMkdocsServer({});

const quotedCwd = `'${process.cwd()}':/content`;
const quotedCwd = `"${process.cwd()}":/content`;
expect(run).toHaveBeenCalledWith(
"docker",
'docker',
expect.arrayContaining([
"run",
'run',
quotedCwd,
"8000:8000",
"serve",
"--dev-addr",
"0.0.0.0:8000",
"spotify/techdocs"
'8000:8000',
'serve',
'--dev-addr',
'0.0.0.0:8000',
'spotify/techdocs',
]),
expect.objectContaining({})
expect.objectContaining({}),
);
});

it("should accept port option", async () => {
await runMkdocsServer({ port: "5678" });
it('should accept port option', async () => {
await runMkdocsServer({ port: '5678' });
expect(run).toHaveBeenCalledWith(
"docker",
expect.arrayContaining(["5678:5678", "0.0.0.0:5678"]),
expect.objectContaining({})
'docker',
expect.arrayContaining(['5678:5678', '0.0.0.0:5678']),
expect.objectContaining({}),
);
});

it("should accept custom docker image", async () => {
await runMkdocsServer({ dockerImage: "my-org/techdocs" });
it('should accept custom docker image', async () => {
await runMkdocsServer({ dockerImage: 'my-org/techdocs' });
expect(run).toHaveBeenCalledWith(
"docker",
expect.arrayContaining(["my-org/techdocs"]),
expect.objectContaining({})
'docker',
expect.arrayContaining(['my-org/techdocs']),
expect.objectContaining({}),
);
});
});

describe("mkdocs", () => {
it("should run mkdocs if specified", async () => {
describe('mkdocs', () => {
it('should run mkdocs if specified', async () => {
await runMkdocsServer({ useDocker: false });

expect(run).toHaveBeenCalledWith(
"mkdocs",
expect.arrayContaining(["serve", "--dev-addr", "127.0.0.1:8000"]),
expect.objectContaining({})
'mkdocs',
expect.arrayContaining(['serve', '--dev-addr', '127.0.0.1:8000']),
expect.objectContaining({}),
);
});

it("should accept port option", async () => {
await runMkdocsServer({ useDocker: false, port: "5678" });
it('should accept port option', async () => {
await runMkdocsServer({ useDocker: false, port: '5678' });
expect(run).toHaveBeenCalledWith(
"mkdocs",
expect.arrayContaining(["127.0.0.1:5678"]),
expect.objectContaining({})
'mkdocs',
expect.arrayContaining(['127.0.0.1:5678']),
expect.objectContaining({}),
);
});
});
Expand Down
38 changes: 19 additions & 19 deletions packages/techdocs-cli/src/lib/mkdocsServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { ChildProcess } from "child_process";
import { run, LogFunc } from "./run";
import { ChildProcess } from 'child_process';
import { run, LogFunc } from './run';

export const runMkdocsServer = async (options: {
port?: string;
Expand All @@ -23,36 +23,36 @@ export const runMkdocsServer = async (options: {
stdoutLogFunc?: LogFunc;
stderrLogFunc?: LogFunc;
}): Promise<ChildProcess> => {
const port = options.port ?? "8000";
const port = options.port ?? '8000';
const useDocker = options.useDocker ?? true;
const dockerImage = options.dockerImage ?? "spotify/techdocs";
const dockerImage = options.dockerImage ?? 'spotify/techdocs';

if (useDocker) {
return await run(
"docker",
'docker',
[
"run",
"--rm",
"-w",
"/content",
"-v",
`'${process.cwd()}':/content`,
"-p",
'run',
'--rm',
'-w',
'/content',
'-v',
`"${process.cwd()}":/content`,
'-p',
`${port}:${port}`,
dockerImage,
"serve",
"--dev-addr",
`0.0.0.0:${port}`
'serve',
'--dev-addr',
`0.0.0.0:${port}`,
],
{
stdoutLogFunc: options.stdoutLogFunc,
stderrLogFunc: options.stderrLogFunc
}
stderrLogFunc: options.stderrLogFunc,
},
);
}

return await run("mkdocs", ["serve", "--dev-addr", `127.0.0.1:${port}`], {
return await run('mkdocs', ['serve', '--dev-addr', `127.0.0.1:${port}`], {
stdoutLogFunc: options.stdoutLogFunc,
stderrLogFunc: options.stderrLogFunc
stderrLogFunc: options.stderrLogFunc,
});
};

0 comments on commit 8fc7384

Please sign in to comment.