Skip to content

Commit e6f2055

Browse files
committed
👌 IMPROVE: .gitignore PR
2 parents 8f53a9c + 216bdc6 commit e6f2055

4 files changed

Lines changed: 39 additions & 8 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ Inside that directory, it will generate the initial project structure and instal
105105
```sh
106106
INSIDE: /local_dev_site.tld/wp-content/plugins/my-block
107107

108+
├── .gitignore
108109
├── plugin.php
109110
├── package.json
110111
├── README.md
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Install a starter .gitignore
3+
*/
4+
5+
'use strict';
6+
7+
const path = require( 'path' );
8+
const fs = require( 'fs-extra' );
9+
const shell = require( 'shelljs' );
10+
11+
module.exports = (blockDir) => {
12+
shell.cd( blockDir );
13+
shell.touch( '.gitignore' );
14+
15+
// Build a default .gitignore
16+
const ignore = [
17+
'node_modules\n',
18+
'## Uncomment line below if you prefer to',
19+
'## keep compiled files out of version control',
20+
'# dist/'
21+
].join('\n');
22+
23+
return new Promise( async resolve => {
24+
await fs.writeFileSync(
25+
path.join( process.cwd(), '.gitignore' ),
26+
ignore + '\n'
27+
);
28+
resolve( true );
29+
} );
30+
};

‎packages/create-guten-block/app/createPluginDir.js‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ const chalk = require( 'chalk' );
1111
const shell = require( 'shelljs' );
1212
const clearConsole = require( './consoleClear' );
1313
const directoryExists = require( 'directory-exists' );
14+
const createGitignore = require( './createGitignore' );
1415

15-
module.exports = blockName => {
16+
module.exports = ( blockName, blockDir ) => {
1617
// Check if the plugin dir is already presnet.
1718
const dirAlreadyExist = directoryExists.sync( `./${ blockName }` );
1819

@@ -40,11 +41,11 @@ module.exports = blockName => {
4041
);
4142
process.exit( 1 );
4243
} else {
43-
return new Promise( resolve => {
44+
return new Promise( async resolve => {
4445
// Where user is at the moment.
45-
shell.exec( `mkdir -p ${ blockName }`, () => {
46-
resolve( true );
47-
} );
46+
shell.exec( `mkdir -p ${ blockName }` );
47+
await createGitignore( blockDir );
48+
resolve(true);
4849
} );
4950
}
5051
};

‎packages/create-guten-block/app/run.js‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ module.exports = async() => {
2626
// 1. Set the CLI and get the blockName.
2727
const blockName = cli();
2828

29-
// 2. Build the block direcotry path.
29+
// 2. Build the block directory path.
3030
const blockDir = await getBlockDir( blockName );
3131

3232
// 2. Pre print.
@@ -41,11 +41,10 @@ module.exports = async() => {
4141
` ${ blockName } `
4242
) }`
4343
);
44-
await createPluginDir( blockName );
44+
await createPluginDir( blockName, blockDir );
4545
spinner.succeed();
4646

4747
// 4. NPM install cgb-scripts.
48-
4948
spinner.start( '2. Installing npm packages...' );
5049
await npmInstallScripts( blockName, blockDir );
5150
spinner.succeed();

0 commit comments

Comments
 (0)