@clarigen/cli 0.2.4 → 0.3.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.
@@ -24,12 +24,9 @@ export async function getClarinetDevConfig(
24
24
  ): Promise<ClarinetDevConfig> {
25
25
  const baseConfigPath = resolve(folder, 'settings', 'Devnet.toml');
26
26
  const configContents = await readFile(baseConfigPath, { encoding: 'utf-8' });
27
- const config = (parse(
28
- configContents,
29
- 1.0,
30
- '\n',
31
- false
32
- ) as unknown) as ClarinetDevConfig;
27
+ const config = (parse(configContents, 1.0, '\n', true, {
28
+ longer: true,
29
+ }) as unknown) as ClarinetDevConfig;
33
30
  return config;
34
31
  }
35
32
 
@@ -49,7 +46,7 @@ export async function getClarinetConfig(folder: string) {
49
46
  configContents,
50
47
  1.0,
51
48
  '\n',
52
- false
49
+ true
53
50
  ) as unknown) as ClarinetConfig;
54
51
  return config;
55
52
  }
@@ -1,5 +1,67 @@
1
- import { Generate as InnerGenerate } from './generate';
1
+ import { Command, flags } from '@oclif/command';
2
+ import { generateProject } from '../utils';
3
+ import { getConfigFile } from '../config';
4
+ import { watch } from 'chokidar';
5
+ import { basename } from 'path';
6
+ import { red, green } from 'chalk';
7
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
8
+ const ora = require('ora');
2
9
 
3
- export class Generate extends InnerGenerate {
10
+ export class Generate extends Command {
11
+ static description = `Generate project files`;
12
+ static strict = true;
4
13
  static hidden = false;
14
+
15
+ static flags = {
16
+ help: flags.help({ char: 'h' }),
17
+ watch: flags.boolean({
18
+ char: 'w',
19
+ description: 'Watch for changes to your contracts',
20
+ }),
21
+ };
22
+
23
+ static args = [];
24
+
25
+ async run() {
26
+ const { flags } = this.parse(Generate);
27
+ const cwd = process.cwd();
28
+
29
+ if (flags.watch) {
30
+ const spinner = ora('Generating files').start();
31
+ const { contractsDir } = await getConfigFile(cwd);
32
+ const watcher = watch([contractsDir], {
33
+ cwd,
34
+ });
35
+ try {
36
+ await generateProject(cwd);
37
+ spinner.succeed(`Finished generating files. Watching for changes.`);
38
+ } catch (error) {
39
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
40
+ spinner.fail(`Error generating files.\n${(error as any).message}`);
41
+ }
42
+ watcher.on('change', async (path) => {
43
+ const file = basename(path);
44
+ spinner.clear();
45
+ spinner.start(`Change detected for ${green(file)}, generating.`);
46
+ try {
47
+ await generateProject(cwd);
48
+ spinner.succeed(
49
+ `Finished generating files for ${green(
50
+ file
51
+ )}. Watching for changes.`
52
+ );
53
+ } catch (error) {
54
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
55
+ const msg = (error as any).message;
56
+ spinner.fail(`Error after saving ${red(file)}.\n${msg}`);
57
+ }
58
+ });
59
+ process.on('SIGINT', async () => {
60
+ await watcher.close();
61
+ process.exit();
62
+ });
63
+ } else {
64
+ await generateProject(cwd);
65
+ }
66
+ }
5
67
  }
@@ -8,7 +8,7 @@ import {
8
8
  getContractNameFromPath,
9
9
  } from '@clarigen/core';
10
10
  import { makeTypes } from './declaration';
11
- import { ConfigContract, ConfigFile } from 'src/config';
11
+ import { ConfigContract, ConfigFile } from '../config';
12
12
  import { dirname, resolve, join } from 'path';
13
13
 
14
14
  export const generateInterface = async ({
@@ -31,7 +31,10 @@ export const generateInterface = async ({
31
31
  '--costs',
32
32
  '--assets',
33
33
  ]);
34
- if (receipt.stderr) {
34
+ if (
35
+ receipt.stderr &&
36
+ !receipt.stderr.includes('Used unimplemented cost function')
37
+ ) {
35
38
  throw new Error(`Error on ${contractFile}:
36
39
  ${receipt.stderr}
37
40
  `);
@@ -133,8 +136,19 @@ export const generateProjectIndexFile = (config: ConfigFile) => {
133
136
 
134
137
  let accounts = '';
135
138
  if ('accounts' in config) {
139
+ const accountLines = Object.keys(config.accounts).map((key) => {
140
+ const account = config.accounts[key];
141
+ return `"${key}": {
142
+ mnemonic: "${account.mnemonic}",
143
+ balance: ${account.balance.toString()}n,
144
+ address: "${account.address}",
145
+ },`;
146
+ });
147
+
136
148
  accounts = `\n\n// prettier-ignore
137
- export const accounts = ${JSON.stringify(config.accounts, null, 2)};`;
149
+ export const accounts = {
150
+ ${accountLines.join('\n ')}
151
+ };`;
138
152
  }
139
153
 
140
154
  config.contracts.forEach((contract) => {
package/src/index.ts CHANGED
@@ -2,3 +2,4 @@ export { run } from '@oclif/command';
2
2
  export * from './config';
3
3
  export * from './generate/declaration';
4
4
  export * from './generate/files';
5
+ export * from './commands';
@@ -1,34 +0,0 @@
1
- import { ConfigContract } from './config';
2
- interface ClarinetConfigAccount {
3
- mnemonic: string;
4
- balance: bigint;
5
- }
6
- interface ClarinetDevConfig {
7
- network: {
8
- name: string;
9
- };
10
- accounts: {
11
- deployer: ClarinetConfigAccount;
12
- [key: string]: ClarinetConfigAccount;
13
- };
14
- }
15
- export declare function getClarinetDevConfig(folder: string): Promise<ClarinetDevConfig>;
16
- interface ClarinetConfig {
17
- contracts: {
18
- [name: string]: {
19
- path: string;
20
- dependsOn: string[];
21
- };
22
- };
23
- }
24
- export declare function getClarinetConfig(folder: string): Promise<ClarinetConfig>;
25
- export declare function getContractsFromClarinet(folder: string, accounts: ClarinetAccounts): Promise<ConfigContract[]>;
26
- export interface ClarinetAccount extends ClarinetConfigAccount {
27
- address: string;
28
- }
29
- export interface ClarinetAccounts {
30
- deployer: ClarinetAccount;
31
- [name: string]: ClarinetAccount;
32
- }
33
- export declare function getClarinetAccounts(folder: string): Promise<ClarinetAccounts>;
34
- export {};