Skip to content
Permalink
Browse files

Improve algorithm

Improve package performance, and only de/recopile when necessary.
  • Loading branch information
danielbayley committed Feb 3, 2016
1 parent d7a8ad8 commit 05eaa51b13f3ef9a2a92bd7e5d5ea95b2c9c0fe7
Showing with 34 additions and 11 deletions.
  1. +34 −11 index.coffee
@@ -1,14 +1,37 @@
{execSync,exec} = require 'child_process'
module.exports =
subs: null
activate: ->
# {name} = require './package.json' if @debug
{exec} = require 'child_process' #,execSync}
#-------------------------------------------------------------------------------

module.exports = activate: ->
atom.workspace.observeTextEditors (editor) ->
scpt = editor.getPath()
#console.log "#{name} package activated." if @debug

if /\.scptd?$/.test scpt
# Decompile .scpt
buffer = execSync "osadecompile '#{scpt}'"
editor.setText buffer.toString()
@subs = atom.workspace.observeTextEditors (editor) ->
scpt = editor.getPath()
{scopeName} = editor.getGrammar()

# Recompile on save/close
editor.onDidDestroy -> #onDidSave
exec "osacompile -l JavaScript -o '#{scpt}'{,}"
if scopeName.endsWith('jxa') and scpt?.endsWith '.scpt'

#require 'fs-cson/register'
# {firstLineMatch} = require './grammars/jxa.cson' #fs.readdir
{createReadStream} = require 'fs'
{createInterface} = require 'readline'

# Determine if .scpt is compiled from the first line
#compiled = new RegExp firstLineMatch.substr 0, firstLineMatch.indexOf '|'
readline = createInterface input: createReadStream scpt
readline.on 'line', (line) -> if /^JsOsa/.test line #compiled.test line

# Decompile .scpt
stdout = exec "osadecompile '#{scpt}'" #execSync
stdout.stdout.on 'data', (data) -> editor.setText data #stdout.toString()
#console.log "#{name}: Decompiled #{scpt}." if @debug

# Recompile on save/close
editor.onDidDestroy -> #onDidSave
exec "osacompile -l JavaScript -o '#{scpt}'{,}"
#console.log "#{name}: Recompiled #{scpt}." if @debug

#-------------------------------------------------------------------------------
deactivate: -> @subs.dispose()

0 comments on commit 05eaa51

Please sign in to comment.
You can’t perform that action at this time.