|
| 1 | +/** |
| 2 | + * Copyright (C) 2022 Jen-Chieh Shen |
| 3 | + * |
| 4 | + * This program is free software; you can redistribute it and/or modify |
| 5 | + * it under the terms of the GNU General Public License as published by |
| 6 | + * the Free Software Foundation; either version 3, or (at your option) |
| 7 | + * any later version. |
| 8 | + * |
| 9 | + * This program is distributed in the hope that it will be useful, |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + * GNU General Public License for more details. |
| 13 | + * |
| 14 | + * You should have received a copy of the GNU General Public License |
| 15 | + * along with GNU Emacs; see the file COPYING. If not, write to the |
| 16 | + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 17 | + * Boston, MA 02110-1301, USA. |
| 18 | + */ |
| 19 | + |
| 20 | +"use strict"; |
| 21 | + |
| 22 | +const init = require('./init'); |
| 23 | +const child_process = require('child_process'); |
| 24 | + |
| 25 | +exports.command = ['create [name]', 'new [name]']; |
| 26 | +exports.desc = 'create a new elisp project'; |
| 27 | +exports.builder = { |
| 28 | + name: { |
| 29 | + description: 'new project name', |
| 30 | + requiresArg: false, |
| 31 | + type: 'string', |
| 32 | + }, |
| 33 | +}; |
| 34 | + |
| 35 | +const TEMPLATE_URL = 'https://github.com/emacs-eask/template-elisp'; |
| 36 | + |
| 37 | +exports.handler = async (argv) => { |
| 38 | + const project_name = argv.name; |
| 39 | + |
| 40 | + let proc = child_process.spawn('git', ['clone', TEMPLATE_URL, project_name], |
| 41 | + { stdio: 'inherit' }); |
| 42 | + |
| 43 | + // You would just need to register the error event, or else it can't print |
| 44 | + // the help instruction below. |
| 45 | + proc.on('error', function () { }); |
| 46 | + |
| 47 | + proc.on('close', function (code) { |
| 48 | + if (code == 0) { |
| 49 | + console.log('✓ Done cloning the template project'); |
| 50 | + process.chdir(project_name); |
| 51 | + cloned(argv); |
| 52 | + return; |
| 53 | + } |
| 54 | + // Help instruction here! |
| 55 | + console.log('✗ Error while cloning template project'); |
| 56 | + console.log(''); |
| 57 | + console.log(' [1] Make sure you have git installed and has the right permission'); |
| 58 | + process.stdout.write(` [2] Failed because of the target directory isn't empty`); |
| 59 | + }); |
| 60 | +}; |
| 61 | + |
| 62 | + |
| 63 | +/* Operations after cloned */ |
| 64 | +async function cloned(argv) { |
| 65 | + await init.create_eask_file(); |
| 66 | + UTIL.e_call(argv, 'core/create'); |
| 67 | +} |
0 commit comments