1 | # Dockerfile AST
|
2 |
|
3 | ![Node.js Builds](https://github.com/rcjsuen/dockerfile-ast/workflows/Node.js%20Builds/badge.svg?branch=master) [![Coverage Status](https://coveralls.io/repos/github/rcjsuen/dockerfile-ast/badge.svg?branch=master)](https://coveralls.io/github/rcjsuen/dockerfile-ast?branch=master) [![Build Dependencies](https://david-dm.org/rcjsuen/dockerfile-ast.svg)](https://david-dm.org/rcjsuen/dockerfile-ast) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![npm downloads per week](https://img.shields.io/npm/dw/dockerfile-ast.svg)](https://www.npmjs.com/package/dockerfile-ast)
|
4 |
|
5 | The `dockerfile-ast` NPM module is a Dockerfile parser written in TypeScript.
|
6 | The module provides full programmatic access to a parsed Dockerfile.
|
7 |
|
8 | Supported features:
|
9 | - escaped newline detection
|
10 | - `escape` parser directive considered when parsing
|
11 | - comments preserved
|
12 | - inlined comments in multiline instructions preserved
|
13 | - continuous empty newlines honoured (albeit discouraged as of Docker CE 17.09)
|
14 | - `ARG` and `ENV` variable lookup and resolution
|
15 |
|
16 | Unsupported:
|
17 | - `\r` as a a line delimiter
|
18 | - only `\r\n` and `\n` are supported as being line delimiters
|
19 | - if a `\r` is detected the parser assumes that it is followed by a `\n`
|
20 |
|
21 | ## Development Instructions
|
22 |
|
23 | If you wish to build and compile this project, you must first install [Node.js](https://nodejs.org/en/download/) if you have not already done so.
|
24 | After you have installed Node.js and cloned the repository with Git, you may now proceed to build and compile the project with the following commands:
|
25 |
|
26 | ```
|
27 | npm install
|
28 | npm run build
|
29 | npm test
|
30 | ```
|
31 |
|
32 | If you are planning to change the code, use `npm run watch` to get the
|
33 | TypeScript files transpiled on-the-fly as they are modified.
|
34 |
|
35 | ## Installation Instructions
|
36 |
|
37 | To add this library as a dependency to your project, please add `dockerfile-ast` as a dependency in your package.json file.
|
38 |
|
39 | ## Using this Module
|
40 |
|
41 | ```TypeScript
|
42 | import { DockerfileParser } from 'dockerfile-ast';
|
43 |
|
44 | const content =
|
45 | `FROM alpine
|
46 | ExposE 8080`
|
47 |
|
48 | let dockerfile = DockerfileParser.parse(content);
|
49 | let instructions = dockerfile.getInstructions();
|
50 | for (let instruction of instructions) {
|
51 | // FROM
|
52 | // EXPOSE
|
53 | console.log(instruction.getKeyword());
|
54 | // FROM
|
55 | // ExposE
|
56 | console.log(instruction.getInstruction());
|
57 | }
|
58 | ```
|