create-native-di
Version:
cli สำหรับ react native ที่มีตัวอย่างโครงสร้างพื้นฐานพร้อมใช้งานประกอบไปด้วย package หลักๆ เช่น mobx,moment,lodash และรองรับภาษา javascript es6 และมี di สำหรับสลับ Store ที่จะติดต่อ api กับ fake mockup ที่สร้างขึ้นเอง ^^
71 lines (64 loc) • 2 kB
JavaScript
require('shelljs/global');
const path = require('path');
const fs = require('fs');
const figlet = require('figlet');
const chalk = require('chalk');
const execSync = require('child_process').execSync;
const spawn = require('cross-spawn');
function shouldUseYarn() {
try {
execSync('yarnpkg --version', { stdio: 'ignore' });
return true;
} catch (e) {
return false;
}
}
const installPackages = () => {
console.log(chalk.white.bold('Installing Packages'));
return new Promise((resolve, reject) => {
let command;
let args = ['install'];
if (shouldUseYarn()) {
command = 'yarn';
} else {
command = 'npm';
}
const child = spawn(command, args, { stdio: 'inherit' });
child.on('close', code => {
if (code !== 0) {
reject({
command: `${command} ${args.join(' ')}`
});
return;
}
resolve();
})
})
}
const build = (appName) => {
cp('-r', __dirname + '/../src/.', appName);
console.log('----------------------------------------------------------');
figlet('create-native-di', function(err, data) {
if (err) {
return;
}
console.log(data);
console.log('----------------------------------------------------------');
console.log(chalk.white.bold('Welcome to create-native-di'));
console.log('----------------------------------------------------------');
cd(appName);
installPackages().then(() => {
console.log(chalk.white.bold('Let\'s get started'));
console.log(chalk.green('Step 1: cd into the newly created ' + appName + ' directory'));
console.log('----------------------------------------------------------');
// add your own custom messages here.
console.log('----------------------------------------------------------');
})
.catch(error => {
console.log(chalk.red('An unexpected error occurred'))
console.log(chalk.red(error));
});
});
}
module.exports = build;