nav-new-publication-cli
v0.5.4
Published
Add new publication to the navigator web project
Downloads
82
Maintainers
Readme
nav-new-publication-cli
This CLI tool is designed to automate the process of adding new publications to the Navigator web project. It collects user input, validates it, and updates or creates the necessary configuration files in the web repository.
Features
- Interactive Prompts: Collects details such as platform, publication title, domain, AWS certificate ARNs, and autoscaling configurations.
- Validation: Ensures input is valid and publication names are unique.
- File Updates: Automatically updates or creates files like
drone/publication.json,storybook/preview.js, and infrastructure configurations. - Template-Based File Creation: Uses a predefined template to generate infrastructure configuration files.
- Error Handling: Logs errors and provides feedback during the process.
Installation
Clone the repository:
git clone [email protected]:trinitymirror-ondemand/nav-new-publication-cli.git cd nav-new-publication-cliInstall dependencies:
yarn installBuild the project:
yarn buildLink the CLI globally (optional):
yarn link
Usage
Run the CLI using the following command:
node dist/index.jsAlternatively, if linked globally:
create-nav-publicationOptions
-p, --platform <type>: Specify the platform (e.g., nationals, regionals).-t, --title <type>: Set the publication title.-c, --cue-name <type>: Specify the name in the cue.--vr, --vr-steps <type>: Number of VR steps.-f, --func-steps <type>: Number of functional steps.-d, --domain <type>: Domain of the site.--db, --debug: Output extra debugging information.
Example
create-nav-publication -p nationals -t "New Publication" -d "newpublication.co.uk"File Updates
The CLI updates or creates the following files in the web repository:
drone/publication.json:- Purpose: Stores the list of publications categorized by platform.
- Update Logic: Finds the appropriate platform array (e.g.,
"nationals": [) and appends the new publication as a JSON object. - Insertion Point: The insertion point is determined by locating the platform key in the JSON structure.
storybook/preview.js:- Purpose: Manages CSS imports and configurations for Storybook.
- Update Logic: Adds new
importstatements for the publication's CSS and updates thecssListandcssVariables.filessections. - Insertion Point: The last
importstatement or specific sections likecssListandcssVariables.files.
Infrastructure Configurations:
- Purpose: Defines infrastructure settings for the publication.
- Creation Logic: Uses the
template/infrastucture.txtfile to generate a new configuration file ininfrastructure/configs/publications/. - Template Replacement: Replaces placeholders in the template with publication-specific details.
localProxy.config.js:- Purpose: Configures local proxy settings for the publication.
- Update Logic: Adds a new entry to the
domainNameobject. - Insertion Point: The closing brace of the
domainNameobject.
web-fargate.ts:- Purpose: Configures AWS Fargate settings for the publication.
- Update Logic: Adds a new entry for the publication's Fargate configuration.
- Insertion Point: Determined by scanning for the appropriate section in the file.
Constants Files:
- Purpose: Stores constants related to the publication.
- Update Logic: Adds new constants for the publication.
- Insertion Point: The end of the constants section.
utils.ts:- Purpose: Provides utility functions for logging, error handling, and other common tasks.
- Update Logic: Adds new utility functions as required by the CLI.
- Insertion Point: Functions are added at the end of the file or grouped logically with similar utilities.
constants.ts:- Purpose: Stores reusable constants used across the CLI.
- Update Logic: Adds new constants for publications or other configurations as needed.
- Insertion Point: The end of the constants section or a specific category of constants.
tsconfig.json:- Purpose: Configures TypeScript compilation settings for the project.
- Update Logic: Rarely updated, but may include new paths or compiler options if additional files or features are added.
- Insertion Point: Determined by the structure of the JSON file.
infrastucture.txt:- Purpose: Serves as a template for generating infrastructure configuration files.
- Update Logic: Updated when new placeholders or configurations are required for infrastructure files.
- Insertion Point: Placeholders are replaced dynamically during file generation.
Development
Project Structure
src/: Contains the source code.index.ts: Entry point of the CLI. Handles command-line arguments, initializes prompts, and orchestrates the overall workflow.fileUpdates.ts: Contains logic for updating or creating files. Defines functions to locate insertion points and generate new content.prompts.ts: Manages interactive prompts. Defines the structure and validation of user inputs.readWritePublications.ts: Handles reading and writing of thepublication.jsonfile. Ensures data integrity during updates.checkers.ts: Provides validation functions for user inputs, such as checking for valid ARNs, domains, and publication names.utils.ts: Utility functions for logging errors, warnings, and success messages.
template/: Contains the template for infrastructure configuration files.drone/: Stores thepublication.jsonfile.
Scripts
yarn build: Compiles the TypeScript code to JavaScript.yarn build:watch: Watches for changes and rebuilds the project.yarn start: Runs the CLI.
How Insertion Points Are Decided
- JSON Files: The insertion point is determined by parsing the JSON structure and locating the appropriate key or array.
- JavaScript Files: The insertion point is identified by scanning for specific patterns, such as the last
importstatement or a specific object key. - Template Files: Placeholders in the template are replaced with publication-specific details, and the file is saved in the appropriate directory.
