smartboxes-sticker-printer v1.1.0
Smart Boxes Sticker Printer
This repo contains a command line tool for printing SmartBoxes-branded QR codes.
At it's core, the tool is built using Node.js, TypeScript, and commander.js.
This tool is distributed via NPM, and can be installed from the NPM repository using npm install -g smartboxes-sticker-printer
Getting Started
- Install dependencies using
npm install
. - Run
npm run start
to launch the CLI.
Code Guide
User Interface
The CLI user interface is primarily orchestrated through the use of commander (for creating the basic command structure) and inquirer (for gathering more complex user input). Note that Inquirer
is wrapped as a UserInputService
and injected through the Environment
.
Services
This application integrates with a number of external dependencies. Typically, these are abstracted into "services" and injected using the Environment
(see below). Services can be found in the src/services
directory.
See PDFService.ts
for an example.
Environment
The Environment
API is a basic dependency injection solution, and is primarily used for accessing external services, as mentioned above.
The environment is set (once) on startup and can be used for mocking during testing by using Environment.set(...)
and the mockEnvironment(...)
function defined in __tests__/MockEnvironment.ts
.
Environment.set({
debugMode: false,
services: {
exampleService: MyExampleService,
},
});
To access the current environment during execution, use Environment.current()
:
const { services } = Environment.current();
services.exampleService.doSomething();
Key NPM Scripts
npm run start
(or just npm start
)
Launches the CLI wrapped in a nodemon
process that will watch for changes in the src
directory.
When any changes are deteced in that directory, the CLI will automatically re-launch.
npm run debug
Launches the CLI with an adjacent Node debugger process. The process will automatically break (pause) on the first line of execution in index.ts
.
To attach to the debugger process, you can use any set of debugger tools compatible with Node debugging. e.g.:
Chrome's Node Dev Tools
- Open
chrome:inspect
in Google Chrome, and select "Open Dedicated Dev Tools for Node". The tools should automatically attach to the running debugger process.
- Open
VSCode's Debugging tools
- In the Run tab on the right, run the "Attach to Debugger process".
npm run debug-watch
Performs the same as npm run debug
, but wraps the process in nodemon
and re-launches when the src
directory changes.
Launches the CLI wrapped in a nodemon
process with an adjacent Node debugger process. The process will automatically break (pause) on the first line of execution in index.ts
.
npm run test
(or npm test
)
Runs tests.
npm run try
Builds and installs the CLI on your system as globally available under the sb-print
alias.
e.g.
npm run try
sb-print