-
Notifications
You must be signed in to change notification settings - Fork 0
/
create.ts
75 lines (62 loc) · 2.34 KB
/
create.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
* Copyright (c) 2021, jayree
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import { dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
import { flags, SfdxCommand } from '@salesforce/command';
import { Messages } from '@salesforce/core';
import { AnyJson } from '@salesforce/ts-types';
import AdmZip from 'adm-zip';
import { js2Manifest } from '../../../utils/xml.js';
// eslint-disable-next-line no-underscore-dangle
const __filename = fileURLToPath(import.meta.url);
// eslint-disable-next-line no-underscore-dangle
const __dirname = dirname(__filename);
Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@jayree/sfdx-plugin-legacy', 'createpackagedescription');
export default class CreatePackageDescription extends SfdxCommand {
// hotfix to receive only one help page
// public static hidden = true;
public static description = messages.getMessage('commandDescription');
public static examples = [
`$ sfdx jayree:packagedescription:create --file FILENAME --description 'DESCRIPTION'
`,
];
public static args = [{ name: 'file' }];
protected static flagsConfig = {
file: flags.string({
char: 'f',
description: messages.getMessage('fileFlagDescription'),
required: true,
}),
description: flags.string({
char: 'd',
description: messages.getMessage('descriptionFlagDescription'),
dependsOn: ['file'],
required: true,
}),
};
protected static requiresUsername = false;
protected static supportsDevhubUsername = false;
protected static requiresProject = false;
// eslint-disable-next-line @typescript-eslint/require-await
public async run(): Promise<AnyJson> {
const inputfile = this.args.file || this.flags.file;
const newZip = new AdmZip();
const text = this.flags.description.replace(/\\n/g, '\n');
const fileContentjs = {
Package: {
description: [text],
version: ['52.0'],
},
};
newZip.addFile('unpackaged/package.xml', Buffer.from(js2Manifest(fileContentjs)), '', 0o644);
newZip.writeZip(inputfile);
// this.ux.log(newZip.getEntries()[0].header.toString());
this.ux.log(text);
return { description: text, task: 'created' };
}
}