@clarigen/cli 0.3.6 → 1.0.0-next.10

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.
@@ -1,6 +1,6 @@
1
1
  import { Command, flags } from '@oclif/command';
2
2
  import { generateProject } from '../utils';
3
- import { getConfigFile } from '../config';
3
+ import { getProjectConfig } from '../config';
4
4
  import { watch } from 'chokidar';
5
5
  import { basename } from 'path';
6
6
  import { red, green } from 'chalk';
@@ -28,7 +28,7 @@ export class Generate extends Command {
28
28
 
29
29
  if (flags.watch) {
30
30
  const spinner = ora('Generating files').start();
31
- const { contractsDir } = await getConfigFile(cwd);
31
+ const { contractsDir } = await getProjectConfig(cwd);
32
32
  const watcher = watch([contractsDir], {
33
33
  cwd,
34
34
  });
package/src/config.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { resolve, join, relative } from 'path';
2
- import { readFile } from 'fs/promises';
2
+ import { readFile, access } from 'fs/promises';
3
+ import { constants } from 'fs';
3
4
  import {
4
5
  ClarinetAccounts,
5
6
  getClarinetAccounts,
@@ -9,52 +10,69 @@ import {
9
10
  export interface ConfigContract {
10
11
  address: string;
11
12
  file: string;
13
+ name: string;
12
14
  }
13
15
 
14
- export interface ConfigFileBase {
16
+ export interface ConfigFileContents {
15
17
  outputDir: string;
16
- }
17
-
18
- export interface ConfigFileWithClarinet extends ConfigFileBase {
19
18
  clarinet: string;
20
19
  }
21
20
 
22
- export interface ConfigFileRegular extends ConfigFileBase {
21
+ export interface ConfigFile extends ConfigFileContents {
23
22
  contractsDir: string;
24
23
  contracts: ConfigContract[];
24
+ accounts: ClarinetAccounts;
25
+ clarinet: string;
25
26
  }
26
27
 
27
- export type ConfigFileContents = ConfigFileRegular | ConfigFileWithClarinet;
28
+ export const defaultConfigFile: ConfigFileContents = {
29
+ outputDir: 'src/clarigen',
30
+ clarinet: '.',
31
+ };
28
32
 
29
- export interface ConfigFileWithClarinetInfo extends ConfigFileRegular {
30
- clarinet: string;
31
- accounts: ClarinetAccounts;
33
+ export function configFilePath(rootPath: string) {
34
+ return resolve(rootPath, 'clarigen.config.json');
32
35
  }
33
36
 
34
- export type ConfigFile = ConfigFileRegular | ConfigFileWithClarinetInfo;
35
-
36
- export async function getConfigFile(rootPath: string): Promise<ConfigFile> {
37
- const fullPath = resolve(rootPath, 'clarigen.config.json');
38
- const configContents = await readFile(fullPath, { encoding: 'utf-8' });
39
- const configFile: ConfigFileContents = JSON.parse(configContents);
40
- if (!configFile.outputDir) throw new Error('Config file missing "outputDir"');
41
- if ('clarinet' in configFile) {
42
- const clarinetPath = resolve(rootPath, configFile.clarinet);
43
- const accounts = await getClarinetAccounts(clarinetPath);
44
- const contracts = await getContractsFromClarinet(clarinetPath, accounts);
45
- const contractsDir = relative(
46
- process.cwd(),
47
- join(configFile.clarinet, 'contracts')
48
- );
37
+ export async function configFileExists(configPath: string): Promise<boolean> {
38
+ try {
39
+ await access(configPath, constants.R_OK);
40
+ return true;
41
+ } catch (error) {
42
+ return false;
43
+ }
44
+ }
45
+
46
+ export async function getConfigFile(
47
+ rootPath: string
48
+ ): Promise<ConfigFileContents> {
49
+ const fullPath = configFilePath(rootPath);
50
+ const exists = await configFileExists(fullPath);
51
+ if (exists) {
52
+ const configContents = await readFile(fullPath, { encoding: 'utf-8' });
53
+ const configFile: ConfigFileContents = JSON.parse(configContents);
49
54
  return {
55
+ ...defaultConfigFile,
50
56
  ...configFile,
51
- contracts,
52
- contractsDir,
53
- accounts,
54
57
  };
55
58
  }
56
- if (!configFile.contracts) throw new Error('Config file missing "contracts"');
57
- if (!configFile.contractsDir)
58
- throw new Error('Config file missing "contractDir"');
59
- return configFile;
59
+ return defaultConfigFile;
60
+ }
61
+
62
+ export async function getProjectConfig(rootPath: string): Promise<ConfigFile> {
63
+ const configFile = await getConfigFile(rootPath);
64
+ const clarinetPath = resolve(rootPath, configFile.clarinet || '.');
65
+ const accounts = await getClarinetAccounts(clarinetPath);
66
+ const contracts = await getContractsFromClarinet(clarinetPath, accounts);
67
+ const contractsDir = relative(
68
+ process.cwd(),
69
+ join(configFile.clarinet, 'contracts')
70
+ );
71
+ return {
72
+ ...configFile,
73
+ contracts,
74
+ contractsDir,
75
+ accounts,
76
+ clarinet: configFile.clarinet || '.',
77
+ };
60
78
  }
@@ -1,5 +1,4 @@
1
1
  import {
2
- ClarityAbiType,
3
2
  isClarityAbiBuffer,
4
3
  isClarityAbiList,
5
4
  isClarityAbiOptional,
@@ -8,44 +7,10 @@ import {
8
7
  isClarityAbiStringAscii,
9
8
  isClarityAbiStringUtf8,
10
9
  isClarityAbiTuple,
11
- } from '@stacks/transactions';
10
+ } from 'micro-stacks/transactions';
11
+ import { ClarityAbiFunction, ClarityAbiType } from 'micro-stacks/clarity';
12
12
  import { toCamelCase, ClarityAbi } from '@clarigen/core';
13
-
14
- export const cvFromType = (val: ClarityAbiType) => {
15
- if (isClarityAbiPrimitive(val)) {
16
- if (val === 'uint128') {
17
- return 'ClarityTypes.UIntCV';
18
- } else if (val === 'int128') {
19
- return 'ClarityTypes.IntCV';
20
- } else if (val === 'bool') {
21
- return 'ClarityTypes.BooleanCV';
22
- } else if (val === 'principal') {
23
- return 'ClarityTypes.PrincipalCV';
24
- } else if (val === 'none') {
25
- return 'ClarityTypes.NoneCV';
26
- } else {
27
- throw new Error(
28
- `Unexpected Clarity ABI type primitive: ${JSON.stringify(val)}`
29
- );
30
- }
31
- } else if (isClarityAbiBuffer(val)) {
32
- return 'ClarityTypes.BufferCV';
33
- } else if (isClarityAbiResponse(val)) {
34
- return 'ClarityTypes.ResponseCV';
35
- } else if (isClarityAbiOptional(val)) {
36
- return 'ClarityTypes.OptionalCV';
37
- } else if (isClarityAbiTuple(val)) {
38
- return 'ClarityTypes.TupleCV';
39
- } else if (isClarityAbiList(val)) {
40
- return 'ClarityTypes.ListCV';
41
- } else if (isClarityAbiStringAscii(val)) {
42
- return 'ClarityTypes.StringAsciiCV';
43
- } else if (isClarityAbiStringUtf8(val)) {
44
- return 'ClarityTypes.StringUtf8CV';
45
- } else {
46
- throw new Error(`Unexpected Clarity ABI type: ${JSON.stringify(val)}`);
47
- }
48
- };
13
+ import { check } from 'reserved-words';
49
14
 
50
15
  export const jsTypeFromAbiType = (
51
16
  val: ClarityAbiType,
@@ -72,7 +37,7 @@ export const jsTypeFromAbiType = (
72
37
  );
73
38
  }
74
39
  } else if (isClarityAbiBuffer(val)) {
75
- return 'Buffer';
40
+ return 'Uint8Array';
76
41
  } else if (isClarityAbiResponse(val)) {
77
42
  const ok: any = jsTypeFromAbiType(val.response.ok);
78
43
  const err: any = jsTypeFromAbiType(val.response.error);
@@ -103,38 +68,49 @@ export const jsTypeFromAbiType = (
103
68
  }
104
69
  };
105
70
 
106
- export const makeTypes = (abi: ClarityAbi) => {
71
+ // Check if it's a reserved word, and then camelCase
72
+ function getArgName(name: string) {
73
+ const camel = toCamelCase(name);
74
+ const prefix = check(camel, 6) ? '_' : '';
75
+ return `${prefix}${camel}`;
76
+ }
77
+
78
+ const accessToReturnType = {
79
+ public: 'Public',
80
+ read_only: 'ReadOnly',
81
+ private: 'Private',
82
+ } as const;
83
+
84
+ export function makePureTypes(abi: ClarityAbi) {
107
85
  let typings = '';
108
86
  abi.functions.forEach((func, index) => {
109
- if (func.access === 'private') return;
110
87
  let functionLine = `${toCamelCase(func.name)}: `;
111
88
  const args = func.args.map((arg) => {
112
- return `${toCamelCase(arg.name)}: ${jsTypeFromAbiType(arg.type, true)}`;
89
+ return `${getArgName(arg.name)}: ${jsTypeFromAbiType(arg.type, true)}`;
113
90
  });
114
91
  functionLine += `(${args.join(', ')}) => `;
92
+ const funcType = accessToReturnType[func.access];
93
+ functionLine += `ContractCalls.${funcType}<`;
115
94
  if (func.access === 'public') {
116
95
  const { type } = func.outputs;
117
96
  if (!isClarityAbiResponse(type))
118
97
  throw new Error('Expected response type for public function');
119
- functionLine += 'Transaction';
120
98
  const ok = jsTypeFromAbiType(type.response.ok);
121
99
  const err = jsTypeFromAbiType(type.response.error);
122
- functionLine += `<${ok}, ${err}>;`;
100
+ functionLine += `${ok}, ${err}>;`;
123
101
  } else {
124
- const jsType = jsTypeFromAbiType(func.outputs.type);
125
- functionLine += `Promise<${jsType}>;`;
126
- // const { type } = func.outputs;
127
- // if (isClarityAbiResponse(type)) {
128
- // const ok = jsTypeFromAbiType(type.response.ok);
129
- // const err = jsTypeFromAbiType(type.response.error);
130
- // functionLine += `Promise<ClarityTypes.Response<${ok}, ${err}>>;`;
131
- // } else {
132
- // const jsType = jsTypeFromAbiType(func.outputs.type);
133
- // functionLine += `Promise<${jsType}>;`;
134
- // }
102
+ const returnType = jsTypeFromAbiType(func.outputs.type);
103
+ functionLine += `${returnType}>;`;
135
104
  }
136
105
  typings += `${index === 0 ? '' : '\n'} ${functionLine}`;
137
106
  });
138
-
107
+ abi.maps.forEach((map) => {
108
+ let functionLine = `${toCamelCase(map.name)}: `;
109
+ const keyType = jsTypeFromAbiType(map.key, true);
110
+ const arg = `key: ${keyType}`;
111
+ const valType = jsTypeFromAbiType(map.value);
112
+ functionLine += `(${arg}) => ContractCalls.Map<${keyType}, ${valType}>;`;
113
+ typings += `\n ${functionLine}`;
114
+ });
139
115
  return typings;
140
- };
116
+ }
@@ -1,28 +1,20 @@
1
- import {
2
- NativeClarityBinProvider,
3
- createClarityBin,
4
- hasStdErr,
5
- } from '@clarigen/native-bin';
6
- import {
7
- ClarityAbi,
8
- toCamelCase,
9
- getContractNameFromPath,
10
- } from '@clarigen/core';
11
- import { makeTypes } from './declaration';
1
+ import { NativeClarityBinProvider, hasStdErr } from '@clarigen/native-bin';
2
+ import { ClarityAbi, toCamelCase } from '@clarigen/core';
12
3
  import { ConfigContract, ConfigFile } from '../config';
13
4
  import { dirname, resolve, join } from 'path';
5
+ import { makePureTypes } from '..';
14
6
 
15
7
  export const generateInterface = async ({
16
- provider: _provider,
8
+ provider,
17
9
  contractFile,
18
- contractAddress = 'S1G2081040G2081040G2081040G208105NK8PE5',
10
+ contractAddress,
11
+ contractName,
19
12
  }: {
20
13
  contractFile: string;
21
- provider?: NativeClarityBinProvider;
22
- contractAddress?: string;
14
+ provider: NativeClarityBinProvider;
15
+ contractAddress: string;
16
+ contractName: string;
23
17
  }): Promise<ClarityAbi> => {
24
- const provider = _provider || (await createClarityBin());
25
- const contractName = getContractNameFromPath(contractFile);
26
18
  const receipt = await provider.runCommand([
27
19
  'launch',
28
20
  `${contractAddress}.${contractName}`,
@@ -62,15 +54,15 @@ export const generateInterface = async ({
62
54
  };
63
55
 
64
56
  export const generateInterfaceFile = ({
65
- contractFile,
57
+ contractName,
66
58
  abi,
67
59
  }: {
68
- contractFile: string;
60
+ contractName: string;
69
61
  abi: ClarityAbi;
70
62
  }) => {
71
- const contractName = getContractNameFromPath(contractFile);
72
63
  const variableName = toCamelCase(contractName, true);
73
- const abiString = JSON.stringify(abi, null, 2);
64
+ const { clarity_version, ...rest } = abi;
65
+ const abiString = JSON.stringify(rest, null, 2);
74
66
 
75
67
  const fileContents = `import { ClarityAbi } from '@clarigen/core';
76
68
 
@@ -83,30 +75,37 @@ export const ${variableName}Interface: ClarityAbi = ${abiString};
83
75
 
84
76
  export const generateIndexFile = ({
85
77
  contractFile,
86
- address,
78
+ contractAddress,
79
+ contractName,
87
80
  }: {
88
81
  contractFile: string;
89
- address: string;
82
+ contractAddress: string;
83
+ contractName: string;
90
84
  }) => {
91
- const contractName = getContractNameFromPath(contractFile);
92
85
  const contractTitle = toCamelCase(contractName, true);
93
86
  const varName = toCamelCase(contractName);
94
87
  const contractType = `${contractTitle}Contract`;
88
+ const interfaceVar = `${contractTitle}Interface`;
95
89
 
96
- const fileContents = `import { proxy, BaseProvider, Contract } from '@clarigen/core';
90
+ const fileContents = `import { pureProxy, Contract } from '@clarigen/core';
97
91
  import type { ${contractType} } from './types';
98
- import { ${contractTitle}Interface } from './abi';
92
+ import { ${interfaceVar} } from './abi';
99
93
  export type { ${contractType} } from './types';
100
94
 
101
- export const ${varName}Contract = (provider: BaseProvider) => {
102
- const contract = proxy<${contractType}>(${contractTitle}Interface, provider);
103
- return contract;
104
- };
95
+ export function ${varName}Contract(contractAddress: string, contractName: string) {
96
+ return pureProxy<${contractType}>({
97
+ abi: ${interfaceVar},
98
+ contractAddress,
99
+ contractName,
100
+ });
101
+ }
105
102
 
106
103
  export const ${varName}Info: Contract<${contractType}> = {
107
104
  contract: ${varName}Contract,
108
- address: '${address}',
105
+ address: '${contractAddress}',
109
106
  contractFile: '${contractFile}',
107
+ name: '${contractName}',
108
+ abi: ${interfaceVar},
110
109
  };
111
110
  `;
112
111
 
@@ -115,8 +114,8 @@ export const ${varName}Info: Contract<${contractType}> = {
115
114
 
116
115
  export const generateTypesFile = (abi: ClarityAbi, contractName: string) => {
117
116
  const name = toCamelCase(contractName, true);
118
- const typings = makeTypes(abi);
119
- const fileContents = `import { ClarityTypes, Transaction } from '@clarigen/core';
117
+ const typings = makePureTypes(abi);
118
+ const fileContents = `import { ClarityTypes, ContractCalls } from '@clarigen/core';
120
119
 
121
120
  // prettier-ignore
122
121
  export interface ${name}Contract {
@@ -128,7 +127,9 @@ ${typings}
128
127
  };
129
128
 
130
129
  export const generateProjectIndexFile = (config: ConfigFile) => {
131
- const imports: string[] = [];
130
+ const imports: string[] = [
131
+ "import type { ContractInstances } from '@clarigen/core';",
132
+ ];
132
133
  const exports: string[] = [];
133
134
  const contractMap: string[] = [];
134
135
 
@@ -150,7 +151,7 @@ export const accounts = {
150
151
  }
151
152
 
152
153
  config.contracts.forEach((contract) => {
153
- const contractName = getContractNameFromPath(contract.file);
154
+ const contractName = contract.name;
154
155
  const contractVar = toCamelCase(contractName);
155
156
  const contractInfo = `${contractVar}Info`;
156
157
  const contractInterface = `${toCamelCase(contractName, true)}Contract`;
@@ -167,9 +168,11 @@ export const accounts = {
167
168
  contractMap.push(map);
168
169
  });
169
170
 
171
+ const contractsType = `\nexport type Contracts = ContractInstances<typeof contracts>;\n`;
172
+
170
173
  const file = `${imports.join('\n')}
171
174
  ${exports.join('\n')}
172
-
175
+ ${contractsType}
173
176
  export const contracts = {
174
177
  ${contractMap.join('\n ')}
175
178
  };${accounts}
package/src/utils.ts CHANGED
@@ -5,14 +5,13 @@ import {
5
5
  generateProjectIndexFile,
6
6
  generateTypesFile,
7
7
  } from './generate/files';
8
- import { getContractNameFromPath } from '@clarigen/core';
9
8
  import {
10
9
  NativeClarityBinProvider,
11
10
  createClarityBin,
12
11
  } from '@clarigen/native-bin';
13
12
  import { resolve, relative, dirname } from 'path';
14
13
  import { mkdir, writeFile } from 'fs/promises';
15
- import { getConfigFile } from './config';
14
+ import { getProjectConfig } from './config';
16
15
 
17
16
  export const generateFilesForContract = async ({
18
17
  contractFile: _contractFile,
@@ -20,33 +19,32 @@ export const generateFilesForContract = async ({
20
19
  provider,
21
20
  contractAddress,
22
21
  dirName,
22
+ contractName,
23
23
  }: {
24
24
  contractFile: string;
25
- outputFolder?: string;
26
- provider?: NativeClarityBinProvider;
27
- contractAddress?: string;
25
+ outputFolder: string;
26
+ provider: NativeClarityBinProvider;
27
+ contractAddress: string;
28
28
  dirName?: string;
29
+ contractName: string;
29
30
  }) => {
30
31
  const contractFile = resolve(process.cwd(), _contractFile);
31
- const contractName = getContractNameFromPath(contractFile);
32
32
 
33
33
  const abi = await generateInterface({
34
34
  contractFile,
35
35
  provider,
36
36
  contractAddress,
37
+ contractName,
37
38
  });
38
39
  const typesFile = generateTypesFile(abi, contractName);
39
- if (!contractAddress && process.env.NODE_ENV !== 'test') {
40
- console.warn('Please provide an address with every contract.');
41
- }
42
40
  const indexFile = generateIndexFile({
43
41
  contractFile: relative(process.cwd(), contractFile),
44
- address: contractAddress || '',
42
+ contractAddress: contractAddress,
43
+ contractName,
45
44
  });
46
- const abiFile = generateInterfaceFile({ contractFile, abi });
45
+ const abiFile = generateInterfaceFile({ contractName, abi });
47
46
 
48
- const baseDir = outputFolder || resolve(process.cwd(), `tmp/${contractName}`);
49
- const outputPath = resolve(baseDir, dirName || '.', contractName);
47
+ const outputPath = resolve(outputFolder, dirName || '.', contractName);
50
48
  await mkdir(outputPath, { recursive: true });
51
49
 
52
50
  await writeFile(resolve(outputPath, 'abi.ts'), abiFile);
@@ -55,7 +53,7 @@ export const generateFilesForContract = async ({
55
53
  };
56
54
 
57
55
  export const generateProject = async (projectPath: string) => {
58
- const configFile = await getConfigFile(projectPath);
56
+ const configFile = await getProjectConfig(projectPath);
59
57
  const { contractsDir, outputDir, contracts } = configFile;
60
58
  const outputFolder = resolve(projectPath, outputDir);
61
59
  const provider = await createClarityBin();
@@ -69,6 +67,7 @@ export const generateProject = async (projectPath: string) => {
69
67
  provider,
70
68
  contractAddress: contract.address,
71
69
  dirName,
70
+ contractName: contract.name,
72
71
  });
73
72
  }
74
73
 
@@ -1,71 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getClarinetAccounts = exports.sortClarinetContracts = exports.getContractsFromClarinet = exports.getClarinetConfig = exports.getClarinetDevConfig = void 0;
4
- const j_toml_1 = require("@ltd/j-toml");
5
- const path_1 = require("path");
6
- const promises_1 = require("fs/promises");
7
- const wallet_sdk_1 = require("@stacks/wallet-sdk");
8
- const toposort_1 = require("toposort");
9
- async function getClarinetDevConfig(folder) {
10
- const baseConfigPath = path_1.resolve(folder, 'settings', 'Devnet.toml');
11
- const configContents = await promises_1.readFile(baseConfigPath, { encoding: 'utf-8' });
12
- const config = j_toml_1.parse(configContents, 1.0, '\n', true, {
13
- longer: true,
14
- });
15
- return config;
16
- }
17
- exports.getClarinetDevConfig = getClarinetDevConfig;
18
- async function getClarinetConfig(folder) {
19
- const baseConfigPath = path_1.resolve(folder, 'Clarinet.toml');
20
- const configContents = await promises_1.readFile(baseConfigPath, { encoding: 'utf-8' });
21
- const config = j_toml_1.parse(configContents, 1.0, '\n', true);
22
- return config;
23
- }
24
- exports.getClarinetConfig = getClarinetConfig;
25
- async function getContractsFromClarinet(folder, accounts) {
26
- const clarinetConfig = await getClarinetConfig(folder);
27
- const deployerAddress = accounts.deployer.address;
28
- const sortedContracts = sortClarinetContracts(clarinetConfig.contracts);
29
- const contracts = sortedContracts.map(contractName => {
30
- const info = clarinetConfig.contracts[contractName];
31
- const file = info.path.replace(/^contracts\//, '');
32
- return {
33
- file,
34
- address: deployerAddress,
35
- };
36
- });
37
- return contracts;
38
- }
39
- exports.getContractsFromClarinet = getContractsFromClarinet;
40
- function sortClarinetContracts(contractsConfig) {
41
- const edges = [];
42
- const nodes = [];
43
- Object.entries(contractsConfig).forEach(([contractName, info]) => {
44
- nodes.push(contractName);
45
- info.depends_on.forEach((dependency) => edges.push([contractName, dependency]));
46
- });
47
- const sorted = toposort_1.array(nodes, edges).reverse();
48
- return sorted;
49
- }
50
- exports.sortClarinetContracts = sortClarinetContracts;
51
- async function getClarinetAccounts(folder) {
52
- const devConfig = await getClarinetDevConfig(folder);
53
- const accountEntries = await Promise.all(Object.entries(devConfig.accounts).map(async ([key, info]) => {
54
- const wallet = await wallet_sdk_1.generateWallet({
55
- secretKey: info.mnemonic,
56
- password: 'password',
57
- });
58
- const [account] = wallet.accounts;
59
- const address = wallet_sdk_1.getStxAddress({ account });
60
- return [
61
- key,
62
- {
63
- ...info,
64
- address,
65
- },
66
- ];
67
- }));
68
- const accounts = Object.fromEntries(accountEntries);
69
- return accounts;
70
- }
71
- exports.getClarinetAccounts = getClarinetAccounts;
@@ -1,33 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Contract = void 0;
4
- const command_1 = require("@oclif/command");
5
- const utils_1 = require("../utils");
6
- class Contract extends command_1.Command {
7
- async run() {
8
- const { argv, flags } = this.parse(Contract);
9
- const [contractFile] = argv;
10
- await utils_1.generateFilesForContract({
11
- contractFile,
12
- outputFolder: flags.output,
13
- });
14
- }
15
- }
16
- exports.Contract = Contract;
17
- Contract.description = `Generate files for a single contract`;
18
- Contract.strict = true;
19
- Contract.hidden = true;
20
- Contract.flags = {
21
- help: command_1.flags.help({ char: 'h' }),
22
- output: command_1.flags.string({
23
- char: 'o',
24
- description: 'Output destination folder',
25
- default: 'clarion',
26
- }),
27
- };
28
- Contract.args = [
29
- {
30
- name: 'contract',
31
- description: 'The file path for your contract',
32
- },
33
- ];
package/dist/config.js DELETED
@@ -1,31 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getConfigFile = void 0;
4
- const path_1 = require("path");
5
- const promises_1 = require("fs/promises");
6
- const clarinet_config_1 = require("./clarinet-config");
7
- async function getConfigFile(rootPath) {
8
- const fullPath = path_1.resolve(rootPath, 'clarigen.config.json');
9
- const configContents = await promises_1.readFile(fullPath, { encoding: 'utf-8' });
10
- const configFile = JSON.parse(configContents);
11
- if (!configFile.outputDir)
12
- throw new Error('Config file missing "outputDir"');
13
- if ('clarinet' in configFile) {
14
- const clarinetPath = path_1.resolve(rootPath, configFile.clarinet);
15
- const accounts = await clarinet_config_1.getClarinetAccounts(clarinetPath);
16
- const contracts = await clarinet_config_1.getContractsFromClarinet(clarinetPath, accounts);
17
- const contractsDir = path_1.relative(process.cwd(), path_1.join(configFile.clarinet, 'contracts'));
18
- return {
19
- ...configFile,
20
- contracts,
21
- contractsDir,
22
- accounts,
23
- };
24
- }
25
- if (!configFile.contracts)
26
- throw new Error('Config file missing "contracts"');
27
- if (!configFile.contractsDir)
28
- throw new Error('Config file missing "contractDir"');
29
- return configFile;
30
- }
31
- exports.getConfigFile = getConfigFile;