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

create config directory using recursive, and use .config folder as root for linux and other platforms #39

Closed
wants to merge 4 commits into from
Closed
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
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "github-pewpew",
"version": "1.2.2",
"version": "1.2.3",
"description": "Clean up and remove those unnecessary GitHub repositories. Pew pew!",
"main": "index.js",
"bin": {
Expand Down
13 changes: 9 additions & 4 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ const Utils = require('./utils');

const { package: PACKAGE, author: PACKAGE_AUTHOR } = Utils.getPackageDetails();
const HOME_DIR = require('os').homedir();

const CONFIG_PATH_BY_PLATFORM = {
'win32': path.join('AppData', 'Roaming', PACKAGE_AUTHOR, PACKAGE.name),
'darwin': path.join('Library', `com.${PACKAGE_AUTHOR}.${PACKAGE.name}`)
}
const DEFAULT_CONFIG_PATH = path.join('.config', `com.${PACKAGE_AUTHOR}.${PACKAGE.name}`)
const CONFIG_DIR = getConfigDir(HOME_DIR);
const CONFIG_FILE = path.join(CONFIG_DIR, 'auth.json');

Expand All @@ -15,7 +21,7 @@ function save(token) {
token: token,
};

if (!fs.existsSync(CONFIG_DIR)) fs.mkdirSync(CONFIG_DIR);
if (!fs.existsSync(CONFIG_DIR)) fs.mkdirSync(CONFIG_DIR, { recursive: true });
fs.writeFileSync(CONFIG_FILE, JSON.stringify(configuration), 'utf8');

return true;
Expand All @@ -41,11 +47,10 @@ function deleteFile() {
}

function getConfigDir(homeDir) {
const configPath = CONFIG_PATH_BY_PLATFORM[process.platform] || DEFAULT_CONFIG_PATH
const configDir = path.join(
homeDir,
process.platform === 'win32'
? path.join('AppData', 'Roaming', PACKAGE_AUTHOR, PACKAGE.name)
: path.join('Library', `com.${PACKAGE_AUTHOR}.${PACKAGE.name}`)
configPath
);

return configDir;
Expand Down