Skip to content

Commit bfcec48

Browse files
authored
Ask to enable Yarn Zero-install during setup (#273)
1 parent aec0aa0 commit bfcec48

File tree

4 files changed

+41
-11
lines changed

4 files changed

+41
-11
lines changed

.github/workflows/pull_request.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
runs-on: ubuntu-latest
1818
steps:
1919
- uses: actions/checkout@v2
20-
- run: yarn install --immutable-cache
20+
- run: yarn install
2121

2222
# Analyze code for potential problems
2323
- run: yarn prettier --check .

.gitignore

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@
1010
node_modules/
1111

1212
# Yarn Zero-installs
13-
# https://yarnpkg.com/advanced/qa/#which-files-should-be-gitignored
13+
# https://yarnpkg.com/getting-started/qa#which-files-should-be-gitignored
1414
.yarn/*
15-
!.yarn/cache
15+
#!.yarn/cache
1616
!.yarn/releases
1717
!.yarn/plugins
1818
!.yarn/sdks
19-
!.yarn/versionss
19+
!.yarn/versions
20+
.pnp.*
2021

2122
# Logs
2223
yarn-debug.log*

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ Just clone the repo and run `yarn setup` followed by `yarn start`:
4545
$ git clone --origin=upstream --branch=main --single-branch \
4646
https://github.com/kriasoft/nodejs-api-starter.git example
4747
$ cd ./example # Change current directory to the newly created one
48+
$ yarn install # Install project dependencies
4849
$ yarn setup # Configure environment variables
4950
$ yarn start # Launch Node.js API and web application
5051
```

setup.js

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,12 @@ const questions = [
127127
);
128128
},
129129
})),
130+
{
131+
type: "confirm",
132+
name: "yarn",
133+
message: "Enable Yarn Zero-install?",
134+
default: true,
135+
},
130136
{
131137
type: "confirm",
132138
name: "clean",
@@ -137,6 +143,25 @@ const questions = [
137143
];
138144

139145
async function done(answers) {
146+
// Enable/disable Yarn Zero-install
147+
if (answers.yarn) {
148+
await replace(`.gitignore`, /^#!\.yarn\/cache$/m, `!.yarn/cache`);
149+
await replace(`.gitignore`, /^\.pnp\.\*$/m, `#.pnp.*`);
150+
await replace(
151+
`.github/workflows/pull_request.yaml`,
152+
/yarn install$/m,
153+
`yarn install --immutable --immutable-cache`,
154+
);
155+
} else {
156+
await replace(`.gitignore`, /^!\.yarn\/cache$/m, `#!.yarn/cache`);
157+
await replace(`.gitignore`, /^#\.pnp\.\*$/m, `.pnp.*`);
158+
await replace(
159+
`.github/workflows/pull_request.yaml`,
160+
/yarn install.*$/m,
161+
`yarn install`,
162+
);
163+
}
164+
140165
// Remove this script
141166
if (answers.clean) {
142167
fs.unlinkSync("./setup.js");
@@ -146,8 +171,6 @@ async function done(answers) {
146171
spawn.sync("yarn", ["remove", "inquirer", "cross-spawn", "dotenv"], {
147172
stdio: "inherit",
148173
});
149-
} else {
150-
spawn.sync("yarn", ["install"], { stdio: "inherit" });
151174
}
152175

153176
if (answers.setup) {
@@ -166,14 +189,19 @@ async function done(answers) {
166189
console.log(
167190
` Done! Now you can migrate the database and launch the app by running:`,
168191
);
169-
console.log(` `);
170-
console.log(` $ yarn db:reset`);
171-
console.log(` $ yarn api:start`);
172-
console.log(` $ yarn web:start`);
173-
console.log(` `);
174192
} else {
193+
console.log(` `);
175194
console.log(` No problem. You can run this script at any time later.`);
195+
console.log(
196+
` Now you can migrate the database and launch the app by running:`,
197+
);
176198
}
199+
200+
console.log(` `);
201+
console.log(` $ yarn db:reset`);
202+
console.log(` $ yarn api:start`);
203+
console.log(` $ yarn web:start`);
204+
console.log(` `);
177205
}
178206

179207
inquirer

0 commit comments

Comments
 (0)