Skip to content

Commit

Permalink
Merge pull request ksky521#194 from leeqiang/refactor/es6-and-yarn
Browse files Browse the repository at this point in the history
refactor: add es6 & yarn support
  • Loading branch information
ksky521 authored Feb 5, 2018
2 parents c825aea + 2819eae commit 5c64755
Show file tree
Hide file tree
Showing 10 changed files with 2,552 additions and 1,354 deletions.
215 changes: 103 additions & 112 deletions bin/nodeppt
Original file line number Diff line number Diff line change
@@ -1,130 +1,121 @@
#!/usr/bin/env node

var fs = require('fs');
var path = require('path');
var nodeppt = require('../lib/nodeppt');
var versions = require('../package').version;
var program = require('commander');
var ipv4 = require('ipv4');
const nodeppt = require('../lib/nodeppt')
const versions = require('../package').version
const program = require('commander')
const ipv4 = require('ipv4')
if (process.argv[2] && process.argv[2] === '-v') {
process.argv[2] = '-V';
process.argv[2] = '-V'
}
program
.version(versions);
.version(versions)

program
.command('create')
.alias('new')
.usage('[filename] [option]')
.description('create a slide')
.option('-d, --dir [path]', 'set slide file destination path')
.action(function (filename, options) {
if (typeof filename === 'object') {
console.log('ERROR: please input filename!'.bold.red);
this.outputHelp();
return;
}

nodeppt.create(filename, options)
}).on('--help', function () {
console.log(' Examples:');
console.log();
console.log(' nodeppt create myslide');
console.log(' nodeppt create myslide -d D:/webppt');
console.log();
});

function assetPathWarn(){
console.warn('The asset-path params will be ignored when output all files.');
.command('create')
.alias('new')
.usage('[filename] [option]')
.description('create a slide')
.option('-d, --dir [path]', 'set slide file destination path')
.action(function (filename, options) {
if (typeof filename === 'object') {
console.log('ERROR: please input filename!'.bold.red)
this.outputHelp()
return
}
nodeppt.create(filename, options)
}).on('--help', function () {
console.log(' Examples:')
console.log()
console.log(' nodeppt create myslide')
console.log(' nodeppt create myslide -d D:/webppt')
console.log()
})

function assetPathWarn () {
console.warn('The asset-path params will be ignored when output all files.')
}

program
.command('generate')
.alias('release')
.usage('[file_path] [save_path]')
.description('export html file')
.option('-a, --all [false]', 'output all style(include js,css) file', false)
.option('-p, --asset-path [path]','set the relative path of html to assets(in website), ignored when -a is specified','.')
.action(function (cmd, output, options) {
var filename = '';
var shouldAll = false;
var path = '';
if (typeof output !== 'string') {
options = output;
output = undefined;
}

if (typeof cmd === 'string') {
filename = cmd;
shouldAll = options.all;
if (options.assetPath && shouldAll ) {
assetPathWarn();
} else {
path = options.assetPath;
}
} else if (typeof cmd === 'object') {
shouldAll = cmd.all;
output = cmd.output;
if (cmd.assetPath && shouldAll ) {
assetPathWarn();
} else {
path = cmd.assetPath;
}
}

nodeppt.generate(filename, output, shouldAll, path || '');
})
.on('--help', function () {
console.log(' Examples:');
console.log();
console.log(' nodeppt generate /markdown/path.md /output/path');
console.log(' nodeppt generate /markdown/path.md /output/path -a');
console.log(' nodeppt generate /markdown/path.md /output/path -p ../lib/nodeppt');
console.log();
});

.command('generate')
.alias('release')
.usage('[file_path] [save_path]')
.description('export html file')
.option('-a, --all [false]', 'output all style(include js,css) file', false)
.option('-p, --asset-path [path]', 'set the relative path of html to assets(in website), ignored when -a is specified', '.')
.action(function (cmd, output, options) {
var filename = ''
var shouldAll = false
var path = ''
if (typeof output !== 'string') {
options = output
output = undefined
}

if (typeof cmd === 'string') {
filename = cmd
shouldAll = options.all
if (options.assetPath && shouldAll) {
assetPathWarn()
} else {
path = options.assetPath
}
} else if (typeof cmd === 'object') {
shouldAll = cmd.all
output = cmd.output
if (cmd.assetPath && shouldAll) {
assetPathWarn()
} else {
path = cmd.assetPath
}
}

nodeppt.generate(filename, output, shouldAll, path || '')
})
.on('--help', function () {
console.log(' Examples:')
console.log()
console.log(' nodeppt generate /markdown/path.md /output/path')
console.log(' nodeppt generate /markdown/path.md /output/path -a')
console.log(' nodeppt generate /markdown/path.md /output/path -p ../lib/nodeppt')
console.log()
})

program
.command('start')
.description('start local sever show slide')
.option('-d, --dir [dir]', 'set slide path', '')
.option('-p, --port [port]', 'set server port ', 8080)
.option('-c, --controller [socket]', 'support websocket mutil screen controller')
.option('-H, --host [host]', 'set host address', ipv4 || '0.0.0.0')
.option('-w, --watch', 'livereload')
.action(function (cmd) {
if (typeof cmd !== 'object') {
this.outputHelp();
return;
}

nodeppt.start(cmd)
})
.on('--help', function () {
console.log(' Examples:');
console.log();
console.log(' nodeppt start -d D:/webppt -p 8080');
console.log(' nodeppt start -d D:/webppt -c socket');
console.log();
});

.command('start')
.description('start local sever show slide')
.option('-d, --dir [dir]', 'set slide path', '')
.option('-p, --port [port]', 'set server port ', 8080)
.option('-c, --controller [socket]', 'support websocket mutil screen controller')
.option('-H, --host [host]', 'set host address', ipv4 || '0.0.0.0')
.option('-w, --watch', 'livereload')
.action(function (cmd) {
if (typeof cmd !== 'object') {
this.outputHelp()
return
}
nodeppt.start(cmd)
})
.on('--help', function () {
console.log(' Examples:')
console.log()
console.log(' nodeppt start -d D:/webppt -p 8080')
console.log(' nodeppt start -d D:/webppt -c socket')
console.log()
})

program
.command('pdf')
.description('export pdf file. ' + 'Deprecated'.bold.red)
.action(function (http_url, save_path) {
console.log(' Warning: '.bold.red + 'This command has been ' + 'Removed'.bold.red);
})
.on('--help', function () {
console.log(' Warning: '.bold.red + 'This command has been ' + 'Removed'.bold.red);
});



program.parse(process.argv);
.command('pdf')
.description('export pdf file. ' + 'Deprecated'.bold.red)
.action(function (httpUrl, savePath) {
console.log(' Warning: '.bold.red + 'This command has been ' + 'Removed'.bold.red)
})
.on('--help', function () {
console.log(' Warning: '.bold.red + 'This command has been ' + 'Removed'.bold.red)
})

program.parse(process.argv)

if (!program.args[0]) {
process.stdout.write(program.helpInformation());
program.emit('--help');
process.stdout.write(program.helpInformation())
program.emit('--help')
}
69 changes: 34 additions & 35 deletions lib/copy.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,38 @@
var fs = require('fs');
var path = require('path');
const path = require('path')

var libDir = __dirname + path.sep;
var $ = require('./helper');
var rootDir = path.join(libDir, '../') + path.sep;
const libDir = path.join(__dirname, path.sep)
const $ = require('./helper')
const rootDir = path.join(libDir, '../', path.sep)

module.exports = function(destDir) {
destDir = $.getDirPath(destDir);
var assetsDir = rootDir + 'assets';
//复制assets文件夹
$.copy(assetsDir, path.join(destDir, 'assets'), function(filename, dir, subdir) {
if (!subdir) {
module.exports = function (destDir) {
destDir = $.getDirPath(destDir)
let assetsDir = rootDir + 'assets'
// 复制assets文件夹
$.copy(assetsDir, path.join(destDir, 'assets'), function (filename, dir, subdir) {
if (!subdir) {
return false
}
return true
})
// 复制template文件夹
$.copy(rootDir + 'template', path.join(destDir, 'template'), function (filename, dir, subdir) {
if (!subdir && filename === 'default.ejs') {
return false
}
return true
})
// 复制ppts文件夹
$.copy(rootDir + 'ppts', path.join(destDir, 'ppts'), function (filename, dir, subdir) {
if (!subdir && filename === 'demo.html') {
return false
}
return true
})

return false;
}
return true;
});
//复制template文件夹
$.copy(rootDir + 'template', path.join(destDir, 'template'), function(filename, dir, subdir) {
if (!subdir && filename === 'default.ejs') {
return false;
}
return true;
});
//复制ppts文件夹
$.copy(rootDir + 'ppts', path.join(destDir, 'ppts'), function(filename, dir, subdir) {
if (!subdir && filename === 'demo.html') {
return false;
}
return true;
});

//复制config.json
['config.json'].map(function(filename) {
filepath = rootDir + filename;
$.copy(filepath, path.join(destDir, filename));
});
// 复制 config.json
let configs = ['config.json']
configs.map(function (filename) {
let filepath = path.join(rootDir, filename)
$.copy(filepath, path.join(destDir, filename))
})
}
Loading

0 comments on commit 5c64755

Please sign in to comment.