From 5d62398f5965a98864dc171dde1aa4fcacb6297e Mon Sep 17 00:00:00 2001 From: Liu Date: Sat, 8 May 2021 23:14:10 +0800 Subject: [PATCH] feat: add setup command --- bin/lcui.js | 6 ++++++ lib/create.js | 8 +++----- lib/setup.js | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 5 deletions(-) create mode 100644 lib/setup.js diff --git a/bin/lcui.js b/bin/lcui.js index 053c105..215d042 100755 --- a/bin/lcui.js +++ b/bin/lcui.js @@ -3,6 +3,7 @@ const program = require('commander'); const logger = require('../lib/logger'); const { create } = require('../lib/create'); +const { setup } = require('../lib/setup'); const { generate } = require('../lib/generator'); const { compile } = require('../lib/compiler'); const { build, run } = require('../lib/builder'); @@ -29,6 +30,11 @@ program .description('generate files with template of specified type') .action(wrapAction(generate)); +program + .command('setup') + .description('set up the development environment for the current project') + .action(wrapAction(setup)); + program .command('compile ') .description('compile config file of the specified type to C code') diff --git a/lib/create.js b/lib/create.js index 36c4814..4994769 100644 --- a/lib/create.js +++ b/lib/create.js @@ -5,7 +5,6 @@ const path = require('path'); const chalk = require('chalk'); const got = require('got'); const decompress = require('decompress'); -const { execSync } = require('child_process'); const cliProgress = require('cli-progress'); const simplegit = require('simple-git/promise'); @@ -76,15 +75,14 @@ class Creator { console.log('Skipped git commit due to missing username and email in git config.'); console.log('You will need to perform the initial commit yourself.'); } - console.log('Install dependencies'); - execSync('npm install --silent', { cwd: this.dir, stdio: 'inherit' }); console.log(`Successfully created project ${chalk.yellow(this.name)}.`); console.log('Get started with the following commands:\n'); if (this.dir !== process.cwd()) { console.log(chalk.cyan(` ${chalk.gray('$')} cd ${this.name}`)); } - console.log(chalk.cyan(` ${chalk.gray('$')} lcpkg install`)); - console.log(chalk.cyan(` ${chalk.gray('$')} lcpkg run start\n`)); + console.log(chalk.cyan(` ${chalk.gray('$')} lcui setup`)); + console.log(chalk.cyan(` ${chalk.gray('$')} lcui build`)); + console.log(chalk.cyan(` ${chalk.gray('$')} lcui run\n`)); } async run() { diff --git a/lib/setup.js b/lib/setup.js new file mode 100644 index 0000000..a4af968 --- /dev/null +++ b/lib/setup.js @@ -0,0 +1,38 @@ +const fs = require('fs'); +const path = require('path'); +const { execSync } = require('child_process'); +const chalk = require('chalk'); +const logger = require('./logger'); +const { generate } = require('./generator'); + +function installDependencies() { + const scriptFile = path.resolve(process.cwd(), 'setup.sh'); + + logger.log(`\n${chalk.grey('[setup::dependencies]')}`); + if (process.platform === 'win32') { + if (execSync('lcpkg --version')) { + logger.log('> lcpkg install\n'); + execSync('lcpkg install', { stdio: 'inherit' }); + } else { + logger.warning('lcpkg is missing'); + } + } else if (fs.existsSync(scriptFile)) { + logger.log(`> sh ${scriptFile}\n`); + execSync(`sh ${scriptFile}`, { stdio: 'inherit' }); + } +} + +function generateMakefiles() { + logger.log(`\n${chalk.grey('[setup::makefiles]')}`); + generate('makefile', 'xmake'); + generate('makefile', 'cmake'); +} + +function setup() { + installDependencies(); + generateMakefiles(); +} + +module.exports = { + setup +};