Skip to content

Commit

Permalink
feat: [BD-46] add paragon-cli (#2460)
Browse files Browse the repository at this point in the history
Exposes a `paragon` CLI with an `install-theme` command.

Example usage in `package.json`:

```
{
  "scripts": {
    "start:with-theme": "paragon install-theme && npm start",
    "build:with-theme": "paragon install-theme && npm run build"
  }
}
```

The Paragon CLI will prompt from which NPM package you wish to install as the `@edx/brand` package (e.g., `@edx/brand-edx.org@latest`), and install it without modifying the `package.json` or `package-lock.json` files.

Additional commands will be added to the `paragon` CLI tool in the future.
  • Loading branch information
monteri authored Aug 18, 2023
1 parent 7e5b37d commit 33a7c74
Show file tree
Hide file tree
Showing 6 changed files with 571 additions and 2,476 deletions.
28 changes: 28 additions & 0 deletions bin/install-theme.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const inquirer = require('inquirer');
const childProcess = require('child_process');

function promptUserForTheme() {
return inquirer.prompt([
{
type: 'input',
name: 'theme',
message: 'What @edx/brand package do you want to install?',
default: '@edx/brand-openedx@latest',
},
]);
}

function installTheme(theme) {
const version = theme ? `npm:${theme}` : '';

const installCommand = `npm install "@edx/brand@${version}" --no-save`;

childProcess.execSync(installCommand, { stdio: 'inherit' });
}

async function themeCommand() {
const answers = await promptUserForTheme();
installTheme(answers.theme);
}

module.exports = themeCommand;
27 changes: 27 additions & 0 deletions bin/paragon-scripts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env node
const chalk = require('chalk');
const themeCommand = require('./install-theme');

// command: executor function
const COMMANDS = {
'install-theme': themeCommand,
};

(async () => {
const [command] = process.argv.slice(2);
const executor = COMMANDS[command];

if (!executor) {
// eslint-disable-next-line no-console
console.log(chalk.red.bold('Unknown command. Usage: paragon <command>'));
return;
}

try {
await executor();
} catch (error) {
// eslint-disable-next-line no-console
console.error(chalk.red.bold('An error occurred:', error.message));
process.exit(1);
}
})();
3 changes: 2 additions & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
"precommit": "npm run lint",
"snapshot": "fedx-scripts jest --updateSnapshot",
"start": "fedx-scripts webpack-dev-server --progress",
"start:with-theme": "../bin/paragon-scripts.js install-theme && npm start",
"test": "fedx-scripts jest --coverage --passWithNoTests"
},
"author": "",
"license": "ISC",
"dependencies": {
"@edx/brand-openedx": "^1.1.0",
"@edx/brand": "npm:@edx/brand-openedx@^1.1.0",
"@edx/frontend-platform": "^4.2.0",
"@faker-js/faker": "^7.6.0",
"core-js": "^3.22.2",
Expand Down
6 changes: 3 additions & 3 deletions example/src/index.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import "@edx/brand-openedx/paragon/fonts";
@import "@edx/brand-openedx/paragon/variables";
@import "@edx/brand/paragon/fonts";
@import "@edx/brand/paragon/variables";
@import "~@edx/paragon/scss/core/core";
@import "@edx/brand-openedx/paragon/overrides";
@import "@edx/brand/paragon/overrides";
Loading

0 comments on commit 33a7c74

Please sign in to comment.