Sha256: 74f4dfd8d83919a718854d6adbcb5ac770a60e635ec13100a1cb22b0e5e15b22

Contents?: true

Size: 1.16 KB

Versions: 2

Compression:

Stored size: 1.16 KB

Contents

require 'commander'
require_relative '../lib/generator'
require_relative '../lib/setup'

module SiteCommand
	def site(c)
		c.syntax = 'm2m site [options]'
		c.summary = ''
		c.description = ''
		c.option '-s STRING', '--source STRING', String, 'Markdown源文件的目录'
		c.option '-t STRING', '--target STRING', String, '生成的目标目录'
		c.option '--force', String, '强行生成,如果目录存在,则会被删除'
		c.option '--git', String, '提交到git仓库'
		c.action do |args, options|
			target = options.target
			source = options.source


			util = Util.instance
			setup = Setup.instance

			#合并目录
			util.workbench = util.get_merge_path(source)
			#设置构建目录
			setup.target_dir = target

			#检查目标目录是否存在
			if File::exists? setup.target_dir
				question = "目标目录已经存在,您确认需要删除吗?[y/n]"
				tips = "目标目录存在,生成失败"
				util.error tips if not (options.force or agree question)
			end

			#执行生成
			Generator.new

			if options.git
				command = "cd #{util.workbench} && git add . && git commit -m 'update by m2m' && git push";
				exec command
			end
		end
	end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
m2m-0.2.3 exe/site.rb
m2m-0.2.1 exe/site.rb