docker-preprocessor v0.1.0
docker-preprocessor
A general-purpose module for preprocessing using Docker.
Install
npm install --save-dev docker-preprocessorUsage
docker-preprocessor can be used for extremely complex (Emscripten, for C++ to
WebAssembly compilation) to very simple tasks (checking output of a Node.js
version). It is meant to be unopinionated and easy to fit into any preprocessor
toolchain.
file.txt
Hello, World!preprocessor.js
import dockerPreprocessor from 'docker-preprocessor';
const options = {
image: 'node',
createOptions: {
Binds: ['/:/host'],
WorkingDir: '/src',
},
command: path => [
'sh',
'-c',
`
node \
-e \
" \
const { readFileSync, writeFileSync } = require('fs'); \
const content = readFileSync('/host${path}', { encoding: 'utf8' }).split('').reverse().join(''); \
writeFileSync('./result', content); \
" \
;
`,
],
paths: {
main: '/src/result',
},
};
const { content } = await dockerPreprocessor(options)('file.txt');
console.log(bufferOfContentsReversedByDockerContainer.toString('utf8')); // !dlroW ,olleHDocumentation
dockerPreprocessor(options)
options<Object>dockerOptions<Object>Options passed todockerode's instantiation of aDockerobject.image<string>Image and tag string to create a Docker container with. Defaults to'ubuntu'(which defaults to thelatesttag).command<Function>A function that takes apathstring and returns an exec array. Thepathstring is provided bydockerPreprocessorRunner. Defaults to() => ['bash'].streams<Writable>,<Array>AWritablestream or an array ofWritablestreams to pipe to from a Docker container. Seedockerodefor a more in-depth explanation. Defaults toprocess.stdout.[createOptions]<Object>Optional options used for container creation. Seedockerodefor a more in-depth explanation.[startOptions]<Object>Optional options used for container start. Seedockerodefor a more in-depth explanation.paths<Object>An object with paths to file locations within the Docker container to retrieve and return asBuffers.
Returns a function, dockerPreprocessorRunner.
dockerPreprocessorRunner(filePath)
filePath<string>Path to a source file. This string is given to thecommandfunction property given todockerPreprocessorin its option object.
Returns a Promise which resolves to a result object.