-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use package name to set keys and use json
- Loading branch information
Showing
10 changed files
with
82 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
node_modules | ||
npm-debug.log | ||
.config | ||
yarn-error.log |
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 |
---|---|---|
@@ -1,32 +1,40 @@ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
|
||
import { getConfigPath } from './utils'; | ||
import { getConfigPath, getProjectName } from './utils'; | ||
|
||
|
||
export default function init(key) { | ||
const value = `LOCALEAPP_KEY="${key}"`; | ||
const configPath = getConfigPath(true); | ||
const projectName = getProjectName(); | ||
let existingKeys = {}; | ||
try { | ||
existingKeys = JSON.parse(fs.readFileSync(configPath, 'utf8')); | ||
} | ||
catch (e) { | ||
console.log('No previous keys'); | ||
} | ||
const combined = { ...existingKeys, [projectName]: key }; | ||
fs.open(configPath, 'w', (err, fd) => { | ||
if (err) { | ||
fs.writeFile(configPath, '', (err) => { | ||
if(err) throw err; | ||
writeConfig(fd, value); | ||
writeConfig(fd, combined); | ||
}); | ||
} | ||
else { | ||
writeConfig(fd, value); | ||
writeConfig(fd, combined); | ||
} | ||
}); | ||
} | ||
|
||
|
||
function writeConfig(fd, value) { | ||
fs.write(fd, value, (err, written) => { | ||
function writeConfig(fd, keys) { | ||
fs.write(fd, JSON.stringify(keys), (err, written) => { | ||
if (err) { | ||
console.error('Could not save key'); | ||
throw err; | ||
} | ||
console.log('Successfully saved localeapp 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
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