create-ton 0.0.6 → 0.0.8

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/CHANGELOG.md ADDED
@@ -0,0 +1,22 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [0.0.8] - 2023-02-05
9
+
10
+ ### Changed
11
+
12
+ - Bumped sandbox version to 0.3.0
13
+
14
+ ## [0.0.7] - 2023-02-03
15
+
16
+ ### Added
17
+
18
+ - CLI now asks for contract name to be created first
19
+
20
+ ### Changed
21
+
22
+ - Contract template files are no longer stored in this package, templates from [blueprint](https://github.com/ton-community/blueprint) are now used instead
package/dist/cli.js CHANGED
@@ -11,11 +11,21 @@ const inquirer_1 = __importDefault(require("inquirer"));
11
11
  const chalk_1 = __importDefault(require("chalk"));
12
12
  const PACKAGE_JSON = 'package.json';
13
13
  async function main() {
14
- const { name, variant } = await inquirer_1.default.prompt([
15
- {
16
- name: 'name',
17
- message: 'Project name',
18
- },
14
+ const name = (await inquirer_1.default.prompt({
15
+ name: 'name',
16
+ message: 'Project name',
17
+ })).name.trim();
18
+ if (name.length === 0)
19
+ throw new Error('Cannot initialize a project with an empty name');
20
+ const contractName = (await inquirer_1.default.prompt({
21
+ name: 'contractName',
22
+ message: 'First created contract name',
23
+ })).contractName.trim();
24
+ if (contractName.length === 0)
25
+ throw new Error(`Cannot create a contract with an empty name`);
26
+ if (contractName.toLowerCase() === 'contract' || !/^[a-zA-Z0-9]+$/.test(contractName))
27
+ throw new Error(`Cannot create a contract with the name '${contractName}'`);
28
+ const { variant } = await inquirer_1.default.prompt([
19
29
  {
20
30
  name: 'variant',
21
31
  message: 'Choose the project template',
@@ -32,35 +42,28 @@ async function main() {
32
42
  ],
33
43
  },
34
44
  ]);
35
- if (name.length === 0)
36
- throw new Error('Cannot initialize a project with an empty name');
37
45
  await fs_extra_1.default.mkdir(name);
38
- const steps = 2;
39
- console.log(`[1/${steps}] Copying files...`);
46
+ const steps = 3;
47
+ console.log(`\n[1/${steps}] Copying files...`);
40
48
  const basePath = path_1.default.join(__dirname, 'template');
41
49
  for (const file of await fs_extra_1.default.readdir(basePath)) {
42
- if (file === PACKAGE_JSON || file === 'variants')
50
+ if (file === PACKAGE_JSON)
43
51
  continue;
44
52
  await fs_extra_1.default.copy(path_1.default.join(basePath, file), path_1.default.join(name, file));
45
53
  }
46
- const variantPath = path_1.default.join(basePath, 'variants', variant);
47
- for (const file of await fs_extra_1.default.readdir(variantPath)) {
48
- await fs_extra_1.default.copy(path_1.default.join(variantPath, file), path_1.default.join(name, file));
49
- }
50
54
  await fs_extra_1.default.writeFile(path_1.default.join(name, '.gitignore'), `node_modules
51
55
  temp
52
56
  build`);
53
57
  await fs_extra_1.default.writeFile(path_1.default.join(name, PACKAGE_JSON), (await fs_extra_1.default.readFile(path_1.default.join(basePath, PACKAGE_JSON))).toString().replace('{{name}}', name));
54
- console.log(`[2/${steps}] Installing dependencies...`);
55
- (0, child_process_1.execSync)('npm i', {
56
- stdio: 'inherit',
57
- cwd: name,
58
- });
59
- (0, child_process_1.execSync)('git init', {
58
+ console.log(`[2/${steps}] Installing dependencies...\n`);
59
+ const execOpts = {
60
60
  stdio: 'inherit',
61
61
  cwd: name,
62
- });
63
- console.log('\nInitialized git repository.\n');
62
+ };
63
+ (0, child_process_1.execSync)('npm i', execOpts);
64
+ console.log(`\n[3/${steps}] Creating your first contract...`);
65
+ (0, child_process_1.execSync)(`npx blueprint create ${contractName} --type ${variant}`, execOpts);
66
+ (0, child_process_1.execSync)('git init', execOpts);
64
67
  console.log(`Success!`);
65
68
  console.log(chalk_1.default.blueBright(`
66
69
  ____ _ _ _ _____ ____ ____ ___ _ _ _____
@@ -6,8 +6,8 @@
6
6
  "test": "jest"
7
7
  },
8
8
  "devDependencies": {
9
- "@ton-community/blueprint": "^0.0.2",
10
- "@ton-community/sandbox": "^0.2.0",
9
+ "@ton-community/blueprint": "^0.1.0",
10
+ "@ton-community/sandbox": "^0.3.0",
11
11
  "@ton-community/test-utils": "^0.0.2",
12
12
  "@types/jest": "^29.2.6",
13
13
  "@types/node": "^18.11.18",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-ton",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "license": "MIT",
5
5
  "description": "Tool to quickly create TON projects",
6
6
  "author": "TonTech",
@@ -19,7 +19,7 @@
19
19
  },
20
20
  "devDependencies": {
21
21
  "@types/fs-extra": "^11.0.1",
22
- "@types/inquirer": "^8.0.0",
22
+ "@types/inquirer": "^8.2.5",
23
23
  "@types/node": "^18.11.18",
24
24
  "prettier": "^2.8.3",
25
25
  "typescript": "^4.9.5"
@@ -27,6 +27,6 @@
27
27
  "dependencies": {
28
28
  "chalk": "^4.1.0",
29
29
  "fs-extra": "^11.1.0",
30
- "inquirer": "^8.0.0"
30
+ "inquirer": "^8.2.5"
31
31
  }
32
32
  }
@@ -1,71 +0,0 @@
1
- #include "imports/stdlib.fc";
2
-
3
- const op::increase = "op::increase"c; ;; create an opcode from string using the "c" prefix, this results in 0x7e8764ef opcode in this case
4
-
5
- ;; storage variables
6
-
7
- ;; id is required to be able to create different instances of counters
8
- ;; since addresses in TON depend on the initial state of the contract
9
- global int ctx_id;
10
- global int ctx_counter;
11
-
12
- ;; load_data populates storage variables using stored data
13
- () load_data() impure {
14
- var ds = get_data().begin_parse();
15
-
16
- ctx_id = ds~load_uint(32);
17
- ctx_counter = ds~load_uint(32);
18
-
19
- ds.end_parse();
20
- }
21
-
22
- ;; save_data stores storage variables as a cell into persistent storage
23
- () save_data() impure {
24
- set_data(
25
- begin_cell()
26
- .store_uint(ctx_id, 32)
27
- .store_uint(ctx_counter, 32)
28
- .end_cell()
29
- );
30
- }
31
-
32
- ;; recv_internal is the main function of the contract and is called when it receives a message from other contract's
33
- () recv_internal(int my_balance, int msg_value, cell in_msg_full, slice in_msg_body) impure {
34
- if (in_msg_body.slice_empty?()) { ;; ignore all empty messages
35
- return ();
36
- }
37
-
38
- slice cs = in_msg_full.begin_parse();
39
- int flags = cs~load_uint(4);
40
- if (flags & 1) { ;; ignore all bounced messages
41
- return ();
42
- }
43
-
44
- load_data(); ;; here we populate the storage variables
45
-
46
- int op = in_msg_body~load_uint(32); ;; by convention, the first 32 bits of incoming message is the op
47
- int query_id = in_msg_body~load_uint(64); ;; also by convention, the next 64 bits contain the "query id", although this is not always the case
48
-
49
- if (op == op::increase) {
50
- int increase_by = in_msg_body~load_uint(32);
51
- ctx_counter += increase_by;
52
- save_data();
53
- return ();
54
- }
55
-
56
- throw(0xffff); ;; if the message contains an op that is not known to this contract, we throw
57
- }
58
-
59
- ;; get methods are a means to conveniently read contract data using, for example, HTTP APIs
60
- ;; they are marked with method_id
61
- ;; note that unlike in many other smart contract VMs, get methods cannot be called by other contracts
62
-
63
- int get_counter() method_id {
64
- load_data();
65
- return ctx_counter;
66
- }
67
-
68
- int get_id() method_id {
69
- load_data();
70
- return ctx_id;
71
- }