Skip to content

Commit b9417c7

Browse files
committed
init first version
0 parents  commit b9417c7

17 files changed

+12413
-0
lines changed

.DS_Store

6 KB
Binary file not shown.

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/

README.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# create-react-rust
2+
This is a template generator for a React app that uses Rust with wasm.
3+
4+
5+
## Installation
6+
Install the package globally with npm.
7+
8+
```bash
9+
npm install -g create-react-rust
10+
```
11+
12+
## Usage
13+
provide a name for your app and it will be created in a folder with the same name.
14+
15+
```bash
16+
create-react-rust my-app
17+
```
18+
19+
## License
20+
MIT
21+
22+
## Dependencies
23+
- Node.js >= 12.0.0
24+
- rust cargo
25+
26+
## Contributing
27+
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

index.js

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import chalk from 'chalk';
2+
import fs from 'fs-extra';
3+
import path from 'path';
4+
import { execSync } from 'child_process';
5+
import yargs from 'yargs'
6+
import { hideBin } from 'yargs/helpers'
7+
8+
const __dirname = path.resolve();
9+
10+
const templates = {
11+
default: path.join(__dirname, 'templates', 'default'),
12+
// add other templates here open the PR/issue
13+
};
14+
const createReactApp = (name ="reactive-rust", template) => {
15+
console.log(chalk.green(`Creating a new React Rust project "${name}" `));
16+
17+
const templateDir = templates[template];
18+
const targetDir = path.join(process.cwd(), name);
19+
20+
fs.ensureDirSync(targetDir);
21+
fs.copySync(templateDir, targetDir);
22+
console.log(chalk.bgGreenBright(chalk.green(`Installing npm dependencies...`)));
23+
execSync(`cd ${name} && npm install`, { stdio: 'inherit' });
24+
console.log(chalk.bgRed(chalk.green(`Setting up rust env...`)));
25+
execSync(`rustup target add wasm32-unknown-unknown`);
26+
execSync(`cd ${name} && cargo build --target wasm32-unknown-unknown`);
27+
console.log(chalk.bgMagenta(chalk.green(`Installing webassembly support...`)));
28+
execSync(`cd ${name} && cargo install -f wasm-bindgen-cli`);
29+
execSync(`cd ${name} && wasm-bindgen target/wasm32-unknown-unknown/debug/rusty_react.wasm --out-dir build`)
30+
console.log(chalk.bgGray(chalk.green(`Building your app, this may take few moments...`)));
31+
execSync(`cd ${name} && npm run build`);
32+
console.log(chalk.green(`Done!`));
33+
execSync(`cd ${name} && npm run dev`);
34+
};
35+
36+
yargs(hideBin(process.argv))
37+
.command(
38+
'create <name>',
39+
'create a new react-rust project',
40+
(yargs) => {
41+
return yargs
42+
.positional('name', {
43+
describe: 'name of the project',
44+
type: 'string'
45+
})
46+
}, (argv) => {
47+
createReactApp(argv.name, argv.template)
48+
})
49+
.demandCommand(1)
50+
.parse()

0 commit comments

Comments
 (0)