Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3461348

Browse files
authored
feat(init): create .gitignore with lerna init (#3270)
1 parentdfd30fa commit3461348

File tree

6 files changed

+51
-0
lines changed

6 files changed

+51
-0
lines changed

‎commands/init/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ When run, this command will:
1818

1919
1. Add`lerna` as a[`devDependency`](https://docs.npmjs.com/files/package.json#devdependencies) in`package.json` if it doesn't already exist.
2020
2. Create a`lerna.json` config file to store the`version` number.
21+
3. Generate a`.gitignore` file if one doesn't already exist.
2122

2223
Example output on a new git repo:
2324

‎commands/init/__tests__/init-command.test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,17 @@ describe("InitCommand", () => {
6363
expect(gitDirExists).toBe(true);
6464
});
6565

66+
it("initializes .gitignore",async()=>{
67+
consttestDir=tempy.directory();
68+
69+
awaitlernaInit(testDir)();
70+
71+
constgitIgnorePath=path.join(testDir,".gitignore");
72+
constgitIgnoreContent=awaitfs.readFile(gitIgnorePath,"utf8");
73+
74+
expect(gitIgnoreContent).toMatchInlineSnapshot(`"node_modules/"`);
75+
});
76+
6677
it("initializes git repo with lerna files in independent mode",async()=>{
6778
consttestDir=tempy.directory();
6879

@@ -147,6 +158,21 @@ describe("InitCommand", () => {
147158
});
148159
});
149160

161+
describe("when .gitignore exists",()=>{
162+
it("does not change existing .gitignore",async()=>{
163+
consttestDir=awaittempy.directory();
164+
165+
constgitIgnorePath=path.join(testDir,".gitignore");
166+
awaitfs.writeFile(gitIgnorePath,"dist/");
167+
168+
awaitlernaInit(testDir)();
169+
170+
constgitIgnoreContent=awaitfs.readFile(gitIgnorePath,"utf8");
171+
172+
expect(gitIgnoreContent).toMatchInlineSnapshot(`"dist/"`);
173+
});
174+
});
175+
150176
describe("when package.json exists",()=>{
151177
it("adds lerna to sorted devDependencies",async()=>{
152178
consttestDir=awaitinitFixture("has-package");

‎commands/init/index.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class InitCommand extends Command {
4242
execute(){
4343
letchain=Promise.resolve();
4444

45+
chain=chain.then(()=>this.ensureGitIgnore());
4546
chain=chain.then(()=>this.ensureConfig());
4647
chain=chain.then(()=>this.ensurePackagesDir());
4748

@@ -51,6 +52,19 @@ class InitCommand extends Command {
5152
});
5253
}
5354

55+
ensureGitIgnore(){
56+
constgitIgnorePath=path.join(this.project.rootPath,".gitignore");
57+
58+
letchain=Promise.resolve();
59+
60+
if(!fs.existsSync(gitIgnorePath)){
61+
this.logger.info("","Creating .gitignore");
62+
chain=chain.then(()=>fs.writeFile(gitIgnorePath,"node_modules/"));
63+
}
64+
65+
returnchain;
66+
}
67+
5468
ensureConfig(){
5569
consthasExistingLernaConfig=!!this.project.version;
5670
consthasExistingPackageJson=!!this.project.manifest;

‎e2e/tests/lerna-init/lerna-init.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ describe("lerna-init", () => {
2020
expect(output.stderr).toMatchInlineSnapshot(`
2121
"lerna notice cli v999.9.9-e2e.0
2222
lerna info Initializing Git repository
23+
lerna info Creating .gitignore
2324
lerna info Creating package.json
2425
lerna info Creating lerna.json
2526
lerna info Creating packages directory
@@ -50,6 +51,7 @@ describe("lerna-init", () => {
5051
}
5152
"
5253
`);
54+
expect(awaitfixture.readWorkspaceFile(".gitignore")).toMatchInlineSnapshot(`"node_modules/"`);
5355
});
5456

5557
describe("--independent",()=>{
@@ -59,6 +61,7 @@ describe("lerna-init", () => {
5961
expect(output.stderr).toMatchInlineSnapshot(`
6062
"lerna notice cli v999.9.9-e2e.0
6163
lerna info Initializing Git repository
64+
lerna info Creating .gitignore
6265
lerna info Creating package.json
6366
lerna info Creating lerna.json
6467
lerna info Creating packages directory
@@ -89,6 +92,7 @@ describe("lerna-init", () => {
8992
}
9093
"
9194
`);
95+
expect(awaitfixture.readWorkspaceFile(".gitignore")).toMatchInlineSnapshot(`"node_modules/"`);
9296
});
9397
});
9498

@@ -99,6 +103,7 @@ describe("lerna-init", () => {
99103
expect(output.stderr).toMatchInlineSnapshot(`
100104
"lerna notice cli v999.9.9-e2e.0
101105
lerna info Initializing Git repository
106+
lerna info Creating .gitignore
102107
lerna info Creating package.json
103108
lerna info Creating lerna.json
104109
lerna info Creating packages directory
@@ -134,6 +139,7 @@ describe("lerna-init", () => {
134139
}
135140
"
136141
`);
142+
expect(awaitfixture.readWorkspaceFile(".gitignore")).toMatchInlineSnapshot(`"node_modules/"`);
137143
});
138144
});
139145

@@ -144,6 +150,7 @@ describe("lerna-init", () => {
144150
expect(output.stderr).toMatchInlineSnapshot(`
145151
"lerna notice cli v999.9.9-e2e.0
146152
lerna info Initializing Git repository
153+
lerna info Creating .gitignore
147154
lerna info Creating package.json
148155
lerna info Creating lerna.json
149156
lerna info Creating packages directory
@@ -179,6 +186,7 @@ describe("lerna-init", () => {
179186
}
180187
"
181188
`);
189+
expect(awaitfixture.readWorkspaceFile(".gitignore")).toMatchInlineSnapshot(`"node_modules/"`);
182190
});
183191
});
184192
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dist/

‎integration/lerna-init.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ describe("lerna init", () => {
1919
expect(stderr).toMatchInlineSnapshot(`
2020
lerna notice cli __TEST_VERSION__
2121
lerna info Initializing Git repository
22+
lerna info Creating .gitignore
2223
lerna info Creating package.json
2324
lerna info Creating lerna.json
2425
lerna info Creating packages directory

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp