Skip to content
This repository

Provide a filename-only placeholder for exec #100

Open
wants to merge 2 commits into from

3 participants

Marc Andrew Eisenberg Andy Clement
Marc

Say we want to run unit-tests when the current file foo.js is saved. Our tests require that the following command is run:
node tests\test-foo.js

In order for this to work we need a ${filename} placeholder which returns only foo.js and not the full path (as ${file} currently does).

"exec": {
  "afterSave": {
    "*.js": "node tests/test-${filename}"
  }
}
Marc cawoodm Provide a filename-only placeholder for exec
Say we want to run unit-tests when the current file `foo.js` is saved. Our tests require that the following command is run:
`node tests\test-foo.js`

In order for this to work we need a `${filename}` placeholder which returns only `foo.js` and not the full path (as `${file}` currently does).

```javascript
  "exec": {
    "afterSave": {
      "*.js": "node tests/test-${filename}.js"
    }
  }
```
5583394
Marc

Trust me - it's awesome:
tests

Andrew Eisenberg

Thanks for the Christmas present!

Marc

Ho ho ho!

I have an update/addition. If you run exec in a subfolder (foo/) it seems to remain in the projectDir so you need the subpath foo/db.js.

Should we adapt my code above or add a new ${filenamer} (filename __r__elative):

def("${filenamer}", function() {
    var p = editor.getFilePath();
    return p.substring((window.fsroot || getDir()).length+1);
});
Andrew Eisenberg
Marc cawoodm Renamed ${fileName}. Added ${fileBase} ${filePath}
Renamed ${filename} to ${fileName}
Added ${fileBase} and ${filePath}
dfbbd33
Marc

OK, I went with:
$fileName -> hello.js
$fileBase -> hello
$filePath -> subdir/hello.js

Marc

@aeisenberg can you merge my cawoodm@dfbbd33 changes?

Andy Clement
Owner

Marc - I'm afraid we are still waiting for a contributor agreement to be setup so that you can sign it and we can take the contribution. I'm really hoping it'll be in the next few days.

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

Showing 2 unique commits by 1 author.

Dec 25, 2012
Marc cawoodm Provide a filename-only placeholder for exec
Say we want to run unit-tests when the current file `foo.js` is saved. Our tests require that the following command is run:
`node tests\test-foo.js`

In order for this to work we need a `${filename}` placeholder which returns only `foo.js` and not the full path (as `${file}` currently does).

```javascript
  "exec": {
    "afterSave": {
      "*.js": "node tests/test-${filename}.js"
    }
  }
```
5583394
Dec 30, 2012
Marc cawoodm Renamed ${fileName}. Added ${fileBase} ${filePath}
Renamed ${filename} to ${fileName}
Added ${fileBase} and ${filePath}
dfbbd33
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 19 additions and 0 deletions. Show diff stats Hide diff stats

  1. +19 0 client/scripts/scripted/exec/param-resolver.js
19 client/scripts/scripted/exec/param-resolver.js
@@ -83,6 +83,25 @@ function forEditor(editor) {
83 83 return editor.getFilePath();
84 84 });
85 85
  86 + // Returns 'hello.js' from '/path/project/sub/helloworld.js'
  87 + def("${fileName}", function() {
  88 + var p = editor.getFilePath();
  89 + return p.substring(p.lastIndexOf('/')+1);
  90 + });
  91 +
  92 + // Returns 'sub/hello.js' from '/path/project/sub/helloworld.js'
  93 + def("${filePath}", function() {
  94 + var p = editor.getFilePath();
  95 + return p.substring((window.fsroot || getDir()).length+1);
  96 + });
  97 +
  98 + // Returns 'hello' from '/path/project/sub/helloworld.js'
  99 + def("${fileBase}", function() {
  100 + var p = editor.getFilePath();
  101 + p = p.substring(p.lastIndexOf('/')+1);
  102 + return p.substring(0, p.lastIndexOf('.'));
  103 + });
  104 +
86 105 def("${dir}", getDir);
87 106
88 107 def("${projectDir}", function () {

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.