Skip to content

Commit cc2680f

Browse files
author
Ahmed Elshaabany
committed
Modify package.json file
1 parent 03fc298 commit cc2680f

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

script.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,37 @@
11
#!/usr/bin/env node
22

3+
const execSync = require('child_process').execSync;
4+
const fs = require('fs');
5+
const path = require('path');
6+
7+
/**
8+
* Use Yarn if available, it's much faster than the npm client.
9+
* Return the version of yarn installed on the system, null if yarn is not available.
10+
*/
11+
function getYarnVersionIfAvailable() {
12+
let yarnVersion;
13+
try {
14+
// execSync returns a Buffer -> convert to string
15+
yarnVersion = (execSync('yarn --version', {
16+
stdio: [0, 'pipe', 'ignore'],
17+
}).toString() || '').trim();
18+
} catch (error) {
19+
return null;
20+
}
21+
return yarnVersion;
22+
}
23+
24+
function installDevDependencies() {
25+
console.log('Adding dev dependencies for the project...');
26+
27+
if (getYarnVersionIfAvailable()) {
28+
execSync(`yarn install`, { stdio: 'inherit' });
29+
} else {
30+
execSync(`npm install`);
31+
}
32+
}
33+
34+
installDevDependencies();
35+
createScripts();
36+
337
console.log("This is post init script");

0 commit comments

Comments
 (0)