create-near-app 6.0.0 → 6.0.1

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 CHANGED
@@ -42,7 +42,6 @@ const show = __importStar(require("./messages"));
42
42
  contract,
43
43
  frontend,
44
44
  tests,
45
- projectName,
46
45
  templatesDir: path_1.default.resolve(__dirname, '../templates'),
47
46
  projectPath,
48
47
  });
package/dist/make.js CHANGED
@@ -32,22 +32,21 @@ 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, tests, projectPath, projectName, templatesDir }) {
35
+ async function createProject({ contract, frontend, tests, projectPath, templatesDir }) {
36
36
  if (contract !== 'none') {
37
- await createContract({ contract, tests, projectPath, projectName, templatesDir });
37
+ await createContract({ contract, tests, projectPath, templatesDir });
38
38
  }
39
39
  else {
40
- await createGateway({ frontend, projectPath, projectName, templatesDir });
40
+ await createGateway({ frontend, projectPath, templatesDir });
41
41
  }
42
42
  return true;
43
43
  }
44
44
  exports.createProject = createProject;
45
- async function createContract({ contract, tests, projectPath, projectName, templatesDir }) {
45
+ async function createContract({ contract, tests, projectPath, templatesDir }) {
46
46
  // contract folder
47
47
  const sourceContractDir = path_1.default.resolve(templatesDir, 'contracts', contract);
48
- const targetContractDir = projectPath;
49
- fs_1.default.mkdirSync(targetContractDir, { recursive: true });
50
- await copyDir(sourceContractDir, targetContractDir);
48
+ fs_1.default.mkdirSync(projectPath, { recursive: true });
49
+ await copyDir(sourceContractDir, projectPath);
51
50
  // copy sandbox-test dir
52
51
  const targetTestDir = path_1.default.resolve(projectPath, `sandbox-${tests}`);
53
52
  const sourceTestDir = path_1.default.resolve(`${templatesDir}/sandbox-tests/sandbox-${tests}`);
@@ -71,11 +70,10 @@ async function createContract({ contract, tests, projectPath, projectName, templ
71
70
  }
72
71
  }
73
72
  }
74
- async function createGateway({ frontend, projectPath, projectName, templatesDir }) {
73
+ async function createGateway({ frontend, projectPath, templatesDir }) {
75
74
  const sourceFrontendDir = path_1.default.resolve(`${templatesDir}/frontend/${frontend}`);
76
- const targetFrontendDir = path_1.default.resolve(`${projectPath}`);
77
- fs_1.default.mkdirSync(targetFrontendDir, { recursive: true });
78
- await copyDir(sourceFrontendDir, targetFrontendDir);
75
+ fs_1.default.mkdirSync(projectPath, { recursive: true });
76
+ await copyDir(sourceFrontendDir, projectPath);
79
77
  }
80
78
  // Wrap `ncp` tool to wait for the copy to finish when using `await`
81
79
  function copyDir(source, dest) {
package/dist/messages.js CHANGED
@@ -56,9 +56,10 @@ ${!install ? (0, chalk_1.default) ` - {inverse Install all dependencies}
56
56
  - {inverse Start your app}:
57
57
  {blue pnpm {bold run dev}}`;
58
58
  exports.gatewayInstructions = gatewayInstructions;
59
- const argsError = () => (0, exports.show)((0, chalk_1.default) `{red Arguments error}
59
+ const argsError = (msg) => (0, exports.show)((0, chalk_1.default) `{red Arguments error: {white ${msg}}}
60
+
60
61
  Run {blue npx create-near-app} without arguments, or use:
61
- npx create-near-app <projectName> --frontend next|vanilla|none --contract rs|ts|none --tests rs|ts|none`);
62
+ npx create-near-app <projectName> [--frontend next|vanilla|none] [--contract rs|ts|none --tests rs|ts|none]`);
62
63
  exports.argsError = argsError;
63
64
  const unsupportedNodeVersion = (supported) => (0, exports.show)((0, chalk_1.default) `{red We support node.js version ${supported} or later}`);
64
65
  exports.unsupportedNodeVersion = unsupportedNodeVersion;
package/dist/tracking.js CHANGED
@@ -6,11 +6,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.trackUsage = exports.trackingMessage = void 0;
7
7
  const chalk_1 = __importDefault(require("chalk"));
8
8
  const mixpanel_1 = __importDefault(require("mixpanel"));
9
- const MIXPANEL_TOKEN = 'df164f13212cbb0dfdae991da60e87f2';
9
+ const MIXPANEL_TOKEN = '24177ef1ec09ffea5cb6f68909c66a61';
10
10
  const tracker = mixpanel_1.default.init(MIXPANEL_TOKEN);
11
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
12
  // TODO: track different failures & install usage
13
- const trackUsage = async (frontend, contract) => {
13
+ const trackUsage = async (frontend, contract, testing) => {
14
14
  // prevents logging from CI
15
15
  if (process.env.NEAR_ENV === 'ci' || process.env.NODE_ENV === 'ci') {
16
16
  console.log('Mixpanel logging is skipped in CI env');
@@ -20,11 +20,12 @@ const trackUsage = async (frontend, contract) => {
20
20
  const mixPanelProperties = {
21
21
  frontend,
22
22
  contract,
23
+ testing,
23
24
  os: process.platform,
24
25
  nodeVersion: process.versions.node,
25
26
  timestamp: new Date().toString()
26
27
  };
27
- tracker.track('track create near app', mixPanelProperties);
28
+ tracker.track('CNA', mixPanelProperties);
28
29
  }
29
30
  catch (e) {
30
31
  console.error('Warning: problem while sending tracking data. Error: ', e);
@@ -26,7 +26,7 @@ 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.getUserAnswers = exports.validateUserArgs = exports.getUserArgs = void 0;
29
+ exports.projectPath = exports.promptAndGetConfig = exports.getUserAnswers = exports.getUserArgs = void 0;
30
30
  const types_1 = require("./types");
31
31
  const chalk_1 = __importDefault(require("chalk"));
32
32
  const prompts_1 = __importDefault(require("prompts"));
@@ -38,8 +38,8 @@ const fs_1 = __importDefault(require("fs"));
38
38
  async function getUserArgs() {
39
39
  commander_1.program
40
40
  .argument('[projectName]')
41
- .option('--contract [ts|rs|none]')
42
41
  .option('--frontend [next|vanilla|none]')
42
+ .option('--contract [ts|rs|none]')
43
43
  .option('--tests [rs|ts|none]')
44
44
  .option('--install')
45
45
  .addHelpText('after', 'You can create a frontend or a contract with tests');
@@ -50,31 +50,6 @@ async function getUserArgs() {
50
50
  return { contract, frontend, projectName, tests, install };
51
51
  }
52
52
  exports.getUserArgs = getUserArgs;
53
- function validateUserArgs(args) {
54
- if (args === null) {
55
- return 'error';
56
- }
57
- const { projectName, contract, frontend, tests } = args;
58
- const hasAllOptions = contract !== undefined && frontend !== undefined;
59
- const hasPartialOptions = contract !== undefined || frontend !== undefined;
60
- const hasProjectName = projectName !== undefined;
61
- const hasAllArgs = hasAllOptions && hasProjectName;
62
- const hasNoArgs = !hasPartialOptions && !hasProjectName;
63
- const optionsAreValid = hasAllOptions
64
- && types_1.FRONTENDS.includes(frontend)
65
- && types_1.CONTRACTS.includes(contract)
66
- && types_1.TESTING_FRAMEWORKS.includes(tests);
67
- if (hasNoArgs) {
68
- return 'none';
69
- }
70
- else if (hasAllArgs && optionsAreValid) {
71
- return 'ok';
72
- }
73
- else {
74
- return 'error';
75
- }
76
- }
77
- exports.validateUserArgs = validateUserArgs;
78
53
  const appChoices = [
79
54
  { title: 'A Near Gateway (Web App)', description: 'A multi-chain App that talks with Near contracts and Near components', value: 'gateway' },
80
55
  { title: 'A Near Smart Contract', description: 'A smart contract to be deployed in the Near Blockchain', value: 'contract' },
@@ -161,20 +136,20 @@ async function promptAndGetConfig() {
161
136
  }
162
137
  // process cli args
163
138
  let args = await getUserArgs();
164
- if (args.contract && (!args.tests || args.frontend)) {
165
- return show.argsError();
166
- }
167
- if (args.frontend && (args.tests || args.contract)) {
168
- return show.argsError();
169
- }
170
139
  // If no args, prompt user
171
- if (!args.contract && !args.frontend) {
140
+ if (!args.projectName) {
172
141
  show.welcome();
173
142
  args = await getUserAnswers();
174
143
  }
144
+ // Homogenizing terminal args with prompt args
145
+ args.contract = args.contract || 'none';
146
+ args.frontend = args.frontend || 'none';
147
+ args.tests = args.tests || 'none';
148
+ if (!validateUserArgs(args))
149
+ return;
175
150
  // track user input
176
- const { frontend, contract } = args;
177
- (0, tracking_1.trackUsage)(frontend, contract);
151
+ const { frontend, contract, tests } = args;
152
+ (0, tracking_1.trackUsage)(frontend, contract, tests);
178
153
  let path = (0, exports.projectPath)(args.projectName);
179
154
  if (fs_1.default.existsSync(path)) {
180
155
  return show.directoryExists(path);
@@ -184,4 +159,40 @@ async function promptAndGetConfig() {
184
159
  exports.promptAndGetConfig = promptAndGetConfig;
185
160
  const projectPath = (projectName) => `${process.cwd()}/${projectName}`;
186
161
  exports.projectPath = projectPath;
162
+ const validateUserArgs = (args) => {
163
+ if (!types_1.FRONTENDS.includes(args.frontend)) {
164
+ show.argsError(`Invalid frontend type: ${args.frontend}`);
165
+ return false;
166
+ }
167
+ if (!types_1.CONTRACTS.includes(args.contract)) {
168
+ show.argsError(`Invalid contract type: ${args.contract}`);
169
+ return false;
170
+ }
171
+ if (!types_1.TESTING_FRAMEWORKS.includes(args.tests)) {
172
+ show.argsError(`Invalid testing framework: ${args.tests}`);
173
+ return false;
174
+ }
175
+ if (!args.projectName) {
176
+ show.argsError('Please provide a project name');
177
+ return false;
178
+ }
179
+ if ((args.contract === 'none') === (args.frontend === 'none')) {
180
+ console.log(args.contract, args.frontend);
181
+ show.argsError('Please create a contract OR a frontend');
182
+ return false;
183
+ }
184
+ if (args.contract !== 'none' && args.tests === 'none') {
185
+ show.argsError('Please select a testing framework for your contract');
186
+ return false;
187
+ }
188
+ if (args.frontend !== 'none' && args.tests !== 'none') {
189
+ show.argsError('Remove the --tests flag when creating a frontend');
190
+ return false;
191
+ }
192
+ if (args.contract === 'ts' && args.tests === 'rs') {
193
+ show.argsError('We currently do not support creating a contract in TS with Rust tests, please create it manually');
194
+ return false;
195
+ }
196
+ return true;
197
+ };
187
198
  //# sourceMappingURL=user-input.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-near-app",
3
- "version": "6.0.0",
3
+ "version": "6.0.1",
4
4
  "description": "Quickly scaffold your dApp on NEAR Blockchain",
5
5
  "main": "index.js",
6
6
  "engines": {
@@ -1,9 +1,9 @@
1
- require("util").inspect.defaultOptions.depth = 5; // Increase AVA's printing depth
1
+ require('util').inspect.defaultOptions.depth = 5; // Increase AVA's printing depth
2
2
 
3
3
  module.exports = {
4
- timeout: "300000",
5
- files: ["src/*.ava.ts"],
4
+ timeout: '300000',
5
+ files: ['src/*.ava.ts'],
6
6
  failWithoutAssertions: false,
7
- extensions: ["ts"],
8
- require: ["ts-node/register"],
7
+ extensions: ['ts'],
8
+ require: ['ts-node/register'],
9
9
  };