create-near-app 3.0.0 → 4.0.0-beta.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +37 -31
- package/dist/app.js +76 -0
- package/dist/checks.js +34 -0
- package/dist/make.js +135 -0
- package/dist/messages.js +56 -0
- package/dist/package-json.js +164 -0
- package/dist/tracking.js +34 -0
- package/dist/types.js +3 -0
- package/dist/user-input.js +211 -0
- package/index.js +1 -184
- package/package.json +49 -40
- package/{contracts → templates/contracts}/assemblyscript/README.md +6 -5
- package/templates/contracts/assemblyscript/as-pect.config.js +1 -0
- package/{contracts → templates/contracts}/assemblyscript/asconfig.json +0 -0
- package/{contracts → templates/contracts}/assemblyscript/assembly/__tests__/as-pect.d.ts +0 -0
- package/templates/contracts/assemblyscript/assembly/__tests__/main.spec.ts +11 -0
- package/{contracts → templates/contracts}/assemblyscript/assembly/as_types.d.ts +0 -0
- package/{contracts → templates/contracts}/assemblyscript/assembly/index.ts +5 -5
- package/{contracts → templates/contracts}/assemblyscript/assembly/tsconfig.json +0 -0
- package/templates/contracts/assemblyscript/package.json +14 -0
- package/templates/contracts/js/README.md +23 -0
- package/templates/contracts/js/babel.config.json +7 -0
- package/templates/contracts/js/package.json +18 -0
- package/templates/contracts/js/src/contract.ts +31 -0
- package/templates/contracts/js/tsconfig.json +10 -0
- package/{contracts → templates/contracts}/rust/.cargo/config +0 -0
- package/{contracts → templates/contracts}/rust/Cargo.toml +1 -1
- package/{contracts → templates/contracts}/rust/README.md +6 -8
- package/{contracts → templates/contracts}/rust/src/lib.rs +0 -0
- package/templates/frontend/react/frontend/App.js +66 -0
- package/templates/{react/frontend/assets/img → frontend/react/frontend/assets}/favicon.ico +0 -0
- package/templates/{vanilla/frontend/assets/css → frontend/react/frontend/assets}/global.css +64 -80
- package/templates/{react/frontend/assets/img → frontend/react/frontend/assets}/logo-black.svg +0 -0
- package/templates/{react/frontend/assets/img → frontend/react/frontend/assets}/logo-white.svg +0 -0
- package/templates/frontend/react/frontend/index.html +15 -0
- package/templates/frontend/react/frontend/index.js +15 -0
- package/templates/{react/frontend/assets/js/near/utils.js → frontend/react/frontend/near-api.js} +19 -19
- package/templates/frontend/react/frontend/near-config.js +61 -0
- package/templates/frontend/react/frontend/package.json +44 -0
- package/templates/frontend/react/frontend/ui-components.js +60 -0
- package/templates/{vanilla/frontend/assets/img → frontend/vanilla/frontend/assets}/favicon.ico +0 -0
- package/templates/{react/frontend/assets/css → frontend/vanilla/frontend/assets}/global.css +64 -80
- package/templates/{vanilla/frontend/assets/img → frontend/vanilla/frontend/assets}/logo-black.svg +0 -0
- package/templates/{vanilla/frontend/assets/img → frontend/vanilla/frontend/assets}/logo-white.svg +0 -0
- package/templates/frontend/vanilla/frontend/index.html +86 -0
- package/templates/frontend/vanilla/frontend/index.js +78 -0
- package/templates/{vanilla/frontend/assets/js/near/utils.js → frontend/vanilla/frontend/near-api.js} +18 -18
- package/templates/frontend/vanilla/frontend/near-config.js +62 -0
- package/templates/frontend/vanilla/frontend/package.json +18 -0
- package/{integration-tests/ts → templates/integration-tests/classic-tests}/ava.config.cjs +9 -9
- package/{integration-tests/ts → templates/integration-tests/classic-tests}/package.json +5 -4
- package/templates/integration-tests/classic-tests/src/config.ts +34 -0
- package/templates/integration-tests/classic-tests/src/main.ava.ts +32 -0
- package/{integration-tests → templates/integration-tests/workspaces-tests}/rs/Cargo.toml +0 -0
- package/{integration-tests → templates/integration-tests/workspaces-tests}/rs/src/tests.rs +5 -3
- package/templates/{react → integration-tests/workspaces-tests/ts}/ava.config.cjs +9 -9
- package/templates/integration-tests/workspaces-tests/ts/package.json +17 -0
- package/templates/integration-tests/workspaces-tests/ts/src/main.ava.ts +50 -0
- package/templates/{react → shared}/.gitpod.yml +2 -2
- package/templates/{vanilla → shared}/README.md +29 -30
- package/templates/{react → shared}/near.gitignore +1 -1
- package/contracts/assemblyscript/as-pect.config.js +0 -1
- package/contracts/assemblyscript/assembly/__tests__/main.spec.ts +0 -11
- package/contracts/assemblyscript/package.json +0 -13
- package/integration-tests/ts/src/main.ava.ts +0 -44
- package/templates/react/README.md +0 -102
- package/templates/react/frontend/App.js +0 -202
- package/templates/react/frontend/__mocks__/fileMock.js +0 -3
- package/templates/react/frontend/assets/js/near/config.js +0 -63
- package/templates/react/frontend/index.html +0 -25
- package/templates/react/frontend/index.js +0 -14
- package/templates/react/neardev/shared-test/test.near.json +0 -1
- package/templates/react/package.json +0 -55
- package/templates/vanilla/.gitattributes +0 -2
- package/templates/vanilla/.gitpod.yml +0 -6
- package/templates/vanilla/frontend/assets/js/index.js +0 -74
- package/templates/vanilla/frontend/assets/js/near/config.js +0 -63
- package/templates/vanilla/frontend/index.html +0 -103
- package/templates/vanilla/near.gitignore +0 -27
- package/templates/vanilla/neardev/shared-test/test.near.json +0 -1
- package/templates/vanilla/package.json +0 -34
- package/utils/rust-setup.js +0 -102
- package/utils/tracking.js +0 -29
package/README.md
CHANGED
|
@@ -1,62 +1,70 @@
|
|
|
1
|
-
|
|
1
|
+
# Create NEAR App
|
|
2
2
|
===============
|
|
3
3
|
[](https://gitpod.io/#https://github.com/nearprotocol/create-near-app)
|
|
4
4
|
|
|
5
5
|
Quickly build apps backed by the [NEAR](https://near.org) blockchain
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
Prerequisites
|
|
9
|
-
=============
|
|
8
|
+
## Prerequisites
|
|
10
9
|
|
|
11
|
-
Make sure you have a [current version of Node.js](https://nodejs.org/en/about/releases/) installed – we are targeting versions `
|
|
12
|
-
**Note**: if using Node version 13 please be advised that you will need version >= 13.7.0
|
|
10
|
+
Make sure you have a [current version of Node.js](https://nodejs.org/en/about/releases/) installed – we are targeting versions `16+`.
|
|
13
11
|
|
|
12
|
+
Read about other [prerequisites](https://docs.near.org/develop/prerequisites) in our docs.
|
|
14
13
|
|
|
15
|
-
Getting Started
|
|
16
|
-
|
|
14
|
+
## Getting Started
|
|
15
|
+
|
|
16
|
+
To create a new NEAR project run this and follow interactive prompts:
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
npx create-near-app
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
Follow the instructions in the README.md in the project you just created! 🚀
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
You can create contracts written in:
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
- [JavaScript](https://docs.near.org/develop/quickstart-guide)
|
|
25
|
+
- [Rust](https://docs.near.org/develop/prerequisites)
|
|
26
|
+
- AssemblyScript
|
|
25
27
|
|
|
26
|
-
|
|
28
|
+
You can create a frontend template in:
|
|
27
29
|
|
|
28
|
-
|
|
30
|
+
- [React](https://reactjs.org/)
|
|
31
|
+
- Vanilla JavaScript
|
|
29
32
|
|
|
30
|
-
|
|
33
|
+
For testing we use a sandboxed environment of NEAR (called Workspaces).
|
|
34
|
+
You can write the tests in JavaScript or Rust.
|
|
31
35
|
|
|
32
|
-
|
|
33
|
-
* `--contract=rust` – use [Rust](https://docs.near.org/docs/develop/contracts/rust/near-sdk-rs) for your smart contract
|
|
36
|
+
### Using CLI arguments to run `create-near-app`
|
|
34
37
|
|
|
38
|
+
This CLI supports arguments to skip interactive prompts:
|
|
35
39
|
|
|
36
|
-
|
|
37
|
-
|
|
40
|
+
```shell
|
|
41
|
+
npx create-near-app
|
|
42
|
+
<project-name>
|
|
43
|
+
--contract js|rust|assemblyscript
|
|
44
|
+
--frontend vanilla|react|none
|
|
45
|
+
--tests js|rust
|
|
46
|
+
--install
|
|
47
|
+
```
|
|
38
48
|
|
|
39
|
-
|
|
49
|
+
Use `--install` to automatically install dependencies from all `package.json` files.
|
|
40
50
|
|
|
51
|
+
When using arguments, all arguments are required, except for `--install`.
|
|
41
52
|
|
|
42
|
-
Getting Help
|
|
43
|
-
============
|
|
53
|
+
## Getting Help
|
|
44
54
|
|
|
45
55
|
Check out our [documentation](https://docs.near.org) or chat with us on [Discord](http://near.chat). We'd love to hear from you!
|
|
46
56
|
|
|
47
57
|
|
|
48
|
-
Contributing
|
|
49
|
-
============
|
|
58
|
+
## Contributing to `create-near-app`
|
|
50
59
|
|
|
51
60
|
To make changes to `create-near-app` itself:
|
|
52
61
|
|
|
53
62
|
* clone the repository (Windows users, [use `git clone -c core.symlinks=true`](https://stackoverflow.com/a/42137273/249801))
|
|
54
63
|
* in your terminal, enter one of the folders inside `templates`, such as `templates/vanilla`
|
|
55
|
-
* now you can run `
|
|
64
|
+
* now you can run `npm install` to install dependencies and `npm run dev` to run the local development server, just like you can in a new app created with `create-near-app`
|
|
56
65
|
|
|
57
66
|
|
|
58
|
-
|
|
59
|
-
---------------------
|
|
67
|
+
#### About commit messages
|
|
60
68
|
|
|
61
69
|
`create-near-app` uses semantic versioning and auto-generates nice release notes & a changelog all based off of the commits. We do this by enforcing [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/). In general the pattern mostly looks like this:
|
|
62
70
|
|
|
@@ -73,8 +81,7 @@ Real world examples can look like this:
|
|
|
73
81
|
If your change should show up in release notes as a feature, use `feat:`. If it should show up as a fix, use `fix:`. Otherwise, you probably want `refactor:` or `chore:`. [More info](https://github.com/conventional-changelog/commitlint/#what-is-commitlint)
|
|
74
82
|
|
|
75
83
|
|
|
76
|
-
Deploy
|
|
77
|
-
------
|
|
84
|
+
#### Deploy `create-near-app`
|
|
78
85
|
|
|
79
86
|
If you want to deploy a new version, you will need two prerequisites:
|
|
80
87
|
|
|
@@ -85,13 +92,12 @@ If you want to deploy a new version, you will need two prerequisites:
|
|
|
85
92
|
|
|
86
93
|
Then run one script:
|
|
87
94
|
|
|
88
|
-
|
|
95
|
+
npm run release
|
|
89
96
|
|
|
90
97
|
Or just `release-it`
|
|
91
98
|
|
|
92
99
|
|
|
93
|
-
License
|
|
94
|
-
=======
|
|
100
|
+
## License
|
|
95
101
|
|
|
96
102
|
This repository is distributed under the terms of both the MIT license and the Apache License (Version 2.0).
|
|
97
103
|
See [LICENSE](LICENSE) and [LICENSE-APACHE](LICENSE-APACHE) for details.
|
package/dist/app.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
const path_1 = __importDefault(require("path"));
|
|
30
|
+
const make_1 = require("./make");
|
|
31
|
+
const user_input_1 = require("./user-input");
|
|
32
|
+
const show = __importStar(require("./messages"));
|
|
33
|
+
(async function () {
|
|
34
|
+
const promptResult = await (0, user_input_1.promptAndGetConfig)();
|
|
35
|
+
if (promptResult === null) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const { config: { projectName, contract, frontend, tests, install }, projectPath, isFromPrompts, } = promptResult;
|
|
39
|
+
show.creatingApp();
|
|
40
|
+
if (contract === 'assemblyscript') {
|
|
41
|
+
show.assemblyscriptWarning();
|
|
42
|
+
}
|
|
43
|
+
let createSuccess;
|
|
44
|
+
try {
|
|
45
|
+
createSuccess = await (0, make_1.createProject)({
|
|
46
|
+
contract,
|
|
47
|
+
frontend,
|
|
48
|
+
tests,
|
|
49
|
+
projectName,
|
|
50
|
+
verbose: false,
|
|
51
|
+
rootDir: path_1.default.resolve(__dirname, '../templates'),
|
|
52
|
+
projectPath,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
catch (e) {
|
|
56
|
+
console.error(e);
|
|
57
|
+
createSuccess = false;
|
|
58
|
+
}
|
|
59
|
+
if (createSuccess) {
|
|
60
|
+
show.setupSuccess(projectPath, contract, frontend);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
show.setupFailed();
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
if (install) {
|
|
67
|
+
await (0, make_1.runDepsInstall)(projectPath);
|
|
68
|
+
}
|
|
69
|
+
else if (isFromPrompts) {
|
|
70
|
+
const { depsInstall } = await (0, user_input_1.showDepsInstallPrompt)();
|
|
71
|
+
if (depsInstall) {
|
|
72
|
+
await (0, make_1.runDepsInstall)(projectPath);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
})();
|
|
76
|
+
//# sourceMappingURL=app.js.map
|
package/dist/checks.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.postMessage = exports.preMessage = void 0;
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
function preMessage(settings) {
|
|
9
|
+
switch (settings.contract) {
|
|
10
|
+
case 'assemblyscript':
|
|
11
|
+
return asPreMessage(settings);
|
|
12
|
+
default:
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.preMessage = preMessage;
|
|
17
|
+
function postMessage(settings) {
|
|
18
|
+
switch (settings.contract) {
|
|
19
|
+
default:
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.postMessage = postMessage;
|
|
24
|
+
// AS preMessage
|
|
25
|
+
const AS_NOT_SUPPORTED_MSG = (0, chalk_1.default) `
|
|
26
|
+
{yellow Warning} NEAR-SDK-AS might {bold {red not be compatible}} with your system
|
|
27
|
+
`;
|
|
28
|
+
async function asPreMessage({ tests }) {
|
|
29
|
+
if (tests === 'workspaces') {
|
|
30
|
+
console.log(AS_NOT_SUPPORTED_MSG);
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=checks.js.map
|
package/dist/make.js
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.runDepsInstall = exports.copyDir = exports.renameFile = exports.createFiles = exports.createProject = void 0;
|
|
30
|
+
const show = __importStar(require("./messages"));
|
|
31
|
+
const cross_spawn_1 = __importDefault(require("cross-spawn"));
|
|
32
|
+
const fs_1 = __importDefault(require("fs"));
|
|
33
|
+
const ncp_1 = require("ncp");
|
|
34
|
+
const path_1 = __importDefault(require("path"));
|
|
35
|
+
const package_json_1 = require("./package-json");
|
|
36
|
+
async function createProject({ contract, frontend, tests, projectPath, projectName, verbose, rootDir }) {
|
|
37
|
+
// Create files in the project folder
|
|
38
|
+
await createFiles({ contract, frontend, projectName, tests, projectPath, verbose, rootDir });
|
|
39
|
+
// Create package.json
|
|
40
|
+
const packageJson = (0, package_json_1.buildPackageJson)({ contract, frontend, tests, projectName });
|
|
41
|
+
fs_1.default.writeFileSync(path_1.default.resolve(projectPath, 'package.json'), Buffer.from(JSON.stringify(packageJson, null, 2)));
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
exports.createProject = createProject;
|
|
45
|
+
async function createFiles({ contract, frontend, tests, projectPath, verbose, rootDir }) {
|
|
46
|
+
// skip build artifacts and symlinks
|
|
47
|
+
const skip = ['.cache', 'dist', 'out', 'node_modules'];
|
|
48
|
+
// copy frontend
|
|
49
|
+
if (frontend !== 'none') {
|
|
50
|
+
const sourceTemplateDir = `${rootDir}/frontend/${frontend}`;
|
|
51
|
+
await copyDir(sourceTemplateDir, projectPath, { verbose, skip: skip.map(f => path_1.default.join(sourceTemplateDir, f)) });
|
|
52
|
+
}
|
|
53
|
+
// shared files
|
|
54
|
+
const sourceSharedDir = `${rootDir}/shared`;
|
|
55
|
+
await copyDir(sourceSharedDir, projectPath, { verbose, skip: skip.map(f => path_1.default.join(sourceSharedDir, f)) });
|
|
56
|
+
// copy contract files
|
|
57
|
+
const contractSourceDir = `${rootDir}/contracts/${contract}`;
|
|
58
|
+
await copyDir(contractSourceDir, `${projectPath}/contract`, {
|
|
59
|
+
verbose,
|
|
60
|
+
skip: skip.map(f => path_1.default.join(contractSourceDir, f))
|
|
61
|
+
});
|
|
62
|
+
// copy tests
|
|
63
|
+
let sourceTestDir = `${rootDir}/integration-tests`;
|
|
64
|
+
if (tests === 'js') {
|
|
65
|
+
sourceTestDir = path_1.default.resolve(sourceTestDir, 'workspaces-tests/ts');
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
sourceTestDir = path_1.default.resolve(sourceTestDir, 'workspaces-tests/rs');
|
|
69
|
+
}
|
|
70
|
+
await copyDir(sourceTestDir, `${projectPath}/integration-tests/`, {
|
|
71
|
+
verbose,
|
|
72
|
+
skip: skip.map(f => path_1.default.join(sourceTestDir, f))
|
|
73
|
+
});
|
|
74
|
+
// add .gitignore
|
|
75
|
+
await (0, exports.renameFile)(`${projectPath}/near.gitignore`, `${projectPath}/.gitignore`);
|
|
76
|
+
}
|
|
77
|
+
exports.createFiles = createFiles;
|
|
78
|
+
const renameFile = async function (oldPath, newPath) {
|
|
79
|
+
return new Promise((resolve, reject) => {
|
|
80
|
+
fs_1.default.rename(oldPath, newPath, err => {
|
|
81
|
+
if (err) {
|
|
82
|
+
console.error(err);
|
|
83
|
+
reject(err);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
resolve();
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
exports.renameFile = renameFile;
|
|
91
|
+
// Wrap `ncp` tool to wait for the copy to finish when using `await`
|
|
92
|
+
// Allow passing `skip` variable to skip copying an array of filenames
|
|
93
|
+
function copyDir(source, dest, { skip, verbose }) {
|
|
94
|
+
return new Promise((resolve, reject) => {
|
|
95
|
+
const copied = [];
|
|
96
|
+
const skipped = [];
|
|
97
|
+
const filter = skip && function (filename) {
|
|
98
|
+
const shouldCopy = !skip.find(f => filename.includes(f));
|
|
99
|
+
shouldCopy ? copied.push(filename) : skipped.push(filename);
|
|
100
|
+
return !skip.find(f => filename.includes(f));
|
|
101
|
+
};
|
|
102
|
+
(0, ncp_1.ncp)(source, dest, { filter }, err => {
|
|
103
|
+
if (err) {
|
|
104
|
+
reject(err);
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
if (verbose) {
|
|
108
|
+
console.log('Copied:');
|
|
109
|
+
copied.forEach(f => console.log(' ' + f));
|
|
110
|
+
console.log('Skipped:');
|
|
111
|
+
skipped.forEach(f => console.log(' ' + f));
|
|
112
|
+
}
|
|
113
|
+
resolve();
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
exports.copyDir = copyDir;
|
|
118
|
+
async function runDepsInstall(projectPath) {
|
|
119
|
+
show.depsInstall();
|
|
120
|
+
const npmCommandArgs = ['run', 'deps-install'];
|
|
121
|
+
await new Promise((resolve, reject) => (0, cross_spawn_1.default)('npm', npmCommandArgs, {
|
|
122
|
+
cwd: projectPath,
|
|
123
|
+
stdio: 'inherit',
|
|
124
|
+
}).on('close', (code) => {
|
|
125
|
+
if (code !== 0) {
|
|
126
|
+
show.depsInstallError();
|
|
127
|
+
reject(code);
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
resolve();
|
|
131
|
+
}
|
|
132
|
+
}));
|
|
133
|
+
}
|
|
134
|
+
exports.runDepsInstall = runDepsInstall;
|
|
135
|
+
//# sourceMappingURL=make.js.map
|
package/dist/messages.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.depsInstallError = exports.depsInstall = exports.creatingApp = exports.directoryExists = exports.assemblyscriptWarning = exports.windowsWarning = exports.unsupportedNodeVersion = exports.argsError = exports.setupSuccess = exports.successFrontendToText = exports.successContractToText = exports.setupFailed = exports.welcome = exports.log = void 0;
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
const tracking_1 = require("./tracking");
|
|
9
|
+
const log = (...args) => console.log(...args);
|
|
10
|
+
exports.log = log;
|
|
11
|
+
const welcome = () => (0, exports.log)((0, chalk_1.default) `{blue ======================================================}
|
|
12
|
+
👋 {bold {green Welcome to NEAR!}} Learn more: https://docs.near.org/
|
|
13
|
+
🔧 Let's get your dApp ready.
|
|
14
|
+
{blue ======================================================}
|
|
15
|
+
(${tracking_1.trackingMessage})
|
|
16
|
+
`);
|
|
17
|
+
exports.welcome = welcome;
|
|
18
|
+
const setupFailed = () => (0, exports.log)((0, chalk_1.default) `{bold {red ==========================================}}
|
|
19
|
+
{red ⛔️ There was a problem during NEAR project setup}.
|
|
20
|
+
Please refer to https://github.com/near/create-near-app README to troubleshoot.
|
|
21
|
+
Notice: some platforms aren't supported (yet).
|
|
22
|
+
{bold {red ==========================================}}`);
|
|
23
|
+
exports.setupFailed = setupFailed;
|
|
24
|
+
const successContractToText = (contract) => (0, chalk_1.default) `with a smart contract in {bold ${contract === 'rust' ? 'Rust' : contract === 'js' ? 'JavaScript' : 'AssemblyScript'}}`;
|
|
25
|
+
exports.successContractToText = successContractToText;
|
|
26
|
+
const successFrontendToText = (frontend) => frontend === 'none' ? '' : (0, chalk_1.default) ` and a frontend template${frontend === 'react' ? (0, chalk_1.default) `{bold in React.js}` : ''}`;
|
|
27
|
+
exports.successFrontendToText = successFrontendToText;
|
|
28
|
+
const setupSuccess = (projectName, contract, frontend) => (0, exports.log)((0, chalk_1.default) `
|
|
29
|
+
✅ Success! Created '${projectName}'
|
|
30
|
+
${(0, exports.successContractToText)(contract)}${(0, exports.successFrontendToText)(frontend)}.
|
|
31
|
+
🧠 See {bold {green README.md}} to get started.
|
|
32
|
+
${contract === 'rust' ? (0, chalk_1.default) `🦀 If you are new to Rust please visit {bold {green https://www.rust-lang.org }}` : ''}
|
|
33
|
+
Happy Hacking! 👍
|
|
34
|
+
{blue ======================================================}`);
|
|
35
|
+
exports.setupSuccess = setupSuccess;
|
|
36
|
+
const argsError = () => (0, exports.log)((0, chalk_1.default) `{red Arguments error}
|
|
37
|
+
Run {blue npx create-near-app} without arguments, or use:
|
|
38
|
+
npx create-near-app <projectName> --contract rust|js|assemblyscript --frontend react|vanilla|none --tests js|rust`);
|
|
39
|
+
exports.argsError = argsError;
|
|
40
|
+
const unsupportedNodeVersion = (supported) => (0, exports.log)((0, chalk_1.default) `{red We support node.js version ${supported} or later}`);
|
|
41
|
+
exports.unsupportedNodeVersion = unsupportedNodeVersion;
|
|
42
|
+
const windowsWarning = () => (0, exports.log)((0, chalk_1.default) `👉 Notice: On Windows we recommend using WSL.`);
|
|
43
|
+
exports.windowsWarning = windowsWarning;
|
|
44
|
+
const assemblyscriptWarning = () => (0, exports.log)((0, chalk_1.default) `👉 Notice: AssemblyScript is not supported on all platforms.`);
|
|
45
|
+
exports.assemblyscriptWarning = assemblyscriptWarning;
|
|
46
|
+
const directoryExists = (dirName) => (0, exports.log)((0, chalk_1.default) `{red This directory already exists! ${dirName}}`);
|
|
47
|
+
exports.directoryExists = directoryExists;
|
|
48
|
+
const creatingApp = () => (0, exports.log)((0, chalk_1.default) `\n...creating a new NEAR app...`);
|
|
49
|
+
exports.creatingApp = creatingApp;
|
|
50
|
+
const depsInstall = () => (0, exports.log)((0, chalk_1.default) `
|
|
51
|
+
{green Installing dependencies in a few folders, this might take a while...}
|
|
52
|
+
`);
|
|
53
|
+
exports.depsInstall = depsInstall;
|
|
54
|
+
const depsInstallError = () => (0, exports.log)(chalk_1.default.red('Error installing NEAR project dependencies'));
|
|
55
|
+
exports.depsInstallError = depsInstallError;
|
|
56
|
+
//# sourceMappingURL=messages.js.map
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildPackageJson = void 0;
|
|
4
|
+
function buildPackageJson({ contract, frontend, tests, projectName }) {
|
|
5
|
+
const result = basePackage({
|
|
6
|
+
contract, frontend, tests, projectName,
|
|
7
|
+
});
|
|
8
|
+
return result;
|
|
9
|
+
}
|
|
10
|
+
exports.buildPackageJson = buildPackageJson;
|
|
11
|
+
function basePackage({ contract, frontend, tests, projectName }) {
|
|
12
|
+
const hasFrontend = frontend !== 'none';
|
|
13
|
+
return {
|
|
14
|
+
'name': projectName,
|
|
15
|
+
'version': '1.0.0',
|
|
16
|
+
'license': '(MIT AND Apache-2.0)',
|
|
17
|
+
'scripts': {
|
|
18
|
+
...startScript(hasFrontend),
|
|
19
|
+
...deployScript(contract),
|
|
20
|
+
...buildScript(hasFrontend),
|
|
21
|
+
...buildContractScript(contract),
|
|
22
|
+
'test': 'npm run test:unit && npm run test:integration',
|
|
23
|
+
...unitTestScripts(contract),
|
|
24
|
+
...integrationTestScripts(contract, tests),
|
|
25
|
+
...npmInstallScript(contract, hasFrontend, tests),
|
|
26
|
+
},
|
|
27
|
+
'devDependencies': {
|
|
28
|
+
'near-cli': '^3.3.0',
|
|
29
|
+
},
|
|
30
|
+
'dependencies': {}
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
const startScript = (hasFrontend) => hasFrontend ? {
|
|
34
|
+
'start': 'cd frontend && npm run start'
|
|
35
|
+
} : {};
|
|
36
|
+
const buildScript = (hasFrontend) => hasFrontend ? {
|
|
37
|
+
'build': 'npm run build:contract && npm run build:web',
|
|
38
|
+
'build:web': 'cd frontend && npm run build',
|
|
39
|
+
} : {
|
|
40
|
+
'build': 'npm run build:contract',
|
|
41
|
+
};
|
|
42
|
+
const buildContractScript = (contract) => {
|
|
43
|
+
switch (contract) {
|
|
44
|
+
case 'assemblyscript':
|
|
45
|
+
return {
|
|
46
|
+
'build:contract': 'cd contract && npm run build',
|
|
47
|
+
};
|
|
48
|
+
case 'js':
|
|
49
|
+
return {
|
|
50
|
+
'build:contract': 'cd contract && npm run build',
|
|
51
|
+
};
|
|
52
|
+
case 'rust':
|
|
53
|
+
return {
|
|
54
|
+
'build:contract': 'cd contract && rustup target add wasm32-unknown-unknown && cargo build --all --target wasm32-unknown-unknown --release',
|
|
55
|
+
};
|
|
56
|
+
default:
|
|
57
|
+
return {};
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
const deployScript = (contract) => {
|
|
61
|
+
switch (contract) {
|
|
62
|
+
case 'assemblyscript':
|
|
63
|
+
case 'js':
|
|
64
|
+
return {
|
|
65
|
+
'deploy': 'cd contract && npm run deploy',
|
|
66
|
+
};
|
|
67
|
+
case 'rust':
|
|
68
|
+
return {
|
|
69
|
+
'deploy': 'npm run build:contract && cd contract && near dev-deploy --wasmFile ./target/wasm32-unknown-unknown/release/hello_near.wasm',
|
|
70
|
+
};
|
|
71
|
+
default:
|
|
72
|
+
return {};
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
const unitTestScripts = (contract) => {
|
|
76
|
+
switch (contract) {
|
|
77
|
+
case 'js':
|
|
78
|
+
case 'assemblyscript':
|
|
79
|
+
return { 'test:unit': 'cd contract && npm test' };
|
|
80
|
+
case 'rust':
|
|
81
|
+
return { 'test:unit': 'cd contract && cargo test' };
|
|
82
|
+
default:
|
|
83
|
+
return {};
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
const integrationTestScripts = (contract, tests) => {
|
|
87
|
+
switch (contract) {
|
|
88
|
+
case 'assemblyscript':
|
|
89
|
+
if (tests === 'js') {
|
|
90
|
+
return {
|
|
91
|
+
'test:integration': 'npm run build:contract && cd integration-tests && npm test -- -- "./contract/build/release/hello_near.wasm"',
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
return {
|
|
96
|
+
'test:integration': 'npm run build:contract && cd integration-tests && cargo run --example integration-tests "../contract/build/release/hello_near.wasm"',
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
case 'js':
|
|
100
|
+
if (tests === 'js') {
|
|
101
|
+
return {
|
|
102
|
+
'test:integration': 'npm run build:contract && cd integration-tests && npm test -- -- "./contract/build/hello_near.wasm" "js"',
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
return {
|
|
107
|
+
'test:integration': 'npm run build:contract && cd integration-tests && cargo run --example integration-tests "../contract/build/hello_near.wasm"',
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
case 'rust':
|
|
111
|
+
if (tests === 'js') {
|
|
112
|
+
return {
|
|
113
|
+
'test:integration': 'npm run build:contract && cd integration-tests && npm test -- -- "./contract/target/wasm32-unknown-unknown/release/hello_near.wasm"',
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
return {
|
|
118
|
+
'test:integration': 'npm run build:contract && cd integration-tests && cargo run --example integration-tests "../contract/target/wasm32-unknown-unknown/release/hello_near.wasm"',
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
default:
|
|
122
|
+
return {};
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
const npmInstallScript = (contract, hasFrontend, tests) => {
|
|
126
|
+
switch (contract) {
|
|
127
|
+
case 'assemblyscript':
|
|
128
|
+
case 'js':
|
|
129
|
+
if (hasFrontend) {
|
|
130
|
+
if (tests === 'js') {
|
|
131
|
+
return { 'deps-install': 'npm install && cd contract && npm install && cd ../integration-tests && npm install && cd ../frontend && npm install && cd ..' };
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
return { 'deps-install': 'npm install && cd contract && npm install && cd ../frontend && npm install && cd ..' };
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
if (tests === 'js') {
|
|
139
|
+
return { 'deps-install': 'npm install && cd contract && npm install && cd ../integration-tests && npm install && cd ..' };
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
return { 'deps-install': 'npm install && cd contract && npm install && cd ..' };
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
case 'rust':
|
|
146
|
+
if (hasFrontend) {
|
|
147
|
+
if (tests === 'js') {
|
|
148
|
+
return { 'deps-install': 'npm install && cd frontend && npm install && cd ../integration-tests && npm install && cd ..' };
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
return { 'deps-install': 'npm install && cd frontend && npm install && cd ..' };
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
if (tests === 'js') {
|
|
156
|
+
return { 'deps-install': 'npm install && cd ./integration-tests && npm install && cd ..' };
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
return { 'deps-install': 'npm install' };
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
//# sourceMappingURL=package-json.js.map
|
package/dist/tracking.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.trackUsage = exports.trackingMessage = void 0;
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
const mixpanel_1 = __importDefault(require("mixpanel"));
|
|
9
|
+
const MIXPANEL_TOKEN = 'df164f13212cbb0dfdae991da60e87f2';
|
|
10
|
+
const tracker = mixpanel_1.default.init(MIXPANEL_TOKEN);
|
|
11
|
+
exports.trackingMessage = (0, chalk_1.default) `NEAR collects anonymous information on the commands used. No personal information that could identify you is shared`;
|
|
12
|
+
// TODO: track different failures & deps-install usage
|
|
13
|
+
const trackUsage = async (frontend, contract) => {
|
|
14
|
+
// prevents logging from CI
|
|
15
|
+
if (process.env.IS_GITHUB_ACTION) {
|
|
16
|
+
console.log('Mixpanel logging is skipped in CI env');
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
try {
|
|
20
|
+
const mixPanelProperties = {
|
|
21
|
+
frontend,
|
|
22
|
+
contract,
|
|
23
|
+
os: process.platform,
|
|
24
|
+
nodeVersion: process.versions.node,
|
|
25
|
+
timestamp: new Date().toString()
|
|
26
|
+
};
|
|
27
|
+
tracker.track('track create near app', mixPanelProperties);
|
|
28
|
+
}
|
|
29
|
+
catch (e) {
|
|
30
|
+
console.error('Warning: problem while sending tracking data. Error: ', e);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
exports.trackUsage = trackUsage;
|
|
34
|
+
//# sourceMappingURL=tracking.js.map
|
package/dist/types.js
ADDED