Skip to content
This repository was archived by the owner on Dec 1, 2022. It is now read-only.

Commit 0c7ba0a

Browse files
Try to use cross-spawn to resolve issues on Windows
1 parent 2694cc6 commit 0c7ba0a

File tree

4 files changed

+49
-24
lines changed

4 files changed

+49
-24
lines changed

dist/index.js

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
55
};
66
Object.defineProperty(exports, "__esModule", { value: true });
77
const LogColor = '\x1b[32m';
8-
const child_process_1 = require("child_process");
8+
const cross_spawn_1 = __importDefault(require("cross-spawn"));
99
const fs_extra_1 = __importDefault(require("fs-extra"));
1010
const path_1 = __importDefault(require("path"));
1111
const yargs_1 = __importDefault(require("yargs"));
@@ -113,7 +113,7 @@ async function installPackagesAdvanced(packages, directory, dev) {
113113
return new Promise((resolve, reject) => {
114114
const joinedPackages = packages.map((p) => p.name + (p.version ? `@${p.version}` : ``));
115115
// console.log({ joinedPackages });
116-
const createReactNativeProcess = child_process_1.spawn(spawnPlatform('yarn'), [
116+
const createReactNativeProcess = cross_spawn_1.default('yarn', [
117117
'--cwd',
118118
directory,
119119
'add',
@@ -130,7 +130,7 @@ async function installPackagesAdvanced(packages, directory, dev) {
130130
}
131131
async function createReactNativeApp(appName) {
132132
return new Promise((resolve, reject) => {
133-
const createReactNativeProcess = child_process_1.spawn(spawnPlatform('npx'), ['react-native', 'init', appName], { stdio: 'inherit', shell: true });
133+
const createReactNativeProcess = cross_spawn_1.default('npx', ['react-native', 'init', appName], { stdio: 'inherit', shell: true });
134134
createReactNativeProcess.on('error', function (error) {
135135
reject(error);
136136
});
@@ -141,7 +141,7 @@ async function createReactNativeApp(appName) {
141141
}
142142
async function createReactScriptsApp(appName) {
143143
return new Promise(function (resolve, reject) {
144-
const createReactNativeProcess = child_process_1.spawn(spawnPlatform('npx'), ['create-react-app', appName], { stdio: 'inherit', shell: true });
144+
const createReactNativeProcess = cross_spawn_1.default('npx', ['create-react-app', appName], { stdio: 'inherit', shell: true });
145145
createReactNativeProcess.on('error', function (error) {
146146
reject(error);
147147
});
@@ -150,13 +150,6 @@ async function createReactScriptsApp(appName) {
150150
});
151151
});
152152
}
153-
function spawnPlatform(s) {
154-
const isWin = process.platform === 'win32';
155-
if (isWin) {
156-
return s + '.cmd';
157-
}
158-
return s;
159-
}
160153
function logSpaced(args) {
161154
console.log('');
162155
console.log(LogColor, args);

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "create-react-native-web-application",
3-
"version": "0.1.11",
3+
"version": "0.1.12",
44
"bin": {
55
"create-react-native-web-application": "dist/index.js"
66
},
@@ -19,6 +19,7 @@
1919
"node": ">=12"
2020
},
2121
"dependencies": {
22+
"cross-spawn": "^7.0.3",
2223
"fs-extra": "^9.0.0",
2324
"node-fs-extra": "^0.8.2",
2425
"yargs": "^15.3.1"

src/index.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ interface PackageType {
77
}
88
const LogColor = '\x1b[32m';
99

10-
import { spawn } from 'child_process';
10+
import spawn from 'cross-spawn';
11+
1112
import fs from 'fs-extra';
1213
import path from 'path';
1314
import yargs from 'yargs';
@@ -166,7 +167,7 @@ async function installPackagesAdvanced(
166167
);
167168
// console.log({ joinedPackages });
168169
const createReactNativeProcess = spawn(
169-
spawnPlatform('yarn'),
170+
'yarn',
170171
[
171172
'--cwd',
172173
directory,
@@ -189,7 +190,7 @@ async function installPackagesAdvanced(
189190
async function createReactNativeApp(appName: string): Promise<any> {
190191
return new Promise((resolve, reject) => {
191192
const createReactNativeProcess = spawn(
192-
spawnPlatform('npx'),
193+
'npx',
193194
['react-native', 'init', appName],
194195
{ stdio: 'inherit', shell: true }
195196
);
@@ -206,7 +207,7 @@ async function createReactNativeApp(appName: string): Promise<any> {
206207
async function createReactScriptsApp(appName: string): Promise<any> {
207208
return new Promise<any>(function (resolve, reject) {
208209
const createReactNativeProcess = spawn(
209-
spawnPlatform('npx'),
210+
'npx',
210211
['create-react-app', appName],
211212
{ stdio: 'inherit', shell: true }
212213
);
@@ -220,14 +221,6 @@ async function createReactScriptsApp(appName: string): Promise<any> {
220221
});
221222
}
222223

223-
function spawnPlatform(s: string): string {
224-
const isWin = process.platform === 'win32';
225-
if (isWin) {
226-
return s + '.cmd';
227-
}
228-
return s;
229-
}
230-
231224
function logSpaced(args) {
232225
console.log('');
233226
console.log(LogColor, args);

yarn.lock

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,15 @@ color-name@~1.1.4:
7575
resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.4.tgz#c2a09a87acbde69543de6f63fa3995c826c536a2"
7676
integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==
7777

78+
cross-spawn@^7.0.3:
79+
version "7.0.3"
80+
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.3.tgz#f73a85b9d5d41d045551c177e2882d4ac85728a6"
81+
integrity sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==
82+
dependencies:
83+
path-key "^3.1.0"
84+
shebang-command "^2.0.0"
85+
which "^2.0.1"
86+
7887
decamelize@^1.2.0:
7988
version "1.2.0"
8089
resolved "https://registry.yarnpkg.com/decamelize/-/decamelize-1.2.0.tgz#f6534d15148269b20352e7bee26f501f9a191290"
@@ -118,6 +127,11 @@ is-fullwidth-code-point@^3.0.0:
118127
resolved "https://registry.yarnpkg.com/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz#f116f8064fe90b3f7844a38997c0b75051269f1d"
119128
integrity sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==
120129

130+
isexe@^2.0.0:
131+
version "2.0.0"
132+
resolved "https://registry.yarnpkg.com/isexe/-/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10"
133+
integrity sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=
134+
121135
jsonfile@^6.0.1:
122136
version "6.0.1"
123137
resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-6.0.1.tgz#98966cba214378c8c84b82e085907b40bf614179"
@@ -183,6 +197,11 @@ path-exists@^4.0.0:
183197
resolved "https://registry.yarnpkg.com/path-exists/-/path-exists-4.0.0.tgz#513bdbe2d3b95d7762e8c1137efa195c6c61b5b3"
184198
integrity sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==
185199

200+
path-key@^3.1.0:
201+
version "3.1.1"
202+
resolved "https://registry.yarnpkg.com/path-key/-/path-key-3.1.1.tgz#581f6ade658cbba65a0d3380de7753295054f375"
203+
integrity sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==
204+
186205
require-directory@^2.1.1:
187206
version "2.1.1"
188207
resolved "https://registry.yarnpkg.com/require-directory/-/require-directory-2.1.1.tgz#8c64ad5fd30dab1c976e2344ffe7f792a6a6df42"
@@ -203,6 +222,18 @@ set-blocking@^2.0.0:
203222
resolved "https://registry.yarnpkg.com/set-blocking/-/set-blocking-2.0.0.tgz#045f9782d011ae9a6803ddd382b24392b3d890f7"
204223
integrity sha1-BF+XgtARrppoA93TgrJDkrPYkPc=
205224

225+
shebang-command@^2.0.0:
226+
version "2.0.0"
227+
resolved "https://registry.yarnpkg.com/shebang-command/-/shebang-command-2.0.0.tgz#ccd0af4f8835fbdc265b82461aaf0c36663f34ea"
228+
integrity sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==
229+
dependencies:
230+
shebang-regex "^3.0.0"
231+
232+
shebang-regex@^3.0.0:
233+
version "3.0.0"
234+
resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-3.0.0.tgz#ae16f1644d873ecad843b0307b143362d4c42172"
235+
integrity sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==
236+
206237
string-width@^4.1.0, string-width@^4.2.0:
207238
version "4.2.0"
208239
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.0.tgz#952182c46cc7b2c313d1596e623992bd163b72b5"
@@ -234,6 +265,13 @@ which-module@^2.0.0:
234265
resolved "https://registry.yarnpkg.com/which-module/-/which-module-2.0.0.tgz#d9ef07dce77b9902b8a3a8fa4b31c3e3f7e6e87a"
235266
integrity sha1-2e8H3Od7mQK4o6j6SzHD4/fm6Ho=
236267

268+
which@^2.0.1:
269+
version "2.0.2"
270+
resolved "https://registry.yarnpkg.com/which/-/which-2.0.2.tgz#7c6a8dd0a636a0327e10b59c9286eee93f3f51b1"
271+
integrity sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==
272+
dependencies:
273+
isexe "^2.0.0"
274+
237275
wrap-ansi@^6.2.0:
238276
version "6.2.0"
239277
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-6.2.0.tgz#e9393ba07102e6c91a3b221478f0257cd2856e53"

0 commit comments

Comments
 (0)