Skip to content

Commit

Permalink
feat: specify custom version of Re.Pack to install with `@callstack/r…
Browse files Browse the repository at this point in the history
…epack-init` (#557)

* feat: enable installing custom version of repack with init

* refactor: disable wrapping of output

* refactor: adjust descriptions of init --help

* refactor: typo

* chore: add changeset

* chore: update README.md in init
  • Loading branch information
jbroma authored Apr 17, 2024
1 parent e9cf635 commit 8a57f57
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/polite-islands-fetch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@callstack/repack-init": minor
---

add `custom-version` flag
8 changes: 5 additions & 3 deletions packages/init/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ npx @callstack/repack-init [options]

## Options

- `-e, --entry` Path to main entry point for the React-Native project. Defaults to: `index.js`
- `-c, --custom-version` Specify the version of `@callstack/repack` to install.

- `-f, --format` Format of the webpack.config file. Available choices: `"mjs"`, `"cjs"` Defaults to: `"mjs"`
- `-e, --entry` Path to the main entry point of the React-Native project. Defaults to: `index.js`.

- `-v, --verbose` Enables verbose logging. Defaults to: `false`
- `-f, --format` Format of the webpack.config file. Available choices: `"mjs"`, `"cjs"`. Defaults to: `"mjs"`.

- `-v, --verbose` Enable verbose logging. Defaults to: `false`.

- `--version` Show version number.

Expand Down
11 changes: 9 additions & 2 deletions packages/init/src/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@ const info = require('../package.json');

const argv = yargs(hideBin(process.argv))
.usage(`Usage: ${info.name} [options]`)
.option('custom-version', {
alias: 'c',
type: 'string',
description: 'Specify the version of `@callstack/repack` to install',
})
.option('entry', {
alias: 'e',
type: 'string',
description: 'Path to main entry point for the React-Native project',
description: 'Path to the main entry point of the React-Native project',
default: 'index.js',
})
.option('format', {
Expand All @@ -27,16 +32,18 @@ const argv = yargs(hideBin(process.argv))
.option('verbose', {
alias: 'v',
type: 'boolean',
description: 'Enables verbose logging',
description: 'Enable verbose logging',
default: false,
})
.conflicts('mjs', 'cjs')
.version(info.version)
.help()
.wrap(null)
.parseSync();

void run({
entry: argv.entry,
repackVersion: argv.customVersion,
templateType: argv.format as 'mjs' | 'cjs',
verbose: argv.verbose,
});
10 changes: 8 additions & 2 deletions packages/init/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,17 @@ import logger, { enableVerboseLogging } from './utils/logger.js';

interface Options {
entry: string;
repackVersion?: string;
templateType: 'mjs' | 'cjs';
verbose: boolean;
}

export default async function run({ entry, templateType, verbose }: Options) {
export default async function run({
entry,
repackVersion,
templateType,
verbose,
}: Options) {
const cwd = process.cwd();

if (verbose) {
Expand All @@ -25,7 +31,7 @@ export default async function run({ entry, templateType, verbose }: Options) {
const packageManager = await checkPackageManager(cwd);
const reactNativeVersion = checkReactNative(cwd);

await addDependencies(packageManager);
await addDependencies(packageManager, repackVersion);

await createWebpackConfig(cwd, templateType, entry);

Expand Down
12 changes: 11 additions & 1 deletion packages/init/src/tasks/addDependencies.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { PM } from 'detect-package-manager';
import { execa } from 'execa';
import ora from 'ora';
import logger from '../utils/logger.js';

const dependencies = [
'webpack',
Expand All @@ -14,7 +15,10 @@ const dependencies = [
*
* @param packageManager yarn, npm or pnpm
*/
export default async function addDependencies(packageManager: PM) {
export default async function addDependencies(
packageManager: PM,
repackVersion?: string
) {
let installCommand: string;

if (packageManager === 'yarn' || packageManager === 'bun') {
Expand All @@ -23,6 +27,12 @@ export default async function addDependencies(packageManager: PM) {
installCommand = 'install';
}

if (repackVersion) {
const index = dependencies.indexOf('@callstack/repack');
dependencies[index] = `@callstack/repack@${repackVersion}`;
logger.info(`Using custom Re.Pack version ${repackVersion}`);
}

const deps = dependencies.join(' ');
const command = `${packageManager} ${installCommand} -D ${deps}`;

Expand Down

0 comments on commit 8a57f57

Please sign in to comment.