create-canton-app 1.0.0 → 1.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.
package/README.md CHANGED
@@ -1,7 +1,46 @@
1
1
  # create-canton-app
2
2
  Scaffold Canton Network Daml projects in seconds. A CLI tool to quickly bootstrap Canton Network dApp.
3
3
 
4
- ## Adding Custom Templates
4
+ [![npm version](https://img.shields.io/npm/v/create-canton-app.svg)](https://www.npmjs.com/package/create-canton-app)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
+ [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/Jatinp26/create-canton-app/pulls)
7
+
8
+
9
+ ## Requirements
10
+ - Node.js v16+
11
+ - Java Runtime (for tests)
12
+
13
+ ## Quick Start
14
+
15
+ ### Create Your First Canton dApp
16
+
17
+ ```bash
18
+ npx create-canton-app my-first-dapp
19
+ ```
20
+
21
+ ### Build and Test
22
+
23
+ ```bash
24
+ cd my-first-dapp
25
+ daml build
26
+ daml test
27
+ ```
28
+
29
+ **That's it!** You now have a working Canton smart contract.
30
+
31
+ ## Contributing
32
+
33
+ 1. Fork the repository
34
+
35
+ 2. Create a feature branch (`git checkout -b feature/amazing-template`)
36
+
37
+ 3. Commit your changes (`git commit -m 'Add amazing template'`)
38
+
39
+ 4. Push to the branch (`git push origin feature/amazing-template`)
40
+
41
+ 5. Open a Pull Request
42
+
43
+ ### Adding Custom Templates
5
44
 
6
45
  1. Create Your Template folder with a 'daml' subdir (rename 'my-template' as your desired template name)
7
46
 
@@ -29,7 +68,7 @@ choices: [
29
68
  ]
30
69
  ```
31
70
 
32
- 4. Test it
71
+ 4. Try it
33
72
 
34
73
  ```bash
35
74
  cd test-my-template
@@ -45,7 +84,10 @@ daml test
45
84
  - [ ] Has clear use case
46
85
  - [ ] daml.yaml includes `daml-script` dependency
47
86
 
48
- ## Requirements
49
- - Node.js v16+
50
- - Daml SDK v3.4.9+
51
- - Java Runtime (for tests)
87
+ <div align="center">
88
+
89
+ **[⬆ back to top](#create-canton-app)**
90
+
91
+ Made with 💜 for [Canton](https://canton.network)
92
+
93
+ </div>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-canton-app",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Scaffold Canton Network/Daml projects in seconds",
5
5
  "main": "bin/create-canton-app.js",
6
6
  "repository": {
@@ -14,8 +14,121 @@ const colors = {
14
14
  bold: (text) => `\x1b[1m${text}\x1b[0m`
15
15
  };
16
16
 
17
+ // Check if Daml SDK is installed
18
+ function isDamlInstalled() {
19
+ return shell.which('daml') !== null;
20
+ }
21
+
22
+ // Get Daml version
23
+ function getDamlVersion() {
24
+ try {
25
+ const result = shell.exec('daml version', { silent: true });
26
+ const match = result.stdout.match(/(\d+\.\d+\.\d+)/);
27
+ return match ? match[1] : null;
28
+ } catch {
29
+ return null;
30
+ }
31
+ }
32
+
33
+ // Install Daml SDK automatically
34
+ async function installDamlSDK() {
35
+ console.log('');
36
+ console.log(colors.yellow('⚠️ Daml SDK not found!'));
37
+ console.log('');
38
+ console.log(colors.white('Daml SDK is required to compile Canton smart contracts.'));
39
+ console.log('');
40
+
41
+ const answers = await inquirer.prompt([
42
+ {
43
+ type: 'confirm',
44
+ name: 'installDaml',
45
+ message: 'Would you like to install Daml SDK now? (Recommended)',
46
+ default: true
47
+ }
48
+ ]);
49
+
50
+ if (!answers.installDaml) {
51
+ console.log('');
52
+ console.log(colors.yellow('⚠️ Skipping Daml SDK installation.'));
53
+ console.log(colors.dim('You can install it later with:'));
54
+ console.log(colors.white(' curl -sSL https://get.daml.com/ | sh'));
55
+ console.log('');
56
+ return false;
57
+ }
58
+
59
+ console.log('');
60
+ const spinner = ora('Installing Daml SDK (this may take a few minutes)...').start();
61
+
62
+ try {
63
+ // Install Daml SDK
64
+ const result = shell.exec('curl -sSL https://get.daml.com/ | sh', {
65
+ silent: true
66
+ });
67
+
68
+ if (result.code !== 0) {
69
+ spinner.fail(colors.red('Failed to install Daml SDK'));
70
+ console.log('');
71
+ console.log(colors.red('Error:'), result.stderr);
72
+ console.log('');
73
+ console.log(colors.yellow('Please install manually:'));
74
+ console.log(colors.white(' curl -sSL https://get.daml.com/ | sh'));
75
+ console.log('');
76
+ return false;
77
+ }
78
+
79
+ // Add to PATH for current session
80
+ const damlPath = path.join(process.env.HOME, '.daml', 'bin');
81
+ process.env.PATH = `${damlPath}:${process.env.PATH}`;
82
+
83
+ spinner.succeed(colors.green('✨ Daml SDK installed successfully!'));
84
+
85
+ console.log('');
86
+ console.log(colors.cyan('📝 Important: Add Daml to your PATH permanently'));
87
+ console.log(colors.dim('Add this line to your ~/.zshrc or ~/.bashrc:'));
88
+ console.log('');
89
+ console.log(colors.white(` export PATH="$HOME/.daml/bin:$PATH"`));
90
+ console.log('');
91
+ console.log(colors.dim('Then reload your shell:'));
92
+ console.log(colors.white(' source ~/.zshrc'));
93
+ console.log('');
94
+
95
+ return true;
96
+ } catch (error) {
97
+ spinner.fail(colors.red('Installation failed: ' + error.message));
98
+ return false;
99
+ }
100
+ }
101
+
17
102
  async function create(projectName, options) {
18
103
  try {
104
+ // Check prerequisites BEFORE asking for project details
105
+ console.log('');
106
+ console.log(colors.cyan('🔍 Checking prerequisites...'));
107
+ console.log('');
108
+
109
+ // Check Daml SDK
110
+ if (!isDamlInstalled()) {
111
+ const installed = await installDamlSDK();
112
+ if (!installed) {
113
+ console.log(colors.yellow('⚠️ Continuing without Daml SDK...'));
114
+ console.log(colors.dim('You can still create the project, but won\'t be able to compile until Daml is installed.'));
115
+ console.log('');
116
+ }
117
+ } else {
118
+ const version = getDamlVersion();
119
+ console.log(colors.green(`✅ Daml SDK found${version ? ` (v${version})` : ''}`));
120
+ }
121
+
122
+ // Check Java (just informational)
123
+ if (!shell.which('java')) {
124
+ console.log(colors.yellow('⚠️ Java not found (optional, needed for tests)'));
125
+ } else {
126
+ console.log(colors.green('✅ Java Runtime found'));
127
+ }
128
+
129
+ console.log('');
130
+
131
+ // Now proceed with project creation
19
132
  if (!projectName) {
20
133
  const answers = await inquirer.prompt([
21
134
  {
@@ -75,12 +188,22 @@ async function create(projectName, options) {
75
188
 
76
189
  spinner.succeed(colors.green('✨ Project created successfully!'));
77
190
 
191
+ // Show next steps
78
192
  console.log('');
79
193
  console.log(colors.cyan(colors.bold('📚 Next steps:')));
80
194
  console.log('');
81
195
  console.log(colors.white(` cd ${projectName}`));
82
- console.log(colors.white(` daml build ${colors.dim('# Compile your contracts')}`));
83
- console.log(colors.white(` daml test ${colors.dim('# Run tests')}`));
196
+
197
+ if (isDamlInstalled()) {
198
+ console.log(colors.white(` daml build ${colors.dim('# Compile your contracts')}`));
199
+ console.log(colors.white(` daml test ${colors.dim('# Run tests')}`));
200
+ } else {
201
+ console.log(colors.yellow(` # First, install Daml SDK:`));
202
+ console.log(colors.white(` curl -sSL https://get.daml.com/ | sh`));
203
+ console.log(colors.white(` source ~/.zshrc`));
204
+ console.log(colors.white(` daml build`));
205
+ }
206
+
84
207
  console.log('');
85
208
  console.log(colors.dim('📖 Read README.md for more information'));
86
209
  console.log('');
@@ -110,7 +233,6 @@ daml test
110
233
  }
111
234
 
112
235
  function createConfig(projectPath, projectName) {
113
- // THE FIX: Added daml-script dependency!
114
236
  const damlConfig = `sdk-version: 3.4.9
115
237
  name: ${projectName}
116
238
  source: daml
@@ -150,6 +272,16 @@ daml build
150
272
  daml test
151
273
  \`\`\`
152
274
 
275
+ ## Prerequisites
276
+
277
+ If you don't have Daml SDK installed, the CLI will offer to install it automatically.
278
+
279
+ Or install manually:
280
+
281
+ \`\`\`bash
282
+ curl -sSL https://get.daml.com/ | sh
283
+ \`\`\`
284
+
153
285
  ## Learn More
154
286
 
155
287
  - [Canton Docs](https://docs.digitalasset.com)
@@ -160,4 +292,4 @@ daml test
160
292
  fs.writeFileSync(path.join(projectPath, 'README.md'), readme);
161
293
  }
162
294
 
163
- module.exports = create;
295
+ module.exports = create;