Skip to content

Commit 0f15dd0

Browse files
committed
Put compiled coffee sources into asar archive
1 parent 0b8efc4 commit 0f15dd0

File tree

3 files changed

+78
-31
lines changed

3 files changed

+78
-31
lines changed

atom.gyp

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -625,40 +625,31 @@
625625
{
626626
'target_name': 'compile_coffee',
627627
'type': 'none',
628-
'sources': [
629-
'<@(coffee_sources)',
630-
],
631-
'rules': [
628+
'actions': [
632629
{
633-
'rule_name': 'coffee',
634-
'extension': 'coffee',
630+
'action_name': 'compile_coffee',
631+
'variables': {
632+
'conditions': [
633+
['OS=="mac"', {
634+
'resources_path': '<(PRODUCT_DIR)/<(product_name).app/Contents/Resources',
635+
},{
636+
'resources_path': '<(PRODUCT_DIR)/resources',
637+
}],
638+
],
639+
},
635640
'inputs': [
636-
'tools/compile-coffee.py',
641+
'<@(coffee_sources)',
637642
],
638-
'conditions': [
639-
['OS=="mac"', {
640-
'outputs': [
641-
'<(PRODUCT_DIR)/<(product_name).app/Contents/Resources/<(RULE_INPUT_DIRNAME)/<(RULE_INPUT_ROOT).js',
642-
],
643-
'action': [
644-
'python',
645-
'tools/compile-coffee.py',
646-
'<(RULE_INPUT_PATH)',
647-
'<(PRODUCT_DIR)/<(product_name).app/Contents/Resources/<(RULE_INPUT_DIRNAME)/<(RULE_INPUT_ROOT).js',
648-
],
649-
},{ # OS=="mac"
650-
'outputs': [
651-
'<(PRODUCT_DIR)/resources/<(RULE_INPUT_DIRNAME)/<(RULE_INPUT_ROOT).js',
652-
],
653-
'action': [
654-
'python',
655-
'tools/compile-coffee.py',
656-
'<(RULE_INPUT_PATH)',
657-
'<(PRODUCT_DIR)/resources/<(RULE_INPUT_DIRNAME)/<(RULE_INPUT_ROOT).js',
658-
],
659-
}], # OS=="win" or OS=="linux"
643+
'outputs': [
644+
'<(resources_path)/atom.asar',
660645
],
661-
},
646+
'action': [
647+
'python',
648+
'tools/coffee2asar.py',
649+
'<@(_outputs)',
650+
'<@(_inputs)',
651+
],
652+
}
662653
],
663654
}, # target compile_coffee
664655
{

atom/common/node_bindings.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ node::Environment* NodeBindings::CreateEnvironment(
169169
exec_path.DirName().Append(FILE_PATH_LITERAL("resources"));
170170
#endif
171171
base::FilePath script_path =
172-
resources_path.Append(FILE_PATH_LITERAL("atom"))
172+
resources_path.Append(FILE_PATH_LITERAL("atom.asar"))
173173
.Append(is_browser_ ? FILE_PATH_LITERAL("browser") :
174174
FILE_PATH_LITERAL("renderer"))
175175
.Append(FILE_PATH_LITERAL("lib"))

tools/coffee2asar.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/usr/bin/env python
2+
3+
import os
4+
import shutil
5+
import subprocess
6+
import sys
7+
import tempfile
8+
9+
10+
SOURCE_ROOT = os.path.dirname(os.path.dirname(__file__))
11+
12+
13+
def main():
14+
archive = sys.argv[1]
15+
coffee_source_files = sys.argv[2:]
16+
17+
output_dir = tempfile.mkdtemp()
18+
compile_coffee(coffee_source_files, output_dir)
19+
call_asar(archive, output_dir)
20+
shutil.rmtree(output_dir)
21+
22+
23+
def compile_coffee(coffee_source_files, output_dir):
24+
for source_file in coffee_source_files:
25+
output_filename = os.path.splitext(source_file)[0] + '.js'
26+
output_path = os.path.join(output_dir, output_filename)
27+
call_compile_coffee(source_file, output_path)
28+
29+
30+
def call_compile_coffee(source_file, output_filename):
31+
compile_coffee = os.path.join(SOURCE_ROOT, 'tools', 'compile-coffee.py')
32+
subprocess.check_call([sys.executable, compile_coffee, source_file,
33+
output_filename])
34+
35+
36+
def call_asar(archive, output_dir):
37+
js_dir = os.path.join(output_dir, 'atom')
38+
asar = os.path.join(SOURCE_ROOT, 'node_modules', 'asar', 'bin', 'asar')
39+
subprocess.check_call([find_node(), asar, 'pack', js_dir, archive])
40+
41+
42+
def find_node():
43+
WINDOWS_NODE_PATHs = [
44+
'C:/Program Files (x86)/nodejs',
45+
'C:/Program Files/nodejs',
46+
] + os.environ['PATH'].split(os.pathsep)
47+
48+
if sys.platform in ['win32', 'cygwin']:
49+
for path in WINDOWS_NODE_PATHs:
50+
full_path = os.path.join(path, 'node.exe')
51+
if os.path.exists(full_path):
52+
return full_path
53+
return 'node'
54+
55+
if __name__ == '__main__':
56+
sys.exit(main())

0 commit comments

Comments
 (0)