-
-
Notifications
You must be signed in to change notification settings - Fork 450
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add prompt and dat.json to dat create (#765)
* make create command much nicer * add dat-json package + standard * a bit of cleanup * move key + plural to elements * exit on prompt error * fix prompt for tests
- Loading branch information
Showing
9 changed files
with
138 additions
and
20 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
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
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,51 @@ | ||
var output = require('neat-log/output') | ||
var pretty = require('prettier-bytes') | ||
var chalk = require('chalk') | ||
var importUI = require('./components/import-progress') | ||
var keyEl = require('./elements/key') | ||
var pluralize = require('./elements/pluralize') | ||
|
||
module.exports = createUI | ||
|
||
function createUI (state) { | ||
if (!state.dat) { | ||
return output` | ||
Creating a Dat! Add information to your dat.json file: | ||
` | ||
} | ||
|
||
var dat = state.dat | ||
var stats = dat.stats.get() | ||
var title = '\n' | ||
var progressView | ||
var exitMsg = ` | ||
Your dat is created! Run ${chalk.green('dat sync')} to share: | ||
${keyEl(dat.key)} | ||
` | ||
if (!state.opts.import) { | ||
// set exiting right away | ||
state.exiting = true | ||
} | ||
|
||
if (!state.exiting) { | ||
// Only show key if not about to exit | ||
title = `${keyEl(dat.key)}\n` | ||
} | ||
if (state.title) title += state.title | ||
|
||
if (stats.version > 0) title += `: ${stats.files} ${pluralize('file', stats.files)} (${pretty(stats.byteLength)})` | ||
else if (stats.version === 0) title += ': (empty archive)' | ||
|
||
if (state.opts.import) { | ||
progressView = importUI(state) + '\n' | ||
} else { | ||
progressView = 'Not importing files.' | ||
} | ||
|
||
return output` | ||
${title} | ||
${progressView} | ||
${state.exiting ? exitMsg : chalk.dim('Ctrl+C to 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,6 @@ | ||
var stringKey = require('dat-encoding').toStr | ||
var chalk = require('chalk') | ||
|
||
module.exports = function (key) { | ||
return `${chalk.blue(`dat://${stringKey(key)}`)}` | ||
} |
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,3 @@ | ||
module.exports = function pluralize (str, val) { | ||
return `${str}${val === 1 ? '' : 's'}` | ||
} |
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