<commit_before># Build plugin for Evothings Studio.
# Author: <NAME>

require './sibling-repos.rb'

$buildTimeStamp = Time.new

def distPackageName
	"EvothingsStudio"
end

def applicationName
	"EvothingsWorkbench"
end

def distCopyright
	"Copyright (c) 2016 Evothings AB"
end

# TODO: Update on new release.
def distVersion
	"2.1.0"
end

# TODO: Update on new release.
def distVersionLabel
	# TODO: Remove alpha/beta label for final release.
	distVersion + "-alpha1"
end

# TODO: Update on new release.
def distPackageVersion
	time = $buildTimeStamp

	timestamp =
		time.year.to_s[-2..-1] +
		time.month.to_s.rjust(2, '0') +
		time.day.to_s.rjust(2, '0') +
		"_" +
		time.hour.to_s.rjust(2, '0') +
		time.min.to_s.rjust(2, '0')

	# TODO: Remove tag for final release.
	distVersion + "-alpha1_" + timestamp
end

def root
	"../"
end

# Destination folder for distribution packages.
def pathDist

	root + distPackageName + "_" + distPackageVersion + "/"
end

# Destination temporary folder for application code.
def pathDistSource
	pathDist + "source/"
end

def cwdName
	File.basename(File.dirname(File.expand_path(__FILE__)))
end

# Source of main HyperReload application code.
def pathSourceHyper
	root + cwdName + "/"
end

# Source file for package.json.
def pathSourcePackageJson
	"./package-template.json"
end

# Source of documentation files.
def pathSourceDoc
	root + "evothings-doc"
end

def nodeWebKitVersion
	"0.12.3"
end

# "node-webkit" for 0.11 and earlier.
# "nwjs" for 0.12.
def nodeWebKitName
	"nwjs"
end

def pathNodeWebkitLinux32
	root + "node-webkit-bin-" + nodeWebKitVersion +
		"/nwjs-v" + nodeWebKitVersion +
		"-linux-ia32/"
end

def pathNodeWebkitLinux64
	root + "node-webkit-bin-" + nodeWebKitVersion +
		"/nwjs-v" + nodeWebKitVersion +
		"-linux-x64/"
end

def pathNodeWebkitWin32
	root + "node-webkit-bin-" + nodeWebKitVersion +
		"/nwjs-v" + nodeWebKitVersion +
		"-win-ia32/"
end

def pathNodeWebkitWin64
	root + "node-webkit-bin-" + nodeWebKitVersion +
		"/nwjs-v" + nodeWebKitVersion +
		"-win-x64/"
end

def pathNodeWebkitMac64
	root + "node-webkit-bin-" + nodeWebKitVersion +
		"/nwjs-v" + nodeWebKitVersion +
		"-osx-x64/"
end

def pathIconsMac64
	if(RUBY_PLATFORM =~ /darwin/)
		return "./build/nw.icns"
	else
		return nil
	end
end

def updateFile(tar, src)
	if(!FileUtils.uptodate?(tar, [src]))
		FileUtils::Verbose.cp(src, tar)
	end
end

def buildOSXIcons
	# Only on OSX.
	if(RUBY_PLATFORM =~ /darwin/)
		osxIcons = [
			16,
			32,
			128,
			256,
			512,
		]
		FileUtils.mkdir_p('build/icon.iconset')
		osxIcons.each do |size|
			updateFile("build/icon.iconset/icon_#{size}x#{size}.png", "#{root}evothings-viewer/config/icons/icon-#{size}.png")
			updateFile("build/icon.iconset/icon_#{size}x#{size}@2x.png", "#{root}evothings-viewer/config/icons/icon-#{size*2}.png")
		end
		sh 'iconutil -c icns --output build/nw.icns build/icon.iconset'
	end
end

def buildGitVersionFile
puts 'buildGitVersionFile'
puts pathDistSource + 'gitVersions.txt'
	open(pathDistSource + 'gitVersions.txt', 'w') do |file|
		([SiblingRepo.new(cwdName)]+siblingRepos).each do |repo|
			path = root+repo.name
			if(!File.exist?("#{path}/.git"))
				raise "Missing source directory: #{path}"
			end
			o = `git --git-dir=#{path}/.git rev-parse HEAD`
			file.puts "#{repo.name}: #{o.strip}"
		end
	end
end

def buildPreProcess
	sh "ruby ./init.rb"
	buildGitVersionFile
	buildOSXIcons
end

# Not used
#def buildDocumentation
#	include FileUtils::Verbose
#	cwd = pwd
#
#	mkdir_p pathDistSource + 'documentation'
#
#	# plugins
#	cd "#{root}evothings-client"<commit_msg>Removed debug printouts.<commit_after># Build plugin for Evothings Studio.
# Author: <NAME>

require './sibling-repos.rb'

$buildTimeStamp = Time.new

def distPackageName
	"EvothingsStudio"
end

def applicationName
	"EvothingsWorkbench"
end

def distCopyright
	"Copyright (c) 2016 Evothings AB"
end

# TODO: Update on new release.
def distVersion
	"2.1.0"
end

# TODO: Update on new release.
def distVersionLabel
	# TODO: Remove alpha/beta label for final release.
	distVersion + "-alpha1"
end

# TODO: Update on new release.
def distPackageVersion
	time = $buildTimeStamp

	timestamp =
		time.year.to_s[-2..-1] +
		time.month.to_s.rjust(2, '0') +
		time.day.to_s.rjust(2, '0') +
		"_" +
		time.hour.to_s.rjust(2, '0') +
		time.min.to_s.rjust(2, '0')

	# TODO: Remove tag for final release.
	distVersion + "-alpha1_" + timestamp
end

def root
	"../"
end

# Destination folder for distribution packages.
def pathDist

	root + distPackageName + "_" + distPackageVersion + "/"
end

# Destination temporary folder for application code.
def pathDistSource
	pathDist + "source/"
end

def cwdName
	File.basename(File.dirname(File.expand_path(__FILE__)))
end

# Source of main HyperReload application code.
def pathSourceHyper
	root + cwdName + "/"
end

# Source file for package.json.
def pathSourcePackageJson
	"./package-template.json"
end

# Source of documentation files.
def pathSourceDoc
	root + "evothings-doc"
end

def nodeWebKitVersion
	"0.12.3"
end

# "node-webkit" for 0.11 and earlier.
# "nwjs" for 0.12.
def nodeWebKitName
	"nwjs"
end

def pathNodeWebkitLinux32
	root + "node-webkit-bin-" + nodeWebKitVersion +
		"/nwjs-v" + nodeWebKitVersion +
		"-linux-ia32/"
end

def pathNodeWebkitLinux64
	root + "node-webkit-bin-" + nodeWebKitVersion +
		"/nwjs-v" + nodeWebKitVersion +
		"-linux-x64/"
end

def pathNodeWebkitWin32
	root + "node-webkit-bin-" + nodeWebKitVersion +
		"/nwjs-v" + nodeWebKitVersion +
		"-win-ia32/"
end

def pathNodeWebkitWin64
	root + "node-webkit-bin-" + nodeWebKitVersion +
		"/nwjs-v" + nodeWebKitVersion +
		"-win-x64/"
end

def pathNodeWebkitMac64
	root + "node-webkit-bin-" + nodeWebKitVersion +
		"/nwjs-v" + nodeWebKitVersion +
		"-osx-x64/"
end

def pathIconsMac64
	if(RUBY_PLATFORM =~ /darwin/)
		return "./build/nw.icns"
	else
		return nil
	end
end

def updateFile(tar, src)
	if(!FileUtils.uptodate?(tar, [src]))
		FileUtils::Verbose.cp(src, tar)
	end
end

def buildOSXIcons
	# Only on OSX.
	if(RUBY_PLATFORM =~ /darwin/)
		osxIcons = [
			16,
			32,
			128,
			256,
			512,
		]
		FileUtils.mkdir_p('build/icon.iconset')
		osxIcons.each do |size|
			updateFile("build/icon.iconset/icon_#{size}x#{size}.png", "#{root}evothings-viewer/config/icons/icon-#{size}.png")
			updateFile("build/icon.iconset/icon_#{size}x#{size}@2x.png", "#{root}evothings-viewer/config/icons/icon-#{size*2}.png")
		end
		sh 'iconutil -c icns --output build/nw.icns build/icon.iconset'
	end
end

def buildGitVersionFile
	open(pathDistSource + 'gitVersions.txt', 'w') do |file|
		([SiblingRepo.new(cwdName)]+siblingRepos).each do |repo|
			path = root+repo.name
			if(!File.exist?("#{path}/.git"))
				raise "Missing source directory: #{path}"
			end
			o = `git --git-dir=#{path}/.git rev-parse HEAD`
			file.puts "#{repo.name}: #{o.strip}"
		end
	end
end

def buildPreProcess
	sh "ruby ./init.rb"
	buildGitVersionFile
	buildOSXIcons
end

# Not used
#def buildDocumentation
#	include FileUtils::Verbose
#	cwd = pwd
#
#	mkdir_p pathDistSource + 'documentation'
#
#	# plugins
#	cd "#{root}evothings-client"
{'fraction_non_alphanumeric': 0.1400959367945824, 'fraction_numerical': 0.018623024830699775, 'mean_word_length': 3.9538784067085953, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '54663', 'n_tokens_mistral': 2987, 'n_tokens_neox': 2739, 'n_words': 614}