Repository: Yoctol/bottender
Pull request #81 (2017-12-05 08:48:35)

Create README and .gitignore after init


Patch:
diff --git a/src/cli/providers/sh/init/index.js b/src/cli/providers/sh/init/index.js
index 9c982c69..4a306b9d 100644
--- a/src/cli/providers/sh/init/index.js
+++ b/src/cli/providers/sh/init/index.js
@@ -209,6 +209,16 @@ const run = async (root, botName, answer, useYarn) => {
         })};`
       );
     }
+
+    const gitignore = fs.readFileSync(
+      path.resolve(__dirname, './template/gitignore')
+    );
+    fs.writeFileSync(path.join(root, '.gitignore'), gitignore);
+
+    const readme = fs.readFileSync(
+      path.resolve(__dirname, './template/README.md')
+    );
+    fs.writeFileSync(path.join(root, 'README.md'), readme);
   } catch (reason) {
     print('');
     print('Aborting installation.');
diff --git a/src/cli/providers/sh/init/template/README.md b/src/cli/providers/sh/init/template/README.md
new file mode 100644
index 00000000..35e810da
--- /dev/null
+++ b/src/cli/providers/sh/init/template/README.md
@@ -0,0 +1,52 @@
+This project was bootstrapped with
+[Bottender](https://github.com/Yoctol/bottender) init script.
+
+## Sending Feedback
+
+Always feel free to open issue to
+[Bottender](https://github.com/Yoctol/bottender/issues).
+
+## Folder Structure
+
+After creation, your project should look like this:
+
+```
+my-bot/
+  .gitignore
+  node_modules/
+  bottender.config.js
+  index.js
+  package.json
+  README.md
+  yarn.lock
+```
+
+### index.js
+
+All functionalities start from here.\
+Mainly it's a server which listen on port 5000. You are encouraged to add more [event listener](https://bottender.js.org/docs/APIReference-Event)
+and [handler](https://bottender.js.org/docs/APIReference-Handler) to enrich the bot.
+
+See more examples, please refer to
+[Bottender examples](https://github.com/Yoctol/bottender/tree/master/examples).
+
+### bottender.config.js
+
+The config file for the bot.\
+We suggests you to put all platform configs into this file and use it as a parameter
+of createServer.
+
+## Available Scripts
+
+There are two default scripts you can run:
+
+### `npm run dev`
+
+Run the bot in the development mode.\
+It will automatically restart the bot if there are any changes in `index.js`.\
+For more information, check [nodemon's repo](https://github.com/remy/nodemon)
+
+### `npm start`
+
+Run the bot without being monitored.\
+The bot won't be restarted when you change anything in `index.js`
diff --git a/src/cli/providers/sh/init/template/gitignore b/src/cli/providers/sh/init/template/gitignore
new file mode 100644
index 00000000..cf42f808
--- /dev/null
+++ b/src/cli/providers/sh/init/template/gitignore
@@ -0,0 +1,63 @@
+# Taken from https://github.com/github/gitignore/blob/master/Node.gitignore
+
+# Logs
+logs
+*.log
+npm-debug.log*
+yarn-debug.log*
+yarn-error.log*
+
+# Runtime data
+pids
+*.pid
+*.seed
+*.pid.lock
+
+# Directory for instrumented libs generated by jscoverage/JSCover
+lib-cov
+
+# Coverage directory used by tools like istanbul
+coverage
+
+# nyc test coverage
+.nyc_output
+
+# jest-junit
+junit.xml
+
+# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
+.grunt
+
+# Bower dependency directory (https://bower.io/)
+bower_components
+
+# node-waf configuration
+.lock-wscript
+
+# Compiled binary addons (https://nodejs.org/api/addons.html)
+build/Release
+
+# Dependency directories
+node_modules/
+jspm_packages/
+
+# Typescript v1 declaration files
+typings/
+
+# Optional npm cache directory
+.npm
+
+# Optional eslint cache
+.eslintcache
+
+# Optional REPL history
+.node_repl_history
+
+# Output of 'npm pack'
+*.tgz
+
+# Yarn Integrity file
+.yarn-integrity
+
+# dotenv environment variables file
+.env


Test patch:
diff --git a/src/cli/providers/sh/__tests__/init.spec.js b/src/cli/providers/sh/__tests__/init.spec.js
index e76412e0..af1ed73d 100644
--- a/src/cli/providers/sh/__tests__/init.spec.js
+++ b/src/cli/providers/sh/__tests__/init.spec.js
@@ -56,16 +56,30 @@ describe('init', () => {
       },
     };
     const root = path.resolve('newbot');
+    const gitignore = fs.readFileSync(
+      path.resolve(__dirname, '../init/template/gitignore')
+    );
+    const readme = fs.readFileSync(
+      path.resolve(__dirname, '../init/template/README.md')
+    );
 
     await init();
 
     expect(process.exit).not.toBeCalled();
-    expect(fs.writeFileSync).lastCalledWith(
+    expect(fs.writeFileSync).toBeCalledWith(
       path.join(root, 'bottender.config.js'),
       `module.exports = ${stringifyObject(botConfig, {
         indent: '  ',
       })};`
     );
+    expect(fs.writeFileSync).toBeCalledWith(
+      path.join(root, '.gitignore'),
+      gitignore
+    );
+    expect(fs.writeFileSync).toBeCalledWith(
+      path.join(root, 'README.md'),
+      readme
+    );
   });
 
   it('should not create bottender.config.js if select console as platform', async () => {