@getpara/create-para-app 0.4.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/package.json +1 -1
- package/dist/src/commands/scaffold.js +23 -3
- package/dist/src/integrations/codeGenerators.js +13 -17
- package/dist/src/integrations/sdkSetupNextjs.js +1 -1
- package/dist/src/integrations/sdkSetupVite.js +1 -1
- package/dist/src/templates/nextjs.js +23 -16
- package/dist/src/templates/vite-react.js +10 -1
- package/dist/src/utils/exec.js +3 -3
- package/package.json +1 -1
package/dist/package.json
CHANGED
|
@@ -9,6 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import chalk from 'chalk';
|
|
11
11
|
import fs from 'fs-extra';
|
|
12
|
+
import ora from 'ora';
|
|
13
|
+
import { execa } from 'execa';
|
|
12
14
|
import { promptInteractive } from '../prompts/interactive.js';
|
|
13
15
|
import { scaffoldNextjs } from '../templates/nextjs.js';
|
|
14
16
|
import { scaffoldViteReact } from '../templates/vite-react.js';
|
|
@@ -45,7 +47,6 @@ export default function scaffold(positionalProjectName, options) {
|
|
|
45
47
|
try {
|
|
46
48
|
validateOptions(options);
|
|
47
49
|
const { projectName: cliProjectName, template: cliTemplate, useLatest, noPrompt, noGit, packageManager, skipDeps, typescript = true, eslint = true, tailwind = true, srcDir = true, app = true, networks, evmSigner, externalWallet, apiKey, } = options || {};
|
|
48
|
-
// For rollback reference
|
|
49
50
|
const finalProjectName = cliProjectName || positionalProjectName;
|
|
50
51
|
let config = {
|
|
51
52
|
projectName: finalProjectName || '',
|
|
@@ -64,14 +65,12 @@ export default function scaffold(positionalProjectName, options) {
|
|
|
64
65
|
srcDir,
|
|
65
66
|
app,
|
|
66
67
|
};
|
|
67
|
-
// Populate networks if provided
|
|
68
68
|
if (networks) {
|
|
69
69
|
config.networks = networks.split(',').map(n => n.trim());
|
|
70
70
|
}
|
|
71
71
|
if (evmSigner) {
|
|
72
72
|
config.evmSigner = evmSigner;
|
|
73
73
|
}
|
|
74
|
-
// We'll decide if we must prompt
|
|
75
74
|
const needTemplate = !config.template;
|
|
76
75
|
const needProjectName = !config.projectName;
|
|
77
76
|
const needNetworks = !config.networks.length;
|
|
@@ -126,6 +125,27 @@ export default function scaffold(positionalProjectName, options) {
|
|
|
126
125
|
yield scaffoldNextjs(config);
|
|
127
126
|
}
|
|
128
127
|
yield runSDKSetup(config);
|
|
128
|
+
if (!config.skipDeps) {
|
|
129
|
+
const spinner = ora('Installing updated dependencies...').start();
|
|
130
|
+
try {
|
|
131
|
+
if (config.packageManager === 'yarn') {
|
|
132
|
+
yield execa('yarn', { cwd: config.projectName, stdio: 'pipe' });
|
|
133
|
+
}
|
|
134
|
+
else if (config.packageManager === 'pnpm') {
|
|
135
|
+
yield execa('pnpm', ['install'], { cwd: config.projectName, stdio: 'pipe' });
|
|
136
|
+
}
|
|
137
|
+
else if (config.packageManager === 'bun') {
|
|
138
|
+
yield execa('bun', ['install'], { cwd: config.projectName, stdio: 'pipe' });
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
yield execa('npm', ['install'], { cwd: config.projectName, stdio: 'pipe' });
|
|
142
|
+
}
|
|
143
|
+
spinner.succeed('Dependencies re-installed successfully.');
|
|
144
|
+
}
|
|
145
|
+
catch (err) {
|
|
146
|
+
spinner.fail('Failed to re-install dependencies. You might try manually running the install command.');
|
|
147
|
+
}
|
|
148
|
+
}
|
|
129
149
|
logInfo(chalk.green('✅ Scaffolding complete!'));
|
|
130
150
|
}
|
|
131
151
|
catch (error) {
|
|
@@ -431,12 +431,12 @@ export function getHelloParaFile(tailwind, isTypescript, isNext) {
|
|
|
431
431
|
}
|
|
432
432
|
`;
|
|
433
433
|
}
|
|
434
|
-
export function getHomeFile(tailwind, isNext, externalWalletSupport) {
|
|
434
|
+
export function getHomeFile(tailwind, isNext, externalWalletSupport, networks = []) {
|
|
435
435
|
const maybeUseClient = isNext ? `"use client";\n` : '';
|
|
436
436
|
const helloParaImport = isNext
|
|
437
437
|
? `import HelloPara from "@/components/HelloPara";`
|
|
438
438
|
: `import HelloPara from "./HelloPara";`;
|
|
439
|
-
let externalImports =
|
|
439
|
+
let externalImports = '';
|
|
440
440
|
if (externalWalletSupport) {
|
|
441
441
|
if (isNext) {
|
|
442
442
|
externalImports = `import { ExternalWallet } from "@getpara/react-sdk";
|
|
@@ -447,26 +447,22 @@ import { ParaWalletsProvider } from "@/components/ParaWalletsProvider";`;
|
|
|
447
447
|
import { ParaWalletsProvider } from "./ParaWalletsProvider";`;
|
|
448
448
|
}
|
|
449
449
|
}
|
|
450
|
+
let externalWallets = [];
|
|
451
|
+
if (networks.includes('evm')) {
|
|
452
|
+
externalWallets.push('ExternalWallet.METAMASK', 'ExternalWallet.RABBY', 'ExternalWallet.RAINBOW', 'ExternalWallet.WALLETCONNECT', 'ExternalWallet.COINBASE', 'ExternalWallet.ZERION');
|
|
453
|
+
}
|
|
454
|
+
if (networks.includes('solana')) {
|
|
455
|
+
externalWallets.push('ExternalWallet.BACKPACK', 'ExternalWallet.GLOW', 'ExternalWallet.PHANTOM');
|
|
456
|
+
}
|
|
457
|
+
if (networks.includes('cosmos')) {
|
|
458
|
+
externalWallets.push('ExternalWallet.KEPLR', 'ExternalWallet.LEAP');
|
|
459
|
+
}
|
|
460
|
+
const externalWalletSnippet = externalWalletSupport ? ` externalWallets={[${externalWallets.join(', ')}]}` : ``;
|
|
450
461
|
const wrapBegin = externalWalletSupport ? `<ParaWalletsProvider>` : ``;
|
|
451
462
|
const wrapEnd = externalWalletSupport ? `</ParaWalletsProvider>` : ``;
|
|
452
463
|
const maybeClass = tailwind
|
|
453
464
|
? `className="bg-[#FF4E00] hover:bg-[#E73461] text-white font-semibold py-2 px-4 rounded"`
|
|
454
465
|
: `className="open-button"`;
|
|
455
|
-
const externalWalletSnippet = externalWalletSupport
|
|
456
|
-
? ` externalWallets={[
|
|
457
|
-
ExternalWallet.BACKPACK,
|
|
458
|
-
ExternalWallet.COINBASE,
|
|
459
|
-
ExternalWallet.GLOW,
|
|
460
|
-
ExternalWallet.KEPLR,
|
|
461
|
-
ExternalWallet.LEAP,
|
|
462
|
-
ExternalWallet.METAMASK,
|
|
463
|
-
ExternalWallet.PHANTOM,
|
|
464
|
-
ExternalWallet.RABBY,
|
|
465
|
-
ExternalWallet.RAINBOW,
|
|
466
|
-
ExternalWallet.WALLETCONNECT,
|
|
467
|
-
ExternalWallet.ZERION,
|
|
468
|
-
]}`
|
|
469
|
-
: ``;
|
|
470
466
|
return `
|
|
471
467
|
${maybeUseClient}import React, { useState } from "react";
|
|
472
468
|
import { para } from "@/client/para";
|
|
@@ -46,7 +46,7 @@ export function sdkSetupNextjs(config) {
|
|
|
46
46
|
const formatted = yield formatWithPrettier(helloParaCode, filePath);
|
|
47
47
|
yield fs.outputFile(filePath, formatted);
|
|
48
48
|
}
|
|
49
|
-
const homeCode = getHomeFile(!!tailwind, !noTypescript, !!externalWalletSupport);
|
|
49
|
+
const homeCode = getHomeFile(!!tailwind, !noTypescript, !!externalWalletSupport, networks);
|
|
50
50
|
let mainPath = '';
|
|
51
51
|
if (noAppRouter) {
|
|
52
52
|
if (noSrcDir) {
|
|
@@ -43,7 +43,7 @@ export function sdkSetupVite(config) {
|
|
|
43
43
|
const formatted = yield formatWithPrettier(helloParaCode, filePath);
|
|
44
44
|
yield fs.outputFile(filePath, formatted);
|
|
45
45
|
}
|
|
46
|
-
const homeCode = getHomeFile(!!tailwind, !noTypescript, !!externalWalletSupport);
|
|
46
|
+
const homeCode = getHomeFile(!!tailwind, !noTypescript, !!externalWalletSupport, networks);
|
|
47
47
|
const mainFileDir = noSrcDir ? projectName : path.join(projectName, 'src');
|
|
48
48
|
const mainFilePath = path.join(mainFileDir, `App.${noTypescript ? 'jsx' : 'tsx'}`);
|
|
49
49
|
const exists = yield fs.pathExists(mainFilePath);
|
|
@@ -9,13 +9,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { execCommand } from '../utils/exec.js';
|
|
11
11
|
import { logInfo } from '../utils/logger.js';
|
|
12
|
+
import ora from 'ora';
|
|
12
13
|
export function scaffoldNextjs(config) {
|
|
13
14
|
return __awaiter(this, void 0, void 0, function* () {
|
|
14
15
|
logInfo(`🔧 Scaffolding Next.js app for project ${config.projectName}...`);
|
|
15
16
|
const versionTag = config.useLatest ? 'latest' : 'latest';
|
|
16
|
-
// Start with these flags for a default Next.js TS, ESLint, Tailwind, src, app setup
|
|
17
17
|
const baseFlags = new Set(['--typescript', '--eslint', '--tailwind', '--src-dir', '--app', '--no-turbopack', '--yes']);
|
|
18
|
-
// If user wants no typescript => remove --typescript, add --javascript
|
|
19
18
|
if (!config.typescript) {
|
|
20
19
|
baseFlags.delete('--typescript');
|
|
21
20
|
baseFlags.add('--javascript');
|
|
@@ -36,26 +35,34 @@ export function scaffoldNextjs(config) {
|
|
|
36
35
|
for (const f of baseFlags) {
|
|
37
36
|
cmd += ` ${f}`;
|
|
38
37
|
}
|
|
38
|
+
if (config.packageManager === 'yarn') {
|
|
39
|
+
cmd += ' --use-yarn';
|
|
40
|
+
}
|
|
41
|
+
else if (config.packageManager === 'npm') {
|
|
42
|
+
cmd += ' --use-npm';
|
|
43
|
+
}
|
|
44
|
+
else if (config.packageManager === 'pnpm') {
|
|
45
|
+
cmd += ' --use-pnpm';
|
|
46
|
+
}
|
|
47
|
+
else if (config.packageManager === 'bun') {
|
|
48
|
+
logInfo('Warning: create-next-app does not officially support "--use-bun". Using npm instead.');
|
|
49
|
+
cmd += ' --use-npm';
|
|
50
|
+
}
|
|
39
51
|
if (config.noGit) {
|
|
40
52
|
cmd += ' --no-git';
|
|
41
53
|
}
|
|
42
54
|
if (config.skipDeps) {
|
|
43
55
|
cmd += ' --skip-install';
|
|
44
56
|
}
|
|
45
|
-
|
|
46
|
-
if (config.packageManager === 'npm') {
|
|
47
|
-
cmd += ' --use-npm';
|
|
48
|
-
}
|
|
49
|
-
else if (config.packageManager === 'pnpm') {
|
|
50
|
-
cmd += ' --use-pnpm';
|
|
51
|
-
}
|
|
52
|
-
else if (config.packageManager === 'bun') {
|
|
53
|
-
// create-next-app doesn't have a built-in --use-bun, we might skip or log a warning
|
|
54
|
-
logInfo('Warning: create-next-app does not officially support "--use-bun". Using npm instead.');
|
|
55
|
-
cmd += ' --use-npm';
|
|
56
|
-
}
|
|
57
|
-
}
|
|
57
|
+
const spinner = ora('Scaffolding your Next.js project...').start();
|
|
58
58
|
logInfo(`💻 Executing command: ${cmd}`);
|
|
59
|
-
|
|
59
|
+
try {
|
|
60
|
+
yield execCommand(cmd, true);
|
|
61
|
+
spinner.succeed('Next.js scaffold complete.');
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
spinner.fail('Failed to scaffold Next.js app.');
|
|
65
|
+
throw error;
|
|
66
|
+
}
|
|
60
67
|
});
|
|
61
68
|
}
|
|
@@ -9,6 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { execCommand } from '../utils/exec.js';
|
|
11
11
|
import { logInfo } from '../utils/logger.js';
|
|
12
|
+
import ora from 'ora';
|
|
12
13
|
export function scaffoldViteReact(config) {
|
|
13
14
|
return __awaiter(this, void 0, void 0, function* () {
|
|
14
15
|
logInfo(`🔧 Scaffolding Vite React app for project ${config.projectName}...`);
|
|
@@ -37,7 +38,15 @@ export function scaffoldViteReact(config) {
|
|
|
37
38
|
if (config.skipDeps) {
|
|
38
39
|
cmd += ' --skip-install';
|
|
39
40
|
}
|
|
41
|
+
const spinner = ora('Scaffolding your Vite project...').start();
|
|
40
42
|
logInfo(`💻 Executing command: ${cmd}`);
|
|
41
|
-
|
|
43
|
+
try {
|
|
44
|
+
yield execCommand(cmd, true);
|
|
45
|
+
spinner.succeed('Vite scaffold complete.');
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
spinner.fail('Failed to scaffold Vite app.');
|
|
49
|
+
throw error;
|
|
50
|
+
}
|
|
42
51
|
});
|
|
43
52
|
}
|
package/dist/src/utils/exec.js
CHANGED
|
@@ -8,9 +8,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { execa } from 'execa';
|
|
11
|
-
export function execCommand(
|
|
12
|
-
return __awaiter(this,
|
|
11
|
+
export function execCommand(command_1) {
|
|
12
|
+
return __awaiter(this, arguments, void 0, function* (command, silent = false) {
|
|
13
13
|
const [cmd, ...args] = command.split(' ');
|
|
14
|
-
yield execa(cmd, args, { stdio: 'inherit' });
|
|
14
|
+
yield execa(cmd, args, { stdio: silent ? 'pipe' : 'inherit' });
|
|
15
15
|
});
|
|
16
16
|
}
|