Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

👌 IMPROVE: Use XDG Specification for history file #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions utils/ask.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const os = require('os');
const fs = require('fs');
const path = require('path');
const { Input } = require('enquirer');
Expand All @@ -7,6 +6,8 @@ const handleError = require('cli-handle-error');
const shouldCancel = require('cli-should-cancel');
const { Store } = require('data-store');

const { getHistoryDirectory } = require('./history');

module.exports = async ({ name, message, hint, initial }) => {
let history = false;
if (
Expand All @@ -18,10 +19,7 @@ module.exports = async ({ name, message, hint, initial }) => {
history = {
autosave: true,
store: new Store({
path: path.join(
os.homedir(),
`.history/create-node-cli/${name}.json`
)
path: path.join(getHistoryDirectory(), `${name}.json`)
})
};
}
Expand Down
17 changes: 17 additions & 0 deletions utils/history.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const os = require('os');
const path = require('path');

module.exports = {
getHistoryDirectory: () => {
const XDG_CACHE_HOME = process.env.XDG_CACHE_HOME;
const FALLBACK_CACHE_DIRECTORY = path.join(os.homedir(), '.cache');

if (XDG_CACHE_HOME) {
return path.join(XDG_CACHE_HOME, 'create-node-cli');
}

if (FALLBACK_CACHE_DIRECTORY) {
return path.join(FALLBACK_CACHE_DIRECTORY, 'create-node-cli');
}
}
};