UNPKG

ccos-cli

Version:

This is a command line interface toolkit. It is used for generating and managing example code for CoocaaOS running on Skyworth/Coocaa TV webos API.

149 lines (130 loc) 8.83 kB
const fse = require('fs-extra'); const path = require('path'); const ora = require('ora') const chalk = require('chalk') module.exports = function (dir, options) { dir = dir || '.'; const spinner = ora('creating the project...\n\n') spinner.start() if (options.tool === 'webpack') { generateWebpackTemplProject(dir, options); } else if(options.tool === 'gulp') { generateGulpTemplProject(dir, options); } else { generateFisTemplProject(dir, options); } spinner.stop(); console.log(chalk.cyan('\n Create complete.\n')) if (options.tool === 'gulp') { console.log(chalk.yellow( ' Tip: gulp构建的项目暂不可用, 敬请期待!\n' )) } else { console.log(chalk.yellow( ' Tip: cd ' + dir + ' && npm install \n' )) } } function generateFisTemplProject(dir, options) { generateProjectDir(dir, options); let sourceDir = "../templ/fis/src/"; let binDir = "../templ/fis/bin/"; let configDir = "../templ/fis/config/"; let onlineEditDir = "../tools/online-edit/" if(options && (options.b === '2.0' || options.build === '2.0')) { console.log(chalk.cyan(' create index.html')); fse.copyFileSync(path.resolve(__dirname, sourceDir, 'index-2.0.html'), path.resolve(dir, 'src', 'index.html')); console.log(chalk.cyan(' create js/ccsdk-2.0.js')); fse.copyFileSync(path.resolve(__dirname, sourceDir, 'js', 'ccsdk-2.0.js'), path.resolve(dir, 'src/js', 'ccsdk-2.0.js')); console.log(chalk.cyan(' create js/index.js')); fse.copyFileSync(path.resolve(__dirname, sourceDir, 'js', 'index-2.0.js'), path.resolve(dir, 'src/js', 'index.js')); } else { console.log(chalk.cyan(' create index.html')); fse.copyFileSync(path.resolve(__dirname, sourceDir, 'index-1.0.html'), path.resolve(dir, 'src', 'index.html')); console.log(chalk.cyan(' create js/ccsdk-1.0.js')); fse.copyFileSync(path.resolve(__dirname, sourceDir, 'js', 'ccsdk-1.0.js'), path.resolve(dir, 'src/js', 'ccsdk-1.0.js')); console.log(chalk.cyan(' create js/ccsdk-common-1.0.js')); fse.copyFileSync(path.resolve(__dirname, sourceDir, 'js', 'ccsdk-common-1.0.js'), path.resolve(dir, 'src/js', 'ccsdk-common-1.0.js')); console.log(chalk.cyan(' create js/index.js')); fse.copyFileSync(path.resolve(__dirname, sourceDir, 'js', 'index-1.0.js'), path.resolve(dir, 'src/js', 'index.js')); } console.log(chalk.cyan(' create index.css')); fse.copyFileSync(path.resolve(__dirname, sourceDir, 'css', 'index.css'), path.resolve(dir, 'src/css', 'index.css')); console.log(chalk.cyan(' create logo.png')); fse.copyFileSync(path.resolve(__dirname, sourceDir, 'images', 'logo.png'), path.resolve(dir, 'src/images', 'logo.png')); console.log(chalk.cyan(' create js/ccmap-2.1.js')); fse.copyFileSync(path.resolve(__dirname, sourceDir, 'js', 'ccmap-2.1.js'), path.resolve(dir, 'src/js', 'ccmap-2.1.js')); console.log(chalk.cyan(' create js/jquery-1.8.3.min.js')); fse.copyFileSync(path.resolve(__dirname, sourceDir, 'js', 'jquery-1.8.3.min.js'), path.resolve(dir, 'src/js', 'jquery-1.8.3.min.js')); console.log(chalk.cyan(' create bin/www')); fse.copyFileSync(path.resolve(__dirname, binDir, 'www'), path.resolve(dir, 'bin', 'www')); console.log(chalk.cyan(' create bin/upload')); fse.copyFileSync(path.resolve(__dirname, binDir, 'upload'), path.resolve(dir, 'bin', 'upload')); console.log(chalk.cyan(' create bin/deploy')); fse.copyFileSync(path.resolve(__dirname, binDir, 'deploy.sh'), path.resolve(dir, 'bin', 'deploy.sh')); console.log(chalk.cyan(' create config/index.js')); fse.copyFileSync(path.resolve(__dirname, configDir, 'index.js'), path.resolve(dir, 'config', 'index.js')); console.log(chalk.cyan(' create package.json')); fse.copyFileSync(path.resolve(__dirname, configDir, 'package.json'), path.resolve(dir, 'package.json')); console.log(chalk.cyan(' create fis-conf.js')); fse.copyFileSync(path.resolve(__dirname, configDir, 'fis-conf.js'), path.resolve(dir, 'src', 'fis-conf.js')); console.log(chalk.cyan(' create online-edit')); fse.copyFileSync(path.resolve(__dirname, binDir, 'online'), path.resolve(dir, 'bin', 'online')); fse.copyFileSync(path.resolve(__dirname, onlineEditDir, 'ccmap-2.1.js'), path.resolve(dir, 'bin/online-edit', 'ccmap-2.1.js')); fse.copyFileSync(path.resolve(__dirname, onlineEditDir, 'index.html'), path.resolve(dir, 'bin/online-edit', 'index.html')); fse.copyFileSync(path.resolve(__dirname, onlineEditDir, 'index.js'), path.resolve(dir, 'bin/online-edit', 'index.js')); fse.copyFileSync(path.resolve(__dirname, onlineEditDir, 'jquery-1.8.3.min.js'), path.resolve(dir, 'bin/online-edit', 'jquery-1.8.3.min.js')); } function generateWebpackTemplProject (dir, options) { generateProjectDir(dir, options); fse.mkdirsSync(path.resolve(dir, 'src/framework')); fse.mkdirsSync(path.resolve(dir, 'src/vendor')); let sourceDir = "../templ/webpack/src/"; let binDir = "../templ/webpack/bin/"; let configDir = "../templ/webpack/config/"; console.log(chalk.cyan(' create index.html')); fse.copyFileSync(path.resolve(__dirname, sourceDir, 'index.html'), path.resolve(dir, 'src', 'index.html')); console.log(chalk.cyan(' create common.css')); fse.copyFileSync(path.resolve(__dirname, sourceDir, 'css', 'common.css'), path.resolve(dir, 'src/css', 'common.css')); console.log(chalk.cyan(' create index.scss')); fse.copyFileSync(path.resolve(__dirname, sourceDir, 'css', 'index.scss'), path.resolve(dir, 'src/css', 'index.scss')); console.log(chalk.cyan(' create logo.png')); fse.copyFileSync(path.resolve(__dirname, sourceDir, 'images', 'logo.png'), path.resolve(dir, 'src/images', 'logo.png')); console.log(chalk.cyan(' create bg.jpg')); fse.copyFileSync(path.resolve(__dirname, sourceDir, 'images', 'bg.jpg'), path.resolve(dir, 'src/images', 'bg.jpg')); //console.log(chalk.cyan(' create ccsdk')); //fse.copyFileSync(path.resolve(__dirname, sourceDir, 'js', 'ccmap-2.1.js'), path.resolve(dir, 'src/framework', 'ccmap-2.1.js')); //fse.copyFileSync(path.resolve(__dirname, sourceDir, 'js', 'ccsdk-1.0.js'), path.resolve(dir, 'src/framework', 'ccsdk-1.0.js')); //fse.copyFileSync(path.resolve(__dirname, sourceDir, 'js', 'ccsdk-common-1.0.js'), path.resolve(dir, 'src/framework', 'ccsdk-common-1.0.js')); console.log(chalk.cyan(' create js/index.js')); fse.copyFileSync(path.resolve(__dirname, sourceDir, 'js', 'index.js'), path.resolve(dir, 'src/js', 'index.js')); fse.copyFileSync(path.resolve(__dirname, sourceDir, 'js', 'index.ts'), path.resolve(dir, 'src/js', 'index.ts')); //console.log(chalk.cyan(' create jquery-1.8.3.min.js')); //fse.copyFileSync(path.resolve(__dirname, sourceDir, 'js', 'jquery-1.8.3.min.js'), path.resolve(dir, 'src/vendor', 'jquery-1.8.3.min.js')); console.log(chalk.cyan(' create bin/www')); fse.copyFileSync(path.resolve(__dirname, binDir, 'www'), path.resolve(dir, 'bin', 'www')); console.log(chalk.cyan(' create bin/upload')); fse.copyFileSync(path.resolve(__dirname, binDir, 'upload'), path.resolve(dir, 'bin', 'upload')); console.log(chalk.cyan(' create bin/deploy')); fse.copyFileSync(path.resolve(__dirname, binDir, 'deploy.sh'), path.resolve(dir, 'bin', 'deploy.sh')); console.log(chalk.cyan(' create config/index.js')); fse.copyFileSync(path.resolve(__dirname, configDir, 'index.js'), path.resolve(dir, 'config', 'index.js')); console.log(chalk.cyan(' create package.json')); fse.copyFileSync(path.resolve(__dirname, configDir, 'package.json'), path.resolve(dir, 'package.json')); console.log(chalk.cyan(' create webpack.config.js')); fse.copyFileSync(path.resolve(__dirname, configDir, 'webpack.config.js'), path.resolve(dir, 'webpack.config.js')); fse.copyFileSync(path.resolve(__dirname, configDir, '.babelrc'), path.resolve(dir, '.babelrc')); fse.copyFileSync(path.resolve(__dirname, configDir, '.eslintrc.js'), path.resolve(dir, '.eslintrc.js')); fse.copyFileSync(path.resolve(__dirname, configDir, 'tsconfig.json'), path.resolve(dir, 'tsconfig.json')); } function generateGulpTemplProject (dir, options) { } function generateProjectDir (dir, options) { console.log(chalk.cyan(' create dir')); fse.mkdirsSync(path.resolve(dir, 'src/css')); fse.mkdirsSync(path.resolve(dir, 'src/js')); fse.mkdirsSync(path.resolve(dir, 'src/images')); fse.mkdirsSync(path.resolve(dir, 'bin')); fse.mkdirsSync(path.resolve(dir, 'bin/online-edit')); fse.mkdirsSync(path.resolve(dir, 'config')); }