ic-mops 0.19.1 → 0.20.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/.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} +29 -16
- 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} +56 -45
- 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/vessel.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export type VesselConfig = {
|
|
2
|
+
dependencies: VesselDependencies;
|
|
3
|
+
'dev-dependencies': VesselDependencies;
|
|
4
|
+
};
|
|
5
|
+
export type VesselDependencies = Array<{
|
|
6
|
+
name: string;
|
|
7
|
+
version?: string;
|
|
8
|
+
repo?: string;
|
|
9
|
+
path?: string;
|
|
10
|
+
}>;
|
|
11
|
+
export declare const readVesselConfig: (dir: string, { cache }?: {
|
|
12
|
+
cache?: boolean | undefined;
|
|
13
|
+
}) => Promise<VesselConfig | null>;
|
|
14
|
+
export declare const downloadFromGithub: (repo: string, dest: string, onProgress: any) => Promise<unknown>;
|
|
15
|
+
export declare const installFromGithub: (name: string, repo: string, { verbose, dep, silent }?: {
|
|
16
|
+
verbose?: boolean | undefined;
|
|
17
|
+
dep?: boolean | undefined;
|
|
18
|
+
silent?: boolean | undefined;
|
|
19
|
+
}) => Promise<void>;
|
package/dist/vessel.js
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, createWriteStream, readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { deleteSync } from 'del';
|
|
4
|
+
import { execaCommand } from 'execa';
|
|
5
|
+
import chalk from 'chalk';
|
|
6
|
+
import logUpdate from 'log-update';
|
|
7
|
+
import got from 'got';
|
|
8
|
+
import decompress from 'decompress';
|
|
9
|
+
import { pipeline } from 'stream';
|
|
10
|
+
import { formatGithubDir, parseGithubURL, progressBar } from './mops.js';
|
|
11
|
+
import { addCache, copyCache, isCached } from './cache.js';
|
|
12
|
+
const dhallFileToJson = async (filePath) => {
|
|
13
|
+
if (existsSync(filePath)) {
|
|
14
|
+
let cwd = new URL(path.dirname(import.meta.url)).pathname;
|
|
15
|
+
let res;
|
|
16
|
+
try {
|
|
17
|
+
res = await execaCommand(`dhall-to-json --file ${filePath}`, { preferLocal: true, cwd });
|
|
18
|
+
}
|
|
19
|
+
catch (err) {
|
|
20
|
+
console.error('dhall-to-json error:', err);
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
if (res.exitCode === 0) {
|
|
24
|
+
return JSON.parse(res.stdout);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
return res;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return null;
|
|
31
|
+
};
|
|
32
|
+
export const readVesselConfig = async (dir, { cache = true } = {}) => {
|
|
33
|
+
const cachedFile = (dir || process.cwd()) + '/vessel.json';
|
|
34
|
+
if (existsSync(cachedFile)) {
|
|
35
|
+
let cachedConfig = readFileSync(cachedFile).toString();
|
|
36
|
+
return JSON.parse(cachedConfig);
|
|
37
|
+
}
|
|
38
|
+
const [vessel, packageSetArray] = await Promise.all([
|
|
39
|
+
dhallFileToJson((dir || process.cwd()) + '/vessel.dhall'),
|
|
40
|
+
dhallFileToJson((dir || process.cwd()) + '/package-set.dhall')
|
|
41
|
+
]);
|
|
42
|
+
if (!vessel || !packageSetArray) {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
let repos = {};
|
|
46
|
+
for (const { name, repo, version } of packageSetArray) {
|
|
47
|
+
const { org, gitName } = parseGithubURL(repo);
|
|
48
|
+
repos[name] = `https://github.com/${org}/${gitName}#${version}`;
|
|
49
|
+
}
|
|
50
|
+
let config = {
|
|
51
|
+
dependencies: vessel.dependencies.map((name) => {
|
|
52
|
+
return { name, repo: repos[name], version: '' };
|
|
53
|
+
}),
|
|
54
|
+
'dev-dependencies': [],
|
|
55
|
+
};
|
|
56
|
+
if (cache === true) {
|
|
57
|
+
writeFileSync(cachedFile, JSON.stringify(config), 'utf-8');
|
|
58
|
+
}
|
|
59
|
+
return config;
|
|
60
|
+
};
|
|
61
|
+
export const downloadFromGithub = async (repo, dest, onProgress) => {
|
|
62
|
+
const { branch, org, gitName } = parseGithubURL(repo);
|
|
63
|
+
const zipFile = `https://github.com/${org}/${gitName}/archive/${branch}.zip`;
|
|
64
|
+
const readStream = got.stream(zipFile);
|
|
65
|
+
const promise = new Promise((resolve, reject) => {
|
|
66
|
+
readStream.on('error', (err) => {
|
|
67
|
+
reject(err);
|
|
68
|
+
});
|
|
69
|
+
readStream.on('downloadProgress', ({ transferred, total }) => {
|
|
70
|
+
onProgress?.(transferred, total || 2 * (1024 ** 2));
|
|
71
|
+
});
|
|
72
|
+
readStream.on('response', (response) => {
|
|
73
|
+
if (response.headers.age > 3600) {
|
|
74
|
+
console.log(chalk.red('Error: ') + 'Failure - response too old');
|
|
75
|
+
readStream.destroy(); // Destroy the stream to prevent hanging resources.
|
|
76
|
+
reject();
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
// Prevent `onError` being called twice.
|
|
80
|
+
readStream.off('error', reject);
|
|
81
|
+
const tmpDir = path.resolve(process.cwd(), '.mops/_tmp/');
|
|
82
|
+
const tmpFile = path.resolve(tmpDir, `${gitName}@${branch}.zip`);
|
|
83
|
+
try {
|
|
84
|
+
mkdirSync(tmpDir, { recursive: true });
|
|
85
|
+
pipeline(readStream, createWriteStream(tmpFile), (err) => {
|
|
86
|
+
if (err) {
|
|
87
|
+
deleteSync([tmpDir]);
|
|
88
|
+
reject(err);
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
let options = {
|
|
92
|
+
extract: true,
|
|
93
|
+
strip: 1,
|
|
94
|
+
headers: {
|
|
95
|
+
accept: 'application/zip',
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
decompress(tmpFile, dest, options).then((unzippedFiles) => {
|
|
99
|
+
deleteSync([tmpDir]);
|
|
100
|
+
resolve(unzippedFiles);
|
|
101
|
+
}).catch(err => {
|
|
102
|
+
deleteSync([tmpDir]);
|
|
103
|
+
reject(err);
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
catch (err) {
|
|
109
|
+
deleteSync([tmpDir]);
|
|
110
|
+
reject(err);
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
return promise;
|
|
115
|
+
};
|
|
116
|
+
export const installFromGithub = async (name, repo, { verbose = false, dep = false, silent = false } = {}) => {
|
|
117
|
+
const { branch } = parseGithubURL(repo);
|
|
118
|
+
const dir = formatGithubDir(name, repo);
|
|
119
|
+
const cacheName = `github_${name}@${branch}`;
|
|
120
|
+
if (existsSync(dir)) {
|
|
121
|
+
silent || logUpdate(`${dep ? 'Dependency' : 'Installing'} ${name}@${branch} (already installed) from Github`);
|
|
122
|
+
}
|
|
123
|
+
else if (isCached(cacheName)) {
|
|
124
|
+
await copyCache(cacheName, dir);
|
|
125
|
+
silent || logUpdate(`${dep ? 'Dependency' : 'Installing'} ${name}@${branch} (cache) from Github`);
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
mkdirSync(dir, { recursive: true });
|
|
129
|
+
let progress = (step, total) => {
|
|
130
|
+
silent || logUpdate(`${dep ? 'Dependency' : 'Installing'} ${name}@${branch} ${progressBar(step, total)}`);
|
|
131
|
+
};
|
|
132
|
+
progress(0, 2 * (1024 ** 2));
|
|
133
|
+
try {
|
|
134
|
+
await downloadFromGithub(repo, dir, progress);
|
|
135
|
+
}
|
|
136
|
+
catch (err) {
|
|
137
|
+
deleteSync([dir]);
|
|
138
|
+
throw err;
|
|
139
|
+
}
|
|
140
|
+
// add to cache
|
|
141
|
+
await addCache(cacheName, dir);
|
|
142
|
+
}
|
|
143
|
+
if (verbose) {
|
|
144
|
+
silent || logUpdate.done();
|
|
145
|
+
}
|
|
146
|
+
const config = await readVesselConfig(dir);
|
|
147
|
+
if (config) {
|
|
148
|
+
for (const { name, repo } of config.dependencies) {
|
|
149
|
+
if (repo) {
|
|
150
|
+
await installFromGithub(name, repo, { verbose, silent, dep: true });
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
};
|
package/global.d.ts
ADDED
package/{mops.js → mops.ts}
RENAMED
|
@@ -1,39 +1,45 @@
|
|
|
1
|
-
import
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import {Actor, HttpAgent, Identity} from '@dfinity/agent';
|
|
2
4
|
import TOML from '@iarna/toml';
|
|
3
5
|
import chalk from 'chalk';
|
|
4
|
-
import fetch from 'node-fetch';
|
|
5
|
-
import path from 'path';
|
|
6
|
-
import fs from 'fs';
|
|
7
6
|
import prompts from 'prompts';
|
|
8
7
|
import ncp from 'ncp';
|
|
8
|
+
import fetch from 'node-fetch';
|
|
9
9
|
|
|
10
|
-
import {idlFactory} from './declarations/main/
|
|
11
|
-
import {
|
|
10
|
+
import {idlFactory} from './declarations/main/index.js';
|
|
11
|
+
import {_SERVICE} from './declarations/main/main.did.js';
|
|
12
|
+
import {idlFactory as storageIdlFactory} from './declarations/storage/index.js';
|
|
13
|
+
import {_SERVICE as _STORAGE_SERVICE} from './declarations/storage/storage.did.js';
|
|
12
14
|
import {decodeFile} from './pem.js';
|
|
15
|
+
import {Config} from './types.js';
|
|
16
|
+
import {Principal} from '@dfinity/principal';
|
|
13
17
|
|
|
14
18
|
|
|
15
|
-
global.fetch
|
|
19
|
+
if (!global.fetch) {
|
|
20
|
+
global.fetch = fetch as any;
|
|
21
|
+
}
|
|
16
22
|
|
|
17
23
|
// (!) make changes in pair with backend
|
|
18
24
|
export let apiVersion = '1.2';
|
|
19
25
|
|
|
20
26
|
let networkFile = new URL('./network.txt', import.meta.url);
|
|
21
27
|
|
|
22
|
-
export let globalConfigDir;
|
|
23
|
-
export let globalCacheDir;
|
|
28
|
+
export let globalConfigDir = '';
|
|
29
|
+
export let globalCacheDir = '';
|
|
24
30
|
|
|
25
31
|
// OS specific dirs
|
|
26
32
|
if (process.platform == 'win32') {
|
|
27
|
-
globalConfigDir = path.join(process.env.LOCALAPPDATA, 'mops/config');
|
|
28
|
-
globalCacheDir = path.join(process.env.LOCALAPPDATA, 'mops/cache');
|
|
33
|
+
globalConfigDir = path.join(process.env.LOCALAPPDATA || '', 'mops/config');
|
|
34
|
+
globalCacheDir = path.join(process.env.LOCALAPPDATA || '', 'mops/cache');
|
|
29
35
|
}
|
|
30
36
|
else if (process.platform == 'darwin') {
|
|
31
|
-
globalConfigDir = path.join(process.env.HOME, 'Library/Application Support/mops');
|
|
32
|
-
globalCacheDir = path.join(process.env.HOME, 'Library/Caches/mops');
|
|
37
|
+
globalConfigDir = path.join(process.env.HOME || '', 'Library/Application Support/mops');
|
|
38
|
+
globalCacheDir = path.join(process.env.HOME || '', 'Library/Caches/mops');
|
|
33
39
|
}
|
|
34
40
|
else {
|
|
35
|
-
globalConfigDir = path.join(process.env.HOME, '.config/mops');
|
|
36
|
-
globalCacheDir = path.join(process.env.HOME, '.cache/mops');
|
|
41
|
+
globalConfigDir = path.join(process.env.HOME || '', '.config/mops');
|
|
42
|
+
globalCacheDir = path.join(process.env.HOME || '', '.cache/mops');
|
|
37
43
|
}
|
|
38
44
|
// XDG overrides
|
|
39
45
|
if (process.env.XDG_CONFIG_HOME) {
|
|
@@ -44,7 +50,7 @@ if (process.env.XDG_CACHE_HOME) {
|
|
|
44
50
|
}
|
|
45
51
|
|
|
46
52
|
// temp: move old config to new location
|
|
47
|
-
let oldGlobalConfigDir = path.resolve(process.env.HOME || process.env.APPDATA, 'mops');
|
|
53
|
+
let oldGlobalConfigDir = path.resolve(process.env.HOME || process.env.APPDATA || '/', 'mops');
|
|
48
54
|
if (fs.existsSync(oldGlobalConfigDir) && !fs.existsSync(globalConfigDir)) {
|
|
49
55
|
fs.mkdirSync(globalConfigDir, {recursive: true});
|
|
50
56
|
if (fs.existsSync(path.join(oldGlobalConfigDir, 'identity.pem'))) {
|
|
@@ -71,7 +77,7 @@ if (fs.existsSync(oldGlobalConfigDir) && !fs.existsSync(globalCacheDir)) {
|
|
|
71
77
|
console.log('Moved cache to ' + chalk.green(globalCacheDir));
|
|
72
78
|
}
|
|
73
79
|
|
|
74
|
-
export function setNetwork(network) {
|
|
80
|
+
export function setNetwork(network: string) {
|
|
75
81
|
fs.writeFileSync(networkFile, network);
|
|
76
82
|
}
|
|
77
83
|
|
|
@@ -81,30 +87,30 @@ export function getNetwork() {
|
|
|
81
87
|
network = fs.readFileSync(networkFile).toString() || 'ic';
|
|
82
88
|
}
|
|
83
89
|
|
|
84
|
-
if (network === '
|
|
90
|
+
if (network === 'staging') {
|
|
85
91
|
return {
|
|
86
92
|
network,
|
|
87
|
-
host: '
|
|
93
|
+
host: 'https://icp-api.io',
|
|
88
94
|
canisterId: '2d2zu-vaaaa-aaaak-qb6pq-cai',
|
|
89
95
|
};
|
|
90
96
|
}
|
|
91
|
-
else if (network === '
|
|
97
|
+
else if (network === 'ic') {
|
|
92
98
|
return {
|
|
93
99
|
network,
|
|
94
100
|
host: 'https://icp-api.io',
|
|
95
|
-
canisterId: '
|
|
101
|
+
canisterId: 'oknww-riaaa-aaaam-qaf6a-cai',
|
|
96
102
|
};
|
|
97
103
|
}
|
|
98
|
-
else
|
|
104
|
+
else {
|
|
99
105
|
return {
|
|
100
106
|
network,
|
|
101
|
-
host: '
|
|
102
|
-
canisterId: '
|
|
107
|
+
host: 'http://127.0.0.1:4943',
|
|
108
|
+
canisterId: '2d2zu-vaaaa-aaaak-qb6pq-cai',
|
|
103
109
|
};
|
|
104
110
|
}
|
|
105
111
|
}
|
|
106
112
|
|
|
107
|
-
export let getIdentity = async () => {
|
|
113
|
+
export let getIdentity = async (): Promise<Identity | undefined> => {
|
|
108
114
|
let identityPem = path.resolve(globalConfigDir, 'identity.pem');
|
|
109
115
|
let identityPemEncrypted = path.resolve(globalConfigDir, 'identity.pem.encrypted');
|
|
110
116
|
if (fs.existsSync(identityPemEncrypted)) {
|
|
@@ -118,14 +124,16 @@ export let getIdentity = async () => {
|
|
|
118
124
|
if (fs.existsSync(identityPem)) {
|
|
119
125
|
return decodeFile(identityPem);
|
|
120
126
|
}
|
|
127
|
+
return undefined;
|
|
121
128
|
};
|
|
122
129
|
|
|
123
|
-
export let mainActor = async (useIdentity = false) => {
|
|
130
|
+
export let mainActor = async (useIdentity = false): Promise<_SERVICE> => {
|
|
124
131
|
let network = getNetwork().network;
|
|
125
132
|
let host = getNetwork().host;
|
|
126
133
|
let canisterId = getNetwork().canisterId;
|
|
127
134
|
|
|
128
|
-
let identity = useIdentity
|
|
135
|
+
let identity = useIdentity ? await getIdentity() : undefined;
|
|
136
|
+
// @ts-ignore exactOptionalPropertyTypes
|
|
129
137
|
let agent = new HttpAgent({host, identity});
|
|
130
138
|
|
|
131
139
|
if (network === 'local') {
|
|
@@ -138,11 +146,12 @@ export let mainActor = async (useIdentity = false) => {
|
|
|
138
146
|
});
|
|
139
147
|
};
|
|
140
148
|
|
|
141
|
-
export let storageActor = async (storageId, useIdentity = false) => {
|
|
149
|
+
export let storageActor = async (storageId: Principal, useIdentity = false): Promise<_STORAGE_SERVICE> => {
|
|
142
150
|
let network = getNetwork().network;
|
|
143
151
|
let host = getNetwork().host;
|
|
144
152
|
|
|
145
153
|
let identity = useIdentity && await getIdentity();
|
|
154
|
+
// @ts-ignore exactOptionalPropertyTypes
|
|
146
155
|
let agent = new HttpAgent({host, identity});
|
|
147
156
|
|
|
148
157
|
if (network === 'local') {
|
|
@@ -157,7 +166,7 @@ export let storageActor = async (storageId, useIdentity = false) => {
|
|
|
157
166
|
|
|
158
167
|
export function getClosestConfigFile(dir = process.cwd()) {
|
|
159
168
|
if (!path.basename(dir)) {
|
|
160
|
-
|
|
169
|
+
throw '';
|
|
161
170
|
}
|
|
162
171
|
let configFile = path.join(dir, 'mops.toml');
|
|
163
172
|
if (fs.existsSync(configFile)) {
|
|
@@ -169,7 +178,7 @@ export function getClosestConfigFile(dir = process.cwd()) {
|
|
|
169
178
|
export function getRootDir() {
|
|
170
179
|
let configFile = getClosestConfigFile();
|
|
171
180
|
if (!configFile) {
|
|
172
|
-
return
|
|
181
|
+
return '';
|
|
173
182
|
}
|
|
174
183
|
return path.dirname(configFile);
|
|
175
184
|
}
|
|
@@ -183,34 +192,34 @@ export function checkConfigFile() {
|
|
|
183
192
|
return true;
|
|
184
193
|
}
|
|
185
194
|
|
|
186
|
-
export function progressBar(step, total) {
|
|
195
|
+
export function progressBar(step: number, total: number) {
|
|
187
196
|
let done = Math.round(step / total * 10);
|
|
188
197
|
return `[${':'.repeat(done)}${' '.repeat(Math.max(0, 10 - done))}]`;
|
|
189
198
|
}
|
|
190
199
|
|
|
191
|
-
export async function getHighestVersion(pkgName) {
|
|
200
|
+
export async function getHighestVersion(pkgName: string) {
|
|
192
201
|
let actor = await mainActor();
|
|
193
202
|
return actor.getHighestVersion(pkgName);
|
|
194
203
|
}
|
|
195
204
|
|
|
196
|
-
export function parseGithubURL(href) {
|
|
205
|
+
export function parseGithubURL(href: string) {
|
|
197
206
|
const url = new URL(href);
|
|
198
207
|
const branch = url.hash?.substring(1) || 'master';
|
|
199
208
|
|
|
200
209
|
let [org, gitName] = url.pathname.split('/').filter(path => !!path);
|
|
201
210
|
|
|
202
|
-
if (gitName
|
|
211
|
+
if (gitName?.endsWith('.git')) {
|
|
203
212
|
gitName = gitName.substring(0, gitName.length - 4);
|
|
204
213
|
}
|
|
205
214
|
|
|
206
215
|
return {org, gitName, branch};
|
|
207
216
|
}
|
|
208
217
|
|
|
209
|
-
export function readConfig(configFile = getClosestConfigFile()) {
|
|
218
|
+
export function readConfig(configFile = getClosestConfigFile()): Config {
|
|
210
219
|
let text = fs.readFileSync(configFile).toString();
|
|
211
220
|
let toml = TOML.parse(text);
|
|
212
221
|
|
|
213
|
-
let processDeps = (deps) => {
|
|
222
|
+
let processDeps = (deps: any) => {
|
|
214
223
|
Object.entries(deps).forEach(([name, data]) => {
|
|
215
224
|
if (!data || typeof data !== 'string') {
|
|
216
225
|
throw Error(`Invalid dependency value ${name} = "${data}"`);
|
|
@@ -233,34 +242,36 @@ export function readConfig(configFile = getClosestConfigFile()) {
|
|
|
233
242
|
return toml;
|
|
234
243
|
}
|
|
235
244
|
|
|
236
|
-
export function writeConfig(config, configFile = getClosestConfigFile()) {
|
|
237
|
-
|
|
238
|
-
|
|
245
|
+
export function writeConfig(config: Config, configFile = getClosestConfigFile()) {
|
|
246
|
+
let resConfig: any = {...config};
|
|
247
|
+
|
|
248
|
+
let deps = resConfig.dependencies || {};
|
|
249
|
+
Object.entries(config.dependencies || {}).forEach(([name, {repo, path, version}]) => {
|
|
239
250
|
deps[name] = repo || path || version;
|
|
240
251
|
});
|
|
241
252
|
|
|
242
|
-
|
|
243
|
-
Object.entries(
|
|
253
|
+
let devDeps = resConfig['dev-dependencies'] || {};
|
|
254
|
+
Object.entries(config['dev-dependencies'] || {}).forEach(([name, {repo, path, version}]) => {
|
|
244
255
|
devDeps[name] = repo || path || version;
|
|
245
256
|
});
|
|
246
257
|
|
|
247
|
-
let text = TOML.stringify(
|
|
258
|
+
let text = TOML.stringify(resConfig).trim();
|
|
248
259
|
if (fs.existsSync(configFile) && fs.readFileSync(configFile).toString().endsWith('\n')) {
|
|
249
260
|
text += '\n';
|
|
250
261
|
}
|
|
251
262
|
fs.writeFileSync(configFile, text);
|
|
252
263
|
}
|
|
253
264
|
|
|
254
|
-
export function formatDir(name, version) {
|
|
265
|
+
export function formatDir(name: string, version: string) {
|
|
255
266
|
return path.join(getRootDir(), '.mops', `${name}@${version}`);
|
|
256
267
|
}
|
|
257
268
|
|
|
258
|
-
export function formatGithubDir(name, repo) {
|
|
269
|
+
export function formatGithubDir(name: string, repo: string) {
|
|
259
270
|
const {branch} = parseGithubURL(repo);
|
|
260
271
|
return path.join(getRootDir(), '.mops/_github', `${name}@${branch}`);
|
|
261
272
|
}
|
|
262
273
|
|
|
263
|
-
export function readDfxJson() {
|
|
274
|
+
export function readDfxJson(): any {
|
|
264
275
|
let dir = process.cwd();
|
|
265
276
|
let dfxJson = null;
|
|
266
277
|
for (let i = 0; i < 5; i++) {
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ic-mops",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.20.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"bin": {
|
|
6
|
-
"mops": "cli.js"
|
|
6
|
+
"mops": "dist/cli.js"
|
|
7
7
|
},
|
|
8
8
|
"files": [
|
|
9
9
|
"*",
|
|
@@ -19,36 +19,61 @@
|
|
|
19
19
|
"author": "Zen Voich <zen.voich@gmail.com>",
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"engines": {
|
|
22
|
-
"node": ">=
|
|
22
|
+
"node": ">=16.0.0"
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "tsc",
|
|
26
|
+
"bundle": "esbuild --bundle --outfile=cli.js --platform=node --packages=external --target=node16 --format=esm ./dist/cli.js",
|
|
27
|
+
"copy": "cp -r declarations templates network.txt package.json dist | true",
|
|
28
|
+
"save-network": "cp -r dist/network.txt . | true",
|
|
29
|
+
"prepare": "npm run save-network && npm run build && npm run copy",
|
|
30
|
+
"check": "tsc --project tsconfig.json --noEmit",
|
|
31
|
+
"tsc": "tsc",
|
|
32
|
+
"esbuild": "esbuild"
|
|
23
33
|
},
|
|
24
34
|
"dependencies": {
|
|
25
|
-
"@dfinity/agent": "^0.
|
|
26
|
-
"@dfinity/candid": "^0.
|
|
27
|
-
"@dfinity/identity": "^0.
|
|
28
|
-
"@dfinity/
|
|
35
|
+
"@dfinity/agent": "^0.18.1",
|
|
36
|
+
"@dfinity/candid": "^0.18.1",
|
|
37
|
+
"@dfinity/identity": "^0.18.1",
|
|
38
|
+
"@dfinity/identity-secp256k1": "^0.18.1",
|
|
39
|
+
"@dfinity/principal": "^0.18.1",
|
|
29
40
|
"@iarna/toml": "^2.2.5",
|
|
30
41
|
"as-table": "^1.0.55",
|
|
31
|
-
"cacheable-request": "10.2.
|
|
32
|
-
"chalk": "^
|
|
42
|
+
"cacheable-request": "10.2.12",
|
|
43
|
+
"chalk": "^5.3.0",
|
|
33
44
|
"chokidar": "^3.5.3",
|
|
34
|
-
"commander": "^
|
|
45
|
+
"commander": "^11.0.0",
|
|
35
46
|
"debounce": "^1.2.1",
|
|
36
47
|
"decompress": "^4.2.1",
|
|
37
|
-
"del": "^
|
|
48
|
+
"del": "^7.0.0",
|
|
38
49
|
"dhall-to-json-cli": "^1.7.6",
|
|
39
|
-
"eslint": "^8.
|
|
40
|
-
"execa": "
|
|
50
|
+
"eslint": "^8.45.0",
|
|
51
|
+
"execa": "7.1.1",
|
|
41
52
|
"get-folder-size": "^4.0.0",
|
|
42
|
-
"glob": "^
|
|
43
|
-
"globby": "^13.
|
|
44
|
-
"got": "
|
|
53
|
+
"glob": "^10.3.3",
|
|
54
|
+
"globby": "^13.2.2",
|
|
55
|
+
"got": "13.0.0",
|
|
45
56
|
"log-update": "^5.0.1",
|
|
46
|
-
"minimatch": "^
|
|
57
|
+
"minimatch": "^9.0.3",
|
|
47
58
|
"ncp": "^2.0.0",
|
|
48
|
-
"node-fetch": "^3.3.
|
|
59
|
+
"node-fetch": "^3.3.2",
|
|
49
60
|
"pem-file": "^1.0.1",
|
|
50
61
|
"prompts": "^2.4.2",
|
|
51
62
|
"stream-to-promise": "^3.0.0",
|
|
52
|
-
"tar": "^6.1.
|
|
63
|
+
"tar": "^6.1.15"
|
|
64
|
+
},
|
|
65
|
+
"devDependencies": {
|
|
66
|
+
"@tsconfig/strictest": "^2.0.1",
|
|
67
|
+
"@types/debounce": "^1.2.1",
|
|
68
|
+
"@types/decompress": "^4.2.4",
|
|
69
|
+
"@types/glob": "^8.1.0",
|
|
70
|
+
"@types/ncp": "^2.0.5",
|
|
71
|
+
"@types/node": "^20.4.4",
|
|
72
|
+
"@types/prompts": "^2.4.4",
|
|
73
|
+
"@types/stream-to-promise": "^2.2.1",
|
|
74
|
+
"@types/tar": "^6.1.5",
|
|
75
|
+
"esbuild": "^0.18.16",
|
|
76
|
+
"tsx": "^3.12.7",
|
|
77
|
+
"typescript": "^5.1.6"
|
|
53
78
|
}
|
|
54
79
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export async function parallel(threads, items, fn) {
|
|
2
|
-
return new Promise((resolve) => {
|
|
1
|
+
export async function parallel(threads: number, items: any[], fn: CallableFunction) {
|
|
2
|
+
return new Promise<void>((resolve) => {
|
|
3
3
|
let busyThreads = 0;
|
|
4
4
|
items = items.slice();
|
|
5
5
|
|
package/{pem.js → pem.ts}
RENAMED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import {Ed25519KeyIdentity
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import {Ed25519KeyIdentity} from '@dfinity/identity';
|
|
3
|
+
import {Secp256k1KeyIdentity} from '@dfinity/identity-secp256k1';
|
|
3
4
|
import pemfile from 'pem-file';
|
|
4
5
|
import crypto from 'crypto';
|
|
5
6
|
|
|
6
|
-
export function decodeFile(file, password) {
|
|
7
|
+
export function decodeFile(file: string, password?: string) {
|
|
7
8
|
let rawKey = fs.readFileSync(file);
|
|
8
9
|
if (password) {
|
|
9
10
|
return decode(decrypt(rawKey, password));
|
|
@@ -11,24 +12,24 @@ export function decodeFile(file, password) {
|
|
|
11
12
|
return decode(rawKey);
|
|
12
13
|
}
|
|
13
14
|
|
|
14
|
-
function decode(rawKey) {
|
|
15
|
-
|
|
15
|
+
function decode(rawKey: Buffer) {
|
|
16
|
+
let buf: Buffer = pemfile.decode(rawKey);
|
|
16
17
|
if (rawKey.includes('EC PRIVATE KEY')) {
|
|
17
18
|
if (buf.length != 118) {
|
|
18
19
|
throw 'expecting byte length 118 but got ' + buf.length;
|
|
19
20
|
}
|
|
20
|
-
return Secp256k1KeyIdentity.fromSecretKey(buf.
|
|
21
|
+
return Secp256k1KeyIdentity.fromSecretKey(buf.subarray(7, 39));
|
|
21
22
|
}
|
|
22
23
|
if (buf.length != 85) {
|
|
23
24
|
throw 'expecting byte length 85 but got ' + buf.length;
|
|
24
25
|
}
|
|
25
|
-
let secretKey = Buffer.concat([buf.
|
|
26
|
+
let secretKey = Buffer.concat([buf.subarray(16, 48), buf.subarray(53, 85)]);
|
|
26
27
|
return Ed25519KeyIdentity.fromSecretKey(secretKey);
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
let algorithm = 'aes-256-ctr';
|
|
30
31
|
|
|
31
|
-
export function encrypt(buffer, password) {
|
|
32
|
+
export function encrypt(buffer: Buffer, password: string) {
|
|
32
33
|
let key = crypto.createHash('sha256').update(password).digest('base64').slice(0, 32);
|
|
33
34
|
// Create an initialization vector
|
|
34
35
|
let iv = crypto.randomBytes(16);
|
|
@@ -39,12 +40,12 @@ export function encrypt(buffer, password) {
|
|
|
39
40
|
return result;
|
|
40
41
|
}
|
|
41
42
|
|
|
42
|
-
function decrypt(encrypted, password) {
|
|
43
|
+
function decrypt(encrypted: Buffer, password: string) {
|
|
43
44
|
let key = crypto.createHash('sha256').update(password).digest('base64').slice(0, 32);
|
|
44
45
|
// Get the iv: the first 16 bytes
|
|
45
|
-
let iv = encrypted.
|
|
46
|
+
let iv = encrypted.subarray(0, 16);
|
|
46
47
|
// Get the rest
|
|
47
|
-
encrypted = encrypted.
|
|
48
|
+
encrypted = encrypted.subarray(16);
|
|
48
49
|
// Create a decipher
|
|
49
50
|
let decipher = crypto.createDecipheriv(algorithm, key, iv);
|
|
50
51
|
// Actually decrypt it
|
package/templates/mops-test.yml
CHANGED
package/tsconfig.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": ["@tsconfig/strictest/tsconfig.json"],
|
|
3
|
+
"include": ["**/*.ts", "**/*.js"],
|
|
4
|
+
"exclude": ["node_modules", "dist", "dist.js", "declarations/**/*.js"],
|
|
5
|
+
"compilerOptions": {
|
|
6
|
+
"types": ["node"],
|
|
7
|
+
"target": "ES2021",
|
|
8
|
+
"outDir": "./dist",
|
|
9
|
+
"allowJs": true,
|
|
10
|
+
"module": "nodenext",
|
|
11
|
+
"moduleResolution": "nodenext",
|
|
12
|
+
"noEmitOnError": false,
|
|
13
|
+
"noPropertyAccessFromIndexSignature": false,
|
|
14
|
+
"declaration": true
|
|
15
|
+
}
|
|
16
|
+
}
|
package/types.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export type Config = {
|
|
2
|
+
package?: {
|
|
3
|
+
name: string;
|
|
4
|
+
version: string;
|
|
5
|
+
description?: string;
|
|
6
|
+
license?: string;
|
|
7
|
+
repository?: string;
|
|
8
|
+
keywords?: string[];
|
|
9
|
+
baseDir?: string;
|
|
10
|
+
readme?: string;
|
|
11
|
+
files?: string[];
|
|
12
|
+
homepage?: string;
|
|
13
|
+
documentation?: string;
|
|
14
|
+
dfx?: string;
|
|
15
|
+
moc?: string;
|
|
16
|
+
donation?: string;
|
|
17
|
+
};
|
|
18
|
+
dependencies?: Dependencies;
|
|
19
|
+
'dev-dependencies'?: Dependencies;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export type Dependencies = Record<string, Dependency>;
|
|
23
|
+
|
|
24
|
+
export type Dependency = {
|
|
25
|
+
name: string;
|
|
26
|
+
version?: string; // mops package
|
|
27
|
+
repo?: string; // github package
|
|
28
|
+
path?: string; // local package
|
|
29
|
+
}
|