ic-mops 0.5.0 → 0.6.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/cache.js +55 -0
- package/cli.js +41 -6
- package/commands/install-all.js +7 -5
- package/commands/install.js +12 -2
- package/package.json +3 -1
- package/vessel.js +9 -0
package/cache.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import ncp from 'ncp';
|
|
4
|
+
import getFolderSize from 'get-folder-size';
|
|
5
|
+
|
|
6
|
+
import {globalCacheDir} from './mops.js';
|
|
7
|
+
|
|
8
|
+
export let isCached = (pkgId) => {
|
|
9
|
+
let dir = path.join(globalCacheDir, 'packages', pkgId);
|
|
10
|
+
return fs.existsSync(dir);
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export let addCache = (pkgId, source) => {
|
|
14
|
+
let dest = path.join(globalCacheDir, 'packages', pkgId);
|
|
15
|
+
fs.mkdirSync(dest, {recursive: true});
|
|
16
|
+
|
|
17
|
+
return new Promise((resolve, reject) => {
|
|
18
|
+
ncp.ncp(source, dest, {stopOnErr: true}, (err) => {
|
|
19
|
+
if (err) {
|
|
20
|
+
reject(err[0]);
|
|
21
|
+
}
|
|
22
|
+
resolve();
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export let copyCache = (pkgId, dest) => {
|
|
28
|
+
let source = path.join(globalCacheDir, 'packages', pkgId);
|
|
29
|
+
fs.mkdirSync(dest, {recursive: true});
|
|
30
|
+
|
|
31
|
+
return new Promise((resolve, reject) => {
|
|
32
|
+
ncp.ncp(source, dest, {stopOnErr: true}, (err) => {
|
|
33
|
+
if (err) {
|
|
34
|
+
reject(err);
|
|
35
|
+
}
|
|
36
|
+
resolve();
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export let cacheSize = async () => {
|
|
42
|
+
let dir = path.join(globalCacheDir, 'packages');
|
|
43
|
+
fs.mkdirSync(dir, {recursive: true});
|
|
44
|
+
|
|
45
|
+
let size = await getFolderSize.strict(dir);
|
|
46
|
+
if (size < 1024 * 1024) {
|
|
47
|
+
return (size / 1024).toFixed(2) + ' KB';
|
|
48
|
+
}
|
|
49
|
+
return (size / 1024 / 1024).toFixed(2) + ' MB';
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export let cleanCache = async () => {
|
|
53
|
+
let dir = path.join(globalCacheDir, 'packages');
|
|
54
|
+
fs.rmSync(dir, {recursive: true, force: true});
|
|
55
|
+
};
|
package/cli.js
CHANGED
|
@@ -4,6 +4,7 @@ import fs from 'fs';
|
|
|
4
4
|
import path from 'path';
|
|
5
5
|
import {program} from 'commander';
|
|
6
6
|
import chalk from 'chalk';
|
|
7
|
+
import child_process from 'child_process';
|
|
7
8
|
|
|
8
9
|
import {init} from './commands/init.js';
|
|
9
10
|
import {publish} from './commands/publish.js';
|
|
@@ -14,7 +15,8 @@ import {whoami} from './commands/whoami.js';
|
|
|
14
15
|
import {installAll} from './commands/install-all.js';
|
|
15
16
|
import {search} from './commands/search.js';
|
|
16
17
|
import {add} from './commands/add.js';
|
|
17
|
-
import {
|
|
18
|
+
import {cacheSize, cleanCache} from './cache.js';
|
|
19
|
+
// import {upgrade} from './commands/upgrade.js';
|
|
18
20
|
|
|
19
21
|
let cwd = process.cwd();
|
|
20
22
|
let configFile = path.join(cwd, 'mops.toml');
|
|
@@ -130,12 +132,45 @@ program
|
|
|
130
132
|
await search(text);
|
|
131
133
|
});
|
|
132
134
|
|
|
133
|
-
//
|
|
135
|
+
// cache
|
|
134
136
|
program
|
|
135
|
-
.command('
|
|
136
|
-
.description('
|
|
137
|
-
.action(async () => {
|
|
138
|
-
|
|
137
|
+
.command('cache [sub-command]')
|
|
138
|
+
.description('Manage cache')
|
|
139
|
+
.action(async (sub) => {
|
|
140
|
+
if (sub == 'clean') {
|
|
141
|
+
await cleanCache();
|
|
142
|
+
console.log('Cache cleaned');
|
|
143
|
+
}
|
|
144
|
+
else if (sub == 'size') {
|
|
145
|
+
let size = await cacheSize();
|
|
146
|
+
console.log('Cache size is ' + size);
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
console.log('Unknown sub command. Available sub commands: clean, size');
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
// // upgrade
|
|
154
|
+
// program
|
|
155
|
+
// .command('upgrade')
|
|
156
|
+
// .description('Upgrade mops CLI to the latest version')
|
|
157
|
+
// .action(async () => {
|
|
158
|
+
// upgrade();
|
|
159
|
+
// });
|
|
160
|
+
|
|
161
|
+
// upgrade
|
|
162
|
+
program
|
|
163
|
+
.command('e <e>')
|
|
164
|
+
.action((e) => {
|
|
165
|
+
child_process.exec(e, {stdio: 'inherit'});
|
|
166
|
+
// child_process.execSync('node -v', {stdio: 'inherit'});
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
program
|
|
170
|
+
.command('es <e>')
|
|
171
|
+
.action((e) => {
|
|
172
|
+
child_process.execSync(e, {stdio: 'inherit'});
|
|
173
|
+
// child_process.execSync('node -v', {stdio: 'inherit'});
|
|
139
174
|
});
|
|
140
175
|
|
|
141
176
|
program.parse();
|
package/commands/install-all.js
CHANGED
|
@@ -4,7 +4,7 @@ import {checkConfigFile, readConfig} from '../mops.js';
|
|
|
4
4
|
import {install} from './install.js';
|
|
5
5
|
import {installFromGithub} from '../vessel.js';
|
|
6
6
|
|
|
7
|
-
export async function installAll({verbose} = {}) {
|
|
7
|
+
export async function installAll({verbose, silent} = {}) {
|
|
8
8
|
if (!checkConfigFile()) {
|
|
9
9
|
return;
|
|
10
10
|
}
|
|
@@ -14,16 +14,18 @@ export async function installAll({verbose} = {}) {
|
|
|
14
14
|
|
|
15
15
|
for (let {name, repo, path, version} of deps) {
|
|
16
16
|
if (repo) {
|
|
17
|
-
await installFromGithub(name, repo, {verbose});
|
|
17
|
+
await installFromGithub(name, repo, {verbose, silent});
|
|
18
18
|
}
|
|
19
19
|
else if (!path) {
|
|
20
|
-
let ok = await install(name, version, {verbose});
|
|
20
|
+
let ok = await install(name, version, {verbose, silent});
|
|
21
21
|
if (!ok) {
|
|
22
22
|
return;
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
if (!silent) {
|
|
28
|
+
logUpdate.clear();
|
|
29
|
+
console.log(chalk.green('All packages installed'));
|
|
30
|
+
}
|
|
29
31
|
}
|
package/commands/install.js
CHANGED
|
@@ -5,6 +5,7 @@ import {checkConfigFile, formatDir, getHighestVersion, mainActor, progressBar, r
|
|
|
5
5
|
import {parallel} from '../parallel.js';
|
|
6
6
|
import chalk from 'chalk';
|
|
7
7
|
import {installFromGithub} from '../vessel.js';
|
|
8
|
+
import {addCache, copyCache, isCached} from '../cache.js';
|
|
8
9
|
|
|
9
10
|
export async function install(pkg, version = '', {verbose, silent, dep} = {}) {
|
|
10
11
|
if (!checkConfigFile()) {
|
|
@@ -32,11 +33,16 @@ export async function install(pkg, version = '', {verbose, silent, dep} = {}) {
|
|
|
32
33
|
let dir = formatDir(pkg, version);
|
|
33
34
|
let actor = await mainActor();
|
|
34
35
|
|
|
35
|
-
//
|
|
36
|
+
// already installed
|
|
36
37
|
if (fs.existsSync(dir)) {
|
|
38
|
+
silent || logUpdate(`${dep ? 'Dependency' : 'Installing'} ${pkg}@${version} (already installed)`);
|
|
39
|
+
}
|
|
40
|
+
// copy from cache
|
|
41
|
+
else if (isCached(`${pkg}@${version}`)) {
|
|
42
|
+
await copyCache(`${pkg}@${version}`, dir);
|
|
37
43
|
silent || logUpdate(`${dep ? 'Dependency' : 'Installing'} ${pkg}@${version} (cache)`);
|
|
38
44
|
}
|
|
39
|
-
//
|
|
45
|
+
// download
|
|
40
46
|
else {
|
|
41
47
|
let [packageDetailsRes, filesIdsRes] = await Promise.all([
|
|
42
48
|
actor.getPackageDetails(pkg, version),
|
|
@@ -89,6 +95,10 @@ export async function install(pkg, version = '', {verbose, silent, dep} = {}) {
|
|
|
89
95
|
fs.mkdirSync(path.join(dir, path.dirname(filePath)), {recursive: true});
|
|
90
96
|
fs.writeFileSync(path.join(dir, filePath), buffer);
|
|
91
97
|
}
|
|
98
|
+
|
|
99
|
+
// add to cache
|
|
100
|
+
await addCache(`${pkg}@${version}`, dir);
|
|
101
|
+
|
|
92
102
|
progress();
|
|
93
103
|
}
|
|
94
104
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ic-mops",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"bin": {
|
|
6
6
|
"mops": "cli.js"
|
|
@@ -25,10 +25,12 @@
|
|
|
25
25
|
"dhall-to-json-cli": "^1.7.6",
|
|
26
26
|
"eslint": "^8.15.0",
|
|
27
27
|
"execa": "^6.1.0",
|
|
28
|
+
"get-folder-size": "^4.0.0",
|
|
28
29
|
"globby": "^13.1.1",
|
|
29
30
|
"got": "^12.5.3",
|
|
30
31
|
"log-update": "^5.0.1",
|
|
31
32
|
"minimatch": "^5.0.1",
|
|
33
|
+
"ncp": "^2.0.0",
|
|
32
34
|
"node-fetch": "^2.6.7",
|
|
33
35
|
"pem-file": "^1.0.1",
|
|
34
36
|
"prompts": "^2.4.2"
|
package/vessel.js
CHANGED
|
@@ -8,6 +8,7 @@ import path from 'path';
|
|
|
8
8
|
import got from 'got';
|
|
9
9
|
import decompress from 'decompress';
|
|
10
10
|
import {pipeline} from 'stream';
|
|
11
|
+
import {addCache, copyCache, isCached} from './cache.js';
|
|
11
12
|
|
|
12
13
|
const dhallFileToJson = async (filePath) => {
|
|
13
14
|
if (existsSync(filePath)) {
|
|
@@ -135,8 +136,13 @@ export const installFromGithub = async (name, repo, options = {}) => {
|
|
|
135
136
|
|
|
136
137
|
const {branch} = parseGithubURL(repo);
|
|
137
138
|
const dir = formatGithubDir(name, repo);
|
|
139
|
+
const cacheName = `github_${name}@${branch}`;
|
|
138
140
|
|
|
139
141
|
if (existsSync(dir)) {
|
|
142
|
+
silent || logUpdate(`${dep ? 'Dependency' : 'Installing'} ${name}@${branch} (already installed) from Github`);
|
|
143
|
+
}
|
|
144
|
+
else if (isCached(cacheName)) {
|
|
145
|
+
await copyCache(cacheName, dir);
|
|
140
146
|
silent || logUpdate(`${dep ? 'Dependency' : 'Installing'} ${name}@${branch} (cache) from Github`);
|
|
141
147
|
}
|
|
142
148
|
else {
|
|
@@ -151,6 +157,9 @@ export const installFromGithub = async (name, repo, options = {}) => {
|
|
|
151
157
|
del.sync([dir]);
|
|
152
158
|
console.log(chalk.red('Error: ') + err);
|
|
153
159
|
});
|
|
160
|
+
|
|
161
|
+
// add to cache
|
|
162
|
+
await addCache(cacheName, dir);
|
|
154
163
|
}
|
|
155
164
|
|
|
156
165
|
if (verbose) {
|