Skip to content

Commit

Permalink
feat: add setup command
Browse files Browse the repository at this point in the history
  • Loading branch information
lc-soft committed May 8, 2021
1 parent 1102cbf commit 5d62398
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 5 deletions.
6 changes: 6 additions & 0 deletions bin/lcui.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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 <type>')
.description('compile config file of the specified type to C code')
Expand Down
8 changes: 3 additions & 5 deletions lib/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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() {
Expand Down
38 changes: 38 additions & 0 deletions lib/setup.js
Original file line number Diff line number Diff line change
@@ -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
};

0 comments on commit 5d62398

Please sign in to comment.