ic-mops 0.23.0 → 0.25.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.
Files changed (38) hide show
  1. package/README.md +6 -18
  2. package/cli.ts +25 -6
  3. package/commands/available-updates.ts +30 -0
  4. package/commands/init.ts +197 -31
  5. package/commands/outdated.ts +22 -0
  6. package/commands/template.ts +83 -15
  7. package/commands/update.ts +22 -0
  8. package/declarations/main/main.did +34 -11
  9. package/declarations/main/main.did.d.ts +19 -8
  10. package/declarations/main/main.did.js +32 -8
  11. package/dist/cli.js +23 -6
  12. package/dist/commands/available-updates.d.ts +2 -0
  13. package/dist/commands/available-updates.js +24 -0
  14. package/dist/commands/init.d.ts +3 -1
  15. package/dist/commands/init.js +174 -29
  16. package/dist/commands/outdated.d.ts +1 -0
  17. package/dist/commands/outdated.js +19 -0
  18. package/dist/commands/template.d.ts +1 -1
  19. package/dist/commands/template.js +78 -15
  20. package/dist/commands/update.d.ts +1 -0
  21. package/dist/commands/update.js +19 -0
  22. package/dist/declarations/main/main.did +34 -11
  23. package/dist/declarations/main/main.did.d.ts +19 -8
  24. package/dist/declarations/main/main.did.js +32 -8
  25. package/dist/package.json +2 -1
  26. package/dist/templates/README.md +13 -0
  27. package/dist/templates/licenses/Apache-2.0 +202 -0
  28. package/dist/templates/licenses/Apache-2.0-NOTICE +13 -0
  29. package/dist/templates/licenses/MIT +21 -0
  30. package/dist/templates/src/lib.mo +15 -0
  31. package/dist/templates/test/lib.test.mo +4 -0
  32. package/package.json +2 -1
  33. package/templates/README.md +13 -0
  34. package/templates/licenses/Apache-2.0 +202 -0
  35. package/templates/licenses/Apache-2.0-NOTICE +13 -0
  36. package/templates/licenses/MIT +21 -0
  37. package/templates/src/lib.mo +15 -0
  38. package/templates/test/lib.test.mo +4 -0
@@ -1,5 +1,3 @@
1
- type Version = text;
2
- type Ver = text;
3
1
  type User__1 =
4
2
  record {
5
3
  displayName: text;
@@ -35,20 +33,34 @@ type StorageStats =
35
33
  memorySize: nat;
36
34
  };
37
35
  type StorageId = principal;
36
+ type SemverPart =
37
+ variant {
38
+ major;
39
+ minor;
40
+ patch;
41
+ };
38
42
  type Script =
39
43
  record {
40
44
  name: text;
41
45
  value: text;
42
46
  };
43
- type Result_6 =
47
+ type Result_7 =
44
48
  variant {
45
49
  err: Err;
46
50
  ok: vec FileId;
47
51
  };
52
+ type Result_6 =
53
+ variant {
54
+ err: Err;
55
+ ok: vec record {
56
+ PackageName__1;
57
+ PackageVersion;
58
+ };
59
+ };
48
60
  type Result_5 =
49
61
  variant {
50
62
  err: Err;
51
- ok: Ver;
63
+ ok: PackageVersion;
52
64
  };
53
65
  type Result_4 =
54
66
  variant {
@@ -78,6 +90,7 @@ type Result =
78
90
  type PublishingId = text;
79
91
  type PublishingErr = text;
80
92
  type PageCount = nat;
93
+ type PackageVersion = text;
81
94
  type PackageSummary__1 =
82
95
  record {
83
96
  config: PackageConfigV2__1;
@@ -181,25 +194,34 @@ type DependencyV2 =
181
194
  version: text;
182
195
  };
183
196
  service : {
197
+ backup: () -> ();
184
198
  claimAirdrop: (principal) -> (text);
185
199
  finishPublish: (PublishingId) -> (Result);
186
200
  getAirdropAmount: () -> (nat) query;
187
201
  getAirdropAmountAll: () -> (nat) query;
188
202
  getApiVersion: () -> (Text) query;
189
- getDefaultPackages: (text) -> (vec record {
190
- PackageName__1;
191
- Version;
192
- }) query;
203
+ getBackupCanisterId: () -> (principal) query;
204
+ getDefaultPackages: (text) ->
205
+ (vec record {
206
+ PackageName__1;
207
+ PackageVersion;
208
+ }) query;
193
209
  getDownloadTrendByPackageId: (PackageId) ->
194
210
  (vec DownloadsSnapshot__1) query;
195
211
  getDownloadTrendByPackageName: (PackageName__1) ->
196
212
  (vec DownloadsSnapshot__1) query;
197
- getFileIds: (PackageName__1, Ver) -> (Result_6) query;
213
+ getFileIds: (PackageName__1, PackageVersion) -> (Result_7) query;
214
+ getHighestSemverBatch:
215
+ (vec record {
216
+ PackageName__1;
217
+ PackageVersion;
218
+ SemverPart;
219
+ }) -> (Result_6) query;
198
220
  getHighestVersion: (PackageName__1) -> (Result_5) query;
199
221
  getMostDownloadedPackages: () -> (vec PackageSummary) query;
200
222
  getMostDownloadedPackagesIn7Days: () -> (vec PackageSummary) query;
201
223
  getNewPackages: () -> (vec PackageSummary) query;
202
- getPackageDetails: (PackageName__1, Ver) -> (Result_4) query;
224
+ getPackageDetails: (PackageName__1, PackageVersion) -> (Result_4) query;
203
225
  getPackagesByCategory: () -> (vec record {
204
226
  text;
205
227
  vec PackageSummary;
@@ -212,7 +234,8 @@ service : {
212
234
  getTotalDownloads: () -> (nat) query;
213
235
  getTotalPackages: () -> (nat) query;
214
236
  getUser: (principal) -> (opt User__1) query;
215
- notifyInstall: (PackageName__1, Ver) -> () oneway;
237
+ notifyInstall: (PackageName__1, PackageVersion) -> () oneway;
238
+ restore: (nat, nat) -> ();
216
239
  search: (Text, opt nat, opt nat) -> (vec PackageSummary, PageCount) query;
217
240
  setUserProp: (text, text) -> (Result_3);
218
241
  startFileUpload: (PublishingId, Text, nat, blob) -> (Result_2);
@@ -94,6 +94,7 @@ export interface PackageSummary__1 {
94
94
  'config' : PackageConfigV2__1,
95
95
  'publication' : PackagePublication,
96
96
  }
97
+ export type PackageVersion = string;
97
98
  export type PageCount = bigint;
98
99
  export type PublishingErr = string;
99
100
  export type PublishingId = string;
@@ -107,11 +108,16 @@ export type Result_3 = { 'ok' : null } |
107
108
  { 'err' : string };
108
109
  export type Result_4 = { 'ok' : PackageDetails } |
109
110
  { 'err' : Err };
110
- export type Result_5 = { 'ok' : Ver } |
111
+ export type Result_5 = { 'ok' : PackageVersion } |
111
112
  { 'err' : Err };
112
- export type Result_6 = { 'ok' : Array<FileId> } |
113
+ export type Result_6 = { 'ok' : Array<[PackageName__1, PackageVersion]> } |
114
+ { 'err' : Err };
115
+ export type Result_7 = { 'ok' : Array<FileId> } |
113
116
  { 'err' : Err };
114
117
  export interface Script { 'value' : string, 'name' : string }
118
+ export type SemverPart = { 'major' : null } |
119
+ { 'minor' : null } |
120
+ { 'patch' : null };
115
121
  export type StorageId = Principal;
116
122
  export interface StorageStats {
117
123
  'fileCount' : bigint,
@@ -144,17 +150,17 @@ export interface User__1 {
144
150
  'githubVerified' : boolean,
145
151
  'github' : string,
146
152
  }
147
- export type Ver = string;
148
- export type Version = string;
149
153
  export interface _SERVICE {
154
+ 'backup' : ActorMethod<[], undefined>,
150
155
  'claimAirdrop' : ActorMethod<[Principal], string>,
151
156
  'finishPublish' : ActorMethod<[PublishingId], Result>,
152
157
  'getAirdropAmount' : ActorMethod<[], bigint>,
153
158
  'getAirdropAmountAll' : ActorMethod<[], bigint>,
154
159
  'getApiVersion' : ActorMethod<[], Text>,
160
+ 'getBackupCanisterId' : ActorMethod<[], Principal>,
155
161
  'getDefaultPackages' : ActorMethod<
156
162
  [string],
157
- Array<[PackageName__1, Version]>
163
+ Array<[PackageName__1, PackageVersion]>
158
164
  >,
159
165
  'getDownloadTrendByPackageId' : ActorMethod<
160
166
  [PackageId],
@@ -164,12 +170,16 @@ export interface _SERVICE {
164
170
  [PackageName__1],
165
171
  Array<DownloadsSnapshot__1>
166
172
  >,
167
- 'getFileIds' : ActorMethod<[PackageName__1, Ver], Result_6>,
173
+ 'getFileIds' : ActorMethod<[PackageName__1, PackageVersion], Result_7>,
174
+ 'getHighestSemverBatch' : ActorMethod<
175
+ [Array<[PackageName__1, PackageVersion, SemverPart]>],
176
+ Result_6
177
+ >,
168
178
  'getHighestVersion' : ActorMethod<[PackageName__1], Result_5>,
169
179
  'getMostDownloadedPackages' : ActorMethod<[], Array<PackageSummary>>,
170
180
  'getMostDownloadedPackagesIn7Days' : ActorMethod<[], Array<PackageSummary>>,
171
181
  'getNewPackages' : ActorMethod<[], Array<PackageSummary>>,
172
- 'getPackageDetails' : ActorMethod<[PackageName__1, Ver], Result_4>,
182
+ 'getPackageDetails' : ActorMethod<[PackageName__1, PackageVersion], Result_4>,
173
183
  'getPackagesByCategory' : ActorMethod<
174
184
  [],
175
185
  Array<[string, Array<PackageSummary>]>
@@ -179,7 +189,8 @@ export interface _SERVICE {
179
189
  'getTotalDownloads' : ActorMethod<[], bigint>,
180
190
  'getTotalPackages' : ActorMethod<[], bigint>,
181
191
  'getUser' : ActorMethod<[Principal], [] | [User__1]>,
182
- 'notifyInstall' : ActorMethod<[PackageName__1, Ver], undefined>,
192
+ 'notifyInstall' : ActorMethod<[PackageName__1, PackageVersion], undefined>,
193
+ 'restore' : ActorMethod<[bigint, bigint], undefined>,
183
194
  'search' : ActorMethod<
184
195
  [Text, [] | [bigint], [] | [bigint]],
185
196
  [Array<PackageSummary>, PageCount]
@@ -4,7 +4,7 @@ export const idlFactory = ({ IDL }) => {
4
4
  const Result = IDL.Variant({ 'ok' : IDL.Null, 'err' : Err });
5
5
  const Text = IDL.Text;
6
6
  const PackageName__1 = IDL.Text;
7
- const Version = IDL.Text;
7
+ const PackageVersion = IDL.Text;
8
8
  const PackageId = IDL.Text;
9
9
  const Time = IDL.Int;
10
10
  const DownloadsSnapshot__1 = IDL.Record({
@@ -12,10 +12,18 @@ export const idlFactory = ({ IDL }) => {
12
12
  'endTime' : Time,
13
13
  'downloads' : IDL.Nat,
14
14
  });
15
- const Ver = IDL.Text;
16
15
  const FileId = IDL.Text;
17
- const Result_6 = IDL.Variant({ 'ok' : IDL.Vec(FileId), 'err' : Err });
18
- const Result_5 = IDL.Variant({ 'ok' : Ver, 'err' : Err });
16
+ const Result_7 = IDL.Variant({ 'ok' : IDL.Vec(FileId), 'err' : Err });
17
+ const SemverPart = IDL.Variant({
18
+ 'major' : IDL.Null,
19
+ 'minor' : IDL.Null,
20
+ 'patch' : IDL.Null,
21
+ });
22
+ const Result_6 = IDL.Variant({
23
+ 'ok' : IDL.Vec(IDL.Tuple(PackageName__1, PackageVersion)),
24
+ 'err' : Err,
25
+ });
26
+ const Result_5 = IDL.Variant({ 'ok' : PackageVersion, 'err' : Err });
19
27
  const User = IDL.Record({
20
28
  'id' : IDL.Principal,
21
29
  'emailVerified' : IDL.Bool,
@@ -138,14 +146,16 @@ export const idlFactory = ({ IDL }) => {
138
146
  const PublishingErr = IDL.Text;
139
147
  const Result_1 = IDL.Variant({ 'ok' : PublishingId, 'err' : PublishingErr });
140
148
  return IDL.Service({
149
+ 'backup' : IDL.Func([], [], []),
141
150
  'claimAirdrop' : IDL.Func([IDL.Principal], [IDL.Text], []),
142
151
  'finishPublish' : IDL.Func([PublishingId], [Result], []),
143
152
  'getAirdropAmount' : IDL.Func([], [IDL.Nat], ['query']),
144
153
  'getAirdropAmountAll' : IDL.Func([], [IDL.Nat], ['query']),
145
154
  'getApiVersion' : IDL.Func([], [Text], ['query']),
155
+ 'getBackupCanisterId' : IDL.Func([], [IDL.Principal], ['query']),
146
156
  'getDefaultPackages' : IDL.Func(
147
157
  [IDL.Text],
148
- [IDL.Vec(IDL.Tuple(PackageName__1, Version))],
158
+ [IDL.Vec(IDL.Tuple(PackageName__1, PackageVersion))],
149
159
  ['query'],
150
160
  ),
151
161
  'getDownloadTrendByPackageId' : IDL.Func(
@@ -158,7 +168,16 @@ export const idlFactory = ({ IDL }) => {
158
168
  [IDL.Vec(DownloadsSnapshot__1)],
159
169
  ['query'],
160
170
  ),
161
- 'getFileIds' : IDL.Func([PackageName__1, Ver], [Result_6], ['query']),
171
+ 'getFileIds' : IDL.Func(
172
+ [PackageName__1, PackageVersion],
173
+ [Result_7],
174
+ ['query'],
175
+ ),
176
+ 'getHighestSemverBatch' : IDL.Func(
177
+ [IDL.Vec(IDL.Tuple(PackageName__1, PackageVersion, SemverPart))],
178
+ [Result_6],
179
+ ['query'],
180
+ ),
162
181
  'getHighestVersion' : IDL.Func([PackageName__1], [Result_5], ['query']),
163
182
  'getMostDownloadedPackages' : IDL.Func(
164
183
  [],
@@ -172,7 +191,7 @@ export const idlFactory = ({ IDL }) => {
172
191
  ),
173
192
  'getNewPackages' : IDL.Func([], [IDL.Vec(PackageSummary)], ['query']),
174
193
  'getPackageDetails' : IDL.Func(
175
- [PackageName__1, Ver],
194
+ [PackageName__1, PackageVersion],
176
195
  [Result_4],
177
196
  ['query'],
178
197
  ),
@@ -194,7 +213,12 @@ export const idlFactory = ({ IDL }) => {
194
213
  'getTotalDownloads' : IDL.Func([], [IDL.Nat], ['query']),
195
214
  'getTotalPackages' : IDL.Func([], [IDL.Nat], ['query']),
196
215
  'getUser' : IDL.Func([IDL.Principal], [IDL.Opt(User__1)], ['query']),
197
- 'notifyInstall' : IDL.Func([PackageName__1, Ver], [], ['oneway']),
216
+ 'notifyInstall' : IDL.Func(
217
+ [PackageName__1, PackageVersion],
218
+ [],
219
+ ['oneway'],
220
+ ),
221
+ 'restore' : IDL.Func([IDL.Nat, IDL.Nat], [], []),
198
222
  'search' : IDL.Func(
199
223
  [Text, IDL.Opt(IDL.Nat), IDL.Opt(IDL.Nat)],
200
224
  [IDL.Vec(PackageSummary), PageCount],
package/dist/cli.js CHANGED
@@ -20,6 +20,8 @@ import { remove } from './commands/remove.js';
20
20
  import { getUserProp, setUserProp } from './commands/user.js';
21
21
  import { bump } from './commands/bump.js';
22
22
  import { sync } from './commands/sync.js';
23
+ import { outdated } from './commands/outdated.js';
24
+ import { update } from './commands/update.js';
23
25
  // import {docs} from './commands/docs.js';
24
26
  program.name('mops');
25
27
  // --version
@@ -27,10 +29,11 @@ let packageJson = JSON.parse(fs.readFileSync(new URL('package.json', import.meta
27
29
  program.version(`CLI ${packageJson.version}\nAPI ${apiVersion}`, '-v --version');
28
30
  // init
29
31
  program
30
- .command('init [name]')
31
- .description('Create mops.toml')
32
- .action(async (name) => {
33
- await init(name);
32
+ .command('init')
33
+ .description('Initialize a new project or package in the current directory')
34
+ .option('-y, --yes', 'Accept all defaults')
35
+ .action(async (options) => {
36
+ await init(options);
34
37
  });
35
38
  // add
36
39
  program
@@ -99,7 +102,7 @@ program
99
102
  program
100
103
  .command('set-network <network>')
101
104
  .alias('sn')
102
- .description('Set network local|dev|ic')
105
+ .description('Set network local|staging|ic')
103
106
  .action(async (network) => {
104
107
  await setNetwork(network);
105
108
  console.log(`Selected '${network}' network`);
@@ -265,7 +268,7 @@ program
265
268
  .command('bump [major|minor|patch]')
266
269
  .description('Bump current package version')
267
270
  .action(async (part) => {
268
- bump(part);
271
+ await bump(part);
269
272
  });
270
273
  // sync
271
274
  program
@@ -274,4 +277,18 @@ program
274
277
  .action(async () => {
275
278
  await sync();
276
279
  });
280
+ // outdated
281
+ program
282
+ .command('outdated')
283
+ .description('Print outdated dependencies specified in mops.toml')
284
+ .action(async () => {
285
+ await outdated();
286
+ });
287
+ // update
288
+ program
289
+ .command('update [pkg]')
290
+ .description('Update dependencies specified in mops.toml')
291
+ .action(async (pkg) => {
292
+ await update(pkg);
293
+ });
277
294
  program.parse();
@@ -0,0 +1,2 @@
1
+ import { Config } from '../types.js';
2
+ export declare function getAvailableUpdates(config: Config, pkg?: string): Promise<Array<[string, string, string]>>;
@@ -0,0 +1,24 @@
1
+ import chalk from 'chalk';
2
+ import { mainActor } from '../mops.js';
3
+ // [pkg, oldVersion, newVersion]
4
+ export async function getAvailableUpdates(config, pkg) {
5
+ let deps = Object.values(config.dependencies || {});
6
+ let devDeps = Object.values(config['dev-dependencies'] || {});
7
+ let allDeps = [...deps, ...devDeps].filter((dep) => dep.version);
8
+ let depsToUpdate = pkg ? allDeps.filter((dep) => dep.name === pkg) : allDeps;
9
+ let getCurrentVersion = (pkg) => {
10
+ for (let dep of allDeps) {
11
+ if (dep.name === pkg && dep.version) {
12
+ return dep.version;
13
+ }
14
+ }
15
+ return '';
16
+ };
17
+ let actor = await mainActor();
18
+ let res = await actor.getHighestSemverBatch(depsToUpdate.map((dep) => [dep.name, dep.version || '', { major: null }]));
19
+ if ('err' in res) {
20
+ console.log(chalk.red('Error:'), res.err);
21
+ process.exit(1);
22
+ }
23
+ return res.ok.filter((dep) => dep[1] !== getCurrentVersion(dep[0])).map((dep) => [dep[0], getCurrentVersion(dep[0]), dep[1]]);
24
+ }
@@ -1 +1,3 @@
1
- export declare function init(name?: string): Promise<void>;
1
+ export declare function init({ yes }?: {
2
+ yes?: boolean | undefined;
3
+ }): Promise<void>;
@@ -1,59 +1,169 @@
1
1
  import { execSync } from 'node:child_process';
2
2
  import path from 'node:path';
3
- import fs from 'node:fs';
3
+ import { existsSync, readFileSync, writeFileSync } from 'node:fs';
4
4
  import chalk from 'chalk';
5
- import { checkApiCompatibility, mainActor, readDfxJson, writeConfig } from '../mops.js';
5
+ import prompts from 'prompts';
6
+ import { checkApiCompatibility, mainActor, writeConfig } from '../mops.js';
6
7
  import { installAll } from './install-all.js';
7
8
  import { readVesselConfig } from '../vessel.js';
8
- export async function init(name = '') {
9
+ import { template } from './template.js';
10
+ export async function init({ yes = false } = {}) {
9
11
  let configFile = path.join(process.cwd(), 'mops.toml');
10
- let exists = fs.existsSync(configFile);
12
+ let exists = existsSync(configFile);
11
13
  if (exists) {
12
14
  console.log(chalk.yellow('mops.toml already exists'));
13
15
  return;
14
16
  }
15
17
  console.log('Initializing...');
16
18
  let config = {};
19
+ if (yes) {
20
+ await applyInit({
21
+ type: 'project',
22
+ config,
23
+ setupWorkflow: true,
24
+ addTest: false,
25
+ copyrightOwner: '',
26
+ });
27
+ return;
28
+ }
29
+ // migrate from vessel
30
+ let vesselFile = path.join(process.cwd(), 'vessel.dhall');
17
31
  let vesselConfig = { dependencies: [], 'dev-dependencies': [] };
18
- let deps = {};
19
- const vesselFile = path.join(process.cwd(), 'vessel.dhall');
20
- if (fs.existsSync(vesselFile)) {
32
+ if (existsSync(vesselFile)) {
21
33
  console.log('Reading vessel.dhall file');
22
- const res = await readVesselConfig(process.cwd(), { cache: false });
34
+ let res = await readVesselConfig(process.cwd(), { cache: false });
23
35
  if (res) {
24
36
  vesselConfig = { ...res };
25
37
  }
26
38
  }
27
39
  if (vesselConfig.dependencies) {
40
+ let deps = {};
28
41
  deps = {};
29
42
  for (const dep of (vesselConfig.dependencies || [])) {
30
43
  deps[dep.name] = dep;
31
44
  }
45
+ if (Object.keys(deps).length) {
46
+ config.dependencies = deps;
47
+ }
32
48
  }
33
- // lib mode
34
- if (name) {
49
+ let promptsConfig = {
50
+ onCancel() {
51
+ console.log('aborted');
52
+ process.exit(0);
53
+ }
54
+ };
55
+ // type
56
+ let { type } = await prompts({
57
+ type: 'select',
58
+ name: 'type',
59
+ message: 'Select type:',
60
+ choices: [
61
+ { title: `Project ${chalk.dim('(I just want to use mops packages in my project)')}`, value: 'project' },
62
+ { title: `Package ${chalk.dim('(I plan to publish this package on mops)')}`, value: 'package' },
63
+ ],
64
+ }, promptsConfig);
65
+ let addTest = false;
66
+ let copyrightOwner = '';
67
+ // package details
68
+ if (type === 'package') {
69
+ let res = await prompts([
70
+ {
71
+ type: 'text',
72
+ name: 'name',
73
+ message: 'Enter package name:',
74
+ initial: '',
75
+ },
76
+ {
77
+ type: 'text',
78
+ name: 'description',
79
+ message: 'Enter package description:',
80
+ initial: '',
81
+ },
82
+ {
83
+ type: 'text',
84
+ name: 'repository',
85
+ message: 'Enter package repository url:',
86
+ initial: '',
87
+ },
88
+ {
89
+ type: 'text',
90
+ name: 'keywords',
91
+ message: 'Enter keywords separated by spaces:',
92
+ initial: '',
93
+ },
94
+ {
95
+ type: 'select',
96
+ name: 'license',
97
+ message: 'Choose a license:',
98
+ choices: [
99
+ { title: 'MIT', value: 'MIT' },
100
+ { title: 'Apache-2.0', value: 'Apache-2.0' },
101
+ ],
102
+ initial: 0,
103
+ },
104
+ {
105
+ type: 'text',
106
+ name: 'copyrightOwner',
107
+ message: 'Enter license copyright owner:',
108
+ initial: '',
109
+ },
110
+ {
111
+ type: 'confirm',
112
+ name: 'addTest',
113
+ message: `Add example test file? ${chalk.dim('(test/lib.test.mo)')}`,
114
+ initial: true,
115
+ },
116
+ ], promptsConfig);
35
117
  config.package = {
36
- name,
37
- version: '0.1.0',
38
- description: '',
39
- repository: '',
118
+ name: (res.name || '').trim(),
119
+ version: '1.0.0',
120
+ description: (res.description || '').trim(),
121
+ repository: (res.repository || '').trim(),
122
+ keywords: [...new Set(res.keywords.split(' ').filter(Boolean))],
123
+ license: (res.license || '').trim(),
40
124
  };
41
- if (deps) {
42
- config.dependencies = deps;
43
- }
44
- writeConfig(config, configFile);
45
- if (Object.keys(config.dependencies || {}).length) {
46
- await installAll({ verbose: true });
125
+ addTest = res.addTest;
126
+ copyrightOwner = res.copyrightOwner;
127
+ }
128
+ // GitHub workflow
129
+ let { setupWorkflow } = await prompts({
130
+ type: 'confirm',
131
+ name: 'setupWorkflow',
132
+ message: `Setup GitHub workflow? ${chalk.dim('(run `mops test` on push)')}`,
133
+ initial: true,
134
+ }, promptsConfig);
135
+ await applyInit({
136
+ type,
137
+ config,
138
+ setupWorkflow,
139
+ addTest,
140
+ copyrightOwner,
141
+ });
142
+ }
143
+ async function applyInit({ type, config, setupWorkflow, addTest, copyrightOwner }) {
144
+ // set packtool in dfx.json
145
+ let dfxJson = path.resolve(process.cwd(), 'dfx.json');
146
+ let dfxJsonData;
147
+ if (existsSync(dfxJson)) {
148
+ let dfxJsonText = readFileSync(dfxJson).toString();
149
+ dfxJsonData = JSON.parse(dfxJsonText);
150
+ console.log('Setting packtool in dfx.json...');
151
+ dfxJsonData.defaults = dfxJsonData.defaults || {};
152
+ dfxJsonData.defaults.build = dfxJsonData.defaults.build || {};
153
+ if (dfxJsonData.defaults.build.packtool !== 'mops sources') {
154
+ dfxJsonData.defaults.build.packtool = 'mops sources';
155
+ let indent = dfxJsonText.match(/([ \t]+)"/)?.[1] || ' ';
156
+ writeFileSync(path.join(process.cwd(), 'dfx.json'), JSON.stringify(dfxJsonData, null, indent));
157
+ console.log(chalk.green('packtool set to "mops sources"'));
47
158
  }
48
159
  }
49
- // project mode
50
- if (!name) {
160
+ // get default packages
161
+ if (type === 'project') {
51
162
  let compatible = await checkApiCompatibility();
52
163
  if (!compatible) {
53
164
  return;
54
165
  }
55
- let dfxJson = readDfxJson();
56
- let dfxVersion = dfxJson?.dfx || '';
166
+ let dfxVersion = dfxJsonData?.dfx || '';
57
167
  if (!dfxVersion) {
58
168
  try {
59
169
  let res = execSync('dfx --version').toString();
@@ -64,19 +174,54 @@ export async function init(name = '') {
64
174
  }
65
175
  catch { }
66
176
  }
177
+ console.log(`Fetching default packages for dfx ${dfxVersion}...`);
67
178
  let actor = await mainActor();
68
179
  let defaultPackages = await actor.getDefaultPackages(dfxVersion);
69
180
  if (!config.dependencies) {
70
181
  config.dependencies = {};
71
182
  }
72
- if (deps) {
73
- config.dependencies = deps;
74
- }
75
183
  for (let [name, version] of defaultPackages) {
76
184
  config.dependencies[name] = { name, version };
77
185
  }
78
- writeConfig(config, configFile);
186
+ }
187
+ // save config
188
+ let configFile = path.join(process.cwd(), 'mops.toml');
189
+ writeConfig(config, configFile);
190
+ console.log(chalk.green('Created'), 'mops.toml');
191
+ // add src/lib.mo
192
+ if (type === 'package' && !existsSync(path.join(process.cwd(), 'src'))) {
193
+ await template('lib.mo');
194
+ }
195
+ // add src/lib.test.mo
196
+ if (addTest && !existsSync(path.join(process.cwd(), 'test'))) {
197
+ await template('lib.test.mo');
198
+ }
199
+ // add license
200
+ if (config.package?.license) {
201
+ await template(`license:${config.package.license}`, { copyrightOwner });
202
+ }
203
+ // add readme
204
+ if (type === 'package') {
205
+ await template('readme');
206
+ }
207
+ // add GitHub workflow
208
+ if (setupWorkflow) {
209
+ await template('github-workflow:mops-test');
210
+ }
211
+ // add .mops to .gitignore
212
+ {
213
+ let gitignore = path.join(process.cwd(), '.gitignore');
214
+ let gitignoreData = existsSync(gitignore) ? readFileSync(gitignore).toString() : '';
215
+ let lf = gitignoreData.endsWith('\n') ? '\n' : '';
216
+ if (!gitignoreData.includes('.mops')) {
217
+ writeFileSync(gitignore, `${gitignoreData}\n.mops${lf}`.trimStart());
218
+ console.log(chalk.green('Added'), '.mops to .gitignore');
219
+ }
220
+ }
221
+ // install deps
222
+ if (Object.keys(config.dependencies || {}).length) {
223
+ console.log('Installing dependencies...');
79
224
  await installAll({ verbose: true });
80
225
  }
81
- console.log(chalk.green('mops.toml has been created'));
226
+ console.log(chalk.green('Done!'));
82
227
  }
@@ -0,0 +1 @@
1
+ export declare function outdated(): Promise<void>;
@@ -0,0 +1,19 @@
1
+ import chalk from 'chalk';
2
+ import { checkConfigFile, readConfig } from '../mops.js';
3
+ import { getAvailableUpdates } from './available-updates.js';
4
+ export async function outdated() {
5
+ if (!checkConfigFile()) {
6
+ return;
7
+ }
8
+ let config = readConfig();
9
+ let available = await getAvailableUpdates(config);
10
+ if (available.length === 0) {
11
+ console.log(chalk.green('All dependencies are up to date!'));
12
+ }
13
+ else {
14
+ console.log('Available updates:');
15
+ for (let dep of available) {
16
+ console.log(`${dep[0]} ${chalk.yellow(dep[1])} -> ${chalk.green(dep[2])}`);
17
+ }
18
+ }
19
+ }
@@ -1 +1 @@
1
- export declare function template(): Promise<void>;
1
+ export declare function template(templateName?: string, options?: any): Promise<void>;