create-near-app 4.0.0-beta.3.0 → 4.0.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/dist/app.js +5 -14
- package/dist/messages.js +33 -20
- package/dist/package-json.js +16 -8
- package/dist/tracking.js +1 -1
- package/dist/types.js +4 -0
- package/dist/user-input.js +34 -50
- package/package.json +1 -4
- package/templates/contracts/js/package.json +1 -1
- package/templates/contracts/js/src/contract.ts +8 -6
- package/templates/frontend/react/frontend/App.js +5 -2
- package/templates/frontend/react/frontend/assets/global.css +62 -4
- package/templates/frontend/vanilla/frontend/assets/global.css +64 -4
- package/templates/frontend/vanilla/frontend/index.html +7 -4
- package/templates/shared/README.md +2 -2
- package/dist/checks.js +0 -34
package/dist/app.js
CHANGED
|
@@ -35,11 +35,8 @@ const show = __importStar(require("./messages"));
|
|
|
35
35
|
if (promptResult === null) {
|
|
36
36
|
return;
|
|
37
37
|
}
|
|
38
|
-
const { config: { projectName, contract, frontend, tests, install }, projectPath,
|
|
38
|
+
const { config: { projectName, contract, frontend, tests, install, }, projectPath, } = promptResult;
|
|
39
39
|
show.creatingApp();
|
|
40
|
-
if (contract === 'assemblyscript') {
|
|
41
|
-
show.assemblyscriptWarning();
|
|
42
|
-
}
|
|
43
40
|
let createSuccess;
|
|
44
41
|
try {
|
|
45
42
|
createSuccess = await (0, make_1.createProject)({
|
|
@@ -56,21 +53,15 @@ const show = __importStar(require("./messages"));
|
|
|
56
53
|
console.error(e);
|
|
57
54
|
createSuccess = false;
|
|
58
55
|
}
|
|
56
|
+
if (install) {
|
|
57
|
+
await (0, make_1.runDepsInstall)(projectPath);
|
|
58
|
+
}
|
|
59
59
|
if (createSuccess) {
|
|
60
|
-
show.setupSuccess(projectPath, contract, frontend);
|
|
60
|
+
show.setupSuccess(projectPath, contract, frontend, install);
|
|
61
61
|
}
|
|
62
62
|
else {
|
|
63
63
|
show.setupFailed();
|
|
64
64
|
return;
|
|
65
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
66
|
})();
|
|
76
67
|
//# sourceMappingURL=app.js.map
|
package/dist/messages.js
CHANGED
|
@@ -3,19 +3,22 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.depsInstallError = exports.depsInstall = exports.creatingApp = exports.directoryExists = exports.
|
|
6
|
+
exports.depsInstallError = exports.depsInstall = exports.creatingApp = exports.directoryExists = exports.windowsWarning = exports.unsupportedNodeVersion = exports.argsError = exports.setupSuccess = exports.successFrontendToText = exports.successContractToText = exports.setupFailed = exports.welcome = exports.show = void 0;
|
|
7
7
|
const chalk_1 = __importDefault(require("chalk"));
|
|
8
8
|
const tracking_1 = require("./tracking");
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
if (process.env.NEAR_NO_COLOR) {
|
|
10
|
+
chalk_1.default.level = 0;
|
|
11
|
+
}
|
|
12
|
+
const show = (...args) => console.log(...args);
|
|
13
|
+
exports.show = show;
|
|
14
|
+
const welcome = () => (0, exports.show)((0, chalk_1.default) `{blue ======================================================}
|
|
12
15
|
👋 {bold {green Welcome to NEAR!}} Learn more: https://docs.near.org/
|
|
13
16
|
🔧 Let's get your dApp ready.
|
|
14
17
|
{blue ======================================================}
|
|
15
18
|
(${tracking_1.trackingMessage})
|
|
16
19
|
`);
|
|
17
20
|
exports.welcome = welcome;
|
|
18
|
-
const setupFailed = () => (0, exports.
|
|
21
|
+
const setupFailed = () => (0, exports.show)((0, chalk_1.default) `{bold {red ==========================================}}
|
|
19
22
|
{red ⛔️ There was a problem during NEAR project setup}.
|
|
20
23
|
Please refer to https://github.com/near/create-near-app README to troubleshoot.
|
|
21
24
|
Notice: some platforms aren't supported (yet).
|
|
@@ -25,32 +28,42 @@ const successContractToText = (contract) => (0, chalk_1.default) `with a smart c
|
|
|
25
28
|
exports.successContractToText = successContractToText;
|
|
26
29
|
const successFrontendToText = (frontend) => frontend === 'none' ? '' : (0, chalk_1.default) ` and a frontend template${frontend === 'react' ? (0, chalk_1.default) `{bold in React.js}` : ''}`;
|
|
27
30
|
exports.successFrontendToText = successFrontendToText;
|
|
28
|
-
const setupSuccess = (projectName, contract, frontend) => (0, exports.
|
|
31
|
+
const setupSuccess = (projectName, contract, frontend, install) => (0, exports.show)((0, chalk_1.default) `
|
|
32
|
+
{green ======================================================}
|
|
29
33
|
✅ Success! Created '${projectName}'
|
|
30
34
|
${(0, exports.successContractToText)(contract)}${(0, exports.successFrontendToText)(frontend)}.
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
{blue
|
|
35
|
+
${contract === 'rust' ? (0, chalk_1.default) `🦀 If you are new to Rust please visit {bold {green https://www.rust-lang.org }}\n` : ''}
|
|
36
|
+
{bold {bgYellow {black Your next steps}}}:
|
|
37
|
+
- {inverse Navigate to your project}:
|
|
38
|
+
{blue cd {bold ${projectName}}}
|
|
39
|
+
${!install ? (0, chalk_1.default) `- {inverse Install all dependencies}
|
|
40
|
+
{blue npm {bold run deps-install}}` : 'Then:'}
|
|
41
|
+
- {inverse Test your contract} in NEAR SandBox:
|
|
42
|
+
{blue npm {bold test}}
|
|
43
|
+
- {inverse Deploy your contract} to NEAR TestNet with a temporary dev account:
|
|
44
|
+
{blue npm {bold run deploy}}
|
|
45
|
+
${frontend !== 'none' ? (0, chalk_1.default) `- {inverse Start your frontend}:
|
|
46
|
+
{blue npm {bold start}}\n` : ''}
|
|
47
|
+
🧠 Read {bold {greenBright README.md}} to explore further.`);
|
|
35
48
|
exports.setupSuccess = setupSuccess;
|
|
36
|
-
const argsError = () => (0, exports.
|
|
49
|
+
const argsError = () => (0, exports.show)((0, chalk_1.default) `{red Arguments error}
|
|
37
50
|
Run {blue npx create-near-app} without arguments, or use:
|
|
38
51
|
npx create-near-app <projectName> --contract rust|js|assemblyscript --frontend react|vanilla|none --tests js|rust`);
|
|
39
52
|
exports.argsError = argsError;
|
|
40
|
-
const unsupportedNodeVersion = (supported) => (0, exports.
|
|
53
|
+
const unsupportedNodeVersion = (supported) => (0, exports.show)((0, chalk_1.default) `{red We support node.js version ${supported} or later}`);
|
|
41
54
|
exports.unsupportedNodeVersion = unsupportedNodeVersion;
|
|
42
|
-
const windowsWarning = () => (0, exports.
|
|
55
|
+
const windowsWarning = () => (0, exports.show)((0, chalk_1.default) `{bgYellow {black Notice: On Win32 please use WSL (Windows Subsystem for Linux).}}
|
|
56
|
+
https://docs.microsoft.com/en-us/windows/wsl/install
|
|
57
|
+
Exiting now.`);
|
|
43
58
|
exports.windowsWarning = windowsWarning;
|
|
44
|
-
const
|
|
45
|
-
exports.assemblyscriptWarning = assemblyscriptWarning;
|
|
46
|
-
const directoryExists = (dirName) => (0, exports.log)((0, chalk_1.default) `{red This directory already exists! ${dirName}}`);
|
|
59
|
+
const directoryExists = (dirName) => (0, exports.show)((0, chalk_1.default) `{red This directory already exists! ${dirName}}`);
|
|
47
60
|
exports.directoryExists = directoryExists;
|
|
48
|
-
const creatingApp = () => (0, exports.
|
|
61
|
+
const creatingApp = () => (0, exports.show)((0, chalk_1.default) `\nCreating a new {bold NEAR dApp}`);
|
|
49
62
|
exports.creatingApp = creatingApp;
|
|
50
|
-
const depsInstall = () => (0, exports.
|
|
51
|
-
{green Installing dependencies in a few folders, this might take a while
|
|
63
|
+
const depsInstall = () => (0, exports.show)((0, chalk_1.default) `
|
|
64
|
+
{green Installing dependencies in a few folders, this might take a while.}
|
|
52
65
|
`);
|
|
53
66
|
exports.depsInstall = depsInstall;
|
|
54
|
-
const depsInstallError = () => (0, exports.
|
|
67
|
+
const depsInstallError = () => (0, exports.show)(chalk_1.default.red('Error installing NEAR project dependencies'));
|
|
55
68
|
exports.depsInstallError = depsInstallError;
|
|
56
69
|
//# sourceMappingURL=messages.js.map
|
package/dist/package-json.js
CHANGED
|
@@ -53,8 +53,6 @@ const buildContractScript = (contract) => {
|
|
|
53
53
|
return {
|
|
54
54
|
'build:contract': 'cd contract && rustup target add wasm32-unknown-unknown && cargo build --all --target wasm32-unknown-unknown --release',
|
|
55
55
|
};
|
|
56
|
-
default:
|
|
57
|
-
return {};
|
|
58
56
|
}
|
|
59
57
|
};
|
|
60
58
|
const deployScript = (contract) => {
|
|
@@ -68,8 +66,6 @@ const deployScript = (contract) => {
|
|
|
68
66
|
return {
|
|
69
67
|
'deploy': 'npm run build:contract && cd contract && near dev-deploy --wasmFile ./target/wasm32-unknown-unknown/release/hello_near.wasm',
|
|
70
68
|
};
|
|
71
|
-
default:
|
|
72
|
-
return {};
|
|
73
69
|
}
|
|
74
70
|
};
|
|
75
71
|
const unitTestScripts = (contract) => {
|
|
@@ -79,8 +75,6 @@ const unitTestScripts = (contract) => {
|
|
|
79
75
|
return { 'test:unit': 'cd contract && npm test' };
|
|
80
76
|
case 'rust':
|
|
81
77
|
return { 'test:unit': 'cd contract && cargo test' };
|
|
82
|
-
default:
|
|
83
|
-
return {};
|
|
84
78
|
}
|
|
85
79
|
};
|
|
86
80
|
const integrationTestScripts = (contract, tests) => {
|
|
@@ -118,13 +112,27 @@ const integrationTestScripts = (contract, tests) => {
|
|
|
118
112
|
'test:integration': 'npm run build:contract && cd integration-tests && cargo run --example integration-tests "../contract/target/wasm32-unknown-unknown/release/hello_near.wasm"',
|
|
119
113
|
};
|
|
120
114
|
}
|
|
121
|
-
default:
|
|
122
|
-
return {};
|
|
123
115
|
}
|
|
124
116
|
};
|
|
125
117
|
const npmInstallScript = (contract, hasFrontend, tests) => {
|
|
126
118
|
switch (contract) {
|
|
127
119
|
case 'assemblyscript':
|
|
120
|
+
if (hasFrontend) {
|
|
121
|
+
if (tests === 'js') {
|
|
122
|
+
return { 'deps-install': 'npm install && cd contract && npm install --ignore-scripts && cd ../integration-tests && npm install && cd ../frontend && npm install && cd ..' };
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
return { 'deps-install': 'npm install && cd contract && npm install --ignore-scripts && cd ../frontend && npm install && cd ..' };
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
if (tests === 'js') {
|
|
130
|
+
return { 'deps-install': 'npm install && cd contract && npm install --ignore-scripts && cd ../integration-tests && npm install && cd ..' };
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
return { 'deps-install': 'npm install && cd contract && npm install --ignore-scripts && cd ..' };
|
|
134
|
+
}
|
|
135
|
+
}
|
|
128
136
|
case 'js':
|
|
129
137
|
if (hasFrontend) {
|
|
130
138
|
if (tests === 'js') {
|
package/dist/tracking.js
CHANGED
|
@@ -12,7 +12,7 @@ exports.trackingMessage = (0, chalk_1.default) `NEAR collects anonymous informat
|
|
|
12
12
|
// TODO: track different failures & deps-install usage
|
|
13
13
|
const trackUsage = async (frontend, contract) => {
|
|
14
14
|
// prevents logging from CI
|
|
15
|
-
if (process.env.
|
|
15
|
+
if (process.env.NEAR_ENV === 'ci' || process.env.NODE_ENV === 'ci') {
|
|
16
16
|
console.log('Mixpanel logging is skipped in CI env');
|
|
17
17
|
return;
|
|
18
18
|
}
|
package/dist/types.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TESTING_FRAMEWORKS = exports.FRONTENDS = exports.CONTRACTS = void 0;
|
|
4
|
+
exports.CONTRACTS = ['assemblyscript', 'js', 'rust'];
|
|
5
|
+
exports.FRONTENDS = ['react', 'vanilla', 'none'];
|
|
6
|
+
exports.TESTING_FRAMEWORKS = ['rust', 'js'];
|
|
3
7
|
//# sourceMappingURL=types.js.map
|
package/dist/user-input.js
CHANGED
|
@@ -26,7 +26,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.projectPath = exports.promptAndGetConfig = exports.userAnswersAreValid = exports.
|
|
29
|
+
exports.projectPath = exports.promptAndGetConfig = exports.userAnswersAreValid = exports.showProjectNamePrompt = exports.getUserAnswers = exports.validateUserArgs = exports.getUserArgs = void 0;
|
|
30
|
+
const types_1 = require("./types");
|
|
30
31
|
const chalk_1 = __importDefault(require("chalk"));
|
|
31
32
|
const prompts_1 = __importDefault(require("prompts"));
|
|
32
33
|
const commander_1 = require("commander");
|
|
@@ -59,9 +60,9 @@ function validateUserArgs(args) {
|
|
|
59
60
|
const hasAllArgs = hasAllOptions && hasProjectName;
|
|
60
61
|
const hasNoArgs = !hasPartialOptions && !hasProjectName;
|
|
61
62
|
const optionsAreValid = hasAllOptions
|
|
62
|
-
&&
|
|
63
|
-
&&
|
|
64
|
-
&&
|
|
63
|
+
&& types_1.FRONTENDS.includes(frontend)
|
|
64
|
+
&& types_1.CONTRACTS.includes(contract)
|
|
65
|
+
&& types_1.TESTING_FRAMEWORKS.includes(tests);
|
|
65
66
|
if (hasNoArgs) {
|
|
66
67
|
return 'none';
|
|
67
68
|
}
|
|
@@ -73,35 +74,38 @@ function validateUserArgs(args) {
|
|
|
73
74
|
}
|
|
74
75
|
}
|
|
75
76
|
exports.validateUserArgs = validateUserArgs;
|
|
77
|
+
const contractChoices = [
|
|
78
|
+
{ title: 'JavaScript', value: 'js' },
|
|
79
|
+
{ title: 'Rust', value: 'rust' },
|
|
80
|
+
{ title: 'AssemblyScript', value: 'assemblyscript' },
|
|
81
|
+
];
|
|
82
|
+
const testsChoices = [
|
|
83
|
+
{ title: 'Rust Sandbox Tests', value: 'rust' },
|
|
84
|
+
{ title: 'JavaScript Sandbox Tests', value: 'js' },
|
|
85
|
+
];
|
|
86
|
+
const frontendChoices = [
|
|
87
|
+
{ title: 'React.js', value: 'react' },
|
|
88
|
+
{ title: 'Vanilla JavaScript', value: 'vanilla' },
|
|
89
|
+
{ title: 'No frontend', value: 'none' },
|
|
90
|
+
];
|
|
76
91
|
const userPrompts = [
|
|
77
92
|
{
|
|
78
93
|
type: 'select',
|
|
79
94
|
name: 'contract',
|
|
80
95
|
message: 'Select your smart-contract language',
|
|
81
|
-
choices:
|
|
82
|
-
{ title: 'JavaScript', value: 'js' },
|
|
83
|
-
{ title: 'Rust', value: 'rust' },
|
|
84
|
-
{ title: 'AssemblyScript', value: 'assemblyscript' },
|
|
85
|
-
]
|
|
96
|
+
choices: contractChoices,
|
|
86
97
|
},
|
|
87
98
|
{
|
|
88
99
|
type: prev => prev === 'rust' ? 'select' : null,
|
|
89
100
|
name: 'tests',
|
|
90
101
|
message: 'Select language for Sandbox Test',
|
|
91
|
-
choices:
|
|
92
|
-
{ title: 'Rust Sandbox Tests', value: 'rust' },
|
|
93
|
-
{ title: 'JavaScript Sandbox Tests', value: 'js' },
|
|
94
|
-
]
|
|
102
|
+
choices: testsChoices,
|
|
95
103
|
},
|
|
96
104
|
{
|
|
97
105
|
type: 'select',
|
|
98
106
|
name: 'frontend',
|
|
99
107
|
message: 'Select a template for your frontend',
|
|
100
|
-
choices:
|
|
101
|
-
{ title: 'React.js', value: 'react' },
|
|
102
|
-
{ title: 'Vanilla JavaScript', value: 'vanilla' },
|
|
103
|
-
{ title: 'No frontend', value: 'none' },
|
|
104
|
-
]
|
|
108
|
+
choices: frontendChoices,
|
|
105
109
|
},
|
|
106
110
|
{
|
|
107
111
|
type: 'text',
|
|
@@ -109,10 +113,15 @@ const userPrompts = [
|
|
|
109
113
|
message: 'Name your project (this will create a directory with that name)',
|
|
110
114
|
initial: 'hello-near',
|
|
111
115
|
},
|
|
116
|
+
{
|
|
117
|
+
type: 'confirm',
|
|
118
|
+
name: 'install',
|
|
119
|
+
message: (0, chalk_1.default) `Run {bold {blue 'npm install'}} now?`,
|
|
120
|
+
initial: true,
|
|
121
|
+
},
|
|
112
122
|
];
|
|
113
123
|
async function getUserAnswers() {
|
|
114
|
-
const
|
|
115
|
-
const answers = await (0, prompts_1.default)([contract, frontend, tests, projectName]);
|
|
124
|
+
const answers = await (0, prompts_1.default)(userPrompts);
|
|
116
125
|
if (!answers.tests) {
|
|
117
126
|
answers.tests = answers.contract !== 'rust' ? 'js' : 'rust';
|
|
118
127
|
}
|
|
@@ -125,22 +134,6 @@ async function showProjectNamePrompt() {
|
|
|
125
134
|
return answers;
|
|
126
135
|
}
|
|
127
136
|
exports.showProjectNamePrompt = showProjectNamePrompt;
|
|
128
|
-
async function showDepsInstallPrompt() {
|
|
129
|
-
const questions = [
|
|
130
|
-
{
|
|
131
|
-
type: 'toggle',
|
|
132
|
-
name: 'depsInstall',
|
|
133
|
-
// message: chalk`One last thing:\n There are few package.json files with dependencies. We can run {bold {blue 'yarn install'}} for you.\n Run {bold {blue 'yarn install'}} now? (To do it yourself: {blue 'yarn run deps-install'}).\n \n`,
|
|
134
|
-
message: (0, chalk_1.default) `Run {bold {blue 'npm install'}} now in all folders? (To do it yourself: {blue 'npm run deps-install'}).\n`,
|
|
135
|
-
initial: true,
|
|
136
|
-
active: 'yes',
|
|
137
|
-
inactive: 'no'
|
|
138
|
-
},
|
|
139
|
-
];
|
|
140
|
-
const answers = await (0, prompts_1.default)(questions);
|
|
141
|
-
return answers;
|
|
142
|
-
}
|
|
143
|
-
exports.showDepsInstallPrompt = showDepsInstallPrompt;
|
|
144
137
|
function userAnswersAreValid(answers) {
|
|
145
138
|
const { contract, frontend, projectName, tests } = answers;
|
|
146
139
|
if ([contract, frontend, projectName, tests].includes(undefined)) {
|
|
@@ -156,7 +149,6 @@ async function promptAndGetConfig() {
|
|
|
156
149
|
let isFromPrompts = false;
|
|
157
150
|
// process cli args
|
|
158
151
|
const args = await getUserArgs();
|
|
159
|
-
const { install } = args;
|
|
160
152
|
const argsValid = validateUserArgs(args);
|
|
161
153
|
if (argsValid === 'error') {
|
|
162
154
|
show.argsError();
|
|
@@ -176,6 +168,7 @@ async function promptAndGetConfig() {
|
|
|
176
168
|
if (process.platform === 'win32') {
|
|
177
169
|
// TODO: track windows
|
|
178
170
|
show.windowsWarning();
|
|
171
|
+
return null;
|
|
179
172
|
}
|
|
180
173
|
// Get user input
|
|
181
174
|
if (config === null) {
|
|
@@ -189,21 +182,12 @@ async function promptAndGetConfig() {
|
|
|
189
182
|
const { frontend, contract } = config;
|
|
190
183
|
(0, tracking_1.trackUsage)(frontend, contract);
|
|
191
184
|
let path = (0, exports.projectPath)(config.projectName);
|
|
192
|
-
// If dir exists
|
|
185
|
+
// If dir exists warn and exit
|
|
193
186
|
if (fs_1.default.existsSync(path)) {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
return null;
|
|
197
|
-
}
|
|
198
|
-
else {
|
|
199
|
-
while (fs_1.default.existsSync(path)) {
|
|
200
|
-
show.directoryExists(path);
|
|
201
|
-
const { projectName: newProjectName } = await showProjectNamePrompt();
|
|
202
|
-
config.projectName = newProjectName;
|
|
203
|
-
}
|
|
204
|
-
}
|
|
187
|
+
show.directoryExists(path);
|
|
188
|
+
return null;
|
|
205
189
|
}
|
|
206
|
-
return { config
|
|
190
|
+
return { config, projectPath: path, isFromPrompts };
|
|
207
191
|
}
|
|
208
192
|
exports.promptAndGetConfig = promptAndGetConfig;
|
|
209
193
|
const projectPath = (projectName) => `${process.cwd()}/${projectName}`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-near-app",
|
|
3
|
-
"version": "4.0.0
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "Quickly scaffold your dApp on NEAR Blockchain",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"engines": {
|
|
@@ -27,7 +27,6 @@
|
|
|
27
27
|
"chalk": "^4.1.2",
|
|
28
28
|
"commander": "^9.4.0",
|
|
29
29
|
"cross-spawn": "^7.0.3",
|
|
30
|
-
"lodash": "^4.17.21",
|
|
31
30
|
"mixpanel": "^0.16.0",
|
|
32
31
|
"ncp": "^2.0.0",
|
|
33
32
|
"prompts": "^2.4.2",
|
|
@@ -44,8 +43,6 @@
|
|
|
44
43
|
"@types/node": "^18.6.1",
|
|
45
44
|
"@types/prompts": "^2.0.14",
|
|
46
45
|
"@types/semver": "^7.3.10",
|
|
47
|
-
"@typescript-eslint/eslint-plugin": "^5.26.0",
|
|
48
|
-
"@typescript-eslint/parser": "^5.26.0",
|
|
49
46
|
"eslint": "^8.20.0",
|
|
50
47
|
"eslint-config-react-app": "^7.0.1",
|
|
51
48
|
"eslint-plugin-import": "^2.26.0",
|
|
@@ -3,21 +3,23 @@ import { NearBindgen, NearContract, near, call, view } from 'near-sdk-js';
|
|
|
3
3
|
// The @NearBindgen decorator allows this code to compile to Base64.
|
|
4
4
|
@NearBindgen
|
|
5
5
|
class MyContract extends NearContract {
|
|
6
|
-
|
|
6
|
+
greeting: string;
|
|
7
7
|
|
|
8
|
-
constructor() {
|
|
8
|
+
constructor({message="Hello"}:{message: string}) {
|
|
9
9
|
//execute the NEAR Contract's constructor
|
|
10
10
|
super();
|
|
11
|
-
this.
|
|
11
|
+
this.greeting = message;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
default(){ return new MyContract({message: "Hello"}) }
|
|
15
|
+
|
|
14
16
|
// @call indicates that this is a 'change method' or a function
|
|
15
17
|
// that changes state on the blockchain. Change methods cost gas.
|
|
16
18
|
// For more info -> https://docs.near.org/docs/concepts/gas
|
|
17
19
|
@call
|
|
18
20
|
set_greeting({ message }: { message: string }): void {
|
|
19
21
|
near.log(`Saving greeting ${message}`);
|
|
20
|
-
this.
|
|
22
|
+
this.greeting = message;
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
// @view indicates a 'view method' or a function that returns
|
|
@@ -25,7 +27,7 @@ class MyContract extends NearContract {
|
|
|
25
27
|
// and do not cost gas.
|
|
26
28
|
@view
|
|
27
29
|
get_greeting(): string {
|
|
28
|
-
near.log(`The current greeting is ${this.
|
|
29
|
-
return this.
|
|
30
|
+
near.log(`The current greeting is ${this.greeting}`);
|
|
31
|
+
return this.greeting;
|
|
30
32
|
}
|
|
31
33
|
}
|
|
@@ -48,7 +48,7 @@ export default function App() {
|
|
|
48
48
|
<h1>
|
|
49
49
|
The contract says: <span className="greeting">{valueFromBlockchain}</span>
|
|
50
50
|
</h1>
|
|
51
|
-
<form onSubmit={changeGreeting} className=
|
|
51
|
+
<form onSubmit={changeGreeting} className="change">
|
|
52
52
|
<label>Change greeting:</label>
|
|
53
53
|
<div>
|
|
54
54
|
<input
|
|
@@ -56,7 +56,10 @@ export default function App() {
|
|
|
56
56
|
defaultValue={valueFromBlockchain}
|
|
57
57
|
id="greetingInput"
|
|
58
58
|
/>
|
|
59
|
-
<button>
|
|
59
|
+
<button>
|
|
60
|
+
<span>Save</span>
|
|
61
|
+
<div className="loader"></div>
|
|
62
|
+
</button>
|
|
60
63
|
</div>
|
|
61
64
|
</form>
|
|
62
65
|
<EducationalText/>
|
|
@@ -30,8 +30,6 @@ main {
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
main.please-wait {
|
|
33
|
-
opacity: 0.5;
|
|
34
|
-
cursor: wait;
|
|
35
33
|
}
|
|
36
34
|
|
|
37
35
|
h1 {
|
|
@@ -90,6 +88,8 @@ ul.information {
|
|
|
90
88
|
}
|
|
91
89
|
.change input {
|
|
92
90
|
flex: 1;
|
|
91
|
+
border-bottom-right-radius: 0;
|
|
92
|
+
border-top-right-radius: 0;
|
|
93
93
|
}
|
|
94
94
|
.change label {
|
|
95
95
|
display: block;
|
|
@@ -97,6 +97,10 @@ ul.information {
|
|
|
97
97
|
margin-right: 10px;
|
|
98
98
|
padding-bottom: 0.5em;
|
|
99
99
|
}
|
|
100
|
+
.change button {
|
|
101
|
+
border-bottom-left-radius: 0;
|
|
102
|
+
border-top-left-radius: 0;
|
|
103
|
+
}
|
|
100
104
|
|
|
101
105
|
a,
|
|
102
106
|
.link {
|
|
@@ -118,7 +122,14 @@ button, input {
|
|
|
118
122
|
font: inherit;
|
|
119
123
|
outline: none;
|
|
120
124
|
}
|
|
121
|
-
|
|
125
|
+
main.please-wait .change button {
|
|
126
|
+
position: relative;
|
|
127
|
+
pointer-events: none;
|
|
128
|
+
background-color: white;
|
|
129
|
+
}
|
|
130
|
+
main.please-wait .change button span {
|
|
131
|
+
visibility: hidden;
|
|
132
|
+
}
|
|
122
133
|
button {
|
|
123
134
|
background-color: var(--secondary);
|
|
124
135
|
border-radius: 5px;
|
|
@@ -131,7 +142,6 @@ button {
|
|
|
131
142
|
button:hover, button:focus {
|
|
132
143
|
box-shadow: 0 0 10em rgba(255, 255, 255, 0.2) inset;
|
|
133
144
|
}
|
|
134
|
-
|
|
135
145
|
input {
|
|
136
146
|
background-color: var(--light-gray);
|
|
137
147
|
border: none;
|
|
@@ -171,3 +181,51 @@ li {
|
|
|
171
181
|
box-shadow: 0 0 10em rgba(255, 255, 255, 0.02) inset;
|
|
172
182
|
}
|
|
173
183
|
}
|
|
184
|
+
|
|
185
|
+
main.please-wait .loader,
|
|
186
|
+
main.please-wait .loader:after{
|
|
187
|
+
display: inline-block;
|
|
188
|
+
}
|
|
189
|
+
.loader,
|
|
190
|
+
.loader:after {
|
|
191
|
+
display: none;
|
|
192
|
+
border-radius: 50%;
|
|
193
|
+
width: 20px;
|
|
194
|
+
height: 20px;
|
|
195
|
+
}
|
|
196
|
+
.loader {
|
|
197
|
+
font-size: 10px;
|
|
198
|
+
position: absolute;
|
|
199
|
+
top: calc(50% - 10px);
|
|
200
|
+
left: calc(50% - 10px);
|
|
201
|
+
text-indent: -9999em;
|
|
202
|
+
border-top: 3px solid var(--secondary);
|
|
203
|
+
border-right: 3px solid var(--secondary);
|
|
204
|
+
border-bottom: 3px solid var(--secondary);
|
|
205
|
+
border-left: 3px solid #ffffff;
|
|
206
|
+
-webkit-transform: translateZ(0);
|
|
207
|
+
-ms-transform: translateZ(0);
|
|
208
|
+
transform: translateZ(0);
|
|
209
|
+
-webkit-animation: load8 1.1s infinite linear;
|
|
210
|
+
animation: load8 1.1s infinite linear;
|
|
211
|
+
}
|
|
212
|
+
@-webkit-keyframes load8 {
|
|
213
|
+
0% {
|
|
214
|
+
-webkit-transform: rotate(0deg);
|
|
215
|
+
transform: rotate(0deg);
|
|
216
|
+
}
|
|
217
|
+
100% {
|
|
218
|
+
-webkit-transform: rotate(360deg);
|
|
219
|
+
transform: rotate(360deg);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
@keyframes load8 {
|
|
223
|
+
0% {
|
|
224
|
+
-webkit-transform: rotate(0deg);
|
|
225
|
+
transform: rotate(0deg);
|
|
226
|
+
}
|
|
227
|
+
100% {
|
|
228
|
+
-webkit-transform: rotate(360deg);
|
|
229
|
+
transform: rotate(360deg);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
@@ -29,10 +29,7 @@ main {
|
|
|
29
29
|
max-width: 26em;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
main.please-wait {
|
|
33
|
-
opacity: 0.5;
|
|
34
|
-
cursor: wait;
|
|
35
|
-
}
|
|
32
|
+
main.please-wait {}
|
|
36
33
|
|
|
37
34
|
h1 {
|
|
38
35
|
background-image: url(./logo-black.svg);
|
|
@@ -90,6 +87,8 @@ ul.information {
|
|
|
90
87
|
}
|
|
91
88
|
.change input {
|
|
92
89
|
flex: 1;
|
|
90
|
+
border-bottom-right-radius: 0;
|
|
91
|
+
border-top-right-radius: 0;
|
|
93
92
|
}
|
|
94
93
|
.change label {
|
|
95
94
|
display: block;
|
|
@@ -97,6 +96,10 @@ ul.information {
|
|
|
97
96
|
margin-right: 10px;
|
|
98
97
|
padding-bottom: 0.5em;
|
|
99
98
|
}
|
|
99
|
+
.change button {
|
|
100
|
+
border-bottom-left-radius: 0;
|
|
101
|
+
border-top-left-radius: 0;
|
|
102
|
+
}
|
|
100
103
|
|
|
101
104
|
a,
|
|
102
105
|
.link {
|
|
@@ -119,6 +122,15 @@ button, input {
|
|
|
119
122
|
outline: none;
|
|
120
123
|
}
|
|
121
124
|
|
|
125
|
+
main.please-wait .change button {
|
|
126
|
+
position: relative;
|
|
127
|
+
pointer-events: none;
|
|
128
|
+
background-color: white;
|
|
129
|
+
}
|
|
130
|
+
main.please-wait .change button span {
|
|
131
|
+
visibility: hidden;
|
|
132
|
+
}
|
|
133
|
+
|
|
122
134
|
button {
|
|
123
135
|
background-color: var(--secondary);
|
|
124
136
|
border-radius: 5px;
|
|
@@ -171,3 +183,51 @@ li {
|
|
|
171
183
|
box-shadow: 0 0 10em rgba(255, 255, 255, 0.02) inset;
|
|
172
184
|
}
|
|
173
185
|
}
|
|
186
|
+
|
|
187
|
+
main.please-wait .loader,
|
|
188
|
+
main.please-wait .loader:after{
|
|
189
|
+
display: inline-block;
|
|
190
|
+
}
|
|
191
|
+
.loader,
|
|
192
|
+
.loader:after {
|
|
193
|
+
display: none;
|
|
194
|
+
border-radius: 50%;
|
|
195
|
+
width: 20px;
|
|
196
|
+
height: 20px;
|
|
197
|
+
}
|
|
198
|
+
.loader {
|
|
199
|
+
font-size: 10px;
|
|
200
|
+
position: absolute;
|
|
201
|
+
top: calc(50% - 10px);
|
|
202
|
+
left: calc(50% - 10px);
|
|
203
|
+
text-indent: -9999em;
|
|
204
|
+
border-top: 3px solid var(--secondary);
|
|
205
|
+
border-right: 3px solid var(--secondary);
|
|
206
|
+
border-bottom: 3px solid var(--secondary);
|
|
207
|
+
border-left: 3px solid #ffffff;
|
|
208
|
+
-webkit-transform: translateZ(0);
|
|
209
|
+
-ms-transform: translateZ(0);
|
|
210
|
+
transform: translateZ(0);
|
|
211
|
+
-webkit-animation: load8 1.1s infinite linear;
|
|
212
|
+
animation: load8 1.1s infinite linear;
|
|
213
|
+
}
|
|
214
|
+
@-webkit-keyframes load8 {
|
|
215
|
+
0% {
|
|
216
|
+
-webkit-transform: rotate(0deg);
|
|
217
|
+
transform: rotate(0deg);
|
|
218
|
+
}
|
|
219
|
+
100% {
|
|
220
|
+
-webkit-transform: rotate(360deg);
|
|
221
|
+
transform: rotate(360deg);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
@keyframes load8 {
|
|
225
|
+
0% {
|
|
226
|
+
-webkit-transform: rotate(0deg);
|
|
227
|
+
transform: rotate(0deg);
|
|
228
|
+
}
|
|
229
|
+
100% {
|
|
230
|
+
-webkit-transform: rotate(360deg);
|
|
231
|
+
transform: rotate(360deg);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
@@ -43,11 +43,14 @@
|
|
|
43
43
|
<label for="greeting">Change greeting:</label>
|
|
44
44
|
<div>
|
|
45
45
|
<input
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
autocomplete="off"
|
|
47
|
+
id="greeting"
|
|
48
|
+
data-behavior="greeting"
|
|
49
49
|
/>
|
|
50
|
-
<button>
|
|
50
|
+
<button>
|
|
51
|
+
<span>Save</span>
|
|
52
|
+
<div class="loader"></div>
|
|
53
|
+
</button>
|
|
51
54
|
</div>
|
|
52
55
|
</form>
|
|
53
56
|
<p>
|
|
@@ -16,11 +16,11 @@ Build and deploy your contract to TestNet with a temporary dev account:
|
|
|
16
16
|
|
|
17
17
|
npm run deploy
|
|
18
18
|
|
|
19
|
-
Test your contract
|
|
19
|
+
Test your contract:
|
|
20
20
|
|
|
21
21
|
npm test
|
|
22
22
|
|
|
23
|
-
If you have a frontend, run `npm
|
|
23
|
+
If you have a frontend, run `npm start`. This will run a dev server.
|
|
24
24
|
|
|
25
25
|
|
|
26
26
|
Exploring The Code
|
package/dist/checks.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
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
|