Skip to content

Commit da03584

Browse files
committed
chore: get rid of shelljs
we are now using native fs system
1 parent ae0058c commit da03584

File tree

3 files changed

+51
-45
lines changed

3 files changed

+51
-45
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@
7979
"rollup-plugin-sourcemaps": "^0.6.3",
8080
"rollup-plugin-terser": "^7.0.2",
8181
"rollup-plugin-typescript2": "^0.33.0",
82-
"shelljs": "^0.8.5",
8382
"ts-jest": "^28.0.8",
8483
"ts-node": "^10.9.1",
8584
"typedoc": "^0.23.14",

tools/init.ts

Lines changed: 49 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@
99
* I just made some modifications and added some new functions.
1010
* **/
1111

12+
const { execSync } = require('child_process');
13+
const {
14+
rmdirSync,
15+
rmSync,
16+
existsSync,
17+
lstatSync,
18+
readdirSync,
19+
unlinkSync,
20+
} = require('fs');
21+
1222
/* eslint-disable @typescript-eslint/no-var-requires */
1323
/* eslint-disable @typescript-eslint/no-explicit-any */
1424

@@ -23,7 +33,23 @@ const replace = require('replace-in-file');
2333
const { readFileSync, writeFileSync } = require('fs');
2434
const { cyan, green, red, underline, yellow } = require('colors');
2535
const _prompt = require('prompt');
26-
const { mv, rm, which, exec } = require('shelljs');
36+
37+
function deleteFolderRecursive(path: any) {
38+
if (existsSync(path)) {
39+
const files = readdirSync(path);
40+
files.forEach(function (file: any) {
41+
const curPath = path + '/' + file;
42+
if (lstatSync(curPath).isDirectory()) {
43+
// recurse
44+
deleteFolderRecursive(curPath);
45+
} else {
46+
// delete file
47+
unlinkSync(curPath);
48+
}
49+
});
50+
rmdirSync(path);
51+
}
52+
}
2753

2854
// Note: These should all be relative to the project root directory
2955
const rmDirs = ['.git', 'tools'];
@@ -45,12 +71,11 @@ function removeItems() {
4571
// The directories and files are combined here, to simplify the function,
4672
// as the 'rm' command checks the item type before attempting to remove it
4773
const rmItems = rmDirs.concat(rmFiles);
48-
rm(
49-
'-rf',
50-
rmItems.map((f) => resolve(__dirname, '..', f))
51-
);
52-
console.log(red(rmItems.join('\n')));
5374

75+
rmItems
76+
.map((f) => resolve(__dirname, '..', f))
77+
.forEach((p) => deleteFolderRecursive(p));
78+
console.log(red(rmItems.join('\n')));
5479
console.log('\n');
5580
}
5681

@@ -103,9 +128,10 @@ function finalize() {
103128
console.log(underline.white('Finalizing'));
104129

105130
// Recreate Git folder
106-
const gitInitOutput = exec('git init "' + resolve(__dirname, '..') + '"', {
107-
silent: true,
108-
}).stdout;
131+
const gitInitOutput = execSync(
132+
'git init "' + resolve(__dirname, '..') + '"',
133+
{}
134+
).toString();
109135
console.log(green(gitInitOutput.replace(/(\n|\r)+/g, '')));
110136

111137
// Remove post-install command
@@ -126,11 +152,11 @@ function finalize() {
126152
console.log(green('Postinstall script has been removed'));
127153

128154
console.log(yellow('Removing yarn.lock and performing a clean install...'));
129-
rm('yarn.lock');
130-
rm('-rf', 'node_modules');
131-
exec('yarn install');
132-
exec('yarn build');
133-
exec("git add . && git commit -am 'chore: init' --no-verify");
155+
rmSync('yarn.lock');
156+
deleteFolderRecursive('node_modules');
157+
execSync('yarn install');
158+
execSync('yarn build');
159+
execSync("git add . && git commit -am 'chore: init' --no-verify");
134160
console.log('\n');
135161
}
136162
/**
@@ -146,23 +172,23 @@ function setupLibrary(libraryName: string, generateExample = false) {
146172
);
147173

148174
// Get the Git username and email before the .git directory is removed
149-
const username = exec('git config user.name').stdout.trim();
150-
const usermail = exec('git config user.email').stdout.trim();
175+
const username = execSync('git config user.name').toString().trim();
176+
const usermail = execSync('git config user.email').toString().trim();
151177

152178
if (generateExample) {
153179
yellow('Installing the test application into example/ directory...');
154-
exec('npx create-react-app example');
155-
exec('echo "SKIP_PREFLIGHT_CHECK=true" >> example/.env');
180+
execSync('npx create-react-app example');
181+
execSync('echo "SKIP_PREFLIGHT_CHECK=true" >> example/.env');
156182
}
157-
mv('tools/README.md', 'README.md');
183+
execSync('mv tools/README.md README.md');
158184
removeItems();
159185

160186
modifyGitignoreFile();
161187
modifyContents(libraryName, username, usermail);
162188

163189
if (generateExample) {
164190
console.log(yellow('Linking packages to the example app...'));
165-
exec(
191+
execSync(
166192
'cd example && yarn add link:.. link:../node_modules/react link:../node_modules/react-dom && cd ..'
167193
);
168194
}
@@ -297,7 +323,9 @@ _prompt.message = '';
297323
// Clear console
298324
process.stdout.write('\x1B[2J\x1B[0f');
299325

300-
if (!which('git')) {
326+
try {
327+
execSync('git --version');
328+
} catch {
301329
console.log(red('Sorry, this script requires git'));
302330
removeItems();
303331
process.exit(1);

yarn.lock

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2983,7 +2983,7 @@ glob-parent@^6.0.1:
29832983
dependencies:
29842984
is-glob "^4.0.3"
29852985

2986-
glob@^7.0.0, glob@^7.0.3, glob@^7.1.3, glob@^7.1.4, glob@^7.2.0:
2986+
glob@^7.0.3, glob@^7.1.3, glob@^7.1.4, glob@^7.2.0:
29872987
version "7.2.0"
29882988
resolved "https://registry.yarnpkg.com/glob/-/glob-7.2.0.tgz#d15535af7732e02e948f4c41628bd910293f6023"
29892989
integrity sha512-lmLf6gtyrPq8tTjSmrO94wBeQbFR3HbLHbuyD69wuyQkImp2hWqMGB47OX65FBkPffO641IP9jWa1z4ivqG26Q==
@@ -3234,11 +3234,6 @@ internal-slot@^1.0.3:
32343234
has "^1.0.3"
32353235
side-channel "^1.0.4"
32363236

3237-
interpret@^1.0.0:
3238-
version "1.4.0"
3239-
resolved "https://registry.yarnpkg.com/interpret/-/interpret-1.4.0.tgz#665ab8bc4da27a774a40584e812e3e0fa45b1a1e"
3240-
integrity sha512-agE4QfB2Lkp9uICn7BAqoscw4SZP9kTE2hxiFI3jBPmXJfdqiahTbUuKGsMoN2GtqL9AxhYioAcVvgsb1HvRbA==
3241-
32423237
is-absolute-url@^3.0.3:
32433238
version "3.0.3"
32443239
resolved "https://registry.yarnpkg.com/is-absolute-url/-/is-absolute-url-3.0.3.tgz#96c6a22b6a23929b11ea0afb1836c36ad4a5d698"
@@ -5083,13 +5078,6 @@ readable-stream@3, readable-stream@^3.0.0:
50835078
string_decoder "^1.1.1"
50845079
util-deprecate "^1.0.1"
50855080

5086-
rechoir@^0.6.2:
5087-
version "0.6.2"
5088-
resolved "https://registry.yarnpkg.com/rechoir/-/rechoir-0.6.2.tgz#85204b54dba82d5742e28c96756ef43af50e3384"
5089-
integrity sha1-hSBLVNuoLVdC4oyWdW70OvUOM4Q=
5090-
dependencies:
5091-
resolve "^1.1.6"
5092-
50935081
redent@^3.0.0:
50945082
version "3.0.0"
50955083
resolved "https://registry.yarnpkg.com/redent/-/redent-3.0.0.tgz#e557b7998316bb53c9f1f56fa626352c6963059f"
@@ -5165,7 +5153,7 @@ resolve.exports@^1.1.0:
51655153
resolved "https://registry.yarnpkg.com/resolve.exports/-/resolve.exports-1.1.0.tgz#5ce842b94b05146c0e03076985d1d0e7e48c90c9"
51665154
integrity sha512-J1l+Zxxp4XK3LUDZ9m60LRJF/mAe4z6a4xyabPHk7pvK5t35dACV32iIjJDFeWZFfZlO29w6SZ67knR0tHzJtQ==
51675155

5168-
resolve@^1.1.6, resolve@^1.10.0, resolve@^1.11.0, resolve@^1.11.1, resolve@^1.19.0, resolve@^1.20.0:
5156+
resolve@^1.10.0, resolve@^1.11.0, resolve@^1.11.1, resolve@^1.19.0, resolve@^1.20.0:
51695157
version "1.20.0"
51705158
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.20.0.tgz#629a013fb3f70755d6f0b7935cc1c2c5378b1975"
51715159
integrity sha512-wENBPt4ySzg4ybFQW2TT1zMQucPK95HSh/nq2CFTZVOGut2+pQvSsgtda4d26YrYcr067wjbmzOG8byDPBX63A==
@@ -5394,15 +5382,6 @@ shebang-regex@^3.0.0:
53945382
resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-3.0.0.tgz#ae16f1644d873ecad843b0307b143362d4c42172"
53955383
integrity sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==
53965384

5397-
shelljs@^0.8.5:
5398-
version "0.8.5"
5399-
resolved "https://registry.yarnpkg.com/shelljs/-/shelljs-0.8.5.tgz#de055408d8361bed66c669d2f000538ced8ee20c"
5400-
integrity sha512-TiwcRcrkhHvbrZbnRcFYMLl30Dfov3HKqzp5tO5b4pt6G/SezKcYhmDg15zXVBswHmctSAQKznqNW2LO5tTDow==
5401-
dependencies:
5402-
glob "^7.0.0"
5403-
interpret "^1.0.0"
5404-
rechoir "^0.6.2"
5405-
54065385
shiki@^0.11.1:
54075386
version "0.11.1"
54085387
resolved "https://registry.yarnpkg.com/shiki/-/shiki-0.11.1.tgz#df0f719e7ab592c484d8b73ec10e215a503ab8cc"

0 commit comments

Comments
 (0)