Hello!

During the development of the project there is a need to increasingly use the command line Unix system. Process automation will inevitably have to be developed. To whom interesting, I ask under kat.

Introduction

The next project requires documentation. We have in development a couple of types of documentation TypeDoc & JSDoc. The final version of our documentation is a directory of HTML files generated by the documentation tool. You know, I as a developer it would be great to start the documentation for the third-party server. Third-party server, there is nothing like our good old Docker container. Run the Docker container is nothing like the Unix system via the command line CLI.

What we face at each step of the document management project? The tools generate the documentation, CLI. No matter how little to say, both of these areas offer a huge range of tools and methodologies of computer science. Let’s not dwell on the tools and try to take in Command-line Interface.

CLI

So what is CLI and what does automation? The CLI is a text-based interface between the human and the Unix system where the user is transmitted through the commands, text strings. The command consists of the command name and its parameters. Typing Unix commands missing, but the General approach is their use regulated.

So, let’s look at the process of creating documentation for the project. Our project consists of both JavaScript and TypeScript code. With the help of JSDoc & TypeDoc we can automate the process of creating code documentation of the project. To generate documentation you need the following commands:

Automation of this operation is supported by npm-scripts.

Created documentation is nothing but a set of HTML files. As mentioned above, let’s create our own server to run our documentation. To start the server will use the standard tools: Docker, Docker Compose. I propose to analyze code.

#!/usr/bin/env node /* * Raman Marozau <engineer.morozov@gmail.com>, 2019-present
*/ const {
execAction,
stop
Logger
EMPTY_LINE,
ANSI_FG_GREEN,
ANSI_FG_NC,
} = require('@softeq/utils'); const { exec, execSync } = require('child_process');
const fs = require('fs'); const DOCKER_COMPOSE_FILE_PATH = `${__dirname}/../docs.docker-compose.yml`;
const DOCKER_COMPOSE_FILE_PATH_DEFAULT = `${__dirname}/../docker-compose.yml`;
const DOCKER_CONTAINER_NAME = 'docs.nginx';
const DOCKER_SERVER_PORT = 7837; if (!fs.existsSync(DOCKER_COMPOSE_FILE_PATH)) { Logger.error(`${DOCKER_COMPOSE_FILE_PATH} DOES NOT exist.${EMPTY_LINE}`);
} exec(`docker stop ${DOCKER_CONTAINER_NAME} && docker rm ${DOCKER_CONTAINER_NAME}`, execAction((_, __, err) => { if (err && !err.message.includes(`No such container: ${DOCKER_CONTAINER_NAME}`)) {
Logger.error(err);
} execSync(`docker-compose --file ${DOCKER_COMPOSE_FILE_PATH_DEFAULT} --file ${DOCKER_COMPOSE_FILE_PATH} --build up-d`); Logger.stack([[`${ANSI_FG_GREEN}%s${ANSI_FG_NC}`, `${EMPTY_LINE}Documentation server: http://localhost:${DOCKER_SERVER_PORT}${EMPTY_LINE}`]]);
}, {"error": false, stderr: false })); 
Docker Compose files

docker-compose.yml (Gist)


version: "3"
services:
nginx docs: image: "nginx" container_name: "nginx"
volumes: - ./.docs/html:/usr/share/nginx/html:ro
ports: - "80:80"
environment: - NGINX_HOST=127.0.0.1 - NGINX_PORT=80 tty: true command: ['nginx', '-g', 'daemon off;']

docs.docker-compose.yml (Gist)


version: "3"
services:
nginx docs: container_name: "docs.nginx"
ports: - "7837:80"

To build the initial step of automating the process of creating a server documentation uses Node.js utilities work with the CLI.

Conclusion

So, it is clear how it works. Shows one problem of development. Our actions are any development tools, but CLI is only text information. I as a developer would be pleased to work with textual information and with variables, objects, classes and the like. It is also worth noting that the creation server provides a tree hierarchy of commands. Let’s try to understand the two paragraphs above.
At the time of the stop.

En

Source