From 3308ce695b8e35e3aca8d9d1e341b3f77735d50c Mon Sep 17 00:00:00 2001 From: kovacsv Date: Sun, 18 Nov 2018 10:44:57 +0100 Subject: [PATCH] Make build parameter from extension list. --- tools/build.py | 24 +++++++++++++++++++++--- website/extensions/example/example.js | 2 +- website/include/importerapp.js | 2 ++ website/index.html | 2 ++ 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/tools/build.py b/tools/build.py index b002c39..70955b9 100644 --- a/tools/build.py +++ b/tools/build.py @@ -16,17 +16,26 @@ def ReplaceInFile (filePath, source, dest): file = open (filePath, 'rb') content = file.read (); file.close () - content = content.replace (source, dest) + content = re.sub (source, dest, content, flags = re.MULTILINE | re.DOTALL) file = open (filePath, 'wb') file.write (content); file.close () -def BuildWebSite (rootFolder, resultFolder): +def BuildWebSite (rootFolder, resultFolder, extensions): targetFolder = os.path.join (resultFolder, 'website') shutil.copytree (os.path.join (rootFolder, 'website'), targetFolder) shutil.copytree (os.path.join (rootFolder, 'jsmodeler'), os.path.join (targetFolder, 'jsmodeler')) indexFilePath = os.path.join (targetFolder, 'index.html') + importerAppFilePath = os.path.join (targetFolder, 'include', 'importerapp.js') ReplaceInFile (indexFilePath, '../jsmodeler/', 'jsmodeler/') + extensionIncludes = '' + for extension in extensions: + extensionIncludes += '\r\n\t' + ReplaceInFile (indexFilePath, '\<\!\-\- ExtensionIncludes \-\-\>.*\<\!\-\- ExtensionIncludesEnd \-\-\>', extensionIncludes) + extensionIncludes = '' + for extension in extensions: + extensionIncludes += 'importerApp.AddExtension (new ' + extension['name'] + ' ());\r\n\t' + ReplaceInFile (importerAppFilePath, '\/\/ ExtensionIncludes.*\/\/ ExtensionIncludesEnd', extensionIncludes) def BuildEmbeddable (rootFolder, resultFolder): targetFolder = os.path.join (resultFolder, 'embeddable') @@ -38,6 +47,15 @@ def BuildEmbeddable (rootFolder, resultFolder): ReplaceInFile (indexFilePath, '../jsmodeler/', 'jsmodeler/') def Main (): + extensions = [] + i = 1 + while i < len (sys.argv): + extensions.append ({ + 'name' : sys.argv[i], + 'path' : sys.argv[i + 1] + }); + i += 2 + rootFolder = os.path.abspath ('..') resultFolder = os.path.join (rootFolder, 'build') if os.path.exists (resultFolder): @@ -45,7 +63,7 @@ def Main (): os.mkdir (resultFolder) PrintInfo ('Building website to folder <' + resultFolder + '>.') - BuildWebSite (rootFolder, resultFolder) + BuildWebSite (rootFolder, resultFolder, extensions) PrintInfo ('Building embeddable example to folder <' + resultFolder + '>.') BuildEmbeddable (rootFolder, resultFolder) diff --git a/website/extensions/example/example.js b/website/extensions/example/example.js index d0fb459..26d06f8 100644 --- a/website/extensions/example/example.js +++ b/website/extensions/example/example.js @@ -5,7 +5,7 @@ ExampleExtension = function () ExampleExtension.prototype.IsEnabled = function () { - return false; + return true; }; ExampleExtension.prototype.Init = function (extensionInterface) diff --git a/website/include/importerapp.js b/website/include/importerapp.js index 412eb15..4ef33d7 100644 --- a/website/include/importerapp.js +++ b/website/include/importerapp.js @@ -550,5 +550,7 @@ window.onload = function () { var importerApp = new ImporterApp (); importerApp.Init (); + // ExtensionIncludes importerApp.AddExtension (new ExampleExtension ()); + // ExtensionIncludesEnd }; diff --git a/website/index.html b/website/index.html index c5b33d0..d3814d7 100644 --- a/website/index.html +++ b/website/index.html @@ -18,7 +18,9 @@ + +