-
Notifications
You must be signed in to change notification settings - Fork 430
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[core] Add
sanity exec
command that registers part loader + babel (#…
…138)
- Loading branch information
Showing
5 changed files
with
44 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const presets = ['es2015-node4', 'stage-2'] | ||
|
||
require('babel-register')({ | ||
presets: presets.map(preset => require.resolve(`babel-preset-${preset}`)), | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const spawn = require('child_process').spawn | ||
const fsp = require('fs-promise') | ||
const path = require('path') | ||
|
||
module.exports = async args => { | ||
const [script] = args.argsWithoutOptions | ||
const scriptPath = path.resolve(script) | ||
|
||
if (!script) { | ||
throw new Error('SCRIPT must be provided. `sanity exec <script>`') | ||
} | ||
|
||
if (!await fsp.exists(scriptPath)) { | ||
throw new Error(`${scriptPath} does not exist`) | ||
} | ||
|
||
const babel = require.resolve('./babel') | ||
const loader = require.resolve('@sanity/plugin-loader/register') | ||
const proc = spawn(process.argv[0], ['-r', babel, '-r', loader, scriptPath]) | ||
|
||
proc.stdout.pipe(process.stdout) | ||
proc.stderr.pipe(process.stderr) | ||
proc.on('close', process.exit) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import lazyRequire from '@sanity/util/lib/lazyRequire' | ||
|
||
export default { | ||
name: 'exec', | ||
signature: 'SCRIPT', | ||
description: 'Runs a script in Sanity context', | ||
action: lazyRequire(require.resolve('../../actions/exec/execScript')) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters