@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.
- package/README.md +0 -13
- package/bin/run +2 -1
- package/dist/clarinet-config.js +57 -0
- package/dist/commands/contract.js +33 -0
- package/dist/commands/index.js +65 -0
- package/dist/config.js +31 -0
- package/dist/generate/declaration.js +157 -0
- package/dist/generate/files.js +142 -0
- package/dist/index.js +19 -8
- package/dist/start.js +9 -0
- package/dist/utils.js +56 -0
- package/package.json +11 -9
- package/src/clarinet-config.ts +4 -7
- package/src/commands/index.ts +64 -2
- package/src/generate/files.ts +17 -3
- package/src/index.ts +1 -0
- package/dist/clarinet-config.d.ts +0 -34
- package/dist/cli.cjs.development.js +0 -1322
- package/dist/cli.cjs.development.js.map +0 -1
- package/dist/cli.cjs.production.min.js +0 -2
- package/dist/cli.cjs.production.min.js.map +0 -1
- package/dist/cli.esm.js +0 -1304
- package/dist/cli.esm.js.map +0 -1
- package/dist/commands/contract.d.ts +0 -15
- package/dist/commands/generate.d.ts +0 -12
- package/dist/commands/index.d.ts +0 -4
- package/dist/config.d.ts +0 -22
- package/dist/generate/declaration.d.ts +0 -5
- package/dist/generate/files.d.ts +0 -18
- package/dist/index.d.ts +0 -4
- package/dist/start.d.ts +0 -1
- package/dist/utils.d.ts +0 -9
- package/src/commands/generate.ts +0 -64
package/src/clarinet-config.ts
CHANGED
|
@@ -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
|
-
|
|
29
|
-
|
|
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
|
-
|
|
49
|
+
true
|
|
53
50
|
) as unknown) as ClarinetConfig;
|
|
54
51
|
return config;
|
|
55
52
|
}
|
package/src/commands/index.ts
CHANGED
|
@@ -1,5 +1,67 @@
|
|
|
1
|
-
import {
|
|
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
|
|
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
|
}
|
package/src/generate/files.ts
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
getContractNameFromPath,
|
|
9
9
|
} from '@clarigen/core';
|
|
10
10
|
import { makeTypes } from './declaration';
|
|
11
|
-
import { ConfigContract, ConfigFile } from '
|
|
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 (
|
|
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 =
|
|
149
|
+
export const accounts = {
|
|
150
|
+
${accountLines.join('\n ')}
|
|
151
|
+
};`;
|
|
138
152
|
}
|
|
139
153
|
|
|
140
154
|
config.contracts.forEach((contract) => {
|
package/src/index.ts
CHANGED
|
@@ -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 {};
|