-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: source code & test app debugger (#685)
- Loading branch information
1 parent
7858af5
commit 61bb4f4
Showing
3 changed files
with
153 additions
and
1 deletion.
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,38 @@ | ||
import path from 'path'; | ||
|
||
import json from 'rollup-plugin-json'; | ||
import babel from 'rollup-plugin-babel'; | ||
import resolve from 'rollup-plugin-node-resolve'; | ||
|
||
export default { | ||
dest: './test/utils/debugger/dist/debug.js', | ||
entry: './test/utils/debugger/src/debug.js', | ||
format: 'cjs', | ||
banner: ( | ||
'require(\'source-map-support\').install({\n' | ||
+ ' environment: \'node\'\n' | ||
+ '});\n' | ||
), | ||
onwarn: ({ code, message }) => { | ||
if (code === 'UNUSED_EXTERNAL_IMPORT') { | ||
return; | ||
} | ||
// eslint-disable-next-line no-console | ||
console.warn(message); | ||
}, | ||
plugins: [ | ||
json(), | ||
babel(), | ||
resolve() | ||
], | ||
external: id => !( | ||
id.startsWith('.') | ||
|| id.startsWith('/') // Absolute path on Unix | ||
|| /^[A-Z]:[\\/]/.test(id) // Absolute path on Windows | ||
|| id.startsWith('src') | ||
|| id.startsWith(path.join(__dirname, 'src')) | ||
|| id === 'babelHelpers' | ||
|| id === '\u0000babelHelpers' | ||
), | ||
sourceMap: true | ||
}; |
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,112 @@ | ||
import childProcess from 'child_process'; | ||
|
||
// @const spawn | ||
// Spawn commands from a node child process | ||
|
||
const { spawn } = childProcess; | ||
|
||
// @const repoDir | ||
// Starting CWD in the repo root | ||
|
||
const repoDir = process.cwd(); | ||
|
||
// @function log | ||
// Shortcut for console.log | ||
|
||
function log(...msg) { console.log(...msg); } | ||
|
||
// @async runCommand | ||
// Run a terminal command | ||
|
||
async function runCommand(command, args = [], [ preMsg = '', successMsg = '' ]) { | ||
log(preMsg); | ||
|
||
return new Promise((resolve, reject) => { | ||
const run = spawn(command, args); | ||
|
||
run.stderr.on('data', err => { | ||
log(err.toString()); | ||
reject(err.toString()); | ||
}); | ||
|
||
run.stdout.on('data', data => log(data.toString())); | ||
|
||
run.on('exit', () => resolve(successMsg)); | ||
|
||
}) | ||
.then(msg => log(msg)) | ||
.catch(err => log(err.toString())); | ||
|
||
} | ||
|
||
// @async runInspector | ||
// Run the node inspector | ||
// and open URL in Chrome window | ||
|
||
async function runInspector() { | ||
log('Starting node inspector...'); | ||
|
||
return new Promise((resolve, reject) => { | ||
|
||
const inspectArgs = '--inspect=4000 dist/boot.js'.split(' '); | ||
const run = spawn('node', inspectArgs); | ||
|
||
let url; | ||
|
||
function openURL(url) { | ||
runCommand( | ||
'osascript', | ||
['-e', `tell application "Google Chrome" to open location "${url}"`], | ||
['Opening in Google Chrome (OSX Users only)'] | ||
); | ||
} | ||
|
||
function parseURL(msg) { | ||
msg = msg.split('chrome-devtools'); | ||
return `chrome-devtools${msg[1]}`.replace(/\s+/g, ''); | ||
} | ||
|
||
run.stderr.on('data', msg => { | ||
if (url) { return; } | ||
msg = msg.toString(); | ||
log(msg); | ||
url = parseURL(msg); | ||
openURL(url); | ||
|
||
}); | ||
|
||
run.stdout.on('data', data => log(data.toString())); | ||
|
||
run.on('exit', (code) => log(`Child exited with code ${code}`)); | ||
|
||
}) | ||
.then(msg => log(msg)) | ||
.catch(err => log(err.toString)); | ||
|
||
} | ||
|
||
// @listener | ||
// Ensure repoDir is returned to when process exits | ||
|
||
process.on('exit', () => { | ||
process.chdir(repoDir); | ||
}); | ||
|
||
// @async | ||
// Run commands | ||
|
||
(async function() { | ||
|
||
const cleanArgs = 'rm -rf .nyc_output coverage dist test/test-app/dist test-results.xml'.split(' '); | ||
|
||
await runCommand('shx', cleanArgs, ['Cleaning Lux repo...', 'Repo cleaned.']); | ||
|
||
await runCommand('rollup', ['-c'], ['Building Lux source...', 'Lux source built.']); | ||
|
||
process.chdir('./test/test-app'); | ||
|
||
await runCommand('lux', ['build'], ['Building Lux test-app...', 'Lux test-app built.']); | ||
|
||
await runInspector(); | ||
|
||
}()); |