|
| 1 | +/** |
| 2 | + * Copyright (C) 2022-2023 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 child_process = require('child_process'); |
| 23 | + |
| 24 | +const init = require('../core/init'); |
| 25 | + |
| 26 | +exports.command = ['package <name>', 'pkg <name>']; |
| 27 | +exports.desc = 'Create a new package'; |
| 28 | +exports.builder = { |
| 29 | + name: { |
| 30 | + description: 'new project name', |
| 31 | + requiresArg: false, |
| 32 | + type: 'string', |
| 33 | + }, |
| 34 | +}; |
| 35 | + |
| 36 | +const TEMPLATE_URL = 'https://github.com/emacs-eask/template-elisp'; |
| 37 | + |
| 38 | +exports.handler = async (argv) => { |
| 39 | + const project_name = argv.name; |
| 40 | + |
| 41 | + let proc = child_process.spawn('git', ['clone', TEMPLATE_URL, project_name], |
| 42 | + { stdio: 'inherit' }); |
| 43 | + |
| 44 | + // You would just need to register the error event, or else it can't print |
| 45 | + // the help instruction below. |
| 46 | + proc.on('error', function () { }); |
| 47 | + |
| 48 | + proc.on('close', function (code) { |
| 49 | + if (code == 0) { |
| 50 | + console.log('✓ Done cloning the elisp package template'); |
| 51 | + console.log(''); |
| 52 | + process.chdir(project_name); |
| 53 | + _cloned(argv); |
| 54 | + return; |
| 55 | + } |
| 56 | + // Help instruction here! |
| 57 | + console.log('✗ Error while cloning template project'); |
| 58 | + console.log(''); |
| 59 | + console.log(' [1] Make sure you have git installed and has the right permission'); |
| 60 | + process.stdout.write(` [2] Failed because of the target directory isn't empty`); |
| 61 | + }); |
| 62 | +}; |
| 63 | + |
| 64 | +/* Operations after _cloned */ |
| 65 | +async function _cloned(argv) { |
| 66 | + console.log('Initialize the Eask-file for your project...'); |
| 67 | + await init.create_eask_file(); |
| 68 | + UTIL.e_call(argv, 'create/package'); |
| 69 | +} |
0 commit comments