-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildExtention.py
124 lines (106 loc) · 3.88 KB
/
buildExtention.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# -*- coding: utf-8 -*-
# ------------------------------------------------------------------------
# Extension build script.
# Created on the basis of a similar Tal Leming script,
# but with the addition of creating Mechanic2 registration files
# ------------------------------------------------------------------------
name = "CodeThemeManager"
title = "CodeEditor Themes Manager"
description = 'Code theme manager for Robofont 4 Scripting Window.'
tags = 'interface, workspace, code, scripting'
version = "0.3"
mainScriptsList = ['CodeThemesManager']
developer = "Alexander Lubovenko"
developerURL = "https://github.com/typedev"
roboFontVersion = "4.0"
iconFile = 'icon.png'
# ------------------------------------------------------------------------
mainScript = ''
launchAtStartUp = False
makeExtension = True
mechanic2support = True
pycOnly = False
masterBranch = 'master' # main
# ------------------------------------------------------------------------
if __name__ == "__main__":
from AppKit import *
import os
import shutil
from mojo.extensions import ExtensionBundle
from datetime import datetime
menuItems = [{'path': '%s.py' % ms,
'preferredName': title,
'shortKey': ''} for ms in mainScriptsList]
# Make the various paths.
basePath = os.path.dirname(__file__)
sourcePath = os.path.join(basePath, "source")
libPath = sourcePath # os.path.join(sourcePath, "code")
licensePath = os.path.join(basePath, 'LICENSE')
requirementsPath = os.path.join(basePath, "requirements.txt")
extensionFile = "%s.roboFontExt" % name
buildPath = basePath # os.path.join(basePath, "build")
extensionPath = os.path.join(buildPath, extensionFile)
iconPath = os.path.join(basePath, iconFile)
# Build the extension.
if makeExtension:
B = ExtensionBundle()
B.name = name
B.developer = developer
B.developerURL = developerURL
B.version = version
B.launchAtStartUp = launchAtStartUp
B.mainScript = mainScript
docPath = os.path.join(sourcePath, "documentation")
haveDocumentation = False
if os.path.exists(os.path.join(docPath, "index.html")):
haveDocumentation = True
elif os.path.exists(os.path.join(docPath, "index.md")):
haveDocumentation = True
if not haveDocumentation:
docPath = None
B.html = haveDocumentation
B.requiresVersionMajor = roboFontVersion.split(".")[0]
B.requiresVersionMinor = roboFontVersion.split(".")[1]
B.addToMenu = menuItems
if os.path.exists(iconPath):
B.icon = iconPath
if os.path.exists(licensePath):
with open(licensePath) as license:
B.license = license.read()
if os.path.exists(requirementsPath):
with open(requirementsPath) as requirements:
B.requirements = requirements.read()
print("Building extension...", end = " ")
v = B.save(extensionPath, libPath = libPath, pycOnly = pycOnly, htmlPath = docPath)
print('Making zip..')
shutil.make_archive(extensionPath, 'zip', extensionPath)
print("done!")
errors = B.validationErrors()
if errors:
print(errors)
# Making Mechanic2 files..
if mechanic2support:
print ('Making Mechanic2 files..')
repository = '%s/%s' % (developerURL, name)
zipPath = '%s/archive/%s.zip' % (repository, masterBranch)
iconRepo = '%s/%s/%s' % (repository.replace('https://github.com','https://raw.githubusercontent.com'),masterBranch, iconFile)
mechanic2info = dict(
extensionName = name,
repository = repository,
extensionPath = extensionFile,
description = description,
developer = developer,
developerURL = developerURL,
tags = '[ %s ]' % tags,
icon = iconRepo,
zipPath = zipPath,
dateAdded = datetime.now().strftime('%Y-%m-%y %-H:%M:%S')
)
text = '\n'.join(['%s: %s' % (k,v) for k,v in mechanic2info.items()])
m2exts = [ '%s.mechanic' % name, '%s.yml' % name ]
for m2 in m2exts:
m2filepath = os.path.join(basePath, m2)
m2file = open(m2filepath, mode = 'w')
m2file.write(text)
m2file.close()
print('File %s saved.' % m2)