|
7 | 7 | * for complete documentation.
|
8 | 8 | */
|
9 | 9 |
|
10 |
| -// Use any standard Node library, along with opn (https://www.npmjs.com/package/opn) and |
11 |
| -// any globally-installed Node packages. |
12 |
| -const path = require('path'); |
13 |
| -const childProcess = require('child_process'); |
14 |
| -const opn = require('opn'); |
15 |
| -const os = require('os'); |
| 10 | +((require) => { |
| 11 | + // Use any standard Node library, along with opn (https://www.npmjs.com/package/opn) and |
| 12 | + // any globally-installed Node packages. |
| 13 | + const path = require('path'); |
| 14 | + const childProcess = require('child_process'); |
| 15 | + const opn = require('opn'); |
| 16 | + const os = require('os'); |
16 | 17 |
|
17 |
| -module.exports = { |
18 |
| - rules: [ |
19 |
| - /* EXAMPLES: |
| 18 | + return { |
| 19 | + rules: [ |
| 20 | + /* |
20 | 21 |
|
21 |
| - // Run script for new file extension |
22 |
| - { |
23 |
| - pattern: '\.awesome$', |
24 |
| - run: (command, filepath) => `awesome-compiler "${filepath}"` |
25 |
| - }, |
| 22 | + // Run script for new file extension |
| 23 | + { |
| 24 | + pattern: '\.awesome$', |
| 25 | + run: (command, filepath) => `awesome-compiler "${filepath}"` |
| 26 | + }, |
26 | 27 |
|
27 |
| - // ------------------------------------------------------ |
| 28 | + // ------------------------------------------------------ |
28 | 29 |
|
29 |
| - // Rule to compile .md (Markdown) file into HTML, then display in default browser. |
30 |
| - // Requires first running `npm -g markdown` (https://github.com/evilstreak/markdown-js) |
31 |
| - { |
32 |
| - pattern: '\.md$', |
33 |
| - run: (command, filepath, args) => { |
34 |
| - const outputHtmlFile = `${args.runDir}/${args.baseFilename}.html`; |
35 |
| - childProcess.execSync(`md2html ${filepath} > ${outputHtmlFile}`); |
36 |
| - opn(outputHtmlFile); |
| 30 | + // Rule to compile .md (Markdown) file into HTML, then display in default browser. |
| 31 | + // Requires first running `npm -g markdown` (https://github.com/evilstreak/markdown-js) |
| 32 | + { |
| 33 | + pattern: '\.md$', |
| 34 | + run: (command, filepath, args) => { |
| 35 | + const outputHtmlFile = `${args.runDir}/${args.baseFilename}.html`; |
| 36 | + childProcess.execSync(`md2html ${filepath} > ${outputHtmlFile}`); |
| 37 | + opn(outputHtmlFile); |
37 | 38 |
|
38 |
| - // Must return a shell command |
39 |
| - return `echo "Generated '${outputHtmlFile}'" and opened in default browser`; |
40 |
| - } |
41 |
| - }, |
| 39 | + // Must return a shell command |
| 40 | + return `echo "Generated '${outputHtmlFile}'" and opened in default browser`; |
| 41 | + } |
| 42 | + }, |
42 | 43 |
|
43 |
| - // ------------------------------------------------------ |
| 44 | + // ------------------------------------------------------ |
44 | 45 |
|
45 |
| - // Filter file by both filename and content. Run pre-execution command. |
46 |
| - // Put "//nvm: v6.10.1" at top of snippet file to use a specific Node version for execution |
47 |
| - { |
48 |
| - pattern: (command) => { |
49 |
| - return /\.js$/.test(command.file.filename) |
50 |
| - && command.file.content.indexOf('//nvm:') >= 0; |
51 |
| - }, |
52 |
| - run: (command, filepath) => { |
53 |
| - let nvmVersion = command.file.content.match(/(\/\/nvm: v(.+))/)[0] |
54 |
| - .replace('//nvm: ', ''); |
| 46 | + // Filter file by both filename and content. Run pre-execution command. |
| 47 | + // Put "//nvm: v6.10.1" at top of snippet file to use a specific Node version for execution |
| 48 | + { |
| 49 | + pattern: (command) => { |
| 50 | + return /\.js$/.test(command.file.filename) |
| 51 | + && command.file.content.indexOf('//nvm:') >= 0; |
| 52 | + }, |
| 53 | + run: (command, filepath) => { |
| 54 | + let nvmVersion = command.file.content.match(/(\/\/nvm: v(.+))/)[0] |
| 55 | + .replace('//nvm: ', ''); |
55 | 56 |
|
56 |
| - return `export NVM_DIR=~/.nvm ` + |
57 |
| - `&& source ~/.nvm/nvm.sh` + |
58 |
| - `&& nvm use ${nvmVersion} ` + |
59 |
| - `&& node "${filepath}"`; |
| 57 | + return `export NVM_DIR=~/.nvm ` + |
| 58 | + `&& source ~/.nvm/nvm.sh` + |
| 59 | + `&& nvm use ${nvmVersion} ` + |
| 60 | + `&& node "${filepath}"`; |
| 61 | + } |
60 | 62 | }
|
61 |
| - } |
62 | 63 |
|
63 |
| - */ |
64 |
| - ] |
65 |
| -}; |
| 64 | + */ |
| 65 | + ] |
| 66 | + }; |
| 67 | +}); |
0 commit comments