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

Add positional arguments to create_account and new_project #47

Merged
merged 8 commits into from
Jun 5, 2019
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ near <command>
```
### Commands:
```Bash
near create_account # create a developer account
near deploy # deploy your smart contract
near create_account <account_id> # create a developer account
near new_project [dir] # generate a new project from template
near deploy # deploy your smart contract
near call <contractName> <methodName> [args] # submits transaction, can change state, account required
near view <contractName> <methodName> [args] # cannot change state, account is contract name
```
Expand Down
4 changes: 2 additions & 2 deletions bin/near
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const build = {
};

const createAccount = {
command: 'create_account',
command: 'create_account <accountId>',
desc: 'create a developer account',
builder: (yargs) => yargs
.option('accountId', {
Expand All @@ -84,7 +84,7 @@ const clean = {
};

const newProject = {
command: 'new_project',
command: 'new_project [projectDir]',
desc: 'create a new blank project',
builder: (yargs) => yargs
.option('projectDir', {
Expand Down
2 changes: 1 addition & 1 deletion blank_project/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
Contract says:
<h1 id="contract-message"></h1>
</div>
<script src="https://cdn.jsdelivr.net/npm/nearlib@0.5.4/dist/nearlib.js"></script>
<script src="https://cdn.jsdelivr.net/npm/nearlib@0.8.0/dist/nearlib.js"></script>
<script src="https://cdn.jsdelivr.net/npm/js-cookie@2/src/js.cookie.min.js"></script>
<script src="./config.js"></script>
<script src="./main.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion get-config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

module.exports = function getConfig() {
const configPath = process.cwd() + '/src/config';
const configPath = process.cwd() + '/src/config.js';
behaviary marked this conversation as resolved.
Show resolved Hide resolved
try {
return require(configPath)(process.env.NODE_ENV || 'development');
} catch (e) {
Expand Down
1 change: 1 addition & 0 deletions gulp-utils.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// FUTURE PEOPLE: This file is called "gulp-utils" but it's not related to the deprecated library called "gulp-utils". Don't panic.
function generateBindings(inputFile, outputFile, callback) {
const asc = getAsc();
asc.main([
Expand Down
14 changes: 7 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ ncp.limit = 16;

// TODO: Fix promisified wrappers to handle error properly

exports.newProject = async function() {
exports.newProject = async function(options) {
// Need to wait for the copy to finish, otherwise next tasks do not find files.
const projectDir = yargs.argv.projectDir;
const projectDir = options.projectDir;
const sourceDir = __dirname + "/blank_project";
console.log(`Copying files to new project directory (${projectDir}) from template source (${sourceDir}).`);
const copyDirFn = () => {
return new Promise(resolve => {
ncp (sourceDir, yargs.argv.projectDir, response => resolve(response));
ncp (sourceDir, options.projectDir, response => resolve(response));
})};
await copyDirFn();
console.log('Copying project files complete.')
Expand All @@ -35,18 +35,18 @@ exports.clean = async function() {
// Only works for dev environments
exports.createDevAccount = async function(options) {
const keyPair = await KeyPair.fromRandomSeed();

const { accountId } = options;
options.useDevAccount = true;
options.deps = {
keyStore: new InMemoryKeyStore(),
storage: {},
};

await neardev.connect(options);
await options.deps.createAccount(options.accountId, keyPair.getPublicKey());
await options.deps.createAccount(accountId, keyPair.getPublicKey());
const keyStore = new UnencryptedFileSystemKeyStore('./', options.networkId);
keyStore.setKey(options.accountId, keyPair);
console.log("Create account complete.");
keyStore.setKey(accountId, keyPair);
console.log("Create account complete for " + accountId);
};

async function connect(options) {
Expand Down
24 changes: 21 additions & 3 deletions test/new_project.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
#!/bin/sh
set -ex
rm -rf tmp-project

RED='\033[0;31m'
GREEN='\033[0;32m'

# remove temporary blank project
rm -rf test/tmp-project
cd test/
# test generating new project in cwd
mkdir tmp-project
cd tmp-project
../bin/near new_project
../../bin/near new_project
npm install
npm uninstall near-shell
npm install ../
npm install ../../
NODE_ENV=development npm run test
cd ..
rm -rf tmp-project
# test generating new project in new dir
behaviary marked this conversation as resolved.
Show resolved Hide resolved
../bin/near new_project 'tmp-project'
cd tmp-project
FILE=package.json
if test -f "$FILE"; then
echo "${GREEN}$FILE exists. Have a cookie!"
else
echo "${RED}ERROR: file not found."
behaviary marked this conversation as resolved.
Show resolved Hide resolved
fi