Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

Commit

Permalink
Merge pull request #362 from near/hotfix/create-neardev-if-absent
Browse files Browse the repository at this point in the history
dev-deploy: create neardev directory if it doesn't exist
  • Loading branch information
vgrichina authored May 13, 2020
2 parents 353d2f1 + f2976ac commit b56d908
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
13 changes: 9 additions & 4 deletions commands/dev-deploy.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
const { KeyPair } = require('near-api-js');
const exitOnError = require('../utils/exit-on-error');
const connect = require('../utils/connect');
const { readFile, writeFile } = require('fs').promises;
const { readFile, writeFile, mkdir } = require('fs').promises;
const { existsSync } = require('fs');
const eventtracking = require('../utils/eventtracking');
const { PROJECT_KEY_DIR } = require('../middleware/key-store');

module.exports = {
command: 'dev-deploy [wasmFile]',
Expand Down Expand Up @@ -51,8 +53,8 @@ async function devDeploy(options) {
async function createDevAccountIfNeeded({ near, keyStore, networkId, init }) {
// TODO: once examples and create-near-app use the dev-account.env file, we can remove the creation of dev-account
// https://github.com/nearprotocol/near-shell/issues/287
const accountFilePath = 'neardev/dev-account';
const accountFilePathEnv = 'neardev/dev-account.env';
const accountFilePath = `${PROJECT_KEY_DIR}/dev-account`;
const accountFilePathEnv = `${PROJECT_KEY_DIR}/dev-account.env`;
if (!init) {
try {
// throws if either file is missing
Expand All @@ -63,7 +65,10 @@ async function createDevAccountIfNeeded({ near, keyStore, networkId, init }) {
}
} catch (e) {
if (e.code === 'ENOENT') {
// Ignore as it means new account needs to be created, which happens below
// Create neardev directory, new account will be created below
if (!existsSync(PROJECT_KEY_DIR)) {
await mkdir(PROJECT_KEY_DIR);
}
} else {
throw e;
}
Expand Down
5 changes: 4 additions & 1 deletion middleware/key-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const MergeKeyStore = keyStores.MergeKeyStore;
const UnencryptedFileSystemKeyStore = keyStores.UnencryptedFileSystemKeyStore;

const CREDENTIALS_DIR = '.near-credentials';
const PROJECT_KEY_DIR = './neardev';

module.exports = async function createKeyStore() {
// ./neardev is an old way of storing keys under project folder. We want to fallback there for backwards compatibility
Expand All @@ -13,7 +14,9 @@ module.exports = async function createKeyStore() {
const credentialsPath = path.join(homedir, CREDENTIALS_DIR);
const keyStores = [
new UnencryptedFileSystemKeyStore(credentialsPath),
new UnencryptedFileSystemKeyStore('./neardev')
new UnencryptedFileSystemKeyStore(PROJECT_KEY_DIR)
];
return { keyStore: new MergeKeyStore(keyStores) };
};

module.exports.PROJECT_KEY_DIR = PROJECT_KEY_DIR;
4 changes: 3 additions & 1 deletion test_environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ const NodeEnvironment = require('jest-environment-node');
const nearAPI = require('near-api-js');
const fs = require('fs');

const { PROJECT_KEY_DIR } = require('./middleware/key-store');

const INITIAL_BALANCE = '500000000000000000000000000';
const testAccountName = 'test.near';

Expand All @@ -20,7 +22,7 @@ class LocalTestEnvironment extends NodeEnvironment {
contractName: 'test' + Date.now(),
accountId: 'test' + Date.now()
});
const keyStore = new nearAPI.keyStores.UnencryptedFileSystemKeyStore('./neardev');
const keyStore = new nearAPI.keyStores.UnencryptedFileSystemKeyStore(PROJECT_KEY_DIR);
config.deps = Object.assign(config.deps || {}, {
storage: this.createFakeStorage(),
keyStore,
Expand Down

0 comments on commit b56d908

Please sign in to comment.