2015-02-13 05:05:51 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2016-01-12 01:29:40 +00:00
|
|
|
import errno
|
2015-02-13 05:05:51 +00:00
|
|
|
import os
|
|
|
|
import shutil
|
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
import tempfile
|
|
|
|
|
|
|
|
SOURCE_ROOT = os.path.dirname(os.path.dirname(__file__))
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
archive = sys.argv[1]
|
2016-03-30 18:50:17 +00:00
|
|
|
folder_name = sys.argv[2]
|
|
|
|
source_files = sys.argv[3:]
|
2015-02-13 05:05:51 +00:00
|
|
|
|
|
|
|
output_dir = tempfile.mkdtemp()
|
2018-07-17 00:26:58 +00:00
|
|
|
copy_files(source_files, output_dir, folder_name)
|
2016-03-30 18:50:17 +00:00
|
|
|
call_asar(archive, os.path.join(output_dir, folder_name))
|
2015-02-13 05:05:51 +00:00
|
|
|
shutil.rmtree(output_dir)
|
|
|
|
|
2016-01-12 01:30:10 +00:00
|
|
|
|
2018-07-17 00:26:58 +00:00
|
|
|
def copy_files(source_files, output_dir, folder_name):
|
2016-03-30 18:50:17 +00:00
|
|
|
for source_file in source_files:
|
|
|
|
output_path = os.path.join(output_dir, source_file)
|
2018-07-17 00:26:58 +00:00
|
|
|
# Files that aren't in the default_app folder need to be put inside
|
|
|
|
# the temp one we are making so they end up in the ASAR
|
2018-07-17 05:31:06 +00:00
|
|
|
if not source_file.startswith(folder_name + os.sep):
|
2018-07-17 00:26:58 +00:00
|
|
|
output_path = os.path.join(output_dir, folder_name, source_file)
|
2016-01-12 01:29:40 +00:00
|
|
|
safe_mkdir(os.path.dirname(output_path))
|
|
|
|
shutil.copy2(source_file, output_path)
|
2015-02-13 05:05:51 +00:00
|
|
|
|
2016-01-12 01:30:10 +00:00
|
|
|
|
2015-02-13 05:05:51 +00:00
|
|
|
def call_asar(archive, output_dir):
|
2016-05-18 19:54:53 +00:00
|
|
|
asar = os.path.join(SOURCE_ROOT, 'node_modules', '.bin', 'asar')
|
2015-02-13 05:05:51 +00:00
|
|
|
if sys.platform in ['win32', 'cygwin']:
|
2016-05-18 19:54:53 +00:00
|
|
|
asar += '.cmd'
|
|
|
|
subprocess.check_call([asar, 'pack', output_dir, archive])
|
2015-02-13 05:05:51 +00:00
|
|
|
|
2016-01-12 01:30:10 +00:00
|
|
|
|
2016-01-12 01:29:40 +00:00
|
|
|
def safe_mkdir(path):
|
|
|
|
try:
|
|
|
|
os.makedirs(path)
|
|
|
|
except OSError as e:
|
|
|
|
if e.errno != errno.EEXIST:
|
|
|
|
raise
|
|
|
|
|
|
|
|
|
2015-02-13 05:05:51 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
sys.exit(main())
|