Skip to content

Commit

Permalink
athloi custom tasks
Browse files Browse the repository at this point in the history
 🐿 v2.8.0
  • Loading branch information
apaleslimghost committed Apr 24, 2018
1 parent 12a6fe7 commit 006cd52
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
42 changes: 42 additions & 0 deletions athloi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const open = require('opn');
const tcpPortUsed = require('tcp-port-used');
const url = require('url');

const openUrls = {
docs: 'http://localhost:8000',
storybook: 'http://localhost:9001',
};

module.exports = ({tasks, prompt, addPrompt}) => ({
start: Object.assign({}, tasks.start, {
requiredArgs: ['open'],

choice: addPrompt(
tasks.start.choice,
() => prompt([{
type: 'list',
name: 'open',
message: 'What do you want to open in the browser?',
choices: [
{value: 'docs', short: 'Docs', name: 'The documentation website'},
{value: 'storybook', short: 'Storybook', name: 'The component explorer'},
]
}])
),

run(options) {
const openUrl = openUrls[options.open];
const port = parseInt(url.parse(openUrl).port, 10);

if(port) {
// wait for whatever (storybook/gatsby) to be listening on the port
// try every 500ms and give up after 30s
tcpPortUsed.waitUntilUsed(port, 500, 30000)
.then(() => open(openUrl))
.catch(e => console.error(e.stack));
}

return tasks.start.run(options);
},
}),
});
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@
},
"devDependencies": {
"@financial-times/secret-squirrel": "^2.8.0",
"athloi": "^1.2.0",
"husky": "^0.14.3",
"jest": "^22.4.3",
"lerna": "^3.0.0-beta.16",
"opn": "^5.3.0",
"react": "^16.3.1",
"react-test-renderer": "^16.3.1"
"react-test-renderer": "^16.3.1",
"tcp-port-used": "^0.1.2"
},
"x-dash": {
"engine": {
Expand All @@ -26,8 +29,5 @@
"factory": "createElement"
}
}
},
"dependencies": {
"athloi": "^1.0.0"
}
}

0 comments on commit 006cd52

Please sign in to comment.