create-near-app 7.0.2 → 8.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.
Files changed (41) hide show
  1. package/dist/app.js +1 -7
  2. package/dist/make.js +3 -7
  3. package/dist/messages.js +2 -2
  4. package/dist/tracking.js +32 -15
  5. package/dist/user-input.js +18 -19
  6. package/package.json +3 -4
  7. package/templates/contracts/rs/Cargo.lock +6619 -0
  8. package/templates/contracts/rs/Cargo.toml +3 -3
  9. package/templates/contracts/rs/src/lib.rs +1 -1
  10. package/templates/contracts/rs/tests/test_basics.rs +6 -5
  11. package/templates/contracts/ts/package.json +4 -2
  12. package/templates/contracts/ts/src/contract.ts +5 -0
  13. package/templates/contracts/ts/yarn.lock +3290 -0
  14. package/templates/frontend/next-app/package.json +21 -9
  15. package/templates/frontend/next-app/src/app/hello-near/page.js +1 -1
  16. package/templates/frontend/next-app/src/app/layout.js +3 -4
  17. package/templates/frontend/next-app/src/components/navigation.js +1 -1
  18. package/templates/frontend/next-app/src/config.js +18 -1
  19. package/templates/frontend/next-app/src/wallets/near.js +89 -15
  20. package/templates/frontend/next-app/src/wallets/web3modal.js +44 -0
  21. package/templates/frontend/next-page/package.json +21 -9
  22. package/templates/frontend/next-page/src/components/navigation.js +1 -1
  23. package/templates/frontend/next-page/src/config.js +18 -1
  24. package/templates/frontend/next-page/src/pages/_app.js +3 -4
  25. package/templates/frontend/next-page/src/pages/hello-near/index.js +1 -1
  26. package/templates/frontend/next-page/src/wallets/near.js +89 -15
  27. package/templates/frontend/next-page/src/wallets/web3modal.js +44 -0
  28. package/templates/frontend/components/next-app/package.json +0 -42
  29. package/templates/frontend/components/next-app/src/app/hello-components/page.js +0 -46
  30. package/templates/frontend/components/next-app/src/components/cards.js +0 -43
  31. package/templates/frontend/components/next-app/src/components/vm.js +0 -31
  32. package/templates/frontend/components/next-app/src/config.js +0 -23
  33. package/templates/frontend/components/next-app/src/wallets/eth.ts +0 -289
  34. package/templates/frontend/components/next-page/package.json +0 -42
  35. package/templates/frontend/components/next-page/src/components/cards.js +0 -43
  36. package/templates/frontend/components/next-page/src/components/vm.js +0 -29
  37. package/templates/frontend/components/next-page/src/config.js +0 -23
  38. package/templates/frontend/components/next-page/src/pages/hello-components/index.js +0 -46
  39. package/templates/frontend/components/next-page/src/wallets/eth.ts +0 -289
  40. package/templates/frontend/next-app/src/context.js +0 -13
  41. package/templates/frontend/next-page/src/context.js +0 -13
package/dist/app.js CHANGED
@@ -31,27 +31,21 @@ const semver_1 = __importDefault(require("semver"));
31
31
  const make_1 = require("./make");
32
32
  const user_input_1 = require("./user-input");
33
33
  const show = __importStar(require("./messages"));
34
- const tracking_1 = require("./tracking");
35
34
  (async function () {
36
35
  const supportedNodeVersion = require('../package.json').engines.node;
37
36
  if (!semver_1.default.satisfies(process.version, supportedNodeVersion)) {
38
37
  return show.unsupportedNodeVersion(supportedNodeVersion);
39
38
  }
40
- if (process.platform === 'win32') {
41
- (0, tracking_1.trackUsage)('none', false, 'none');
42
- return show.windowsWarning();
43
- }
44
39
  const prompt = await (0, user_input_1.promptAndGetConfig)();
45
40
  if (prompt === undefined)
46
41
  return;
47
- const { config: { projectName, contract, frontend, components, install, }, projectPath, } = prompt;
42
+ const { config: { projectName, contract, frontend, install, }, projectPath, } = prompt;
48
43
  show.creatingApp();
49
44
  let createSuccess;
50
45
  try {
51
46
  createSuccess = await (0, make_1.createProject)({
52
47
  contract,
53
48
  frontend,
54
- components,
55
49
  templatesDir: path_1.default.resolve(__dirname, '../templates'),
56
50
  projectPath,
57
51
  });
package/dist/make.js CHANGED
@@ -32,12 +32,12 @@ const cross_spawn_1 = __importDefault(require("cross-spawn"));
32
32
  const fs_1 = __importDefault(require("fs"));
33
33
  const ncp_1 = require("ncp");
34
34
  const path_1 = __importDefault(require("path"));
35
- async function createProject({ contract, frontend, components, projectPath, templatesDir }) {
35
+ async function createProject({ contract, frontend, projectPath, templatesDir }) {
36
36
  if (contract !== 'none') {
37
37
  await createContract({ contract, projectPath, templatesDir });
38
38
  }
39
39
  else {
40
- await createGateway({ frontend, components, projectPath, templatesDir });
40
+ await createGateway({ frontend, projectPath, templatesDir });
41
41
  }
42
42
  return true;
43
43
  }
@@ -48,14 +48,10 @@ async function createContract({ contract, projectPath, templatesDir }) {
48
48
  fs_1.default.mkdirSync(projectPath, { recursive: true });
49
49
  await copyDir(sourceContractDir, projectPath);
50
50
  }
51
- async function createGateway({ frontend, components, projectPath, templatesDir }) {
51
+ async function createGateway({ frontend, projectPath, templatesDir }) {
52
52
  const sourceFrontendDir = path_1.default.resolve(`${templatesDir}/frontend/${frontend}`);
53
53
  fs_1.default.mkdirSync(projectPath, { recursive: true });
54
54
  await copyDir(sourceFrontendDir, projectPath);
55
- if (components) {
56
- const sourceComponentsDir = path_1.default.resolve(`${templatesDir}/frontend/components/${frontend}`);
57
- await copyDir(sourceComponentsDir, projectPath);
58
- }
59
55
  }
60
56
  // Wrap `ncp` tool to wait for the copy to finish when using `await`
61
57
  function copyDir(source, dest) {
package/dist/messages.js CHANGED
@@ -16,7 +16,7 @@ const welcome = () => (0, exports.show)((0, chalk_1.default) `
16
16
  👋 {bold {green Welcome to Near!}} Learn more: https://docs.near.org/
17
17
  🔧 Let's get your project ready.
18
18
  {blue ======================================================}
19
- (${tracking_1.trackingMessage})`);
19
+ (${tracking_1.trackingMessage})\n`);
20
20
  exports.welcome = welcome;
21
21
  const setupFailed = () => (0, exports.show)((0, chalk_1.default) `{bold {red ==========================================}}
22
22
  {red ⛔️ There was a problem during the project setup}.
@@ -84,7 +84,7 @@ npx create-near-app <projectName> [--frontend next-app|next-page] [--contract rs
84
84
  exports.argsError = argsError;
85
85
  const unsupportedNodeVersion = (supported) => (0, exports.show)((0, chalk_1.default) `{red We support node.js version ${supported} or later}`);
86
86
  exports.unsupportedNodeVersion = unsupportedNodeVersion;
87
- const windowsWarning = () => (0, exports.show)((0, chalk_1.default) `{red Please use Windows Subsystem for Linux (WSL)}
87
+ const windowsWarning = () => (0, exports.show)((0, chalk_1.default) `{red Please use Windows Subsystem for Linux (WSL) to develop smart contracts}
88
88
  {yellow Learn more here: https://docs.near.org/blog/getting-started-on-windows}
89
89
  `);
90
90
  exports.windowsWarning = windowsWarning;
package/dist/tracking.js CHANGED
@@ -5,27 +5,44 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.trackUsage = exports.trackingMessage = void 0;
7
7
  const chalk_1 = __importDefault(require("chalk"));
8
- const mixpanel_1 = __importDefault(require("mixpanel"));
9
- const MIXPANEL_TOKEN = '24177ef1ec09ffea5cb6f68909c66a61';
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`;
8
+ const POSTHOG_API_KEY = 'phc_95PGQnbyatmj2TBRPWYfhbHfqB6wgZj5QRL8WY9gW20';
9
+ const POSTHOG_API_URL = 'https://eu.i.posthog.com/capture';
10
+ exports.trackingMessage = chalk_1.default.italic('Near collects anonymous information on the commands used. No personal information that could identify you is shared');
12
11
  // TODO: track different failures & install usage
13
- const trackUsage = async (frontend, components, contract) => {
12
+ const trackUsage = async (frontend, contract) => {
14
13
  // prevents logging from CI
15
14
  if (process.env.NEAR_ENV === 'ci' || process.env.NODE_ENV === 'ci') {
16
- console.log('Mixpanel logging is skipped in CI env');
15
+ console.log('PostHog logging is skipped in CI env');
17
16
  return;
18
17
  }
19
- try {
20
- const mixPanelProperties = {
21
- frontend,
22
- components,
23
- contract,
18
+ const payload = {
19
+ distinct_id: 'create-near-app',
20
+ event: 'error',
21
+ properties: {
22
+ engine: process.versions.node,
24
23
  os: process.platform,
25
- nodeVersion: process.versions.node,
26
- timestamp: new Date().toString()
27
- };
28
- tracker.track('CNA', mixPanelProperties);
24
+ },
25
+ timestamp: new Date(),
26
+ };
27
+ if (contract !== 'none') {
28
+ payload.event = 'contract';
29
+ payload.properties.language = contract;
30
+ }
31
+ if (frontend !== 'none') {
32
+ payload.event = 'frontend';
33
+ payload.properties.framework = frontend;
34
+ }
35
+ const headers = new Headers();
36
+ headers.append('Content-Type', 'application/json');
37
+ try {
38
+ await fetch(POSTHOG_API_URL, {
39
+ method: 'POST',
40
+ body: JSON.stringify({
41
+ api_key: POSTHOG_API_KEY,
42
+ ...payload,
43
+ }),
44
+ headers,
45
+ });
29
46
  }
30
47
  catch (e) {
31
48
  console.error('Warning: problem while sending tracking data. Error: ', e);
@@ -39,19 +39,20 @@ async function getUserArgs() {
39
39
  .argument('[projectName]')
40
40
  .option('--frontend [next-page|next-app|none]')
41
41
  .option('--contract [ts|rs|none]')
42
- .option('--components')
43
42
  .option('--install')
44
43
  .addHelpText('after', 'You can create a frontend or a contract with tests');
45
44
  commander_1.program.parse();
46
45
  const options = commander_1.program.opts();
47
46
  const [projectName] = commander_1.program.args;
48
- const { contract, frontend, install, components } = options;
49
- return { contract, frontend, components, projectName, install };
47
+ const { contract, frontend, install } = options;
48
+ return { contract, frontend, projectName, install, error: undefined };
50
49
  }
51
50
  exports.getUserArgs = getUserArgs;
52
51
  const appChoices = [
53
52
  { title: 'A Web App', description: 'A Web App that talks with Near contracts', value: 'gateway' },
54
- { title: 'A Smart Contract', description: 'A smart contract to be deployed in the Near Blockchain', value: 'contract' },
53
+ {
54
+ title: 'A Smart Contract', description: 'A smart contract to be deployed in the Near Blockchain', value: 'contract',
55
+ },
55
56
  ];
56
57
  const contractChoices = [
57
58
  { title: 'JS/TS Contract', description: 'A Near contract written in javascript/typescript', value: 'ts' },
@@ -61,10 +62,6 @@ const frontendChoices = [
61
62
  { title: 'NextJs (Classic)', description: 'A web-app built using Next.js Page Router', value: 'next-page' },
62
63
  { title: 'NextJS (App Router)', description: 'A web-app built using Next.js new App Router', value: 'next-app' },
63
64
  ];
64
- const componentChoices = [
65
- { title: 'No', value: false },
66
- { title: 'Yes', value: true },
67
- ];
68
65
  const appPrompt = {
69
66
  type: 'select',
70
67
  name: 'app',
@@ -77,12 +74,6 @@ const frontendPrompt = {
77
74
  message: 'Select a framework for your frontend',
78
75
  choices: frontendChoices,
79
76
  };
80
- const componentsPrompt = {
81
- type: 'select',
82
- name: 'components',
83
- message: 'Are you planning in using on-chain NEAR Components (aka BOS Components)?',
84
- choices: componentChoices,
85
- };
86
77
  const contractPrompt = [
87
78
  {
88
79
  type: 'select',
@@ -112,15 +103,19 @@ async function getUserAnswers() {
112
103
  const { app } = await promptUser(appPrompt);
113
104
  if (app === 'gateway') {
114
105
  // If gateway, ask for the framework to use
115
- const { frontend, components, projectName, install } = await promptUser([frontendPrompt, componentsPrompt, namePrompts, npmPrompt]);
116
- return { frontend, components, contract: 'none', projectName, install };
106
+ const { frontend, projectName, install } = await promptUser([frontendPrompt, namePrompts, npmPrompt]);
107
+ return { frontend, contract: 'none', projectName, install, error: undefined };
117
108
  }
118
109
  else {
110
+ // If platform is Window, return the error
111
+ if (process.platform === 'win32') {
112
+ return { frontend: 'none', contract: 'none', projectName: '', install: false, error: show.windowsWarning };
113
+ }
119
114
  // If contract, ask for the language for the contract
120
115
  let { contract } = await promptUser(contractPrompt);
121
116
  const { projectName } = await promptUser(namePrompts);
122
117
  const install = contract === 'ts' ? (await promptUser(npmPrompt)).install : false;
123
- return { frontend: 'none', components: false, contract, projectName, install };
118
+ return { frontend: 'none', contract, projectName, install, error: undefined };
124
119
  }
125
120
  }
126
121
  exports.getUserAnswers = getUserAnswers;
@@ -132,14 +127,18 @@ async function promptAndGetConfig() {
132
127
  show.welcome();
133
128
  args = await getUserAnswers();
134
129
  }
130
+ if (args.error) {
131
+ (0, tracking_1.trackUsage)('none', 'none');
132
+ return args.error();
133
+ }
135
134
  // Homogenizing terminal args with prompt args
136
135
  args.contract = args.contract || 'none';
137
136
  args.frontend = args.frontend || 'none';
138
137
  if (!validateUserArgs(args))
139
138
  return;
140
139
  // track user input
141
- const { frontend, components, contract } = args;
142
- (0, tracking_1.trackUsage)(frontend, components, contract);
140
+ const { frontend, contract } = args;
141
+ (0, tracking_1.trackUsage)(frontend, contract);
143
142
  let path = (0, exports.projectPath)(args.projectName);
144
143
  if (fs_1.default.existsSync(path)) {
145
144
  return show.directoryExists(path);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-near-app",
3
- "version": "7.0.2",
3
+ "version": "8.0.0",
4
4
  "description": "Quickly scaffold your dApp on NEAR Blockchain",
5
5
  "main": "index.js",
6
6
  "engines": {
@@ -27,16 +27,15 @@
27
27
  "chalk": "^4.1.2",
28
28
  "commander": "^11.0.0",
29
29
  "cross-spawn": "^7.0.3",
30
- "mixpanel": "^0.18.0",
31
30
  "ncp": "^2.0.0",
32
31
  "prompts": "^2.4.2",
33
32
  "semver": "^7.5.3"
34
33
  },
35
34
  "devDependencies": {
36
- "@babel/eslint-parser": "^7.22.5",
37
35
  "@babel/core": "^7.23.2",
38
- "@babel/plugin-transform-react-jsx": "^7.22.15",
36
+ "@babel/eslint-parser": "^7.22.5",
39
37
  "@babel/plugin-syntax-flow": "^7.22.5",
38
+ "@babel/plugin-transform-react-jsx": "^7.22.15",
40
39
  "@commitlint/cli": "^17.6.6",
41
40
  "@commitlint/config-conventional": "^17.6.6",
42
41
  "@release-it/conventional-changelog": "^5.1.1",