diff --git a/README.md b/README.md index 02da7aa..4cf9b93 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,14 @@ A collection of bundles for Sequel Ace meant to aide in development of Typescript projects. +The first bundle allows you to generate Typescript interfaces from the currently selected tables. An additional bundle is in the works that will generate a Sequelize model from the selected tables. + ## Installation and Usage 1. Download a ZIP file of the repository and unzip it. 2. Double-click on the bundle package to install it. -3. Launch Sequel Ace and connect to a database. Select a table, then choose a command from the **Bundles** > **Generate** menu. +3. Launch Sequel Ace and connect to a database. Select one or more tables, then choose a command from the **Bundles** > **Generate** menu. + +## Contributing + +Additional contributors are welcome and encouraged. Please make sure your code is well-tested before opening a pull request. diff --git a/Typescript Interface.saBundle/Support/footer.html b/Typescript Interface.saBundle/Support/footer.html new file mode 100644 index 0000000..a2a832e --- /dev/null +++ b/Typescript Interface.saBundle/Support/footer.html @@ -0,0 +1,404 @@ + + + + \ No newline at end of file diff --git a/Typescript Interface.saBundle/Support/header.html b/Typescript Interface.saBundle/Support/header.html index 4f8bd4c..40a4ce6 100644 --- a/Typescript Interface.saBundle/Support/header.html +++ b/Typescript Interface.saBundle/Support/header.html @@ -87,6 +87,42 @@ direction: ltr; unicode-bidi: bidi-override; } + .clipboard { + position: relative; + display: block; + float: right; + } + button { + border-radius: 0; + margin: 0; + font-family: inherit; + font-size: inherit; + line-height: inherit; + text-transform: none; + } + [type="button"], button { + -webkit-appearance: button; + } + .btn-clipboard { + position: absolute; + top: .65rem; + right: .65rem; + z-index: 10; + display: block; + padding: .25rem .5rem; + font-size: .65em; + color: #0d6efd; + background-color: #fff; + border: 1px solid; + border-radius: .25rem; + } + .btn-clipboard:hover, .btn-clipboard:focus { + color: #fff; + background-color: #0d6efd; + } + [type="button"]:not(:disabled), button:not(:disabled) { + cursor: pointer; + } diff --git a/Typescript Interface.saBundle/Support/parseTableData.rb b/Typescript Interface.saBundle/Support/parseTableData.rb index 42aca93..277890f 100644 --- a/Typescript Interface.saBundle/Support/parseTableData.rb +++ b/Typescript Interface.saBundle/Support/parseTableData.rb @@ -2,7 +2,7 @@ table_name = ARGV[0] require 'csv' -puts "
"
+puts "
"
 puts "interface #{table_name.split('_').collect(&:capitalize).join} {"
 CSV.parse(STDIN.read, headers: true)  do |row|
   fieldType = "unknown"
@@ -23,4 +23,4 @@
   puts "  #{row['Field']}: #{fieldType}"
 end
 puts "}"
-puts "
" +puts "
" diff --git a/Typescript Interface.saBundle/Support/processTableData.pl b/Typescript Interface.saBundle/Support/processTableData.pl deleted file mode 100755 index 1dd2b0d..0000000 --- a/Typescript Interface.saBundle/Support/processTableData.pl +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/env perl -w - -while(<>) { - - # split tab delimited data - @data = split(/\t/); - - $pid = $ENV{"PID"}; - $db = $ENV{"DB"}; - $res = $ENV{"RES"}; - $itemType = "table"; - - # $data[1] is NULL indicates item is a view - if($data[1] eq "NULL") { - $img = "file://$res/table-view-small-square.tiff"; - $itemType = "view"; - } else { - $img = "file://$res/table-small-square.tiff"; - } - - print < - - $data[0] - $data[1] - $data[4] - $data[6] - $data[11] - $data[12] - -HTML4 -} diff --git a/Typescript Interface.saBundle/command.plist b/Typescript Interface.saBundle/command.plist index 7a84e54..9487d21 100644 --- a/Typescript Interface.saBundle/command.plist +++ b/Typescript Interface.saBundle/command.plist @@ -10,67 +10,71 @@ Generate command # Error and SP file handling from bundles by Hans-Jörg Bibiko +# Multi-table support and query function from bundles by Colin Viebrock (github.com/cviebrock/sequel-pro-laravel-export) # Output the first portion of the HTML file cat "$SP_BUNDLE_PATH/Support/header.html" -# Check if a table is selected -if [ -z "$SP_SELECTED_TABLE" ]; then - # If no table is selected, output an error to an HTML Tooltip and exit - echo "<div class="alert alert-danger">Please select a table.</div>" - exit $SP_BUNDLE_EXIT_SHOW_AS_HTML_TOOLTIP -fi +delete_temp_files() +{ + rm -f "$SP_QUERY_RESULT_FILE" + rm -f "$SP_QUERY_FILE" + rm -f "$SP_QUERY_RESULT_STATUS_FILE" +} -# Remove handshake files before starting -rm -f "$SP_QUERY_RESULT_FILE" -rm -f "$SP_QUERY_FILE" -rm -f "$SP_QUERY_RESULT_STATUS_FILE" +execute_sql() +{ + # execute the SQL statement; the result will be available in the file $SP_QUERY_RESULT_FILE + open "sequelace://$SP_PROCESS_ID@passToDoc/ExecuteQuery/csv" + # wait for results; status file will be written to disk if query was finished + while [ 1 ] + do + [[ -e "$SP_QUERY_RESULT_STATUS_FILE" ]] && break + sleep 0.01 + done -# Query the table description -echo "DESCRIBE \`${SP_SELECTED_TABLE//\`/\`\`}\`" > "$SP_QUERY_FILE" -open "sequelace://$SP_PROCESS_ID@passToDoc/ExecuteQuery/csv" + # check for errors + if [ `cat "$SP_QUERY_RESULT_STATUS_FILE"` == 1 ]; then + echo "<div class='alert alert-danger'><h4 class='alert-heading'>SQL Error:</h4><pre><code>" + cat "$SP_QUERY_RESULT_FILE" + echo "</code></pre>" + exit "$SP_BUNDLE_EXIT_SHOW_AS_HTML" + fi +} -# Wait for Sequel Ace; status file will be written to disk if query finished -while [ 1 ] -do - [[ -e "$SP_QUERY_RESULT_STATUS_FILE" ]] && break - sleep 0.1 -done +# Check if a table is selected +if [ -z "$SP_SELECTED_TABLES" ]; then + echo "<h2 class='err'>Error</h2><p>No table selected.</p>" + exit "$SP_BUNDLE_EXIT_SHOW_AS_HTML" +fi -# Check returned status 0 := no error; 1 := error -RES=$(cat "$SP_QUERY_RESULT_STATUS_FILE") -[[ ! -e "$SP_QUERY_RESULT_FILE" ]] && RES=1 +# Remove temporary files before starting +delete_temp_files +# Assign selected tables to a variable +read -r -a tables <<< "$SP_SELECTED_TABLES" -# Check if a SQL error has occured -if [ "$RES" == "0" ]; then - # If no SQL error occured, pipe the result file to the Ruby script - cat "$SP_QUERY_RESULT_FILE" | /usr/bin/ruby "$SP_BUNDLE_PATH/Support/parseTableData.rb" "$SP_SELECTED_TABLE" -else - # If error, message will be saved in result file - echo "<div class="alert alert-danger">" - cat "$SP_QUERY_RESULT_FILE" - echo "</div>" - rm -f "$SP_QUERY_RESULT_FILE" - rm -f "$SP_QUERY_FILE" - rm -f "$SP_QUERY_RESULT_STATUS_FILE" - exit $SP_BUNDLE_EXIT_SHOW_AS_HTML_TOOLTIP -fi +# Loop through tables +for table in "${tables[@]}" +do + # Query the table description + echo "DESCRIBE \`${table}\`" > "$SP_QUERY_FILE" + execute_sql + + cat "$SP_QUERY_RESULT_FILE" | /usr/bin/ruby "$SP_BUNDLE_PATH/Support/parseTableData.rb" "${table}" + delete_temp_files +done -# Remove handshake files now that we're done -rm -f "$SP_QUERY_RESULT_FILE" -rm -f "$SP_QUERY_FILE" -rm -f "$SP_QUERY_RESULT_STATUS_FILE" +# Remove temp files now that we're done +delete_temp_files # Output the end of the HTML -echo "</div>" -echo "</body></html>" - +cat "$SP_BUNDLE_PATH/Support/footer.html" contact uggcf://tvguho.pbz/ovaynof/frdhry-npr-glcrfpevcg-ohaqyrf description - Generate a Typescript interfaces from the currently selected table. + Generate Typescript interaces from the currently selected tables. This bundle is not all-encompassing, it is simply meant to save time when creating interfaces. Some manual corrections may need to made to the interface that is generated for you. keyEquivalent @@ -82,7 +86,7 @@ This bundle is not all-encompassing, it is simply meant to save time when creati scope general tooltip - Generate a Typescript Interace from the currently selected table + Generate Typescript interaces from the currently selected tables uuid 8E6D3915-3FBC-4014-B1F6-059182C3FC11