create-near-app 3.1.0 → 4.0.0-beta.1.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.
Files changed (99) hide show
  1. package/README.md +11 -11
  2. package/dist/app.js +98 -0
  3. package/dist/checks.js +34 -0
  4. package/dist/make.js +131 -0
  5. package/dist/messages.js +46 -0
  6. package/dist/package-json.js +140 -0
  7. package/dist/tracking.js +34 -0
  8. package/dist/types.js +3 -0
  9. package/dist/user-input.js +113 -0
  10. package/index.js +1 -233
  11. package/package.json +53 -44
  12. package/{contracts → templates/contracts}/assemblyscript/README.md +4 -3
  13. package/templates/contracts/assemblyscript/as-pect.config.js +1 -0
  14. package/{contracts → templates/contracts}/assemblyscript/asconfig.json +0 -0
  15. package/{contracts → templates/contracts}/assemblyscript/assembly/__tests__/as-pect.d.ts +0 -0
  16. package/templates/contracts/assemblyscript/assembly/__tests__/main.spec.ts +11 -0
  17. package/{contracts → templates/contracts}/assemblyscript/assembly/as_types.d.ts +0 -0
  18. package/{contracts → templates/contracts}/assemblyscript/assembly/index.ts +5 -5
  19. package/{contracts → templates/contracts}/assemblyscript/assembly/tsconfig.json +0 -0
  20. package/templates/contracts/assemblyscript/package.json +14 -0
  21. package/templates/contracts/assemblyscript/yarn.lock +2952 -0
  22. package/templates/contracts/js/babel.config.json +7 -0
  23. package/templates/contracts/js/package.json +18 -0
  24. package/templates/contracts/js/src/contract.ts +31 -0
  25. package/templates/contracts/js/tsconfig.json +10 -0
  26. package/templates/contracts/js/yarn.lock +2534 -0
  27. package/{contracts → templates/contracts}/rust/.cargo/config +0 -0
  28. package/{contracts → templates/contracts}/rust/Cargo.toml +1 -1
  29. package/{contracts → templates/contracts}/rust/README.md +4 -6
  30. package/{contracts → templates/contracts}/rust/src/lib.rs +0 -0
  31. package/templates/frontend/react/frontend/App.js +66 -0
  32. package/templates/{react/frontend/assets/img → frontend/react/frontend/assets}/favicon.ico +0 -0
  33. package/templates/{vanilla/frontend/assets/css → frontend/react/frontend/assets}/global.css +64 -80
  34. package/templates/{react/frontend/assets/img → frontend/react/frontend/assets}/logo-black.svg +0 -0
  35. package/templates/{react/frontend/assets/img → frontend/react/frontend/assets}/logo-white.svg +0 -0
  36. package/templates/frontend/react/frontend/index.html +15 -0
  37. package/templates/frontend/react/frontend/index.js +15 -0
  38. package/templates/{react/frontend/assets/js/near/utils.js → frontend/react/frontend/near-api.js} +19 -19
  39. package/templates/frontend/react/frontend/near-config.js +61 -0
  40. package/templates/frontend/react/frontend/package.json +44 -0
  41. package/templates/frontend/react/frontend/ui-components.js +60 -0
  42. package/templates/frontend/react/frontend/yarn.lock +4550 -0
  43. package/templates/{vanilla/frontend/assets/img → frontend/vanilla/frontend/assets}/favicon.ico +0 -0
  44. package/templates/{react/frontend/assets/css → frontend/vanilla/frontend/assets}/global.css +64 -80
  45. package/templates/{vanilla/frontend/assets/img → frontend/vanilla/frontend/assets}/logo-black.svg +0 -0
  46. package/templates/{vanilla/frontend/assets/img → frontend/vanilla/frontend/assets}/logo-white.svg +0 -0
  47. package/templates/frontend/vanilla/frontend/index.html +86 -0
  48. package/templates/frontend/vanilla/frontend/index.js +78 -0
  49. package/templates/{vanilla/frontend/assets/js/near/utils.js → frontend/vanilla/frontend/near-api.js} +18 -18
  50. package/templates/frontend/vanilla/frontend/near-config.js +62 -0
  51. package/templates/frontend/vanilla/frontend/package.json +18 -0
  52. package/templates/frontend/vanilla/frontend/yarn.lock +2328 -0
  53. package/{integration-tests/js → templates/integration-tests/classic-tests}/ava.config.cjs +9 -9
  54. package/templates/integration-tests/classic-tests/package.json +17 -0
  55. package/templates/integration-tests/classic-tests/src/config.ts +34 -0
  56. package/templates/integration-tests/classic-tests/src/main.ava.ts +32 -0
  57. package/templates/integration-tests/classic-tests/yarn.lock +1323 -0
  58. package/{integration-tests → templates/integration-tests/workspaces-tests}/rs/Cargo.toml +0 -0
  59. package/{integration-tests → templates/integration-tests/workspaces-tests}/rs/src/tests.rs +5 -3
  60. package/{integration-tests → templates/integration-tests/workspaces-tests}/ts/ava.config.cjs +9 -9
  61. package/templates/integration-tests/workspaces-tests/ts/package.json +17 -0
  62. package/templates/integration-tests/workspaces-tests/ts/src/main.ava.ts +45 -0
  63. package/templates/integration-tests/workspaces-tests/ts/yarn.lock +1653 -0
  64. package/templates/{none → shared}/.gitpod.yml +0 -0
  65. package/templates/{vanilla → shared}/README.md +30 -31
  66. package/templates/{react → shared}/near.gitignore +1 -1
  67. package/contracts/assemblyscript/as-pect.config.js +0 -1
  68. package/contracts/assemblyscript/assembly/__tests__/main.spec.ts +0 -11
  69. package/contracts/assemblyscript/package.json +0 -13
  70. package/integration-tests/js/package.json +0 -16
  71. package/integration-tests/js/src/config.ts +0 -31
  72. package/integration-tests/js/src/main.ava.ts +0 -32
  73. package/integration-tests/ts/package.json +0 -16
  74. package/integration-tests/ts/src/main.ava.ts +0 -44
  75. package/templates/none/.gitattributes +0 -2
  76. package/templates/none/README.md +0 -101
  77. package/templates/none/near.gitignore +0 -27
  78. package/templates/none/neardev/shared-test/test.near.json +0 -1
  79. package/templates/none/package.json +0 -33
  80. package/templates/react/.gitpod.yml +0 -6
  81. package/templates/react/README.md +0 -102
  82. package/templates/react/ava.config.cjs +0 -9
  83. package/templates/react/frontend/App.js +0 -202
  84. package/templates/react/frontend/__mocks__/fileMock.js +0 -3
  85. package/templates/react/frontend/assets/js/near/config.js +0 -63
  86. package/templates/react/frontend/index.html +0 -25
  87. package/templates/react/frontend/index.js +0 -14
  88. package/templates/react/neardev/shared-test/test.near.json +0 -1
  89. package/templates/react/package.json +0 -55
  90. package/templates/vanilla/.gitattributes +0 -2
  91. package/templates/vanilla/.gitpod.yml +0 -6
  92. package/templates/vanilla/frontend/assets/js/index.js +0 -74
  93. package/templates/vanilla/frontend/assets/js/near/config.js +0 -63
  94. package/templates/vanilla/frontend/index.html +0 -103
  95. package/templates/vanilla/near.gitignore +0 -27
  96. package/templates/vanilla/neardev/shared-test/test.near.json +0 -1
  97. package/templates/vanilla/package.json +0 -34
  98. package/utils/rust-setup.js +0 -113
  99. package/utils/tracking.js +0 -29
package/README.md CHANGED
@@ -8,29 +8,29 @@ Quickly build apps backed by the [NEAR](https://near.org) blockchain
8
8
  Prerequisites
9
9
  =============
10
10
 
11
- Make sure you have a [current version of Node.js](https://nodejs.org/en/about/releases/) installed – we are targeting versions `12+`.
12
- **Note**: if using Node version 13 please be advised that you will need version >= 13.7.0
11
+ Make sure you have a [current version of Node.js](https://nodejs.org/en/about/releases/) installed – we are targeting versions `16+`.
13
12
 
13
+ Read about other [prerequisites](https://docs.near.org/develop/prerequisites) in our docs.
14
14
 
15
15
  Getting Started
16
16
  ===============
17
17
 
18
- To create a new NEAR project with default settings, you just need one command
18
+ To create a new NEAR project with default settings:
19
19
 
20
20
  Using [npm's npx](https://blog.npmjs.org/post/162869356040/introducing-npx-an-npm-package-runner):
21
21
 
22
- npx create-near-app [options] new-awesome-project
22
+ npx create-near-app
23
23
 
24
- **Or**, if you prefer [yarn](https://classic.yarnpkg.com/en/docs/cli/create/):
24
+ You can create contracts written in:
25
25
 
26
- yarn create near-app [options] new-awesome-project
26
+ - [Rust](https://docs.near.org/develop/prerequisites)
27
+ - [JavaScript](https://docs.near.org/develop/quickstart-guide)
28
+ - AssemblyScript
27
29
 
28
- Without any options, this will create a project with a **vanilla JavaScript** frontend and an [AssemblyScript](https://docs.near.org/docs/develop/contracts/as/intro) smart contract
30
+ You can create a frontend template in:
29
31
 
30
- Other options:
31
-
32
- * `--frontend=react` – use [React](https://reactjs.org/) for your frontend template
33
- * `--contract=rust` – use [Rust](https://docs.near.org/docs/develop/contracts/rust/near-sdk-rs) for your smart contract
32
+ - [React](https://reactjs.org/)
33
+ - Vanilla JavaScript
34
34
 
35
35
 
36
36
  Develop your own Dapp
package/dist/app.js ADDED
@@ -0,0 +1,98 @@
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
+ const path_1 = __importDefault(require("path"));
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const make_1 = require("./make");
9
+ const tracking_1 = require("./tracking");
10
+ const semver_1 = __importDefault(require("semver"));
11
+ const user_input_1 = require("./user-input");
12
+ const messages_1 = require("./messages");
13
+ (async function run() {
14
+ let config = null;
15
+ let configIsFromPrompts = false;
16
+ const args = await (0, user_input_1.getUserArgs)();
17
+ let { install } = args;
18
+ const argsValid = (0, user_input_1.validateUserArgs)(args);
19
+ // sanbox should be well supported by now, assemblyscript will be deprecated soon
20
+ // we explicitly take user's input: --no-sandbox => false, otherwise true
21
+ const supportsSandbox = args.sandbox;
22
+ if (argsValid === 'error') {
23
+ messages_1.show.argsError();
24
+ return;
25
+ }
26
+ else if (argsValid === 'ok') {
27
+ config = args;
28
+ }
29
+ messages_1.show.welcome();
30
+ // Check node.js version
31
+ const current = process.version;
32
+ const supported = require('../package.json').engines.node;
33
+ if (!semver_1.default.satisfies(current, supported)) {
34
+ messages_1.show.unsupportedNodeVersion(supported);
35
+ // TODO: track unsupported versions
36
+ return;
37
+ }
38
+ // Get user input
39
+ if (config === null) {
40
+ const userInput = await (0, user_input_1.showUserPrompts)();
41
+ configIsFromPrompts = true;
42
+ if (!(0, user_input_1.userAnswersAreValid)(userInput)) {
43
+ throw new Error(`Invalid prompt. ${JSON.stringify(userInput)}`);
44
+ }
45
+ config = userInput;
46
+ }
47
+ const { frontend, contract, projectName } = config;
48
+ (0, tracking_1.trackUsage)(frontend, contract);
49
+ let projectPath = `${process.cwd()}/${projectName}`;
50
+ // If dir exists keep asking user
51
+ if (fs_1.default.existsSync(projectPath)) {
52
+ if (!configIsFromPrompts) {
53
+ messages_1.show.directoryExists(projectPath);
54
+ return;
55
+ }
56
+ else {
57
+ while (fs_1.default.existsSync(projectPath)) {
58
+ messages_1.show.directoryExists(projectPath);
59
+ const { projectName: newProjectName } = await (0, user_input_1.showProjectNamePrompt)();
60
+ projectPath = `${process.cwd()}/${newProjectName}`;
61
+ }
62
+ }
63
+ }
64
+ // Create the project
65
+ let createSuccess;
66
+ try {
67
+ createSuccess = await (0, make_1.createProject)({
68
+ contract,
69
+ frontend,
70
+ projectName,
71
+ supportsSandbox,
72
+ verbose: false,
73
+ rootDir: path_1.default.resolve(__dirname, '../templates'),
74
+ projectPath,
75
+ });
76
+ }
77
+ catch (e) {
78
+ console.error(e);
79
+ createSuccess = false;
80
+ }
81
+ if (createSuccess) {
82
+ messages_1.show.setupSuccess(projectPath, contract, frontend);
83
+ }
84
+ else {
85
+ messages_1.show.setupFailed();
86
+ return;
87
+ }
88
+ if (install) {
89
+ await (0, make_1.runDepsInstall)(projectPath);
90
+ }
91
+ else if (configIsFromPrompts) {
92
+ const { depsInstall } = await (0, user_input_1.showDepsInstallPrompt)();
93
+ if (depsInstall) {
94
+ await (0, make_1.runDepsInstall)(projectPath);
95
+ }
96
+ }
97
+ })();
98
+ //# 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({ supportsSandbox }) {
29
+ if (!supportsSandbox) {
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,131 @@
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.runDepsInstall = exports.copyDir = exports.renameFile = exports.createFiles = exports.createProject = void 0;
7
+ const messages_1 = require("./messages");
8
+ const cross_spawn_1 = __importDefault(require("cross-spawn"));
9
+ const fs_1 = __importDefault(require("fs"));
10
+ const ncp_1 = require("ncp");
11
+ const path_1 = __importDefault(require("path"));
12
+ const checks_1 = require("./checks");
13
+ const package_json_1 = require("./package-json");
14
+ // Method to create the project folder
15
+ async function createProject({ contract, frontend, projectPath, projectName, verbose, rootDir, supportsSandbox }) {
16
+ // Make language specific checks
17
+ let preMessagePass = (0, checks_1.preMessage)({ contract, projectName, frontend, projectPath, verbose, rootDir, supportsSandbox });
18
+ if (!preMessagePass) {
19
+ return false;
20
+ }
21
+ messages_1.show.creatingApp();
22
+ // Create files in the project folder
23
+ await createFiles({ contract, frontend, projectName, projectPath, verbose, rootDir, supportsSandbox });
24
+ // Create package.json
25
+ const packageJson = (0, package_json_1.buildPackageJson)({ contract, frontend, projectName, supportsSandbox });
26
+ fs_1.default.writeFileSync(path_1.default.resolve(projectPath, 'package.json'), Buffer.from(JSON.stringify(packageJson, null, 2)));
27
+ // Run language-specific post check
28
+ (0, checks_1.postMessage)({ contract, frontend, projectName, projectPath, verbose, rootDir, supportsSandbox });
29
+ return true;
30
+ }
31
+ exports.createProject = createProject;
32
+ async function createFiles({ contract, frontend, projectPath, verbose, rootDir, supportsSandbox }) {
33
+ // skip build artifacts and symlinks
34
+ const skip = ['.cache', 'dist', 'out', 'node_modules'];
35
+ // copy frontend
36
+ if (frontend !== 'none') {
37
+ const sourceTemplateDir = `${rootDir}/frontend/${frontend}`;
38
+ await copyDir(sourceTemplateDir, projectPath, { verbose, skip: skip.map(f => path_1.default.join(sourceTemplateDir, f)) });
39
+ }
40
+ // shared files
41
+ const sourceSharedDir = `${rootDir}/shared`;
42
+ await copyDir(sourceSharedDir, projectPath, { verbose, skip: skip.map(f => path_1.default.join(sourceSharedDir, f)) });
43
+ // copy contract files
44
+ const contractSourceDir = `${rootDir}/contracts/${contract}`;
45
+ await copyDir(contractSourceDir, `${projectPath}/contract`, {
46
+ verbose,
47
+ skip: skip.map(f => path_1.default.join(contractSourceDir, f))
48
+ });
49
+ // copy tests
50
+ const testFramework = supportsSandbox ? 'workspaces-tests' : 'classic-tests';
51
+ let sourceTestDir = `${rootDir}/integration-tests`;
52
+ if (supportsSandbox) {
53
+ switch (contract) {
54
+ case 'js':
55
+ case 'assemblyscript':
56
+ sourceTestDir = path_1.default.resolve(sourceTestDir, testFramework, 'ts');
57
+ break;
58
+ case 'rust':
59
+ sourceTestDir = path_1.default.resolve(sourceTestDir, 'workspaces-tests/rs');
60
+ break;
61
+ }
62
+ }
63
+ else {
64
+ sourceTestDir = path_1.default.resolve(sourceTestDir, 'classic-tests');
65
+ }
66
+ await copyDir(sourceTestDir, `${projectPath}/integration-tests/`, {
67
+ verbose,
68
+ skip: skip.map(f => path_1.default.join(sourceTestDir, f))
69
+ });
70
+ // add .gitignore
71
+ await (0, exports.renameFile)(`${projectPath}/near.gitignore`, `${projectPath}/.gitignore`);
72
+ }
73
+ exports.createFiles = createFiles;
74
+ const renameFile = async function (oldPath, newPath) {
75
+ return new Promise((resolve, reject) => {
76
+ fs_1.default.rename(oldPath, newPath, err => {
77
+ if (err) {
78
+ console.error(err);
79
+ reject(err);
80
+ return;
81
+ }
82
+ resolve();
83
+ });
84
+ });
85
+ };
86
+ exports.renameFile = renameFile;
87
+ // Wrap `ncp` tool to wait for the copy to finish when using `await`
88
+ // Allow passing `skip` variable to skip copying an array of filenames
89
+ function copyDir(source, dest, { skip, verbose }) {
90
+ return new Promise((resolve, reject) => {
91
+ const copied = [];
92
+ const skipped = [];
93
+ const filter = skip && function (filename) {
94
+ const shouldCopy = !skip.find(f => filename.includes(f));
95
+ shouldCopy ? copied.push(filename) : skipped.push(filename);
96
+ return !skip.find(f => filename.includes(f));
97
+ };
98
+ (0, ncp_1.ncp)(source, dest, { filter }, err => {
99
+ if (err) {
100
+ reject(err);
101
+ return;
102
+ }
103
+ if (verbose) {
104
+ console.log('Copied:');
105
+ copied.forEach(f => console.log(' ' + f));
106
+ console.log('Skipped:');
107
+ skipped.forEach(f => console.log(' ' + f));
108
+ }
109
+ resolve();
110
+ });
111
+ });
112
+ }
113
+ exports.copyDir = copyDir;
114
+ async function runDepsInstall(projectPath) {
115
+ messages_1.show.depsInstall();
116
+ const npmCommandArgs = ['deps-install'];
117
+ await new Promise((resolve, reject) => (0, cross_spawn_1.default)('yarn', npmCommandArgs, {
118
+ cwd: projectPath,
119
+ stdio: 'inherit',
120
+ }).on('close', (code) => {
121
+ if (code !== 0) {
122
+ messages_1.show.depsInstallError();
123
+ reject(code);
124
+ }
125
+ else {
126
+ resolve();
127
+ }
128
+ }));
129
+ }
130
+ exports.runDepsInstall = runDepsInstall;
131
+ //# sourceMappingURL=make.js.map
@@ -0,0 +1,46 @@
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.show = 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
+ const setupFailed = () => (0, exports.log)((0, chalk_1.default) `{bold {red ==========================================}}
18
+ {red ⛔️ There was a problem during NEAR project setup}.
19
+ Please refer to https://github.com/near/create-near-app README to troubleshoot.
20
+ Notice: some platforms aren't supported (yet).
21
+ {bold {red ==========================================}}`);
22
+ const successContractToText = (contract) => (0, chalk_1.default) `with a smart contract in {bold ${contract === 'rust' ? 'Rust' : contract === 'js' ? 'JavaScript' : 'AssemblyScript'}}`;
23
+ const successFrontendToText = (frontend) => frontend === 'none' ? '' : (0, chalk_1.default) ` and a frontend template${frontend === 'react' ? (0, chalk_1.default) `{bold in React.js}` : ''}`;
24
+ const setupSuccess = (projectName, contract, frontend) => (0, exports.log)((0, chalk_1.default) `
25
+ ✅ Success! Created '${projectName}'
26
+ ${successContractToText(contract)}${successFrontendToText(frontend)}.
27
+ 🧠 See {bold {green README.md}} to get started.
28
+ ${contract === 'rust' ? (0, chalk_1.default) `🦀 If you are new to Rust please visit {bold {green https://www.rust-lang.org }}\n` : '\n'}
29
+ Happy Hacking! 👍
30
+ {blue ======================================================}`);
31
+ const argsError = () => (0, exports.log)((0, chalk_1.default) `{red Arguments error}
32
+ Run {blue npx create-near-app} without arguments, or use:
33
+ npx create-near-app <projectName> --contract rust|js|assemblyscript --frontend react|vanilla|none`);
34
+ const unsupportedNodeVersion = (supported) => (0, exports.log)((0, chalk_1.default) `{red We support node.js version ${supported} or later}`);
35
+ const directoryExists = (dirName) => (0, exports.log)((0, chalk_1.default) `{red This directory already exists! ${dirName}}`);
36
+ const creatingApp = () => (0, exports.log)((0, chalk_1.default) `...creating a new NEAR app...`);
37
+ const depsInstall = () => (0, exports.log)((0, chalk_1.default) `
38
+ {green Installing dependencies in a few folders, this might take a while...}
39
+ `);
40
+ const depsInstallError = () => (0, exports.log)(chalk_1.default.red('Error installing NEAR project dependencies'));
41
+ exports.show = {
42
+ welcome, setupFailed, setupSuccess, argsError,
43
+ unsupportedNodeVersion, directoryExists, creatingApp,
44
+ depsInstall, depsInstallError,
45
+ };
46
+ //# sourceMappingURL=messages.js.map
@@ -0,0 +1,140 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildPackageJson = void 0;
4
+ function buildPackageJson({ contract, frontend, projectName, supportsSandbox }) {
5
+ const result = basePackage({
6
+ contract, frontend, projectName, supportsSandbox,
7
+ });
8
+ return result;
9
+ }
10
+ exports.buildPackageJson = buildPackageJson;
11
+ function basePackage({ contract, frontend, projectName, supportsSandbox }) {
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': 'yarn test:unit && yarn test:integration',
23
+ ...unitTestScripts(contract),
24
+ ...integrationTestScripts(contract, supportsSandbox),
25
+ ...npmInstallScript(contract, supportsSandbox, hasFrontend),
26
+ },
27
+ 'devDependencies': {
28
+ 'near-cli': '3.3.0',
29
+ },
30
+ 'dependencies': {}
31
+ };
32
+ }
33
+ const startScript = (hasFrontend) => hasFrontend ? {
34
+ 'start': 'cd frontend && yarn start'
35
+ } : {};
36
+ const buildScript = (hasFrontend) => hasFrontend ? {
37
+ 'build': 'yarn build:contract && yarn build:web',
38
+ 'build:web': 'cd frontend && yarn build',
39
+ } : {
40
+ 'build': 'yarn build:contract',
41
+ };
42
+ const buildContractScript = (contract) => {
43
+ switch (contract) {
44
+ case 'assemblyscript':
45
+ return {
46
+ 'build:contract': 'cd contract && yarn build',
47
+ };
48
+ case 'js':
49
+ return {
50
+ 'build:contract': 'cd contract && yarn 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 && yarn deploy',
66
+ };
67
+ case 'rust':
68
+ return {
69
+ 'deploy': 'yarn 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 && yarn test' };
80
+ case 'rust':
81
+ return { 'test:unit': 'cd contract && cargo test' };
82
+ default:
83
+ return {};
84
+ }
85
+ };
86
+ const integrationTestScripts = (contract, supportsSandbox) => {
87
+ if (supportsSandbox) {
88
+ switch (contract) {
89
+ case 'assemblyscript':
90
+ return {
91
+ 'test:integration': 'yarn build:contract && cd integration-tests && yarn test -- -- "./contract/build/release/hello_near.wasm"',
92
+ };
93
+ case 'js':
94
+ return {
95
+ 'test:integration': 'yarn build:contract && cd integration-tests && yarn test -- -- "./contract/build/hello_near.wasm"',
96
+ };
97
+ case 'rust':
98
+ return {
99
+ 'test:integration': 'yarn build:contract && cd integration-tests && cargo run --example integration-tests "../contract/target/wasm32-unknown-unknown/release/hello_near.wasm"',
100
+ };
101
+ default:
102
+ return {};
103
+ }
104
+ }
105
+ else {
106
+ return {
107
+ 'test:integration': 'yarn deploy && cd integration-tests && yarn test',
108
+ };
109
+ }
110
+ };
111
+ const npmInstallScript = (contract, supportsSandbox, hasFrontend) => {
112
+ switch (contract) {
113
+ case 'assemblyscript':
114
+ case 'js':
115
+ if (hasFrontend) {
116
+ return { 'deps-install': 'yarn && cd contract && yarn && cd ../integration-tests && yarn && cd ../frontend && yarn && cd ..' };
117
+ }
118
+ else {
119
+ return { 'deps-install': 'yarn && cd contract && yarn && cd ../integration-tests && yarn && cd ..' };
120
+ }
121
+ case 'rust':
122
+ if (supportsSandbox) {
123
+ if (hasFrontend) {
124
+ return { 'deps-install': 'yarn && cd frontend && yarn && cd ..' };
125
+ }
126
+ else {
127
+ return { 'deps-install': 'yarn' };
128
+ }
129
+ }
130
+ else {
131
+ if (hasFrontend) {
132
+ return { 'deps-install': 'yarn && cd integration-tests && yarn && cd ../frontend && yarn && cd ..' };
133
+ }
134
+ else {
135
+ return { 'deps-install': 'yarn && cd integration-tests && yarn && cd ..' };
136
+ }
137
+ }
138
+ }
139
+ };
140
+ //# sourceMappingURL=package-json.js.map
@@ -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
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1,113 @@
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.userAnswersAreValid = exports.showDepsInstallPrompt = exports.showProjectNamePrompt = exports.showUserPrompts = exports.validateUserArgs = exports.getUserArgs = void 0;
7
+ const chalk_1 = __importDefault(require("chalk"));
8
+ const prompts_1 = __importDefault(require("prompts"));
9
+ const commander_1 = require("commander");
10
+ async function getUserArgs() {
11
+ commander_1.program
12
+ .argument('[projectName]')
13
+ .option('--contract <contract>')
14
+ .option('--frontend <frontend>')
15
+ .option('--install')
16
+ .option('--no-sandbox');
17
+ commander_1.program.parse();
18
+ const options = commander_1.program.opts();
19
+ const [projectName] = commander_1.program.args;
20
+ const { contract, frontend, sandbox, install } = options;
21
+ return { contract, frontend, projectName, sandbox, install };
22
+ }
23
+ exports.getUserArgs = getUserArgs;
24
+ function validateUserArgs(args) {
25
+ if (args === null) {
26
+ return 'error';
27
+ }
28
+ const { projectName, contract, frontend } = args;
29
+ const hasAllOptions = contract !== undefined && frontend !== undefined;
30
+ const hasPartialOptions = contract !== undefined || frontend !== undefined;
31
+ const hasProjectName = projectName !== undefined;
32
+ const hasAllArgs = hasAllOptions && hasProjectName;
33
+ const hasNoArgs = !hasPartialOptions && !hasProjectName;
34
+ const optionsAreValid = hasAllOptions
35
+ && ['react', 'vanilla', 'none'].includes(frontend)
36
+ && ['js', 'rust', 'assemblyscript'].includes(contract);
37
+ if (hasNoArgs) {
38
+ return 'none';
39
+ }
40
+ else if (hasAllArgs && optionsAreValid) {
41
+ return 'ok';
42
+ }
43
+ else {
44
+ return 'error';
45
+ }
46
+ }
47
+ exports.validateUserArgs = validateUserArgs;
48
+ const userPrompts = [
49
+ {
50
+ type: 'select',
51
+ name: 'contract',
52
+ message: 'Select your smart-contract language',
53
+ choices: [
54
+ { title: 'JavaScript', value: 'js' },
55
+ { title: 'Rust', value: 'rust' },
56
+ { title: 'AssemblyScript', value: 'assemblyscript' },
57
+ ]
58
+ },
59
+ {
60
+ type: 'select',
61
+ name: 'frontend',
62
+ message: 'Select a template for your frontend',
63
+ choices: [
64
+ { title: 'React.js', value: 'react' },
65
+ { title: 'Vanilla JavaScript', value: 'vanilla' },
66
+ { title: 'No frontend', value: 'none' },
67
+ ]
68
+ },
69
+ {
70
+ type: 'text',
71
+ name: 'projectName',
72
+ message: 'Name your project (this will create a directory with that name)}',
73
+ initial: 'my-near-project',
74
+ },
75
+ ];
76
+ async function showUserPrompts() {
77
+ const [contract, frontend, projectName] = userPrompts;
78
+ const answers = await (0, prompts_1.default)([contract, frontend, projectName]);
79
+ return answers;
80
+ }
81
+ exports.showUserPrompts = showUserPrompts;
82
+ async function showProjectNamePrompt() {
83
+ const [, , projectName] = userPrompts;
84
+ const answers = await (0, prompts_1.default)([projectName]);
85
+ return answers;
86
+ }
87
+ exports.showProjectNamePrompt = showProjectNamePrompt;
88
+ async function showDepsInstallPrompt() {
89
+ const questions = [
90
+ {
91
+ type: 'toggle',
92
+ name: 'depsInstall',
93
+ message: (0, chalk_1.default) `One last thing:\n There are few package.json files with dependencies. We can run {bold {blue 'yarn install'}} for you.\n To do it yourself: {bold {blue 'yarn run deps-install'}}.\n Run {bold {blue 'yarn install'}} now?\n`,
94
+ initial: true,
95
+ active: 'yes',
96
+ inactive: 'no'
97
+ },
98
+ ];
99
+ const answers = await (0, prompts_1.default)(questions);
100
+ return answers;
101
+ }
102
+ exports.showDepsInstallPrompt = showDepsInstallPrompt;
103
+ function userAnswersAreValid(answers) {
104
+ const { contract, frontend, projectName } = answers;
105
+ if ([contract, frontend, projectName].includes(undefined)) {
106
+ return false;
107
+ }
108
+ else {
109
+ return true;
110
+ }
111
+ }
112
+ exports.userAnswersAreValid = userAnswersAreValid;
113
+ //# sourceMappingURL=user-input.js.map