ic-mops 0.19.0 → 0.20.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/.gitignore +3 -0
- package/{cache.js → cache.ts} +8 -8
- package/{cli.js → cli.ts} +5 -5
- package/commands/{add.js → add.ts} +16 -8
- package/commands/{bump.js → bump.ts} +5 -5
- package/commands/{docs.js → docs.ts} +10 -10
- package/commands/{import-identity.js → import-identity.ts} +7 -7
- package/commands/{init.js → init.ts} +20 -17
- package/commands/{install-all.js → install-all.ts} +1 -1
- package/commands/{install.js → install.ts} +11 -11
- package/commands/{mmf1.js → mmf1.ts} +20 -18
- package/commands/{publish.js → publish.ts} +28 -15
- package/commands/{remove.js → remove.ts} +23 -16
- package/commands/{search.js → search.ts} +2 -2
- package/commands/self-update.ts +6 -0
- package/commands/{sources.js → sources.ts} +30 -24
- package/commands/{template.js → template.ts} +2 -2
- package/commands/{test.js → test.ts} +24 -19
- package/commands/{user.js → user.ts} +7 -2
- package/declarations/main/index.js +0 -2
- package/declarations/main/main.did +4 -1
- package/declarations/main/main.did.d.ts +4 -4
- package/declarations/main/main.did.js +20 -20
- package/declarations/storage/index.d.ts +50 -0
- package/declarations/storage/index.js +3 -11
- package/dist/cache.d.ts +5 -0
- package/dist/cache.js +46 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +265 -0
- package/dist/commands/add.d.ts +4 -0
- package/dist/commands/add.js +82 -0
- package/dist/commands/bump.d.ts +1 -0
- package/dist/commands/bump.js +50 -0
- package/dist/commands/docs.d.ts +3 -0
- package/dist/commands/docs.js +78 -0
- package/dist/commands/import-identity.d.ts +1 -0
- package/dist/commands/import-identity.js +47 -0
- package/dist/commands/init.d.ts +1 -0
- package/dist/commands/init.js +82 -0
- package/dist/commands/install-all.d.ts +4 -0
- package/dist/commands/install-all.js +29 -0
- package/dist/commands/install.d.ts +5 -0
- package/dist/commands/install.js +110 -0
- package/dist/commands/mmf1.d.ts +21 -0
- package/dist/commands/mmf1.js +93 -0
- package/dist/commands/publish.d.ts +3 -0
- package/dist/commands/publish.js +254 -0
- package/dist/commands/remove.d.ts +5 -0
- package/dist/commands/remove.js +83 -0
- package/dist/commands/search.d.ts +1 -0
- package/dist/commands/search.js +36 -0
- package/dist/commands/self-update.d.ts +3 -0
- package/dist/commands/self-update.js +5 -0
- package/dist/commands/sources.d.ts +3 -0
- package/dist/commands/sources.js +124 -0
- package/dist/commands/template.d.ts +1 -0
- package/dist/commands/template.js +28 -0
- package/dist/commands/test.d.ts +4 -0
- package/dist/commands/test.js +201 -0
- package/dist/commands/user.d.ts +2 -0
- package/dist/commands/user.js +23 -0
- package/dist/commands/whoami.d.ts +1 -0
- package/dist/commands/whoami.js +11 -0
- package/dist/declarations/main/index.d.ts +50 -0
- package/dist/declarations/main/index.js +41 -0
- package/dist/declarations/main/main.did +222 -0
- package/dist/declarations/main/main.did.d.ts +198 -0
- package/dist/declarations/main/main.did.js +218 -0
- package/dist/declarations/storage/index.d.ts +50 -0
- package/dist/declarations/storage/index.js +30 -0
- package/dist/declarations/storage/storage.did +46 -0
- package/dist/declarations/storage/storage.did.d.ts +37 -0
- package/dist/declarations/storage/storage.did.js +38 -0
- package/dist/mops.d.ts +33 -0
- package/dist/mops.js +259 -0
- package/dist/package.json +79 -0
- package/dist/parallel.d.ts +1 -0
- package/dist/parallel.js +24 -0
- package/dist/pem.d.ts +5 -0
- package/dist/pem.js +49 -0
- package/dist/templates/mops-test.yml +30 -0
- package/dist/types.d.ts +27 -0
- package/dist/types.js +1 -0
- package/dist/vessel.d.ts +19 -0
- package/dist/vessel.js +154 -0
- package/global.d.ts +2 -0
- package/{mops.js → mops.ts} +58 -47
- package/package.json +44 -19
- package/{parallel.js → parallel.ts} +2 -2
- package/{pem.js → pem.ts} +12 -11
- package/templates/mops-test.yml +1 -1
- package/tsconfig.json +16 -0
- package/types.ts +29 -0
- package/{vessel.js → vessel.ts} +37 -25
- package/commands/self-update.js +0 -6
- /package/commands/{whoami.js → whoami.ts} +0 -0
package/dist/cli.js
ADDED
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import { program } from 'commander';
|
|
4
|
+
import chalk from 'chalk';
|
|
5
|
+
import { Principal } from '@dfinity/principal';
|
|
6
|
+
import { init } from './commands/init.js';
|
|
7
|
+
import { publish } from './commands/publish.js';
|
|
8
|
+
import { importPem } from './commands/import-identity.js';
|
|
9
|
+
import { sources } from './commands/sources.js';
|
|
10
|
+
import { checkApiCompatibility, getNetwork, setNetwork, apiVersion, checkConfigFile, mainActor } from './mops.js';
|
|
11
|
+
import { whoami } from './commands/whoami.js';
|
|
12
|
+
import { installAll } from './commands/install-all.js';
|
|
13
|
+
import { search } from './commands/search.js';
|
|
14
|
+
import { add } from './commands/add.js';
|
|
15
|
+
import { cacheSize, cleanCache } from './cache.js';
|
|
16
|
+
import { test } from './commands/test.js';
|
|
17
|
+
import { template } from './commands/template.js';
|
|
18
|
+
import { selfUpdate } from './commands/self-update.js';
|
|
19
|
+
import { remove } from './commands/remove.js';
|
|
20
|
+
import { getUserProp, setUserProp } from './commands/user.js';
|
|
21
|
+
import { bump } from './commands/bump.js';
|
|
22
|
+
// import {docs} from './commands/docs.js';
|
|
23
|
+
program.name('mops');
|
|
24
|
+
// --version
|
|
25
|
+
let packageJson = JSON.parse(fs.readFileSync(new URL('package.json', import.meta.url)).toString());
|
|
26
|
+
program.version(`CLI ${packageJson.version}\nAPI ${apiVersion}`, '-v --version');
|
|
27
|
+
// init
|
|
28
|
+
program
|
|
29
|
+
.command('init [name]')
|
|
30
|
+
.description('Create mops.toml')
|
|
31
|
+
.action(async (name) => {
|
|
32
|
+
await init(name);
|
|
33
|
+
});
|
|
34
|
+
// add
|
|
35
|
+
program
|
|
36
|
+
.command('add <pkg>')
|
|
37
|
+
.description('Install the package and save it to mops.toml')
|
|
38
|
+
.option('--dev')
|
|
39
|
+
.option('--verbose')
|
|
40
|
+
.action(async (pkg, options) => {
|
|
41
|
+
if (!checkConfigFile()) {
|
|
42
|
+
process.exit(1);
|
|
43
|
+
}
|
|
44
|
+
await add(pkg, options);
|
|
45
|
+
});
|
|
46
|
+
// remove
|
|
47
|
+
program
|
|
48
|
+
.command('remove <pkg>')
|
|
49
|
+
.alias('rm')
|
|
50
|
+
.description('Remove package and update mops.toml')
|
|
51
|
+
.option('--dev', 'Remove from dev-dependencies instead of dependencies')
|
|
52
|
+
.option('--verbose', 'Show more information')
|
|
53
|
+
.option('--dry-run', 'Do not actually remove anything')
|
|
54
|
+
.action(async (pkg, options) => {
|
|
55
|
+
if (!checkConfigFile()) {
|
|
56
|
+
process.exit(1);
|
|
57
|
+
}
|
|
58
|
+
await remove(pkg, options);
|
|
59
|
+
});
|
|
60
|
+
// install
|
|
61
|
+
program
|
|
62
|
+
.command('install [pkg]')
|
|
63
|
+
.alias('i')
|
|
64
|
+
.description('Install all dependencies specified in mops.toml')
|
|
65
|
+
.option('--verbose')
|
|
66
|
+
.action(async (pkg, options) => {
|
|
67
|
+
if (!checkConfigFile()) {
|
|
68
|
+
process.exit(1);
|
|
69
|
+
}
|
|
70
|
+
let compatible = await checkApiCompatibility();
|
|
71
|
+
if (!compatible) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
if (pkg) {
|
|
75
|
+
// @deprecated
|
|
76
|
+
console.log(chalk.yellow('Consider using the \'mops add\' command to install a specific package.'));
|
|
77
|
+
await add(pkg, options);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
await installAll(options);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
// publish
|
|
84
|
+
program
|
|
85
|
+
.command('publish')
|
|
86
|
+
.description('Publish package to the mops registry')
|
|
87
|
+
.option('--no-docs', 'Do not generate docs')
|
|
88
|
+
.action(async (options) => {
|
|
89
|
+
if (!checkConfigFile()) {
|
|
90
|
+
process.exit(1);
|
|
91
|
+
}
|
|
92
|
+
let compatible = await checkApiCompatibility();
|
|
93
|
+
if (compatible) {
|
|
94
|
+
await publish(options);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
// set-network
|
|
98
|
+
program
|
|
99
|
+
.command('set-network <network>')
|
|
100
|
+
.alias('sn')
|
|
101
|
+
.description('Set network local|dev|ic')
|
|
102
|
+
.action(async (network) => {
|
|
103
|
+
await setNetwork(network);
|
|
104
|
+
console.log(`Selected '${network}' network`);
|
|
105
|
+
});
|
|
106
|
+
// get-network
|
|
107
|
+
program
|
|
108
|
+
.command('get-network')
|
|
109
|
+
.alias('gn')
|
|
110
|
+
.description('Get network')
|
|
111
|
+
.action(async () => {
|
|
112
|
+
console.log(getNetwork().network);
|
|
113
|
+
});
|
|
114
|
+
// import-identity
|
|
115
|
+
program
|
|
116
|
+
.command('import-identity <data>')
|
|
117
|
+
.description('Import .pem file data to use as identity')
|
|
118
|
+
.action(async (data) => {
|
|
119
|
+
await importPem(data);
|
|
120
|
+
await whoami();
|
|
121
|
+
});
|
|
122
|
+
// sources
|
|
123
|
+
program
|
|
124
|
+
.command('sources')
|
|
125
|
+
.description('for dfx packtool')
|
|
126
|
+
.option('--verbose')
|
|
127
|
+
.action(async (options) => {
|
|
128
|
+
if (!checkConfigFile()) {
|
|
129
|
+
process.exit(1);
|
|
130
|
+
}
|
|
131
|
+
await installAll({ silent: true });
|
|
132
|
+
let sourcesArr = await sources(options);
|
|
133
|
+
console.log(sourcesArr.join('\n'));
|
|
134
|
+
});
|
|
135
|
+
// whoami
|
|
136
|
+
program
|
|
137
|
+
.command('whoami')
|
|
138
|
+
.description('Print your principal')
|
|
139
|
+
.action(async () => {
|
|
140
|
+
await whoami();
|
|
141
|
+
});
|
|
142
|
+
// search
|
|
143
|
+
program
|
|
144
|
+
.command('search <text>')
|
|
145
|
+
.description('Search for packages')
|
|
146
|
+
.action(async (text) => {
|
|
147
|
+
await search(text);
|
|
148
|
+
});
|
|
149
|
+
// cache
|
|
150
|
+
program
|
|
151
|
+
.command('cache [sub-command]')
|
|
152
|
+
.description('Manage cache')
|
|
153
|
+
.action(async (sub) => {
|
|
154
|
+
if (sub == 'clean') {
|
|
155
|
+
await cleanCache();
|
|
156
|
+
console.log('Cache cleaned');
|
|
157
|
+
}
|
|
158
|
+
else if (sub == 'size') {
|
|
159
|
+
let size = await cacheSize();
|
|
160
|
+
console.log('Cache size is ' + size);
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
console.log('Unknown sub command. Available sub commands: clean, size');
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
// test
|
|
167
|
+
program
|
|
168
|
+
.command('test [filter]')
|
|
169
|
+
.description('Run tests')
|
|
170
|
+
.option('-w, --watch', 'Enable watch mode')
|
|
171
|
+
.action(async (filter, options) => {
|
|
172
|
+
await test(filter, options);
|
|
173
|
+
});
|
|
174
|
+
// template
|
|
175
|
+
program
|
|
176
|
+
.command('template')
|
|
177
|
+
.description('Apply template')
|
|
178
|
+
.action(async () => {
|
|
179
|
+
if (!checkConfigFile()) {
|
|
180
|
+
process.exit(1);
|
|
181
|
+
}
|
|
182
|
+
await template();
|
|
183
|
+
});
|
|
184
|
+
// docs
|
|
185
|
+
// program
|
|
186
|
+
// .command('docs')
|
|
187
|
+
// .description('Generate documentation (experimental)')
|
|
188
|
+
// .action(async () => {
|
|
189
|
+
// if (!checkConfigFile()) {
|
|
190
|
+
// process.exit(1);
|
|
191
|
+
// }
|
|
192
|
+
// await docs();
|
|
193
|
+
// });
|
|
194
|
+
// self update
|
|
195
|
+
program
|
|
196
|
+
.command('self-update')
|
|
197
|
+
.description('Update mops CLI to the latest version')
|
|
198
|
+
.option('--detached')
|
|
199
|
+
.option('--force')
|
|
200
|
+
.action(async (options) => {
|
|
201
|
+
if (options.force) {
|
|
202
|
+
selfUpdate(options);
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
console.log('Please run \'npm i -g ic-mops\'');
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
// user
|
|
209
|
+
program
|
|
210
|
+
.command('user set|get <prop> [value]')
|
|
211
|
+
.description('User settings')
|
|
212
|
+
.action(async (sub, prop, value) => {
|
|
213
|
+
if (sub == 'get') {
|
|
214
|
+
await getUserProp(prop);
|
|
215
|
+
}
|
|
216
|
+
else if (sub == 'set') {
|
|
217
|
+
if (!value) {
|
|
218
|
+
console.log('error: missing required argument "value"');
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
await setUserProp(prop, value);
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
console.log('Unknown sub command. Available sub commands: set, get');
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
// airdrop
|
|
228
|
+
program
|
|
229
|
+
.command('airdrop <check|claim> [canister]')
|
|
230
|
+
.action(async (sub, canister) => {
|
|
231
|
+
let main = await mainActor(true);
|
|
232
|
+
if (sub === 'check') {
|
|
233
|
+
let amount = await main.getAirdropAmount();
|
|
234
|
+
if (amount === 0n) {
|
|
235
|
+
console.log('No airdrop available');
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
console.log(`You can claim ${Number(amount) / 1000000000000} TCycles`);
|
|
239
|
+
}
|
|
240
|
+
else if (sub === 'claim') {
|
|
241
|
+
let principal;
|
|
242
|
+
try {
|
|
243
|
+
principal = Principal.fromText(canister);
|
|
244
|
+
}
|
|
245
|
+
catch (err) {
|
|
246
|
+
console.log('Invalid canister id');
|
|
247
|
+
console.log(err);
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
console.log('Sending cycles to the canister ' + canister);
|
|
251
|
+
let res = await main.claimAirdrop(principal);
|
|
252
|
+
console.log(res);
|
|
253
|
+
}
|
|
254
|
+
else {
|
|
255
|
+
console.log('Unknown sub command. Available sub commands: check, claim');
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
// bump
|
|
259
|
+
program
|
|
260
|
+
.command('bump [major|minor|patch]')
|
|
261
|
+
.description('Bump current package version')
|
|
262
|
+
.action(async (part) => {
|
|
263
|
+
bump(part);
|
|
264
|
+
});
|
|
265
|
+
program.parse();
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import logUpdate from 'log-update';
|
|
4
|
+
import { checkConfigFile, getHighestVersion, parseGithubURL, readConfig, writeConfig } from '../mops.js';
|
|
5
|
+
import { installFromGithub } from '../vessel.js';
|
|
6
|
+
import { install } from './install.js';
|
|
7
|
+
export async function add(name, { verbose = false, dev = false } = {}) {
|
|
8
|
+
if (!checkConfigFile()) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
let config = readConfig();
|
|
12
|
+
if (dev) {
|
|
13
|
+
if (!config['dev-dependencies']) {
|
|
14
|
+
config['dev-dependencies'] = {};
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
if (!config.dependencies) {
|
|
19
|
+
config.dependencies = {};
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
let pkgDetails;
|
|
23
|
+
// local package
|
|
24
|
+
if (name.startsWith('./') || name.startsWith('../') || name.startsWith('/')) {
|
|
25
|
+
pkgDetails = {
|
|
26
|
+
name: path.parse(name).name === '.' ? '_' : path.parse(name).name,
|
|
27
|
+
path: name,
|
|
28
|
+
repo: '',
|
|
29
|
+
version: '',
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
// github package
|
|
33
|
+
else if (name.startsWith('https://github.com') || name.split('/').length > 1) {
|
|
34
|
+
const { org, gitName, branch } = parseGithubURL(name);
|
|
35
|
+
pkgDetails = {
|
|
36
|
+
name: parseGithubURL(name).gitName,
|
|
37
|
+
repo: `https://github.com/${org}/${gitName}#${branch}`,
|
|
38
|
+
version: '',
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
// mops package
|
|
42
|
+
else {
|
|
43
|
+
let ver;
|
|
44
|
+
if (name.includes('@')) {
|
|
45
|
+
// @ts-ignore
|
|
46
|
+
[name, ver] = name.split('@');
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
let versionRes = await getHighestVersion(name);
|
|
50
|
+
if ('err' in versionRes) {
|
|
51
|
+
console.log(chalk.red('Error: ') + versionRes.err);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
ver = versionRes.ok;
|
|
55
|
+
}
|
|
56
|
+
pkgDetails = {
|
|
57
|
+
name: name,
|
|
58
|
+
repo: '',
|
|
59
|
+
version: ver,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
if (pkgDetails.repo) {
|
|
63
|
+
await installFromGithub(pkgDetails.name, pkgDetails.repo, { verbose: verbose });
|
|
64
|
+
}
|
|
65
|
+
else if (!pkgDetails.path) {
|
|
66
|
+
let ok = await install(pkgDetails.name, pkgDetails.version, { verbose: verbose });
|
|
67
|
+
if (!ok) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const depsProp = dev ? 'dev-dependencies' : 'dependencies';
|
|
72
|
+
let deps = config[depsProp];
|
|
73
|
+
if (deps) {
|
|
74
|
+
deps[pkgDetails.name] = pkgDetails;
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
throw Error(`Invalid config file: [${depsProp}] not found`);
|
|
78
|
+
}
|
|
79
|
+
writeConfig(config);
|
|
80
|
+
logUpdate.clear();
|
|
81
|
+
console.log(chalk.green('Package installed ') + `${pkgDetails.name} = "${pkgDetails.repo || pkgDetails.path || pkgDetails.version}"`);
|
|
82
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function bump(part: string): Promise<void>;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import prompts from 'prompts';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import { checkConfigFile, readConfig, writeConfig } from '../mops.js';
|
|
4
|
+
export async function bump(part) {
|
|
5
|
+
if (!checkConfigFile()) {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
if (part && !['major', 'minor', 'patch'].includes(part)) {
|
|
9
|
+
console.log(chalk.red('Unknown version part. Available parts: major, minor, patch'));
|
|
10
|
+
process.exit(1);
|
|
11
|
+
}
|
|
12
|
+
let config = readConfig();
|
|
13
|
+
if (!config.package) {
|
|
14
|
+
console.log(chalk.red('No [package] section found in mops.toml.'));
|
|
15
|
+
process.exit(1);
|
|
16
|
+
}
|
|
17
|
+
console.log(`Current version: ${chalk.yellow.bold(config.package.version)}`);
|
|
18
|
+
if (!part) {
|
|
19
|
+
let res = await prompts({
|
|
20
|
+
type: 'select',
|
|
21
|
+
name: 'part',
|
|
22
|
+
message: 'Select new version:',
|
|
23
|
+
choices: [
|
|
24
|
+
{ title: `${updateVersion(config.package.version, 'major')} ${chalk.dim('(major, breaking changes)')}`, value: 'major' },
|
|
25
|
+
{ title: `${updateVersion(config.package.version, 'minor')} ${chalk.dim('(minor, new features)')}`, value: 'minor' },
|
|
26
|
+
{ title: `${updateVersion(config.package.version, 'patch')} ${chalk.dim('(patch, bug fixes)')}`, value: 'patch' },
|
|
27
|
+
],
|
|
28
|
+
initial: 2,
|
|
29
|
+
});
|
|
30
|
+
if (!res.part) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
part = res.part;
|
|
34
|
+
}
|
|
35
|
+
config.package.version = updateVersion(config.package.version, part);
|
|
36
|
+
writeConfig(config);
|
|
37
|
+
console.log(`Updated version: ${chalk.green.bold(config.package.version)}`);
|
|
38
|
+
}
|
|
39
|
+
function updateVersion(version, part) {
|
|
40
|
+
let parts = version.split('.');
|
|
41
|
+
let idx = ['major', 'minor', 'patch'].indexOf(part);
|
|
42
|
+
if (!parts[idx]) {
|
|
43
|
+
throw new Error(`Invalid version part: ${part}`);
|
|
44
|
+
}
|
|
45
|
+
parts[idx] = String(parseInt(parts[idx] || '0') + 1);
|
|
46
|
+
for (let i = idx + 1; i < parts.length; i++) {
|
|
47
|
+
parts[i] = '0';
|
|
48
|
+
}
|
|
49
|
+
return parts.join('.');
|
|
50
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { spawn, execSync } from 'node:child_process';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import chalk from 'chalk';
|
|
5
|
+
import { globSync } from 'glob';
|
|
6
|
+
import { deleteSync } from 'del';
|
|
7
|
+
import tar from 'tar';
|
|
8
|
+
import streamToPromise from 'stream-to-promise';
|
|
9
|
+
import { getRootDir } from '../mops.js';
|
|
10
|
+
let moDoc;
|
|
11
|
+
export async function docs({ silent = false } = {}) {
|
|
12
|
+
let rootDir = getRootDir();
|
|
13
|
+
let docsDir = path.join(rootDir, '.mops/.docs');
|
|
14
|
+
let docsDirRelative = path.relative(process.cwd(), docsDir);
|
|
15
|
+
deleteSync([docsDir], { force: true });
|
|
16
|
+
// detect mocv
|
|
17
|
+
if (process.env.DFX_MOC_PATH && process.env.DFX_MOC_PATH.includes('mocv/versions')) {
|
|
18
|
+
moDoc = process.env.DFX_MOC_PATH.replace(/\/moc$/, '/mo-doc');
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
moDoc = execSync('dfx cache show').toString().trim() + '/mo-doc';
|
|
22
|
+
}
|
|
23
|
+
// generate docs
|
|
24
|
+
await new Promise((resolve) => {
|
|
25
|
+
let proc = spawn(moDoc, [`--source=${path.join(rootDir, 'src')}`, `--output=${docsDirRelative}`, '--format=adoc']);
|
|
26
|
+
// stdout
|
|
27
|
+
proc.stdout.on('data', (data) => {
|
|
28
|
+
let text = data.toString().trim();
|
|
29
|
+
let failedText = 'Failed to extract documentation';
|
|
30
|
+
if (text.includes(failedText)) {
|
|
31
|
+
console.log(text.replaceAll(failedText, chalk.yellow('Warning: ') + failedText));
|
|
32
|
+
}
|
|
33
|
+
silent || console.log('stdout', text);
|
|
34
|
+
});
|
|
35
|
+
// stderr
|
|
36
|
+
let stderr = '';
|
|
37
|
+
proc.stderr.on('data', (data) => {
|
|
38
|
+
let text = data.toString().trim();
|
|
39
|
+
if (text.includes('syntax error')) {
|
|
40
|
+
console.log(chalk.red('Error:'), text);
|
|
41
|
+
process.exit(1);
|
|
42
|
+
}
|
|
43
|
+
if (text.includes('No such file or directory') || text.includes('Couldn\'t find a module expression')) {
|
|
44
|
+
silent || console.log(text);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
stderr += text;
|
|
48
|
+
});
|
|
49
|
+
// exit
|
|
50
|
+
proc.on('exit', (code) => {
|
|
51
|
+
// if no source files found
|
|
52
|
+
if (code === 2 && !stderr) {
|
|
53
|
+
resolve();
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (code !== 0) {
|
|
57
|
+
console.log(chalk.red('Error:'), code, stderr);
|
|
58
|
+
process.exit(1);
|
|
59
|
+
}
|
|
60
|
+
resolve();
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
// create archive
|
|
64
|
+
let ignore = [
|
|
65
|
+
`${docsDir}/**/*.test.adoc`,
|
|
66
|
+
`${docsDir}/test/**/*`,
|
|
67
|
+
];
|
|
68
|
+
let files = globSync(`${docsDir}/**/*.adoc`, { ignore }).map(f => path.relative(docsDir, f));
|
|
69
|
+
if (files.length) {
|
|
70
|
+
let stream = tar.create({
|
|
71
|
+
cwd: docsDir,
|
|
72
|
+
gzip: true,
|
|
73
|
+
portable: true,
|
|
74
|
+
}, files).pipe(fs.createWriteStream(path.join(docsDir, 'docs.tgz')));
|
|
75
|
+
await streamToPromise(stream);
|
|
76
|
+
}
|
|
77
|
+
silent || console.log(`${chalk.green('Documentation generated')} at ${docsDirRelative}`);
|
|
78
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function importPem(data: string): Promise<void>;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import chalk from 'chalk';
|
|
4
|
+
import prompts from 'prompts';
|
|
5
|
+
import { deleteSync } from 'del';
|
|
6
|
+
import { globalConfigDir } from '../mops.js';
|
|
7
|
+
import { encrypt } from '../pem.js';
|
|
8
|
+
export async function importPem(data) {
|
|
9
|
+
try {
|
|
10
|
+
if (!fs.existsSync(globalConfigDir)) {
|
|
11
|
+
fs.mkdirSync(globalConfigDir);
|
|
12
|
+
}
|
|
13
|
+
let res = await prompts({
|
|
14
|
+
type: 'password',
|
|
15
|
+
name: 'password',
|
|
16
|
+
message: 'Enter password to encrypt identity.pem',
|
|
17
|
+
});
|
|
18
|
+
let password = res.password;
|
|
19
|
+
if (!password) {
|
|
20
|
+
let res = await prompts({
|
|
21
|
+
type: 'confirm',
|
|
22
|
+
name: 'ok',
|
|
23
|
+
message: 'Are you sure you don\'t want to protect your identity.pem with a password?',
|
|
24
|
+
});
|
|
25
|
+
if (!res.ok) {
|
|
26
|
+
console.log('aborted');
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
let identityPem = path.resolve(globalConfigDir, 'identity.pem');
|
|
31
|
+
let identityPemEncrypted = path.resolve(globalConfigDir, 'identity.pem.encrypted');
|
|
32
|
+
deleteSync([identityPem, identityPemEncrypted], { force: true });
|
|
33
|
+
// encrypted
|
|
34
|
+
if (password) {
|
|
35
|
+
let encrypted = await encrypt(Buffer.from(data), password);
|
|
36
|
+
fs.writeFileSync(identityPemEncrypted, encrypted);
|
|
37
|
+
}
|
|
38
|
+
// unencrypted
|
|
39
|
+
else {
|
|
40
|
+
fs.writeFileSync(identityPem, data);
|
|
41
|
+
}
|
|
42
|
+
console.log(chalk.green('Success'));
|
|
43
|
+
}
|
|
44
|
+
catch (err) {
|
|
45
|
+
console.log(chalk.red('Error: ') + err);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function init(name?: string): Promise<void>;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { execSync } from 'node:child_process';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import chalk from 'chalk';
|
|
5
|
+
import { checkApiCompatibility, mainActor, readDfxJson, writeConfig } from '../mops.js';
|
|
6
|
+
import { installAll } from './install-all.js';
|
|
7
|
+
import { readVesselConfig } from '../vessel.js';
|
|
8
|
+
export async function init(name = '') {
|
|
9
|
+
let configFile = path.join(process.cwd(), 'mops.toml');
|
|
10
|
+
let exists = fs.existsSync(configFile);
|
|
11
|
+
if (exists) {
|
|
12
|
+
console.log(chalk.yellow('mops.toml already exists'));
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
console.log('Initializing...');
|
|
16
|
+
let config = {};
|
|
17
|
+
let vesselConfig = { dependencies: [], 'dev-dependencies': [] };
|
|
18
|
+
let deps = {};
|
|
19
|
+
const vesselFile = path.join(process.cwd(), 'vessel.dhall');
|
|
20
|
+
if (fs.existsSync(vesselFile)) {
|
|
21
|
+
console.log('Reading vessel.dhall file');
|
|
22
|
+
const res = await readVesselConfig(process.cwd(), { cache: false });
|
|
23
|
+
if (res) {
|
|
24
|
+
vesselConfig = { ...res };
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (vesselConfig.dependencies) {
|
|
28
|
+
deps = {};
|
|
29
|
+
for (const dep of (vesselConfig.dependencies || [])) {
|
|
30
|
+
deps[dep.name] = dep;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
// lib mode
|
|
34
|
+
if (name) {
|
|
35
|
+
config.package = {
|
|
36
|
+
name,
|
|
37
|
+
version: '0.1.0',
|
|
38
|
+
description: '',
|
|
39
|
+
repository: '',
|
|
40
|
+
};
|
|
41
|
+
if (deps) {
|
|
42
|
+
config.dependencies = deps;
|
|
43
|
+
}
|
|
44
|
+
writeConfig(config, configFile);
|
|
45
|
+
if (Object.keys(config.dependencies || {}).length) {
|
|
46
|
+
await installAll({ verbose: true });
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
// project mode
|
|
50
|
+
if (!name) {
|
|
51
|
+
let compatible = await checkApiCompatibility();
|
|
52
|
+
if (!compatible) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
let dfxJson = readDfxJson();
|
|
56
|
+
let dfxVersion = dfxJson?.dfx || '';
|
|
57
|
+
if (!dfxVersion) {
|
|
58
|
+
try {
|
|
59
|
+
let res = execSync('dfx --version').toString();
|
|
60
|
+
let match = res.match(/\d+\.\d+\.\d+/);
|
|
61
|
+
if (match) {
|
|
62
|
+
dfxVersion = match[0];
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
catch { }
|
|
66
|
+
}
|
|
67
|
+
let actor = await mainActor();
|
|
68
|
+
let defaultPackages = await actor.getDefaultPackages(dfxVersion);
|
|
69
|
+
if (!config.dependencies) {
|
|
70
|
+
config.dependencies = {};
|
|
71
|
+
}
|
|
72
|
+
if (deps) {
|
|
73
|
+
config.dependencies = deps;
|
|
74
|
+
}
|
|
75
|
+
for (let [name, version] of defaultPackages) {
|
|
76
|
+
config.dependencies[name] = { name, version };
|
|
77
|
+
}
|
|
78
|
+
writeConfig(config, configFile);
|
|
79
|
+
await installAll({ verbose: true });
|
|
80
|
+
}
|
|
81
|
+
console.log(chalk.green('mops.toml has been created'));
|
|
82
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import logUpdate from 'log-update';
|
|
3
|
+
import { checkConfigFile, readConfig } from '../mops.js';
|
|
4
|
+
import { install } from './install.js';
|
|
5
|
+
import { installFromGithub } from '../vessel.js';
|
|
6
|
+
export async function installAll({ verbose = false, silent = false } = {}) {
|
|
7
|
+
if (!checkConfigFile()) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
let config = readConfig();
|
|
11
|
+
let deps = Object.values(config.dependencies || {});
|
|
12
|
+
let devDeps = Object.values(config['dev-dependencies'] || {});
|
|
13
|
+
let allDeps = [...deps, ...devDeps];
|
|
14
|
+
for (let { name, repo, path, version } of allDeps) {
|
|
15
|
+
if (repo) {
|
|
16
|
+
await installFromGithub(name, repo, { verbose, silent });
|
|
17
|
+
}
|
|
18
|
+
else if (!path) {
|
|
19
|
+
let ok = await install(name, version, { verbose, silent });
|
|
20
|
+
if (!ok) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (!silent) {
|
|
26
|
+
logUpdate.clear();
|
|
27
|
+
console.log(chalk.green('All packages installed'));
|
|
28
|
+
}
|
|
29
|
+
}
|