Skip to content

Commit

Permalink
[#88] Fix local cra webpack not working
Browse files Browse the repository at this point in the history
  • Loading branch information
malparty committed Aug 3, 2022
1 parent c7fc71a commit 1742bce
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 20 deletions.
22 changes: 16 additions & 6 deletions packages/cli-tool/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,23 @@ To run the CLI on your local machine:

> 💡 Running just `./bin/dev` without argument will display all the possible commands as well as additional information.
If your changes also impacted the `cra-template` package, you can still test them locally using:
To test with local changes in either the `./packages/cra-template` or the `./vite-temaplte/` folders, use the following commands:
- For Vite:
```BASH
# Assuming the repository `react-temapltes` is in `~/Documents/Source/`.
# The generated app will be in `~/Documents/Source/vite-app`
./bin/dev generate vite-app ~/Documents/Source/ feature/gh88-replace-webpack-with-vite
```
- For Create React App (Webpack):
```BASH
# Assuming the repository `react-temapltes` is in `~/Documents/Source/`.
# The generated app will be in `~/Documents/Source/webpack-app`
./bin/dev generate webpack-app ~/Documents/Source/ file:react-templates/packages/cra-template
```

The last argument is named `templateReference` and is either the branch name (for Vite) or the local repository path (for CRA), relative to the previous argument.
The second argument (`~/Documents/Source`) enables to deploy the app in another directory rather than the current repository.

```BASH
./bin/dev generate test-vite-app "feature/gh88-replace-webpack-with-vite" ~/Documents/Source
```

> The `~/Documents/Source` last argument enables to deploy the app in another directory rather than the current repository.
> Errors might occurs if you try to generate a project within this repository.
Find more the [OCLIF Documentation](https://oclif.io/docs/introduction.html)!
Expand Down
20 changes: 10 additions & 10 deletions packages/cli-tool/src/commands/generate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { setVersionControl } from '../../add-ons/version-control/index';
import { questions } from '../../helpers/questions';
import { initializeTemplate } from '../../template/index';

type generateArguments = { appName: string; branch: string; dest: string };
type generateArguments = { appName: string; templateReference: string; dest: string };

export default class Generate extends Command {
static description = 'Generate Nimble React application';
Expand All @@ -21,30 +21,30 @@ export default class Generate extends Command {
required: true,
description: 'application name',
},
{
name: 'branch',
required: false,
description: 'Specify the branch to download the vite-template from...',
default: 'main',
},
{
name: 'dest',
required: false,
description:
'destination, defines in which folder the project folder will be created',
'destination, defines in which folder the project folder will be created',
default: './',
},
{
name: 'templateReference',
required: false,
description: 'Specify the branch to download the vite-template from or path to a local cra-template folder.',
default: '',
},
];

public async parseArgs(): Promise<generateArguments> {
let destination = '';
const {
args: { appName, branch, dest },
args: { appName, templateReference, dest },
}: { args: generateArguments } = await this.parse(Generate);

destination = dest.endsWith('/') ? dest : `${dest}/`;

return { appName, branch, dest: destination };
return { appName, templateReference, dest: destination };
}

public async run(): Promise<void> {
Expand Down
8 changes: 4 additions & 4 deletions packages/cli-tool/src/template/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@ export const TEMPLATE_OPTIONS = new Map<templateOptions, string>([
export const initializeTemplate = async({
appName,
templateOption,
branch,
templateReference,
dest,
}: {
appName: string;
templateOption: templateOptions;
branch: string;
templateReference: string;
dest: string;
}): Promise<void> => {
if (templateOption === 'vite') {
await initializeViteApp({
appName,
dest,
branch: branch,
branch: templateReference,
});

return;
}

await initializeCraApp(appName, branch, dest);
await initializeCraApp(appName, templateReference, dest);
};
6 changes: 6 additions & 0 deletions packages/cli-tool/src/template/initialize-cra-app.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import runCommand from '../helpers/child-process';

const NIMBLE_CRA_TEMPLATE = '@nimblehq';

const initializeCraApp = async(
appName: string,
template: string,
dest: string,
): Promise<void> => {
if (template === '') {
template = NIMBLE_CRA_TEMPLATE;
}

return runCommand('npx', [
'create-react-app',
`${appName}`,
Expand Down

0 comments on commit 1742bce

Please sign in to comment.