neutrinos-cli 1.0.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/.configs/auth.json +5 -0
- package/.configs/preferences.json +5 -0
- package/.env +6 -0
- package/README.md +173 -0
- package/bin/cli.js +239 -0
- package/cli-auth/auth.js +54 -0
- package/cli-auth/publish.js +7 -0
- package/cli-auth/server.js +44 -0
- package/cli-auth/services/auth-utils.js +68 -0
- package/commands/alpha-publish.js +219 -0
- package/commands/attribute.js +155 -0
- package/commands/build.js +83 -0
- package/commands/deprecate.js +88 -0
- package/commands/dev.js +21 -0
- package/commands/generate.js +19 -0
- package/commands/new-workspace.js +142 -0
- package/commands/publish.js +334 -0
- package/commands/select-packages.mjs +36 -0
- package/commands/serve.js +27 -0
- package/package.json +34 -0
- package/setup.js +55 -0
- package/templates/assets/default-icon.png +0 -0
- package/templates/component/.component.ts.hbs +126 -0
- package/templates/component/.spec.ts.hbs +15 -0
- package/templates/component/.styles.ts.hbs +2 -0
- package/templates/module/.module.js.hbs +11 -0
- package/templates/plugins-server/index.js +18 -0
- package/templates/project/.vscode/extensions.json +6 -0
- package/templates/project/ATTRIBUTE.md +127 -0
- package/templates/project/Dockerfile +15 -0
- package/templates/project/helmchart/.helmignore +23 -0
- package/templates/project/helmchart/Chart.yaml +24 -0
- package/templates/project/helmchart/templates/NOTES.txt +22 -0
- package/templates/project/helmchart/templates/_helpers.tpl +62 -0
- package/templates/project/helmchart/templates/deployment.yaml +69 -0
- package/templates/project/helmchart/templates/ingress.yaml +62 -0
- package/templates/project/helmchart/templates/service.yaml +14 -0
- package/templates/project/helmchart/values.yaml +74 -0
- package/templates/project/index.html +24 -0
- package/templates/project/index.ts +86 -0
- package/templates/project/public-api.ts +0 -0
- package/templates/project/tsconfig.json +27 -0
- package/utils/attribute-utils.js +149 -0
- package/utils/check-valid-ws.js +21 -0
- package/utils/copy-utils.js +68 -0
- package/utils/create-client.js +23 -0
- package/utils/file-utils.js +43 -0
- package/utils/generate-component.js +101 -0
- package/utils/generate-module.js +51 -0
- package/utils/get-package-info.js +53 -0
- package/utils/get-packages.js +15 -0
- package/utils/inquirer-utils.js +49 -0
- package/utils/logger.js +35 -0
- package/utils/marketplace-api-utils.js +34 -0
- package/utils/path-utils.js +40 -0
- package/utils/prettify.js +36 -0
- package/utils/user-seesion-utils.js +43 -0
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
//@ts-check
|
|
2
|
+
import FormData from 'form-data';
|
|
3
|
+
import { execSync } from 'node:child_process';
|
|
4
|
+
import { writeFileSync } from 'node:fs';
|
|
5
|
+
import { join, sep } from 'node:path';
|
|
6
|
+
import { getAlphaComponentDecorator } from '../utils/attribute-utils.js';
|
|
7
|
+
import { getPackageAssetsDirPath, getPackageIcon, getPackageImages } from '../utils/copy-utils.js';
|
|
8
|
+
import { createZipArchive, getFileReadableStream, getIconStream, getPackageJson } from '../utils/file-utils.js';
|
|
9
|
+
import {
|
|
10
|
+
DISPLAY_NAME_QUERY,
|
|
11
|
+
ICON_FILE_PATH_QUERY,
|
|
12
|
+
IMAGES_FILE_PATH_QUERY,
|
|
13
|
+
inquiry,
|
|
14
|
+
multipleInquiry,
|
|
15
|
+
} from '../utils/inquirer-utils.js';
|
|
16
|
+
import { done } from '../utils/logger.js';
|
|
17
|
+
import { publishToMarketplace } from '../utils/marketplace-api-utils.js';
|
|
18
|
+
import { getDefaultIconPath } from '../utils/path-utils.js';
|
|
19
|
+
import { getLoggedInUserSession } from '../utils/user-seesion-utils.js';
|
|
20
|
+
import { selectPackages } from './select-packages.mjs';
|
|
21
|
+
|
|
22
|
+
export async function publish(name, wsPath, options) {
|
|
23
|
+
const session = await getLoggedInUserSession();
|
|
24
|
+
const packages = (await selectPackages(wsPath, options.all ?? false, name)) || [];
|
|
25
|
+
|
|
26
|
+
await Promise.all(
|
|
27
|
+
packages.map(async (pkgDir) => {
|
|
28
|
+
const packageName = pkgDir.split(sep).pop();
|
|
29
|
+
await processPackagePublish(pkgDir, packageName, wsPath, options || {}, session);
|
|
30
|
+
done(`${packageName} Published Successfully`);
|
|
31
|
+
}),
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function validateAlphaPackage(pkgJsonPath, pkgJson, isModule) {
|
|
36
|
+
if (!pkgJson.alpha) throw new Error('It is not an alpha package');
|
|
37
|
+
if (isModule && pkgJson.alpha.metadata?.exposedName) {
|
|
38
|
+
throw new Error(
|
|
39
|
+
'This package need the exposedName key in metadata with the name of the function or class exported',
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
if (pkgJson.alpha.deprecated) {
|
|
43
|
+
pkgJson.version = '1.0.0';
|
|
44
|
+
delete pkgJson.alpha.packageId;
|
|
45
|
+
delete pkgJson.alpha.versionId;
|
|
46
|
+
delete pkgJson.alpha.deprecated;
|
|
47
|
+
writeFileSync(pkgJsonPath, JSON.stringify(pkgJson, null, 2));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function getPackageInfo(pkgJson, componentDirPath) {
|
|
52
|
+
if (!pkgJson.alpha.component) return { name: pkgJson.name, icon: null };
|
|
53
|
+
|
|
54
|
+
const metadata = getAlphaComponentDecorator(componentDirPath);
|
|
55
|
+
return {
|
|
56
|
+
name: metadata?.label,
|
|
57
|
+
icon: metadata?.icon ? join(getPackageAssetsDirPath(componentDirPath), metadata?.icon) : null,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function updatePackageJson(packageJsonPath, packageJson, packageId, versionId) {
|
|
62
|
+
packageJson.alpha.packageId = packageId;
|
|
63
|
+
packageJson.alpha.versionId = versionId;
|
|
64
|
+
writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async function processPackagePublish(componentDirPath, packageName, wsPath, options, session) {
|
|
68
|
+
const pkgJsonPath = join(componentDirPath, 'package.json');
|
|
69
|
+
const pkgJson = getPackageJson(pkgJsonPath);
|
|
70
|
+
const isModule = pkgJson.alpha.module || pkgJson.alpha.plugin;
|
|
71
|
+
validateAlphaPackage(pkgJsonPath, pkgJson);
|
|
72
|
+
|
|
73
|
+
const zipStream = await createZipArchive(join(componentDirPath, 'dist'), packageName, wsPath, isModule);
|
|
74
|
+
|
|
75
|
+
if (pkgJson.alpha.packageId) {
|
|
76
|
+
return publishVersionedPackage(
|
|
77
|
+
pkgJson,
|
|
78
|
+
pkgJsonPath,
|
|
79
|
+
componentDirPath,
|
|
80
|
+
structuredClone(options),
|
|
81
|
+
zipStream,
|
|
82
|
+
session,
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
return publishNewPackage(
|
|
86
|
+
pkgJson,
|
|
87
|
+
pkgJsonPath,
|
|
88
|
+
componentDirPath,
|
|
89
|
+
structuredClone(options),
|
|
90
|
+
zipStream,
|
|
91
|
+
packageName,
|
|
92
|
+
session,
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
const isProdPublish = (mode) => {
|
|
96
|
+
return mode ? mode.trim().toLowerCase() === 'prod' : false;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
async function publishVersionedPackage(pkgJson, pkgJsonPath, componentDirPath, options, zipStream, session) {
|
|
100
|
+
await incrementPackageVersion(componentDirPath, options);
|
|
101
|
+
pkgJson = getPackageJson(pkgJsonPath);
|
|
102
|
+
const iconStream = options.icon ? getFileReadableStream(options.icon) : null;
|
|
103
|
+
const imagesStream = (options.images || []).map(getFileReadableStream).filter(Boolean);
|
|
104
|
+
const formData = prepareVersionFormData(pkgJson, zipStream, iconStream, imagesStream);
|
|
105
|
+
const response =
|
|
106
|
+
(await publishToMarketplace(formData, pkgJson.alpha.packageId, session, isProdPublish(options.publish))) || {};
|
|
107
|
+
|
|
108
|
+
if (response?.version?.version_id) {
|
|
109
|
+
updatePackageJson(pkgJsonPath, pkgJson, pkgJson.alpha.packageId, response?.version?.version_id);
|
|
110
|
+
}
|
|
111
|
+
return response;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
async function publishNewPackage(pkgJson, pkgJsonPath, componentDirPath, options, zipStream, packageName, session) {
|
|
115
|
+
const pkgInfo = getPackageInfo(pkgJson, componentDirPath);
|
|
116
|
+
options.icon = options.icon ?? pkgInfo.icon;
|
|
117
|
+
options.images = options.images ?? [pkgInfo.icon];
|
|
118
|
+
options.displayName = options.displayName ?? pkgInfo.name;
|
|
119
|
+
|
|
120
|
+
const iconPath =
|
|
121
|
+
options.icon ||
|
|
122
|
+
(options.acceptDefaults ? getDefaultIconPath() : (await getIconPath(componentDirPath)) || getDefaultIconPath());
|
|
123
|
+
const iconStream = getIconStream(iconPath, componentDirPath);
|
|
124
|
+
|
|
125
|
+
const imagesForPkg = options.images?.length
|
|
126
|
+
? options.images
|
|
127
|
+
: options.acceptDefaults
|
|
128
|
+
? []
|
|
129
|
+
: await getImagesPath(componentDirPath);
|
|
130
|
+
|
|
131
|
+
const imagesStream = imagesForPkg.map((imagePath) => getIconStream(imagePath, componentDirPath)).filter(Boolean);
|
|
132
|
+
|
|
133
|
+
const displayName = options.displayName || (await inquiry(DISPLAY_NAME_QUERY)).name;
|
|
134
|
+
|
|
135
|
+
const formData = prepareFormData(displayName, pkgJson, zipStream, iconStream, imagesStream, packageName);
|
|
136
|
+
const response = (await publishToMarketplace(formData, '', session, isProdPublish(options.publish))) || {};
|
|
137
|
+
|
|
138
|
+
if (response.package) {
|
|
139
|
+
updatePackageJson(
|
|
140
|
+
pkgJsonPath,
|
|
141
|
+
pkgJson,
|
|
142
|
+
response.package.package_id,
|
|
143
|
+
response.package.latest_version.version_id,
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
return response;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
async function incrementPackageVersion(componentDirPath, options) {
|
|
150
|
+
const versionType =
|
|
151
|
+
options.versionType ||
|
|
152
|
+
(
|
|
153
|
+
await inquiry({
|
|
154
|
+
type: 'list',
|
|
155
|
+
name: 'type',
|
|
156
|
+
choices: ['patch', 'minor', 'major'],
|
|
157
|
+
message: 'Choose the Version type:',
|
|
158
|
+
})
|
|
159
|
+
).type;
|
|
160
|
+
|
|
161
|
+
execSync(`npm version ${versionType}`, {
|
|
162
|
+
cwd: componentDirPath,
|
|
163
|
+
stdio: 'inherit',
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function prepareVersionFormData(packageJson, zipStream, iconStream, imagesStream) {
|
|
168
|
+
const formData = new FormData();
|
|
169
|
+
const packageMetadata = JSON.stringify({
|
|
170
|
+
platform: 'alpha',
|
|
171
|
+
type: packageJson.alpha.component ? 'component' : 'module',
|
|
172
|
+
hasAlphaOwnership: true,
|
|
173
|
+
metadata: packageJson.alpha.metadata || {},
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
formData.append('version_number', packageJson.version);
|
|
177
|
+
formData.append('zip_file', zipStream);
|
|
178
|
+
formData.append('metadata', packageMetadata);
|
|
179
|
+
if (iconStream) {
|
|
180
|
+
formData.append('icon', iconStream);
|
|
181
|
+
}
|
|
182
|
+
(imagesStream || []).forEach((is) => formData.append('images', is));
|
|
183
|
+
|
|
184
|
+
return formData;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function prepareFormData(name, packageJson, zipStream, iconStream, imagesStream, packageName) {
|
|
188
|
+
const formData = new FormData();
|
|
189
|
+
const packageMetadata = JSON.stringify({
|
|
190
|
+
platform: 'alpha',
|
|
191
|
+
type: packageJson.alpha.component ? 'component' : 'module',
|
|
192
|
+
hasAlphaOwnership: true,
|
|
193
|
+
metadata: packageJson.alpha.metadata || {},
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
formData.append('display_name', name);
|
|
197
|
+
formData.append('package_metadata', packageMetadata);
|
|
198
|
+
formData.append('name', packageName);
|
|
199
|
+
formData.append('version_number', packageJson.version);
|
|
200
|
+
formData.append('package_type', 'zip');
|
|
201
|
+
formData.append('version_metadata', packageMetadata);
|
|
202
|
+
formData.append('description', packageJson.description || 'An alpha component');
|
|
203
|
+
formData.append('zip_file', zipStream);
|
|
204
|
+
if (iconStream) {
|
|
205
|
+
formData.append('icon', iconStream);
|
|
206
|
+
}
|
|
207
|
+
imagesStream.forEach((is) => formData.append('images', is));
|
|
208
|
+
|
|
209
|
+
return formData;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
async function getIconPath(componentDirPath) {
|
|
213
|
+
return getPackageIcon(componentDirPath) || (await inquiry(ICON_FILE_PATH_QUERY)).value;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
async function getImagesPath(componentDirPath) {
|
|
217
|
+
const images = getPackageImages(componentDirPath) || [];
|
|
218
|
+
return images.length ? images : (await multipleInquiry(IMAGES_FILE_PATH_QUERY)).map((img) => img.value);
|
|
219
|
+
}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
//@ts-check
|
|
2
|
+
import { pascalCase } from 'change-case';
|
|
3
|
+
import { updateComponentSource } from '../utils/attribute-utils.js';
|
|
4
|
+
import { getPackageMetadata } from '../utils/get-package-info.js';
|
|
5
|
+
import { inquiry, multipleInquiry } from '../utils/inquirer-utils.js';
|
|
6
|
+
|
|
7
|
+
const UI_TYPES = {
|
|
8
|
+
input: 'UI_TYPE.INPUT',
|
|
9
|
+
toggle: 'UI_TYPE.TOGGLE',
|
|
10
|
+
dropdown: 'UI_TYPE.DROPDOWN',
|
|
11
|
+
'multi-select': 'UI_TYPE.MULTISELECT',
|
|
12
|
+
'typed-input': 'UI_TYPE.TYPED_INPUT',
|
|
13
|
+
range: 'UI_TYPE.RANGE',
|
|
14
|
+
'color-picker': 'UI_TYPE.COLOR_PICKER',
|
|
15
|
+
'data-source': 'UI_TYPE.DATASOURCE',
|
|
16
|
+
'data-set': 'UI_TYPE.DATASET',
|
|
17
|
+
'table-actions': 'UI_TYPE.TABLE_ACTIONS',
|
|
18
|
+
'data-mapping': 'UI_TYPE.DATA_MAPPING',
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const ATTR_TYPES = {
|
|
22
|
+
property: 'ATTRIBUTE_TYPE.PROPERTY',
|
|
23
|
+
event: 'ATTRIBUTE_TYPE.EVENT',
|
|
24
|
+
validation: 'ATTRIBUTE_TYPE.VALIDATION',
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const LABEL_QUERY = {
|
|
28
|
+
type: 'input',
|
|
29
|
+
name: 'label',
|
|
30
|
+
message: 'Label of an attribute : ',
|
|
31
|
+
};
|
|
32
|
+
const PLACEHOLDER_QUERY = {
|
|
33
|
+
type: 'input',
|
|
34
|
+
name: 'placeholder',
|
|
35
|
+
message: 'Placeholder for an attribute : ',
|
|
36
|
+
};
|
|
37
|
+
const CATEGORY_QUERY = {
|
|
38
|
+
type: 'input',
|
|
39
|
+
name: 'category',
|
|
40
|
+
message: 'Category of an attribute : ',
|
|
41
|
+
};
|
|
42
|
+
const DEFAULT_VALUE_QUERY = {
|
|
43
|
+
type: 'input',
|
|
44
|
+
name: 'defaultValue',
|
|
45
|
+
message: 'Default Value : ',
|
|
46
|
+
};
|
|
47
|
+
const EVENT_QUERY = { type: 'input', name: 'event', message: 'Event name : ' };
|
|
48
|
+
const UI_TYPE_QUERY = {
|
|
49
|
+
type: 'list',
|
|
50
|
+
name: 'uiType',
|
|
51
|
+
message: 'UI type of an attribute : ',
|
|
52
|
+
choices: Object.keys(UI_TYPES),
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const FIELD_MAPPING_QUERY = {
|
|
56
|
+
'UI_TYPE.DATA_MAPPING': ['response', 'actions', 'columns', 'actionColumn', 'pagination', 'paginationData'],
|
|
57
|
+
'UI_TYPE.DATASET': ['value'],
|
|
58
|
+
'UI_TYPE.DATASOURCE': ['response', 'label', 'value'],
|
|
59
|
+
'UI_TYPE.TYPED_INPUT': ['type', 'value'],
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const OPTIONS_QUERY = {
|
|
63
|
+
'UI_TYPE.DROPDOWN': ['displayText', 'value'],
|
|
64
|
+
'UI_TYPE.DATA_MAPPING': ['displayText', 'value'],
|
|
65
|
+
'UI_TYPE.TYPED_INPUT': ['name', 'value'],
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const getAttributeMetadata = async (options) => {
|
|
69
|
+
const attrMetadata = { ...(options || {}), type: ATTR_TYPES[options.type] };
|
|
70
|
+
if (!attrMetadata.type) {
|
|
71
|
+
const { attrType } = await inquiry({
|
|
72
|
+
type: 'list',
|
|
73
|
+
name: 'attrType',
|
|
74
|
+
message: 'Type of an attribute : ',
|
|
75
|
+
choices: Object.keys(ATTR_TYPES),
|
|
76
|
+
});
|
|
77
|
+
attrMetadata.type = ATTR_TYPES[attrType];
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (attrMetadata.type === 'ATTRIBUTE_TYPE.EVENT') {
|
|
81
|
+
const eventMetadata = {
|
|
82
|
+
label: attrMetadata.label || (await inquiry(LABEL_QUERY)).label,
|
|
83
|
+
event: attrMetadata.event || (await inquiry(EVENT_QUERY)).event,
|
|
84
|
+
};
|
|
85
|
+
Object.assign(attrMetadata, eventMetadata);
|
|
86
|
+
} else {
|
|
87
|
+
const { uiType } = attrMetadata.uiType ? attrMetadata : await inquiry(UI_TYPE_QUERY);
|
|
88
|
+
|
|
89
|
+
if (!UI_TYPES[uiType]) {
|
|
90
|
+
const message = `${uiType} is not valid ui-type, should be one of === ${Object.keys(UI_TYPES).join(', ')}`;
|
|
91
|
+
throw new Error(message);
|
|
92
|
+
}
|
|
93
|
+
const data = {
|
|
94
|
+
uiType: UI_TYPES[uiType],
|
|
95
|
+
label: attrMetadata.label ?? (await inquiry(LABEL_QUERY)).label,
|
|
96
|
+
placeholder: attrMetadata.placeholder ?? (await inquiry(PLACEHOLDER_QUERY)).placeholder,
|
|
97
|
+
category: attrMetadata.category ?? (await inquiry(CATEGORY_QUERY)).category,
|
|
98
|
+
defaultValue: attrMetadata.defaultValue ?? (await inquiry(DEFAULT_VALUE_QUERY)).defaultValue,
|
|
99
|
+
};
|
|
100
|
+
Object.assign(attrMetadata, data);
|
|
101
|
+
|
|
102
|
+
const fieldMappings = FIELD_MAPPING_QUERY[attrMetadata.uiType];
|
|
103
|
+
if (fieldMappings) {
|
|
104
|
+
attrMetadata.fieldMappings =
|
|
105
|
+
options.fieldMappings ||
|
|
106
|
+
(await inquiry(
|
|
107
|
+
fieldMappings.map((f) => ({
|
|
108
|
+
type: 'input',
|
|
109
|
+
name: f,
|
|
110
|
+
message: `Field mapping for ${f} field : `,
|
|
111
|
+
})),
|
|
112
|
+
));
|
|
113
|
+
} else {
|
|
114
|
+
attrMetadata.fieldMappings =
|
|
115
|
+
options.fieldMappings ||
|
|
116
|
+
(
|
|
117
|
+
await inquiry({
|
|
118
|
+
type: 'input',
|
|
119
|
+
name: 'value',
|
|
120
|
+
message: `Field mapping : `,
|
|
121
|
+
})
|
|
122
|
+
).value;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const attrOptions = OPTIONS_QUERY[attrMetadata.uiType];
|
|
126
|
+
if (attrOptions && !attrMetadata.options) {
|
|
127
|
+
const addOptions = (
|
|
128
|
+
await inquiry({
|
|
129
|
+
type: 'confirm',
|
|
130
|
+
name: 'value',
|
|
131
|
+
message: 'Do you want to add options?',
|
|
132
|
+
default: true,
|
|
133
|
+
})
|
|
134
|
+
).value;
|
|
135
|
+
if (addOptions) {
|
|
136
|
+
const query = attrOptions.map((o) => ({
|
|
137
|
+
type: 'input',
|
|
138
|
+
name: o,
|
|
139
|
+
message: `Enter the ${pascalCase(o)} : `,
|
|
140
|
+
}));
|
|
141
|
+
attrMetadata.options = await multipleInquiry(query, 'option');
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return attrMetadata;
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
export const addAttribute = async (name, wsPath, options) => {
|
|
150
|
+
const { componentDirPath, packageName } = await getPackageMetadata(wsPath, name, 'component');
|
|
151
|
+
const attrMetadata = await getAttributeMetadata(options);
|
|
152
|
+
|
|
153
|
+
console.log(attrMetadata);
|
|
154
|
+
updateComponentSource(attrMetadata, wsPath, componentDirPath, packageName);
|
|
155
|
+
};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
import { execSync } from 'node:child_process';
|
|
3
|
+
import { cpSync } from 'node:fs';
|
|
4
|
+
import { join, sep } from 'node:path';
|
|
5
|
+
import { build as _build } from 'vite';
|
|
6
|
+
import { getPackageJson } from '../utils/file-utils.js';
|
|
7
|
+
import { done, inprogress } from '../utils/logger.js';
|
|
8
|
+
import { getGeneratedComponentName } from '../utils/path-utils.js';
|
|
9
|
+
import { selectPackages } from './select-packages.mjs';
|
|
10
|
+
/**
|
|
11
|
+
* Builds the plugin and copies the assets to the static server
|
|
12
|
+
* @param {string} wsPath - The workspace directory
|
|
13
|
+
*/
|
|
14
|
+
export const build = {
|
|
15
|
+
plugins: async (wsPath, pluginName = '', option) => {
|
|
16
|
+
const packagesPaths = await selectPackages(wsPath, option.all ?? false, pluginName);
|
|
17
|
+
await buildComponents(packagesPaths, wsPath, option.module ?? false);
|
|
18
|
+
inprogress('Copying the assets to static server');
|
|
19
|
+
for (const path of packagesPaths) {
|
|
20
|
+
cpSync(join(path, 'dist'), join(wsPath, 'plugins-server', 'plugins'), {
|
|
21
|
+
recursive: true,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
done('Plugin built');
|
|
25
|
+
},
|
|
26
|
+
docker: async (wsPath, pluginName = '') => {
|
|
27
|
+
await build.plugins(wsPath, pluginName);
|
|
28
|
+
inprogress('Building the docker image');
|
|
29
|
+
execSync('docker build -t plugins-server:latest .', {
|
|
30
|
+
cwd: wsPath,
|
|
31
|
+
stdio: 'inherit',
|
|
32
|
+
});
|
|
33
|
+
done('Docker image built');
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Builds the components in the workspace
|
|
39
|
+
* @param {string[]} packages - The paths of the packages in the workspace
|
|
40
|
+
* @param {string} wsPath - The workspace directory
|
|
41
|
+
*/
|
|
42
|
+
const buildComponents = async (packages, wsPath, isModule) => {
|
|
43
|
+
inprogress('Building the plugins');
|
|
44
|
+
if (!isModule) {
|
|
45
|
+
execSync('npx tsc -p ./tsconfig.json', {
|
|
46
|
+
cwd: wsPath,
|
|
47
|
+
stdio: 'inherit',
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
for (const packagePath of packages) {
|
|
52
|
+
const packageName = packagePath.split(sep).pop() || '';
|
|
53
|
+
const packageJson = getPackageJson(join(packagePath, 'package.json'));
|
|
54
|
+
const entryFile = join(
|
|
55
|
+
packagePath,
|
|
56
|
+
packageJson.alpha?.component
|
|
57
|
+
? getGeneratedComponentName(packageName) + '.ts'
|
|
58
|
+
: packageJson.alpha?.module || packageJson.alpha?.plugin
|
|
59
|
+
? packageJson.entryFile || 'index.js'
|
|
60
|
+
: '',
|
|
61
|
+
);
|
|
62
|
+
const outputDir = join(packagePath, 'dist');
|
|
63
|
+
await _build({
|
|
64
|
+
build: {
|
|
65
|
+
lib: {
|
|
66
|
+
entry: entryFile,
|
|
67
|
+
name: packagePath,
|
|
68
|
+
fileName: () => `${packageName}.js`,
|
|
69
|
+
formats: ['es'],
|
|
70
|
+
},
|
|
71
|
+
outDir: join(outputDir),
|
|
72
|
+
minify: true,
|
|
73
|
+
emptyOutDir: true,
|
|
74
|
+
rollupOptions: {
|
|
75
|
+
output: {
|
|
76
|
+
inlineDynamicImports: true,
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
done('Plugins built');
|
|
83
|
+
};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
//@ts-check
|
|
2
|
+
import axios from 'axios';
|
|
3
|
+
import { red } from 'colorette';
|
|
4
|
+
import { readFileSync, writeFileSync } from 'node:fs';
|
|
5
|
+
import { join, sep } from 'node:path';
|
|
6
|
+
import { inquiry } from '../utils/inquirer-utils.js';
|
|
7
|
+
import { done, inprogress } from '../utils/logger.js';
|
|
8
|
+
import { getLoggedInUserSession } from '../utils/user-seesion-utils.js';
|
|
9
|
+
import { selectPackages } from './select-packages.mjs';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
*
|
|
13
|
+
* @param {string} packageName
|
|
14
|
+
* @returns
|
|
15
|
+
*/
|
|
16
|
+
const CONFIRM_INQUIRY = (packageName) => {
|
|
17
|
+
return {
|
|
18
|
+
type: 'Confirm',
|
|
19
|
+
name: 'deletePackage',
|
|
20
|
+
message: `Are you sure you want to deprecate ${red(packageName)} package?`,
|
|
21
|
+
default: false,
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
*
|
|
27
|
+
* @param {string} pkgName
|
|
28
|
+
* @param {string} wsPath
|
|
29
|
+
* @param {any} options
|
|
30
|
+
*/
|
|
31
|
+
export const deprecate = async (pkgName, wsPath, options) => {
|
|
32
|
+
const session = await getLoggedInUserSession();
|
|
33
|
+
const packages = await selectPackages(wsPath, options.all ?? false, pkgName);
|
|
34
|
+
await Promise.all(
|
|
35
|
+
packages.map(async (componentDirPath) => {
|
|
36
|
+
try {
|
|
37
|
+
const packageName = componentDirPath.split(sep).pop();
|
|
38
|
+
if (!options.yes) {
|
|
39
|
+
//@ts-ignore
|
|
40
|
+
const { deletePackage } = await inquiry(CONFIRM_INQUIRY(packageName));
|
|
41
|
+
if (!deletePackage) return;
|
|
42
|
+
}
|
|
43
|
+
const pkgJsonPath = join(componentDirPath, 'package.json');
|
|
44
|
+
const pkgJson = JSON.parse(readFileSync(pkgJsonPath, 'utf-8'));
|
|
45
|
+
const { packageId, deprecated } = pkgJson.alpha || {};
|
|
46
|
+
if (!packageId) {
|
|
47
|
+
throw new Error(`${packageName} is not published to deprecate`);
|
|
48
|
+
}
|
|
49
|
+
if (deprecated) {
|
|
50
|
+
throw new Error(`${packageName} is already deprecated`);
|
|
51
|
+
}
|
|
52
|
+
inprogress(`Deprecating ${packageName}`);
|
|
53
|
+
await deprecatePackage(packageId, session);
|
|
54
|
+
done(`${packageName} Deprecated successfully`);
|
|
55
|
+
pkgJson.alpha.deprecated = true;
|
|
56
|
+
writeFileSync(pkgJsonPath, JSON.stringify(pkgJson, null, 2));
|
|
57
|
+
} catch (err) {
|
|
58
|
+
//@ts-ignore
|
|
59
|
+
console.error(err.message);
|
|
60
|
+
}
|
|
61
|
+
}),
|
|
62
|
+
);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
*
|
|
67
|
+
* @param {string} packageId
|
|
68
|
+
* @param {any} session
|
|
69
|
+
* @returns
|
|
70
|
+
*/
|
|
71
|
+
const deprecatePackage = async (packageId, session) => {
|
|
72
|
+
const url = process.env.MARKETPLACE_URL + packageId;
|
|
73
|
+
const config = {
|
|
74
|
+
method: 'delete',
|
|
75
|
+
url,
|
|
76
|
+
headers: {
|
|
77
|
+
Authorization: `${session.token_type} ${session.access_token}`,
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
try {
|
|
82
|
+
const response = await axios.request(config);
|
|
83
|
+
return response.data;
|
|
84
|
+
} catch (e) {
|
|
85
|
+
//@ts-ignore
|
|
86
|
+
throw new Error(e);
|
|
87
|
+
}
|
|
88
|
+
};
|
package/commands/dev.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { createServer } from 'vite';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Serve the plugin.
|
|
5
|
+
* @param {string} wsPath - The path to the workspace.
|
|
6
|
+
* @param {number} port - The port to serve the plugin.
|
|
7
|
+
*/
|
|
8
|
+
export const servePlugin = async (wsPath, port) => {
|
|
9
|
+
const server = await createServer({
|
|
10
|
+
configFile: false,
|
|
11
|
+
root: wsPath,
|
|
12
|
+
server: {
|
|
13
|
+
port,
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
await server.listen();
|
|
17
|
+
|
|
18
|
+
server.printUrls();
|
|
19
|
+
|
|
20
|
+
server.bindCLIShortcuts({ print: true });
|
|
21
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { generateComponentPackageInWorkspace } from '../utils/generate-component.js';
|
|
2
|
+
import { generateModulePackageInWorkspace } from '../utils/generate-module.js';
|
|
3
|
+
import { log } from '../utils/logger.js';
|
|
4
|
+
|
|
5
|
+
export const generate = {
|
|
6
|
+
component: async ({ name, dir, description }) => {
|
|
7
|
+
return generateComponentPackageInWorkspace(dir, name, description);
|
|
8
|
+
},
|
|
9
|
+
module: async ({ name, dir, description }) => {
|
|
10
|
+
return generateModulePackageInWorkspace(dir, name, description);
|
|
11
|
+
},
|
|
12
|
+
/**
|
|
13
|
+
* This may look weird, but it's a way to handle unknown plugin type generation
|
|
14
|
+
*/
|
|
15
|
+
undefined: async () => {
|
|
16
|
+
log('Please provide a valid command');
|
|
17
|
+
process.exit(1);
|
|
18
|
+
},
|
|
19
|
+
};
|