Skip to content

Introducing "executable" js option #497

Closed

Description

@kristianmandrup
# options#L45
    * option: 'exe'
      alias: 'x'
      type: 'Boolean'
      description: 'compile to executable Script'

Integration of option in command.ls. Not exactly elegant yet.

# command.ls#L148
# Write out a JavaScript source file with the compiled code. By default, files
# are written out in `cwd` as `.js` files with the same name, but the output
# directory can be customized with `--output`.
!function write-JS source, js, base, json
  #     foo.ls     => foo.js
  #     foo.jsm.ls => foo.jsm
  ext = 'X' if o.exe
  ext = '.json' if json
  extension = if ext is void then '.js' else ext
  filename = path.basename(source)replace do
    /(?:(\.\w+)?\.\w+)?$/ -> &1 or ext
  filename = filename.replace /X$/, ''

  dir = path.dirname source
  if o.output
    dir = path.join that, dir.slice if base is '.' then 0 else base.length
  js-path = path.join dir, filename

  if o.exe
    js = "#!/usr/bin/env node\n\n" + js

  !function compile
    e <-! fs.write-file js-path, js || '\n'
    return warn e if e
    util.log "#source => #js-path" if o.watch
    # add executable flag to js file
    if o.exe
      say "executable", js-path
      xe <- fs.chmod js-path, '0755'
      return warn xe if xe
    e <-! fs.stat dir
  return compile! unless e
  require 'child_process' .exec do
    "mkdir #{['-p' unless /^win/test process.platform]} #dir" compile

Activity

  1. changed the title [-]Introducing "executable" js option - how can I test it?[/-] [+]Introducing "executable" js option[/+] on Apr 29, 2014
  2. gkz commented on Oct 7, 2014

    @gkz
    Owner

    I'm not exactly sure of the purpose of this option.

    Is the idea to prepend ""#!/usr/bin/env node" to the outputted JS?

  3. apaleslimghost commented on Oct 7, 2014

    @apaleslimghost
    Contributor

    And apparently also to chmod and install it somewhere. This should be done via npm, using the bin field of package.json.

  4. kristianmandrup commented on Oct 7, 2014

    @kristianmandrup
    Author

    Thanks :)

  5. kristianmandrup commented on Oct 9, 2014

    @kristianmandrup
    Author

    Yes, I set it up via npm "bin" field now, but whenever I save the .ls file, it generates the js file to be non executable in a function wrapper and ditches my #!/usr/bin/env node comment. Would be super if it could detect this type of comment and not ditch it :)

  6. apaleslimghost commented on Oct 9, 2014

    @apaleslimghost
    Contributor

    You can put the shebang in JS-backticks and it will be preserved. npm should chmod +x it. You can get rid of the function wrapper with the -b option of lsc.

  7. kristianmandrup commented on Oct 11, 2014

    @kristianmandrup
    Author

    Didn't work ;/P

    `#!/usr/bin/env node`
    
    # more livescript follows...
    
    /usr/local/bin/lsc --compile library.ls
    Failed at: library.ls
    Error: Parse error on line 1: Unexpected 'BACKTICK'
    
    Process finished with exit code 1
    
  8. vendethiel commented on Oct 11, 2014

    @vendethiel
    Contributor

    You need more backticks. Otherwise it's infix function application.

  9. apaleslimghost commented on Oct 12, 2014

    @apaleslimghost
    Contributor
    ``#!/usr/bin/env node``
    
  10. kristianmandrup commented on Oct 12, 2014

    @kristianmandrup
    Author

    Yes, thanks! Works just fine :)

  11. Matthew-Davey commented on Oct 2, 2015

    @Matthew-Davey

    I was just about to raise an issue for this, glad I searched the archive first! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions