meshjs 0.0.1 → 1.5.3

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 ADDED
@@ -0,0 +1,21 @@
1
+ ![Mesh Logo](https://meshjs.dev/logo-mesh/mesh.png)
2
+
3
+ Mesh is an open-source library to make building dApps accessible. Whether you're a beginner developer, startup, web3 market leader, or a large enterprise, Mesh makes web3 development easy with reliable, scalable, and well-engineered APIs & developer tools.
4
+
5
+ ```sh
6
+ Usage: create-mesh-app [options] <name>
7
+
8
+ A quick and easy way to bootstrap your dApps on Cardano using Mesh.
9
+
10
+ Arguments:
11
+ name Set a name for your dApp.
12
+
13
+ Options:
14
+ -V, --version output the version number
15
+ -t, --template <TEMPLATE-NAME> The template to start your project from. (choices: "starter", "minting", "marketplace")
16
+ -s, --stack <STACK-NAME> The tech stack you want to build on. (choices: "next", "remix")
17
+ -l, --language <LANGUAGE-NAME> The language you want to use. (choices: "js", "ts")
18
+ -h, --help display help for command
19
+ ```
20
+
21
+ Explore the features on [Mesh Playground](https://meshjs.dev/).
@@ -0,0 +1,2 @@
1
+ #! /usr/bin/env node
2
+ require('../dist/create-mesh-app.cjs.js');
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ export * from "./declarations/src/index";
2
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWVzaGpzLmNqcy5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi9kZWNsYXJhdGlvbnMvc3JjL2luZGV4LmQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEifQ==
@@ -0,0 +1,214 @@
1
+ 'use strict';
2
+
3
+ var chalk = require('chalk');
4
+ var figlet = require('figlet');
5
+ var commander = require('commander');
6
+ var got = require('got');
7
+ var prompts = require('prompts');
8
+ var tar = require('tar');
9
+ var util = require('util');
10
+ var stream = require('stream');
11
+ var fs = require('fs');
12
+ var child_process = require('child_process');
13
+ var os = require('os');
14
+ var path = require('path');
15
+
16
+ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
17
+
18
+ var chalk__default = /*#__PURE__*/_interopDefault(chalk);
19
+ var figlet__default = /*#__PURE__*/_interopDefault(figlet);
20
+ var got__default = /*#__PURE__*/_interopDefault(got);
21
+ var prompts__default = /*#__PURE__*/_interopDefault(prompts);
22
+
23
+ const resolvePkgManager = () => {
24
+ try {
25
+ const userAgent = process.env.npm_config_user_agent;
26
+ if (userAgent?.startsWith('yarn')) {
27
+ return 'yarn';
28
+ }
29
+ if (userAgent?.startsWith('pnpm')) {
30
+ return 'pnpm';
31
+ }
32
+ try {
33
+ child_process.execSync('yarn --version', {
34
+ stdio: 'ignore'
35
+ });
36
+ return 'yarn';
37
+ } catch (_) {
38
+ child_process.execSync('pnpm --version', {
39
+ stdio: 'ignore'
40
+ });
41
+ return 'pnpm';
42
+ }
43
+ } catch (_) {
44
+ return 'npm';
45
+ }
46
+ };
47
+
48
+ const setProjectName = (path$1, name) => {
49
+ const packagePath = path.join(path$1, 'package.json');
50
+ const packageContent = fs.readFileSync(packagePath);
51
+ const packageJson = JSON.parse(packageContent.toString());
52
+ if (packageJson) {
53
+ packageJson.name = name;
54
+ }
55
+ fs.writeFileSync(packagePath, JSON.stringify(packageJson, null, 2) + os.EOL);
56
+ };
57
+
58
+ const tryGitInit = () => {
59
+ try {
60
+ child_process.execSync('git --version', {
61
+ stdio: 'ignore'
62
+ });
63
+ if (isInGitRepository() || isInMercurialRepository()) {
64
+ return false;
65
+ }
66
+ child_process.execSync('git init', {
67
+ stdio: 'ignore'
68
+ });
69
+ child_process.execSync('git checkout -b main', {
70
+ stdio: 'ignore'
71
+ });
72
+ child_process.execSync('git add -A', {
73
+ stdio: 'ignore'
74
+ });
75
+ child_process.execSync('git commit -m "Initial commit from npx mesh-create-dapp"', {
76
+ stdio: 'ignore'
77
+ });
78
+ return true;
79
+ } catch (_) {
80
+ return false;
81
+ }
82
+ };
83
+ const isInGitRepository = () => {
84
+ try {
85
+ child_process.execSync('git rev-parse --is-inside-work-tree', {
86
+ stdio: 'ignore'
87
+ });
88
+ return true;
89
+ } catch (_) {}
90
+ return false;
91
+ };
92
+ const isInMercurialRepository = () => {
93
+ try {
94
+ child_process.execSync('hg --cwd . root', {
95
+ stdio: 'ignore'
96
+ });
97
+ return true;
98
+ } catch (_) {}
99
+ return false;
100
+ };
101
+
102
+ const logError = message => {
103
+ console.log(chalk__default["default"].redBright(message + '\n'));
104
+ };
105
+ const logSuccess = message => {
106
+ console.log(chalk__default["default"].greenBright(message + '\n'));
107
+ };
108
+ const logInfo = message => {
109
+ console.log(chalk__default["default"].blueBright(message + '\n'));
110
+ };
111
+
112
+ const create = async (name, options) => {
113
+ const template = options.template ?? (await askUser('What template do you want to use?', [{
114
+ title: 'NextJs starter template',
115
+ value: 'mesh-nextjs'
116
+ },
117
+ // { title: 'Multi-Sig Minting', value: 'minting' },
118
+ // { title: 'Stake-Pool Website', value: 'staking' },
119
+ // { title: 'Cardano Sign-In', value: 'signin' },
120
+ // { title: 'E-Commerce Store', value: 'ecommerce' },
121
+ // { title: 'Marketplace', value: 'marketplace' },
122
+ {
123
+ title: 'Aiken template',
124
+ value: 'mesh-aiken'
125
+ }]));
126
+ console.log('\n');
127
+ try {
128
+ createDirectory(name);
129
+ logInfo('📡 - Downloading files..., This might take a moment.');
130
+ await fetchRepository(template);
131
+ logInfo('🏠 - Starting a new git repository...');
132
+ setNameAndCommitChanges(name);
133
+ logInfo('🧶 - Installing project dependencies...');
134
+ installDependencies();
135
+ } catch (error) {
136
+ logError(error);
137
+ process.exit(1);
138
+ }
139
+ };
140
+ const askUser = async (question, choices) => {
141
+ const response = await prompts__default["default"]({
142
+ type: 'select',
143
+ message: question,
144
+ name: 'selection',
145
+ choices
146
+ }, {
147
+ onCancel: () => process.exit(0)
148
+ });
149
+ return response.selection;
150
+ };
151
+ const createDirectory = name => {
152
+ const path = `${process.cwd()}/${name}`;
153
+ if (fs.existsSync(path)) {
154
+ logError(`❗ A directory with name: "${name}" already exists.`);
155
+ process.exit(1);
156
+ }
157
+ if (fs.mkdirSync(path, {
158
+ recursive: true
159
+ }) === undefined) {
160
+ logError('❌ Unable to create a project in current directory.');
161
+ process.exit(1);
162
+ }
163
+ logInfo('🏗️ - Creating a new mesh dApp in current directory...');
164
+ process.chdir(path);
165
+ };
166
+ const fetchRepository = async template => {
167
+ const pipe = util.promisify(stream.pipeline);
168
+ const name = `${template}-template`;
169
+ const link = `https://codeload.github.com/MeshJS/${name}/tar.gz/main`;
170
+ await pipe(got__default["default"].stream(link), tar.extract({
171
+ strip: 1
172
+ }, [`${name}-main`]));
173
+ };
174
+ const setNameAndCommitChanges = name => {
175
+ try {
176
+ setProjectName(process.cwd(), name);
177
+ } catch (_) {
178
+ logError('🚫 Failed to re-name package.json, continuing...');
179
+ }
180
+ tryGitInit();
181
+ };
182
+ const installDependencies = () => {
183
+ try {
184
+ const pkgManager = resolvePkgManager();
185
+ child_process.execSync(`${pkgManager} install`, {
186
+ stdio: [0, 1, 2]
187
+ });
188
+ } catch (_) {
189
+ logError('🚫 Failed to install project dependencies, continuing...');
190
+ }
191
+ };
192
+
193
+ const main = async () => {
194
+ console.clear();
195
+ console.info(chalk__default["default"].blue(figlet__default["default"].textSync('!Create Mesh dApp', {
196
+ font: 'Speed',
197
+ horizontalLayout: 'full'
198
+ })));
199
+ console.log('\n');
200
+ const program = commander.createCommand();
201
+ program.name('create-mesh-app').description('A quick and easy way to bootstrap your dApps on Cardano using Mesh.').version('1.0.0');
202
+ program.addArgument(commander.createArgument('name', 'Set a name for your dApp.').argParser(name => {
203
+ if (/^([A-Za-z\-\\_\d])+$/.test(name)) return name;
204
+ throw new commander.InvalidArgumentError(chalk__default["default"].redBright('❗ Only letters, numbers, underscores and, hashes are allowed.'));
205
+ }).argRequired()).addOption(commander.createOption('-t, --template <TEMPLATE-NAME>', `The template to start your project from.`).choices(['starter', 'minting', 'staking', 'ecommerce', 'signin', 'marketplace'])).addOption(commander.createOption('-s, --stack <STACK-NAME>', `The tech stack you want to build on.`).choices(['next'])).addOption(commander.createOption('-l, --language <LANGUAGE-NAME>', `The language you want to use.`).choices(['ts'])).action(create);
206
+ await program.parseAsync(process.argv);
207
+ };
208
+ main().then(() => {
209
+ logSuccess('✨✨ Welcome to Web 3.0! ✨✨');
210
+ process.exit(0);
211
+ }).catch(error => {
212
+ logError(error);
213
+ process.exit(1);
214
+ });
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ if (process.env.NODE_ENV === "production") {
4
+ module.exports = require("./meshjs.cjs.prod.js");
5
+ } else {
6
+ module.exports = require("./meshjs.cjs.dev.js");
7
+ }
@@ -0,0 +1,214 @@
1
+ 'use strict';
2
+
3
+ var chalk = require('chalk');
4
+ var figlet = require('figlet');
5
+ var commander = require('commander');
6
+ var got = require('got');
7
+ var prompts = require('prompts');
8
+ var tar = require('tar');
9
+ var util = require('util');
10
+ var stream = require('stream');
11
+ var fs = require('fs');
12
+ var child_process = require('child_process');
13
+ var os = require('os');
14
+ var path = require('path');
15
+
16
+ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
17
+
18
+ var chalk__default = /*#__PURE__*/_interopDefault(chalk);
19
+ var figlet__default = /*#__PURE__*/_interopDefault(figlet);
20
+ var got__default = /*#__PURE__*/_interopDefault(got);
21
+ var prompts__default = /*#__PURE__*/_interopDefault(prompts);
22
+
23
+ const resolvePkgManager = () => {
24
+ try {
25
+ const userAgent = process.env.npm_config_user_agent;
26
+ if (userAgent?.startsWith('yarn')) {
27
+ return 'yarn';
28
+ }
29
+ if (userAgent?.startsWith('pnpm')) {
30
+ return 'pnpm';
31
+ }
32
+ try {
33
+ child_process.execSync('yarn --version', {
34
+ stdio: 'ignore'
35
+ });
36
+ return 'yarn';
37
+ } catch (_) {
38
+ child_process.execSync('pnpm --version', {
39
+ stdio: 'ignore'
40
+ });
41
+ return 'pnpm';
42
+ }
43
+ } catch (_) {
44
+ return 'npm';
45
+ }
46
+ };
47
+
48
+ const setProjectName = (path$1, name) => {
49
+ const packagePath = path.join(path$1, 'package.json');
50
+ const packageContent = fs.readFileSync(packagePath);
51
+ const packageJson = JSON.parse(packageContent.toString());
52
+ if (packageJson) {
53
+ packageJson.name = name;
54
+ }
55
+ fs.writeFileSync(packagePath, JSON.stringify(packageJson, null, 2) + os.EOL);
56
+ };
57
+
58
+ const tryGitInit = () => {
59
+ try {
60
+ child_process.execSync('git --version', {
61
+ stdio: 'ignore'
62
+ });
63
+ if (isInGitRepository() || isInMercurialRepository()) {
64
+ return false;
65
+ }
66
+ child_process.execSync('git init', {
67
+ stdio: 'ignore'
68
+ });
69
+ child_process.execSync('git checkout -b main', {
70
+ stdio: 'ignore'
71
+ });
72
+ child_process.execSync('git add -A', {
73
+ stdio: 'ignore'
74
+ });
75
+ child_process.execSync('git commit -m "Initial commit from npx mesh-create-dapp"', {
76
+ stdio: 'ignore'
77
+ });
78
+ return true;
79
+ } catch (_) {
80
+ return false;
81
+ }
82
+ };
83
+ const isInGitRepository = () => {
84
+ try {
85
+ child_process.execSync('git rev-parse --is-inside-work-tree', {
86
+ stdio: 'ignore'
87
+ });
88
+ return true;
89
+ } catch (_) {}
90
+ return false;
91
+ };
92
+ const isInMercurialRepository = () => {
93
+ try {
94
+ child_process.execSync('hg --cwd . root', {
95
+ stdio: 'ignore'
96
+ });
97
+ return true;
98
+ } catch (_) {}
99
+ return false;
100
+ };
101
+
102
+ const logError = message => {
103
+ console.log(chalk__default["default"].redBright(message + '\n'));
104
+ };
105
+ const logSuccess = message => {
106
+ console.log(chalk__default["default"].greenBright(message + '\n'));
107
+ };
108
+ const logInfo = message => {
109
+ console.log(chalk__default["default"].blueBright(message + '\n'));
110
+ };
111
+
112
+ const create = async (name, options) => {
113
+ const template = options.template ?? (await askUser('What template do you want to use?', [{
114
+ title: 'NextJs starter template',
115
+ value: 'mesh-nextjs'
116
+ },
117
+ // { title: 'Multi-Sig Minting', value: 'minting' },
118
+ // { title: 'Stake-Pool Website', value: 'staking' },
119
+ // { title: 'Cardano Sign-In', value: 'signin' },
120
+ // { title: 'E-Commerce Store', value: 'ecommerce' },
121
+ // { title: 'Marketplace', value: 'marketplace' },
122
+ {
123
+ title: 'Aiken template',
124
+ value: 'mesh-aiken'
125
+ }]));
126
+ console.log('\n');
127
+ try {
128
+ createDirectory(name);
129
+ logInfo('📡 - Downloading files..., This might take a moment.');
130
+ await fetchRepository(template);
131
+ logInfo('🏠 - Starting a new git repository...');
132
+ setNameAndCommitChanges(name);
133
+ logInfo('🧶 - Installing project dependencies...');
134
+ installDependencies();
135
+ } catch (error) {
136
+ logError(error);
137
+ process.exit(1);
138
+ }
139
+ };
140
+ const askUser = async (question, choices) => {
141
+ const response = await prompts__default["default"]({
142
+ type: 'select',
143
+ message: question,
144
+ name: 'selection',
145
+ choices
146
+ }, {
147
+ onCancel: () => process.exit(0)
148
+ });
149
+ return response.selection;
150
+ };
151
+ const createDirectory = name => {
152
+ const path = `${process.cwd()}/${name}`;
153
+ if (fs.existsSync(path)) {
154
+ logError(`❗ A directory with name: "${name}" already exists.`);
155
+ process.exit(1);
156
+ }
157
+ if (fs.mkdirSync(path, {
158
+ recursive: true
159
+ }) === undefined) {
160
+ logError('❌ Unable to create a project in current directory.');
161
+ process.exit(1);
162
+ }
163
+ logInfo('🏗️ - Creating a new mesh dApp in current directory...');
164
+ process.chdir(path);
165
+ };
166
+ const fetchRepository = async template => {
167
+ const pipe = util.promisify(stream.pipeline);
168
+ const name = `${template}-template`;
169
+ const link = `https://codeload.github.com/MeshJS/${name}/tar.gz/main`;
170
+ await pipe(got__default["default"].stream(link), tar.extract({
171
+ strip: 1
172
+ }, [`${name}-main`]));
173
+ };
174
+ const setNameAndCommitChanges = name => {
175
+ try {
176
+ setProjectName(process.cwd(), name);
177
+ } catch (_) {
178
+ logError('🚫 Failed to re-name package.json, continuing...');
179
+ }
180
+ tryGitInit();
181
+ };
182
+ const installDependencies = () => {
183
+ try {
184
+ const pkgManager = resolvePkgManager();
185
+ child_process.execSync(`${pkgManager} install`, {
186
+ stdio: [0, 1, 2]
187
+ });
188
+ } catch (_) {
189
+ logError('🚫 Failed to install project dependencies, continuing...');
190
+ }
191
+ };
192
+
193
+ const main = async () => {
194
+ console.clear();
195
+ console.info(chalk__default["default"].blue(figlet__default["default"].textSync('!Create Mesh dApp', {
196
+ font: 'Speed',
197
+ horizontalLayout: 'full'
198
+ })));
199
+ console.log('\n');
200
+ const program = commander.createCommand();
201
+ program.name('create-mesh-app').description('A quick and easy way to bootstrap your dApps on Cardano using Mesh.').version('1.0.0');
202
+ program.addArgument(commander.createArgument('name', 'Set a name for your dApp.').argParser(name => {
203
+ if (/^([A-Za-z\-\\_\d])+$/.test(name)) return name;
204
+ throw new commander.InvalidArgumentError(chalk__default["default"].redBright('❗ Only letters, numbers, underscores and, hashes are allowed.'));
205
+ }).argRequired()).addOption(commander.createOption('-t, --template <TEMPLATE-NAME>', `The template to start your project from.`).choices(['starter', 'minting', 'staking', 'ecommerce', 'signin', 'marketplace'])).addOption(commander.createOption('-s, --stack <STACK-NAME>', `The tech stack you want to build on.`).choices(['next'])).addOption(commander.createOption('-l, --language <LANGUAGE-NAME>', `The language you want to use.`).choices(['ts'])).action(create);
206
+ await program.parseAsync(process.argv);
207
+ };
208
+ main().then(() => {
209
+ logSuccess('✨✨ Welcome to Web 3.0! ✨✨');
210
+ process.exit(0);
211
+ }).catch(error => {
212
+ logError(error);
213
+ process.exit(1);
214
+ });
package/package.json CHANGED
@@ -1,12 +1,43 @@
1
1
  {
2
2
  "name": "meshjs",
3
- "version": "0.0.1",
4
- "description": "",
5
- "main": "index.js",
3
+ "description": "A quick and easy way to bootstrap your dApps on Cardano using Mesh.",
4
+ "homepage": "https://meshjs.dev",
5
+ "author": "MeshJS",
6
+ "version": "1.5.3",
7
+ "license": "Apache-2.0",
8
+ "main": "dist/meshjs.cjs.js",
9
+ "bin": {
10
+ "meshjs": "./bin/meshjs"
11
+ },
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/MeshJS/mesh.git"
15
+ },
16
+ "bugs": {
17
+ "url": "https://github.com/MeshJS/mesh/issues"
18
+ },
19
+ "keywords": [
20
+ "blockchain",
21
+ "cardano",
22
+ "dapp",
23
+ "npx"
24
+ ],
6
25
  "scripts": {
7
- "test": "echo \"Error: no test specified\" && exit 1"
26
+ "build:scripts": "preconstruct build",
27
+ "start": "preconstruct watch"
28
+ },
29
+ "dependencies": {
30
+ "chalk": "5.3.0",
31
+ "commander": "12.1.0",
32
+ "figlet": "1.7.0",
33
+ "got": "14.4.1",
34
+ "prompts": "2.4.2",
35
+ "tar": "7.2.0"
8
36
  },
9
- "keywords": [],
10
- "author": "Abdelkrim Dib",
11
- "license": "ISC"
12
- }
37
+ "devDependencies": {
38
+ "@preconstruct/cli": "2.8.4",
39
+ "@types/figlet": "1.5.8",
40
+ "@types/prompts": "2.4.9",
41
+ "@types/tar": "6.1.13"
42
+ }
43
+ }
@@ -0,0 +1,101 @@
1
+ import got from 'got';
2
+ import prompts from 'prompts';
3
+ import { extract } from 'tar';
4
+ import { promisify } from 'util';
5
+ import { pipeline } from 'stream';
6
+ import { existsSync, mkdirSync } from 'fs';
7
+ import { execSync } from 'child_process';
8
+ import { resolvePkgManager, setProjectName, tryGitInit } from '../helpers';
9
+ import { logError, logInfo } from '../utils';
10
+
11
+ export const create = async (name, options) => {
12
+ const template =
13
+ options.template ??
14
+ (await askUser('What template do you want to use?', [
15
+ { title: 'NextJs starter template', value: 'mesh-nextjs' },
16
+ // { title: 'Multi-Sig Minting', value: 'minting' },
17
+ // { title: 'Stake-Pool Website', value: 'staking' },
18
+ // { title: 'Cardano Sign-In', value: 'signin' },
19
+ // { title: 'E-Commerce Store', value: 'ecommerce' },
20
+ // { title: 'Marketplace', value: 'marketplace' },
21
+ { title: 'Aiken template', value: 'mesh-aiken' },
22
+ ]));
23
+
24
+ console.log('\n');
25
+
26
+ try {
27
+ createDirectory(name);
28
+
29
+ logInfo('📡 - Downloading files..., This might take a moment.');
30
+ await fetchRepository(template);
31
+
32
+ logInfo('🏠 - Starting a new git repository...');
33
+ setNameAndCommitChanges(name);
34
+
35
+ logInfo('🧶 - Installing project dependencies...');
36
+ installDependencies();
37
+ } catch (error) {
38
+ logError(error);
39
+ process.exit(1);
40
+ }
41
+ };
42
+
43
+ const askUser = async (question, choices) => {
44
+ const response = await prompts(
45
+ {
46
+ type: 'select',
47
+ message: question,
48
+ name: 'selection',
49
+ choices,
50
+ },
51
+ {
52
+ onCancel: () => process.exit(0),
53
+ }
54
+ );
55
+
56
+ return response.selection;
57
+ };
58
+
59
+ const createDirectory = (name) => {
60
+ const path = `${process.cwd()}/${name}`;
61
+
62
+ if (existsSync(path)) {
63
+ logError(`❗ A directory with name: "${name}" already exists.`);
64
+ process.exit(1);
65
+ }
66
+
67
+ if (mkdirSync(path, { recursive: true }) === undefined) {
68
+ logError('❌ Unable to create a project in current directory.');
69
+ process.exit(1);
70
+ }
71
+
72
+ logInfo('🏗️ - Creating a new mesh dApp in current directory...');
73
+ process.chdir(path);
74
+ };
75
+
76
+ const fetchRepository = async (template) => {
77
+ const pipe = promisify(pipeline);
78
+ const name = `${template}-template`;
79
+ const link = `https://codeload.github.com/MeshJS/${name}/tar.gz/main`;
80
+
81
+ await pipe(got.stream(link), extract({ strip: 1 }, [`${name}-main`]));
82
+ };
83
+
84
+ const setNameAndCommitChanges = (name) => {
85
+ try {
86
+ setProjectName(process.cwd(), name);
87
+ } catch (_) {
88
+ logError('🚫 Failed to re-name package.json, continuing...');
89
+ }
90
+
91
+ tryGitInit();
92
+ };
93
+
94
+ const installDependencies = () => {
95
+ try {
96
+ const pkgManager = resolvePkgManager();
97
+ execSync(`${pkgManager} install`, { stdio: [0, 1, 2] });
98
+ } catch (_) {
99
+ logError('🚫 Failed to install project dependencies, continuing...');
100
+ }
101
+ };
@@ -0,0 +1 @@
1
+ export * from './create';
@@ -0,0 +1,3 @@
1
+ export * from './resolvePkgManager';
2
+ export * from './setProjectName';
3
+ export * from './tryGitInit';
@@ -0,0 +1,24 @@
1
+ import { execSync } from 'child_process';
2
+
3
+ export const resolvePkgManager = () => {
4
+ try {
5
+ const userAgent = process.env.npm_config_user_agent;
6
+ if (userAgent?.startsWith('yarn')) {
7
+ return 'yarn';
8
+ }
9
+
10
+ if (userAgent?.startsWith('pnpm')) {
11
+ return 'pnpm';
12
+ }
13
+
14
+ try {
15
+ execSync('yarn --version', { stdio: 'ignore' });
16
+ return 'yarn';
17
+ } catch (_) {
18
+ execSync('pnpm --version', { stdio: 'ignore' });
19
+ return 'pnpm';
20
+ }
21
+ } catch (_) {
22
+ return 'npm';
23
+ }
24
+ };
@@ -0,0 +1,15 @@
1
+ import { EOL } from 'os';
2
+ import { join } from 'path';
3
+ import { readFileSync, writeFileSync } from 'fs';
4
+
5
+ export const setProjectName = (path, name) => {
6
+ const packagePath = join(path, 'package.json');
7
+ const packageContent = readFileSync(packagePath);
8
+ const packageJson = JSON.parse(packageContent.toString());
9
+
10
+ if (packageJson) {
11
+ packageJson.name = name;
12
+ }
13
+
14
+ writeFileSync(packagePath, JSON.stringify(packageJson, null, 2) + EOL);
15
+ };
@@ -0,0 +1,37 @@
1
+ import { execSync } from 'child_process';
2
+
3
+ export const tryGitInit = () => {
4
+ try {
5
+ execSync('git --version', { stdio: 'ignore' });
6
+
7
+ if (isInGitRepository() || isInMercurialRepository()) {
8
+ return false;
9
+ }
10
+
11
+ execSync('git init', { stdio: 'ignore' });
12
+ execSync('git checkout -b main', { stdio: 'ignore' });
13
+ execSync('git add -A', { stdio: 'ignore' });
14
+ execSync('git commit -m "Initial commit from npx mesh-create-dapp"', {
15
+ stdio: 'ignore',
16
+ });
17
+ return true;
18
+ } catch (_) {
19
+ return false;
20
+ }
21
+ };
22
+
23
+ const isInGitRepository = () => {
24
+ try {
25
+ execSync('git rev-parse --is-inside-work-tree', { stdio: 'ignore' });
26
+ return true;
27
+ } catch (_) {}
28
+ return false;
29
+ };
30
+
31
+ const isInMercurialRepository = () => {
32
+ try {
33
+ execSync('hg --cwd . root', { stdio: 'ignore' });
34
+ return true;
35
+ } catch (_) {}
36
+ return false;
37
+ };
package/src/index.ts ADDED
@@ -0,0 +1,77 @@
1
+ import chalk from 'chalk';
2
+ import figlet from 'figlet';
3
+ import {
4
+ createArgument, createCommand,
5
+ createOption, InvalidArgumentError,
6
+ } from 'commander';
7
+ import { create } from './actions';
8
+ import { logError, logSuccess } from './utils';
9
+
10
+ const main = async () => {
11
+ console.clear();
12
+
13
+ console.info(
14
+ chalk.blue(
15
+ figlet.textSync('!Create Mesh dApp', {
16
+ font: 'Speed', horizontalLayout: 'full',
17
+ })
18
+ )
19
+ );
20
+
21
+ console.log('\n');
22
+
23
+ const program = createCommand();
24
+
25
+ program
26
+ .name('create-mesh-app')
27
+ .description(
28
+ 'A quick and easy way to bootstrap your dApps on Cardano using Mesh.'
29
+ )
30
+ .version('1.0.0');
31
+
32
+ program
33
+ .addArgument(
34
+ createArgument('name', 'Set a name for your dApp.')
35
+ .argParser((name) => {
36
+ if (/^([A-Za-z\-\\_\d])+$/.test(name)) return name;
37
+
38
+ throw new InvalidArgumentError(
39
+ chalk.redBright(
40
+ '❗ Only letters, numbers, underscores and, hashes are allowed.',
41
+ ),
42
+ );
43
+ })
44
+ .argRequired()
45
+ )
46
+ .addOption(
47
+ createOption(
48
+ '-t, --template <TEMPLATE-NAME>',
49
+ `The template to start your project from.`
50
+ ).choices(['starter', 'minting', 'staking', 'ecommerce', 'signin', 'marketplace'])
51
+ )
52
+ .addOption(
53
+ createOption(
54
+ '-s, --stack <STACK-NAME>',
55
+ `The tech stack you want to build on.`
56
+ ).choices(['next'])
57
+ )
58
+ .addOption(
59
+ createOption(
60
+ '-l, --language <LANGUAGE-NAME>',
61
+ `The language you want to use.`
62
+ ).choices(['ts'])
63
+ )
64
+ .action(create);
65
+
66
+ await program.parseAsync(process.argv);
67
+ };
68
+
69
+ main()
70
+ .then(() => {
71
+ logSuccess('✨✨ Welcome to Web 3.0! ✨✨');
72
+ process.exit(0);
73
+ })
74
+ .catch((error) => {
75
+ logError(error);
76
+ process.exit(1);
77
+ });
@@ -0,0 +1 @@
1
+ export * from './logger';
@@ -0,0 +1,13 @@
1
+ import chalk from 'chalk';
2
+
3
+ export const logError = (message) => {
4
+ console.log(chalk.redBright(message + '\n'));
5
+ };
6
+
7
+ export const logSuccess = (message) => {
8
+ console.log(chalk.greenBright(message + '\n'));
9
+ };
10
+
11
+ export const logInfo = (message) => {
12
+ console.log(chalk.blueBright(message + '\n'));
13
+ };
package/tsconfig.json ADDED
@@ -0,0 +1,109 @@
1
+ {
2
+ "compilerOptions": {
3
+ /* Visit https://aka.ms/tsconfig to read more about this file */
4
+
5
+ /* Projects */
6
+ // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
7
+ // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
8
+ // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
9
+ // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
10
+ // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
11
+ // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
12
+
13
+ /* Language and Environment */
14
+ "target": "ESNext", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
15
+ "lib": ["DOM", "ESNext"], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
16
+ // "jsx": "preserve", /* Specify what JSX code is generated. */
17
+ "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
18
+ // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
19
+ // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
20
+ // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
21
+ // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
22
+ // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
23
+ // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
24
+ // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
25
+ // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
26
+
27
+ /* Modules */
28
+ "module": "ESNext", /* Specify what module code is generated. */
29
+ "rootDir": "src", /* Specify the root folder within your source files. */
30
+ "moduleResolution": "Node", /* Specify how TypeScript looks up a file from a given module specifier. */
31
+ "baseUrl": ".", /* Specify the base directory to resolve non-relative module names. */
32
+ "paths": {
33
+ "@mesh/*": ["src/*"],
34
+ }, /* Specify a set of entries that re-map imports to additional lookup locations. */
35
+ // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
36
+ // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
37
+ // "types": [], /* Specify type package names to be included without being referenced in a source file. */
38
+ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
39
+ // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
40
+ // "resolveJsonModule": true, /* Enable importing .json files. */
41
+ // "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
42
+
43
+ /* JavaScript Support */
44
+ // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
45
+ // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
46
+ // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
47
+
48
+ /* Emit */
49
+ "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
50
+ // "declarationMap": true, /* Create sourcemaps for d.ts files. */
51
+ // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
52
+ // "sourceMap": true, /* Create source map files for emitted JavaScript files. */
53
+ // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
54
+ "outDir": "dist", /* Specify an output folder for all emitted files. */
55
+ // "removeComments": true, /* Disable emitting comments. */
56
+ "noEmit": true, /* Disable emitting files from a compilation. */
57
+ "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
58
+ // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */
59
+ // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
60
+ // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
61
+ // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
62
+ // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
63
+ // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
64
+ // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
65
+ // "newLine": "crlf", /* Set the newline character for emitting files. */
66
+ // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
67
+ // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
68
+ // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
69
+ // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
70
+ "declarationDir": "dist", /* Specify the output directory for generated declaration files. */
71
+ // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
72
+
73
+ /* Interop Constraints */
74
+ // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
75
+ "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
76
+ "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
77
+ // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
78
+ "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
79
+
80
+ /* Type Checking */
81
+ "strict": true, /* Enable all strict type-checking options. */
82
+ "noImplicitAny": false, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
83
+ // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
84
+ // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
85
+ // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
86
+ // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
87
+ // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
88
+ // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
89
+ // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
90
+ "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
91
+ "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
92
+ // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
93
+ "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
94
+ "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
95
+ // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
96
+ // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
97
+ // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
98
+ // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
99
+ // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
100
+
101
+ /* Completeness */
102
+ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
103
+ "skipLibCheck": true /* Skip type checking all .d.ts files. */
104
+ },
105
+ "include": [
106
+ "src",
107
+ "types"
108
+ ]
109
+ }