diff --git a/.gitignore b/.gitignore index 6a7d6d8..13b97e3 100755 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +*~ # Logs logs *.log diff --git a/main.js b/main.js index 367f4f0..dadc3ae 100755 --- a/main.js +++ b/main.js @@ -168,14 +168,10 @@ app.whenReady().then(() => { } break case 'PUT': - if(fs.existsSync(dataDir + componentDirectory + "/" + componentName)){ - return createComponentDirectory(componentDirectory) - .then(createComponentFile(componentDirectory + "/" + componentName, request)) - .then(function() { return new Response('"ok"', { status: 200})}) - .catch(function(){ return new Response('"something went wrong"', { status : 500 })}) // @TODO : return the error code - } else { - return new Response('"Not found"', { status: 404}) - } + return createComponentDirectory(componentDirectory) + .then(createComponentFile(componentDirectory + "/" + componentName, request)) + .then(function() { return new Response('"ok"', { status: 200})}) + .catch(function(){ return new Response('"something went wrong"', { status : 500 })}) // @TODO : return the error code break case 'GET': default: @@ -262,7 +258,11 @@ app.whenReady().then(() => { } }) - dataDir = dialog.showOpenDialogSync({properties: ['openDirectory']})[0]; + if (process.argv[1]) { + dataDir = path.resolve(process.argv[1]); + } else { + dataDir = dialog.showOpenDialogSync({properties: ['openDirectory']})[0]; + } console.log(dataDir); if (!dataDir.match(/\/$/)) { dataDir += "/"; @@ -273,9 +273,11 @@ app.whenReady().then(() => { app.on('activate', () => { // needed for macos if (BrowserWindow.getAllWindows().length === 0) { - dataDir = dialog.showOpenDialogSync({properties: ['openDirectory']})[0]; - console.log('were here') - console.log(dataDir) + if (process.argv[1]) { + dataDir = path.resolve(process.argv[1]); + } else { + dataDir = dialog.showOpenDialogSync({properties: ['openDirectory']})[0]; + } if (!dataDir.match(/\/$/)) { dataDir += "/"; } diff --git a/package.json b/package.json index 625f773..e593e9d 100755 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "simply-code-app", + "name": "simplycode", "version": "1.0.0", "description": "Simplycode in electron to build websites", "main": "main.js", diff --git a/simplycode/index.html b/simplycode/index.html index 331da58..8dff542 100644 --- a/simplycode/index.html +++ b/simplycode/index.html @@ -1153,9 +1153,9 @@ }) .catch(function() { let defaults = { - "componentPreview.html" : "<!DOCTYPE HTML>\n<html lang=\"en\">\n <head>\n <meta charset=\"utf-8\">\n <!-- Component CSS -->\n <style>\n {{componentCss}}\n </style>\n <!-- /Component CSS -->\n <!-- Page CSS -->\n <style>\n {{pageCss}}\n </style>\n <!-- /Page CSS -->\n <!-- Head HTML -->\n {{headHtml}}\n <!-- /Head HTML -->\n <script>\n function clone(ob) {\n return JSON.parse(JSON.stringify(ob));\n }\n function updateDataSource(name) {\n document.querySelectorAll('[data-simply-data=\"'+name+'\"]').forEach(function(list) {\n editor.list.applyDataSource(list, name);\n list.dataBindingPaused = 0;\n });\n }\n </script>\n </head>\n <body>\n <!-- Component HTML templates -->\n {{componentTemplates}}\n <!-- /Component HTML templates -->\n <div class=\"main\">\n {{componentPreview}}\n </div>\n <script src=\"js/simply.everything.js\"></script>\n <script src=\"js/simply-edit.js\" data-api-key=\"muze\"></script>\n <script>\n /* Transformers */\n editor.transformers = {\n {{transformers}}\n };\n /* /Transformers */\n </script>\n <script>\n /* Sorters */\n editor.sorters = {\n {{sorters}}\n };\n /* /Sorters */\n </script>\n <script>\n window.addEventListener(\"simply-content-loaded\", function() {\n /* Data sources */\n {{dataSources}}\n /* /Data sources */\n });\n </script>\n <!-- Foot HTML -->\n {{footHtml}}\n <!-- /Foot HTML -->\n </body>\n</html>", - "fullApp.html" : "<!DOCTYPE HTML>\n<html lang=\"en\">\n <head>\n <meta charset=\"utf-8\">\n <!-- Component CSS -->\n <style>\n {{componentCss}}\n </style>\n <!-- /Component CSS -->\n <!-- Page CSS -->\n <style>\n {{pageCss}}\n </style>\n <!-- /Page CSS -->\n <!-- Head HTML -->\n {{headHtml}}\n <!-- /Head HTML -->\n <script>\n var simplyDataApi = {};\n var simplyApp = {};\n window.addEventListener(\"simply-content-loaded\", function() {\n simply.bind = false;\n /* Raw API */\n var simplyRawApi = {\n {{rawApi}}\n };\n /* End of Raw API */\n /* Data API */\n simplyDataApi = {\n {{dataApi}}\n };\n /* End of Data API */\n simplyApp = simply.app({\n /* Actions */\n actions: {\n {{actions}}\n },\n /* /Actions */\n /* Commands */\n commands: {\n {{commands}}\n },\n /* /Commands */\n /* Routes */\n routes: {\n {{routes}}\n }\n /* /Routes */\n });\n });\n function clone(ob) {\n return JSON.parse(JSON.stringify(ob));\n }\n function updateDataSource(name) {\n document.querySelectorAll('[data-simply-data=\"'+name+'\"]').forEach(function(list) {\n editor.list.applyDataSource(list, name);\n list.dataBindingPaused = 0;\n });\n }\n </script>\n </head>\n <body>\n <!-- Body HTML -->\n {{bodyHtml}}\n <!-- /Body HTML -->\n <!-- Component HTML templates -->\n {{componentTemplates}}\n <!-- /Component HTML templates -->\n <header data-simply-path=\"/\" data-simply-field=\"header\" data-simply-content=\"template\" data-simply-default-value=\"Header\">\n <template data-simply-template='Header' rel=\"header\"></template>\n </header>\n <nav>\n <simply-render rel=\"menu\"></simply-render>\n </nav>\n <div class=\"main\" data-simply-field=\"page\" data-simply-content=\"template\">\n <!-- Page HTML templates -->\n {{pageTemplates}}\n <!-- /Page HTML templates -->\n </div>\n <script src=\"js/simply.everything.js\"></script>\n <script src=\"js/simply-edit.js\" data-api-key=\"muze\"></script>\n <script>\n /* Transformers */\n editor.transformers = {\n {{transformers}}\n };\n /* /Transformers */\n </script>\n <script>\n /* Sorters */\n editor.sorters = {\n {{sorters}}\n };\n /* /Sorters */\n </script>\n <script>\n window.addEventListener(\"simply-content-loaded\", function() {\n /* Data sources */\n {{dataSources}}\n /* /Data sources */\n });\n </script>\n <!-- Foot HTML -->\n {{footHtml}}\n <!-- /Foot HTML -->\n </body>\n</html>", - "pagePreview.html" : "<!DOCTYPE HTML>\n<html lang=\"en\">\n <head>\n <meta charset=\"utf-8\">\n <!-- Component CSS -->\n <style>\n {{componentCss}}\n </style>\n <!-- /Component CSS -->\n <!-- Page CSS -->\n <style>\n {{pageCss}}\n </style>\n <!-- /Page CSS -->\n <!-- Head HTML -->\n {{headHtml}}\n <!-- /Head HTML -->\n <script>\n function clone(ob) {\n return JSON.parse(JSON.stringify(ob));\n }\n function updateDataSource(name) {\n document.querySelectorAll('[data-simply-data=\"'+name+'\"]').forEach(function(list) {\n editor.list.applyDataSource(list, name);\n list.dataBindingPaused = 0;\n });\n }\n </script>\n </head>\n <body>\n <!-- Component HTML templates -->\n {{componentTemplates}}\n <!-- /Component HTML templates -->\n <header data-simply-path=\"/\" data-simply-field=\"header\" data-simply-content=\"template\" data-simply-default-value=\"Header\">\n <template data-simply-template='Header' rel=\"header\"></template>\n </header>\n <nav>\n <simply-render rel=\"menu\"></simply-render>\n </nav>\n <div class=\"main\" data-simply-field=\"page\" data-simply-content=\"template\">\n {{pagePreview}}\n </div>\n <script src=\"js/simply.everything.js\"></script>\n <script src=\"js/simply-edit.js\" data-api-key=\"muze\"></script>\n <script>\n /* Transformers */\n editor.transformers = {\n {{transformers}}\n };\n /* /Transformers */\n </script>\n <script>\n /* Sorters */\n editor.sorters = {\n {{sorters}}\n };\n /* /Sorters */\n </script>\n <script>\n window.addEventListener(\"simply-content-loaded\", function() {\n /* Data sources */\n {{dataSources}}\n /* /Data sources */\n });\n </script>\n <!-- Foot HTML -->\n {{footHtml}}\n <!-- /Foot HTML -->\n </body>\n</html>" + "componentPreview.html" : "<!DOCTYPE HTML>\n<html lang=\"en\">\n <head>\n <meta charset=\"utf-8\">\n <!-- Component CSS -->\n <style>\n {{componentCss}}\n </style>\n <!-- /Component CSS -->\n <!-- Page CSS -->\n <style>\n {{pageCss}}\n </style>\n <!-- /Page CSS -->\n <!-- Head HTML -->\n {{headHtml}}\n <!-- /Head HTML -->\n <script>\n function clone(ob) {\n return JSON.parse(JSON.stringify(ob));\n }\n function updateDataSource(name) {\n document.querySelectorAll('[data-simply-data=\"'+name+'\"]').forEach(function(list) {\n editor.list.applyDataSource(list, name);\n list.dataBindingPaused = 0;\n });\n }\n </script>\n </head>\n <body>\n <!-- Component HTML templates -->\n {{componentTemplates}}\n <!-- /Component HTML templates -->\n <div class=\"main\">\n {{componentPreview}}\n </div>\n <script src=\"js/simply.everything.js\"></script>\n <script src=\"js/simply-edit.js\" data-simply-storage=\"none\" data-api-key=\"muze\"></script>\n <script>\n /* Transformers */\n editor.transformers = {\n {{transformers}}\n };\n /* /Transformers */\n </script>\n <script>\n /* Sorters */\n editor.sorters = {\n {{sorters}}\n };\n /* /Sorters */\n </script>\n <script>\n window.addEventListener(\"simply-content-loaded\", function() {\n /* Data sources */\n {{dataSources}}\n /* /Data sources */\n });\n </script>\n <!-- Foot HTML -->\n {{footHtml}}\n <!-- /Foot HTML -->\n </body>\n</html>", + "fullApp.html" : "<!DOCTYPE HTML>\n<html lang=\"en\">\n <head>\n <meta charset=\"utf-8\">\n <!-- Component CSS -->\n <style>\n {{componentCss}}\n </style>\n <!-- /Component CSS -->\n <!-- Page CSS -->\n <style>\n {{pageCss}}\n </style>\n <!-- /Page CSS -->\n <!-- Head HTML -->\n {{headHtml}}\n <!-- /Head HTML -->\n <script>\n var simplyDataApi = {};\n var simplyApp = {};\n window.addEventListener(\"simply-content-loaded\", function() {\n simply.bind = false;\n /* Raw API */\n var simplyRawApi = {\n {{rawApi}}\n };\n /* End of Raw API */\n /* Data API */\n simplyDataApi = {\n {{dataApi}}\n };\n /* End of Data API */\n simplyApp = simply.app({\n /* Actions */\n actions: {\n {{actions}}\n },\n /* /Actions */\n /* Commands */\n commands: {\n {{commands}}\n },\n /* /Commands */\n /* Routes */\n routes: {\n {{routes}}\n }\n /* /Routes */\n });\n });\n function clone(ob) {\n return JSON.parse(JSON.stringify(ob));\n }\n function updateDataSource(name) {\n document.querySelectorAll('[data-simply-data=\"'+name+'\"]').forEach(function(list) {\n editor.list.applyDataSource(list, name);\n list.dataBindingPaused = 0;\n });\n }\n </script>\n </head>\n <body>\n <!-- Body HTML -->\n {{bodyHtml}}\n <!-- /Body HTML -->\n <!-- Component HTML templates -->\n {{componentTemplates}}\n <!-- /Component HTML templates -->\n <header data-simply-path=\"/\" data-simply-field=\"header\" data-simply-content=\"template\" data-simply-default-value=\"Header\">\n <template data-simply-template='Header' rel=\"header\"></template>\n </header>\n <nav>\n <simply-render rel=\"menu\"></simply-render>\n </nav>\n <div class=\"main\" data-simply-field=\"page\" data-simply-content=\"template\">\n <!-- Page HTML templates -->\n {{pageTemplates}}\n <!-- /Page HTML templates -->\n </div>\n <script src=\"js/simply.everything.js\"></script>\n <script src=\"js/simply-edit.js\" data-simply-storage=\"none\" data-api-key=\"muze\"></script>\n <script>\n /* Transformers */\n editor.transformers = {\n {{transformers}}\n };\n /* /Transformers */\n </script>\n <script>\n /* Sorters */\n editor.sorters = {\n {{sorters}}\n };\n /* /Sorters */\n </script>\n <script>\n window.addEventListener(\"simply-content-loaded\", function() {\n /* Data sources */\n {{dataSources}}\n /* /Data sources */\n });\n </script>\n <!-- Foot HTML -->\n {{footHtml}}\n <!-- /Foot HTML -->\n </body>\n</html>", + "pagePreview.html" : "<!DOCTYPE HTML>\n<html lang=\"en\">\n <head>\n <meta charset=\"utf-8\">\n <!-- Component CSS -->\n <style>\n {{componentCss}}\n </style>\n <!-- /Component CSS -->\n <!-- Page CSS -->\n <style>\n {{pageCss}}\n </style>\n <!-- /Page CSS -->\n <!-- Head HTML -->\n {{headHtml}}\n <!-- /Head HTML -->\n <script>\n function clone(ob) {\n return JSON.parse(JSON.stringify(ob));\n }\n function updateDataSource(name) {\n document.querySelectorAll('[data-simply-data=\"'+name+'\"]').forEach(function(list) {\n editor.list.applyDataSource(list, name);\n list.dataBindingPaused = 0;\n });\n }\n </script>\n </head>\n <body>\n <!-- Component HTML templates -->\n {{componentTemplates}}\n <!-- /Component HTML templates -->\n <header data-simply-path=\"/\" data-simply-field=\"header\" data-simply-content=\"template\" data-simply-default-value=\"Header\">\n <template data-simply-template='Header' rel=\"header\"></template>\n </header>\n <nav>\n <simply-render rel=\"menu\"></simply-render>\n </nav>\n <div class=\"main\" data-simply-field=\"page\" data-simply-content=\"template\">\n {{pagePreview}}\n </div>\n <script src=\"js/simply.everything.js\"></script>\n <script src=\"js/simply-edit.js\" data-simply-storage=\"none\" data-api-key=\"muze\"></script>\n <script>\n /* Transformers */\n editor.transformers = {\n {{transformers}}\n };\n /* /Transformers */\n </script>\n <script>\n /* Sorters */\n editor.sorters = {\n {{sorters}}\n };\n /* /Sorters */\n </script>\n <script>\n window.addEventListener(\"simply-content-loaded\", function() {\n /* Data sources */\n {{dataSources}}\n /* /Data sources */\n });\n </script>\n <!-- Foot HTML -->\n {{footHtml}}\n <!-- /Foot HTML -->\n </body>\n</html>" }; let elements = {}; @@ -3330,7 +3330,7 @@