diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..48f9944 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,24 @@ + + +##### Checklist + + +- [ ] `npm test` passes +- [ ] tests and/or benchmarks are included +- [ ] documentation is changed or added +- [ ] commit message follows commit guidelines + +##### Affected core subsystem(s) + + + +##### Description of change + diff --git a/.gitignore b/.gitignore index bff0d38..fea4248 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,5 @@ run .idea .DS_Store .tmp +.vscode +yarn.lock \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 1651002..bdf6f64 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,9 @@ sudo: false language: node_js node_js: - - '4' - '6' - '8' + - '10' install: - npm i npminstall && npminstall script: diff --git a/appveyor.yml b/appveyor.yml index 56f601f..3d15e52 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,6 +1,5 @@ environment: matrix: - - nodejs_version: '4' - nodejs_version: '6' - nodejs_version: '8' diff --git a/lib/init_command.js b/lib/init_command.js index 9c06343..efd8cc0 100644 --- a/lib/init_command.js +++ b/lib/init_command.js @@ -9,9 +9,7 @@ const updater = require('npm-updater'); const mkdirp = require('mkdirp'); const inquirer = require('inquirer'); const yargs = require('yargs'); -const memFs = require('mem-fs'); -const editor = require('mem-fs-editor'); -const glob = require('glob'); +const glob = require('globby'); const is = require('is-type-of'); const homedir = require('node-homedir'); const compressing = require('compressing'); @@ -243,24 +241,21 @@ module.exports = class Command { * processFiles(targetDir, templateDir) { const src = path.join(templateDir, 'boilerplate'); const locals = yield this.askForVariable(targetDir, templateDir); - const fsEditor = editor.create(memFs.create()); - const files = glob.sync('**/*', { cwd: src, dot: true, nodir: true }); + const files = glob.sync('**/*', { cwd: src, dot: true }); files.forEach(file => { const from = path.join(src, file); const to = path.join(targetDir, this.replaceTemplate(this.fileMapping[file] || file, locals)); - fsEditor.copy(from, to, { - process: (content, filePath) => { - this.log('write to %s', to); - if (isTextOrBinary.isTextSync(filePath, content)) { // check if filepath's content is a text file - return this.replaceTemplate(content, locals); - } - return content; - }, - }); - }); + const content = fs.readFileSync(from, { encoding: 'utf-8' }); + this.log('write to %s', to); - // write file to disk - yield new Promise(resolve => fsEditor.commit(resolve)); + // check if content is a text file + const result = isTextOrBinary.isTextSync(from, content) + ? this.replaceTemplate(content, locals) + : content; + + mkdirp.sync(path.dirname(to)); + fs.writeFileSync(to, result); + }); return files; } diff --git a/package.json b/package.json index de4c536..191a237 100644 --- a/package.json +++ b/package.json @@ -20,28 +20,26 @@ ], "dependencies": { "co": "^4.6.0", - "colors": "^1.3.2", - "compressing": "^1.3.1", + "colors": "^1.3.3", + "compressing": "^1.4.0", "egg-init-config": "^1.5.0", - "glob": "^7.1.3", + "globby": "^9.0.0", "inquirer": "^3.3.0", "is-type-of": "^1.2.1", - "istextorbinary": "^2.3.0", - "mem-fs": "^1.1.3", - "mem-fs-editor": "^4.0.3", + "istextorbinary": "^2.5.1", "mkdirp": "^0.5.1", "mz-modules": "^2.1.0", "node-homedir": "^1.1.1", "npm-updater": "^3.0.3", "proxy-agent": "^2.3.1", - "urllib": "^2.31.2", + "urllib": "^2.33.0", "yargs": "^11.1.0" }, "devDependencies": { "autod": "^3.0.1", "coffee": "^3.3.0", "egg-bin": "^1.11.1", - "egg-ci": "^1.10.0", + "egg-ci": "^1.11.0", "eslint": "^4.19.1", "eslint-config-egg": "^6.0.0", "mm": "^2.4.1", diff --git a/test/init.test.js b/test/init.test.js index e08c0b8..c072052 100644 --- a/test/init.test.js +++ b/test/init.test.js @@ -74,4 +74,15 @@ describe('test/init.test.js', () => { assert(command.replaceTemplate('hi, {{ user }}', {}) === 'hi, {{ user }}'); assert(command.replaceTemplate('hi, \\{{ user }}', { user: 'egg' }) === 'hi, {{ user }}'); }); + + it('should works with remote boilerplate', function* () { + yield command.run(tmp, [ 'simple-app', '--type=simple', '--silent' ]); + + assert(fs.existsSync(path.join(command.targetDir, '.gitignore'))); + assert(fs.existsSync(path.join(command.targetDir, '.eslintrc'))); + assert(fs.existsSync(path.join(command.targetDir, 'package.json'))); + assert(fs.existsSync(path.join(command.targetDir, 'package.json'))); + assert(fs.existsSync(path.join(command.targetDir, 'test/app/controller/home.test.js'))); + assert(fs.existsSync(path.join(command.targetDir, 'app/controller/home.js'))); + }); });