@contember/create 2.0.0-alpha.14 → 2.0.0-alpha.16
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/dist/development/run.cjs +0 -2
- package/dist/development/run.cjs.map +1 -1
- package/dist/development/run.js +0 -2
- package/dist/development/run.js.map +1 -1
- package/dist/development/src/lib/TemplateInstaller.cjs +1 -8
- package/dist/development/src/lib/TemplateInstaller.cjs.map +1 -1
- package/dist/development/src/lib/TemplateInstaller.js +2 -9
- package/dist/development/src/lib/TemplateInstaller.js.map +1 -1
- package/dist/production/run.cjs +0 -2
- package/dist/production/run.cjs.map +1 -1
- package/dist/production/run.js +0 -2
- package/dist/production/run.js.map +1 -1
- package/dist/production/src/lib/TemplateInstaller.cjs +1 -8
- package/dist/production/src/lib/TemplateInstaller.cjs.map +1 -1
- package/dist/production/src/lib/TemplateInstaller.js +2 -9
- package/dist/production/src/lib/TemplateInstaller.js.map +1 -1
- package/dist/types/lib/TemplateInstaller.d.ts +1 -3
- package/dist/types/lib/TemplateInstaller.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -9
- package/resources/templates/template-workspace/admin/lib/binding/binding.tsx +2 -0
- package/resources/templates/template-workspace/admin/lib/binding/hooks.tsx +2 -2
- package/resources/templates/template-workspace/admin/lib/binding/navigation-guard-dialog.tsx +39 -0
- package/resources/templates/template-workspace/admin/lib/datagrid/toolbar.tsx +1 -1
- package/resources/templates/template-workspace/admin/lib/dict.ts +49 -3
- package/resources/templates/template-workspace/admin/lib/dimensions/dimensions.tsx +1 -1
- package/resources/templates/template-workspace/admin/lib/editor/common/editor-canvas.tsx +2 -2
- package/resources/templates/template-workspace/admin/lib/tenant/forms/memberships-control.tsx +1 -1
- package/resources/templates/template-workspace/admin/lib/tenant/forms/password-reset.tsx +2 -1
- package/resources/templates/template-workspace/admin/lib/tenant/forms/passwordless-signin-init.tsx +31 -0
- package/resources/templates/template-workspace/admin/lib/tenant/forms/passwordless-signin.tsx +59 -0
- package/resources/templates/template-workspace/admin/lib/utils/uic.tsx +3 -3
- package/src/lib/TemplateInstaller.ts +2 -9
- package/src/run.ts +0 -2
- package/dist/development/src/lib/PackageDownloader.cjs +0 -33
- package/dist/development/src/lib/PackageDownloader.cjs.map +0 -1
- package/dist/development/src/lib/PackageDownloader.js +0 -33
- package/dist/development/src/lib/PackageDownloader.js.map +0 -1
- package/dist/production/src/lib/PackageDownloader.cjs +0 -33
- package/dist/production/src/lib/PackageDownloader.cjs.map +0 -1
- package/dist/production/src/lib/PackageDownloader.js +0 -33
- package/dist/production/src/lib/PackageDownloader.js.map +0 -1
- package/dist/types/lib/PackageDownloader.d.ts +0 -7
- package/dist/types/lib/PackageDownloader.d.ts.map +0 -1
- package/src/lib/PackageDownloader.ts +0 -33
package/package.json
CHANGED
|
@@ -1,17 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contember/create",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.16",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"bin": "dist/production/run.js",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@contember/cli-common": "2.0.0-alpha.
|
|
8
|
-
"chalk": "^
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"get-package-json-from-registry": "^2.2.2",
|
|
12
|
-
"js-yaml": "^4.1.0",
|
|
13
|
-
"npm-package-arg": "^11.0.1",
|
|
14
|
-
"registry-info": "^1.0.0"
|
|
7
|
+
"@contember/cli-common": "2.0.0-alpha.16",
|
|
8
|
+
"chalk": "^5.3.0",
|
|
9
|
+
"fs-extra": "^11.2.0",
|
|
10
|
+
"js-yaml": "^4.1.0"
|
|
15
11
|
},
|
|
16
12
|
"type": "module",
|
|
17
13
|
"main": "./dist/production/index.js",
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { ReactNode, useEffect } from 'react'
|
|
2
2
|
import { AccessorTreeState, DataBindingProvider } from '@contember/interface'
|
|
3
3
|
import { Loader } from '../ui/loader'
|
|
4
|
+
import { NavigationGuardDialog } from './navigation-guard-dialog'
|
|
4
5
|
|
|
5
6
|
export const Binding = ({ children }: {
|
|
6
7
|
children: ReactNode
|
|
7
8
|
}) => {
|
|
8
9
|
return (
|
|
9
10
|
<DataBindingProvider stateComponent={BindingStateRenderer}>
|
|
11
|
+
<NavigationGuardDialog />
|
|
10
12
|
{children}
|
|
11
13
|
</DataBindingProvider>
|
|
12
14
|
)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useCallback } from 'react'
|
|
2
2
|
import { dict } from '../dict'
|
|
3
3
|
import { ToastContent, useShowToast } from '../toast'
|
|
4
|
-
import {
|
|
4
|
+
import { ErrorPersistResult, SuccessfulPersistResult, usePersist } from '@contember/interface'
|
|
5
5
|
import { useErrorFormatter } from '../errors'
|
|
6
6
|
|
|
7
7
|
export const usePersistWithFeedback = () => {
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { useCallback, useState } from 'react'
|
|
2
|
+
import { AlertDialog, AlertDialogCancel, AlertDialogContent, AlertDialogTitle } from '../ui/alert-dialog'
|
|
3
|
+
import { BlockNavigationOnDirtyStateResult, useBlockNavigationOnDirtyState } from '@contember/interface'
|
|
4
|
+
import { usePersistFeedbackHandlers } from './hooks'
|
|
5
|
+
import { Button } from '../ui/button'
|
|
6
|
+
import { SaveIcon } from 'lucide-react'
|
|
7
|
+
|
|
8
|
+
export const NavigationGuardDialog = () => {
|
|
9
|
+
const [resolver, setResolver] = useState<((value: BlockNavigationOnDirtyStateResult) => void) | null>(null)
|
|
10
|
+
|
|
11
|
+
const handler = useCallback(() => new Promise<BlockNavigationOnDirtyStateResult>(resolve => {
|
|
12
|
+
setResolver(() => (value: BlockNavigationOnDirtyStateResult) => {
|
|
13
|
+
setResolver(null)
|
|
14
|
+
resolve(value)
|
|
15
|
+
})
|
|
16
|
+
}), [])
|
|
17
|
+
|
|
18
|
+
useBlockNavigationOnDirtyState(handler, usePersistFeedbackHandlers())
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<AlertDialog open={resolver !== null} onOpenChange={it => it ? null : resolver?.('cancel')}>
|
|
22
|
+
<AlertDialogContent>
|
|
23
|
+
<AlertDialogTitle>Unsaved changes</AlertDialogTitle>
|
|
24
|
+
Do you want to save your changes before leaving?
|
|
25
|
+
<div className="flex gap-2 justify-end">
|
|
26
|
+
<Button onClick={() => resolver?.('save')}>
|
|
27
|
+
<SaveIcon className="w-4 h-4 mr-2" />
|
|
28
|
+
Save
|
|
29
|
+
</Button>
|
|
30
|
+
<Button onClick={() => resolver?.('discard')} variant="outline"
|
|
31
|
+
className="border-destructive/50 text-destructive hover:bg-red-100 hover:text-destructive">
|
|
32
|
+
Don't save
|
|
33
|
+
</Button>
|
|
34
|
+
<AlertDialogCancel onClick={() => resolver?.('cancel')} className="border-gray-500">Cancel</AlertDialogCancel>
|
|
35
|
+
</div>
|
|
36
|
+
</AlertDialogContent>
|
|
37
|
+
</AlertDialog>
|
|
38
|
+
)
|
|
39
|
+
}
|
|
@@ -36,7 +36,7 @@ export const DataGridToolbar = Component<DataGridToolbarProps>(({ children }) =>
|
|
|
36
36
|
</Button>
|
|
37
37
|
|
|
38
38
|
<Popover>
|
|
39
|
-
<PopoverTrigger>
|
|
39
|
+
<PopoverTrigger asChild>
|
|
40
40
|
<Button variant={'outline'} size={'sm'} className={'gap-2'}>
|
|
41
41
|
<SettingsIcon className={'w-4 h-4'} />
|
|
42
42
|
</Button>
|
|
@@ -2,7 +2,8 @@ import { TextFilterArtifactsMatchMode } from '@contember/react-dataview'
|
|
|
2
2
|
import { InviteErrorCodes } from './tenant/hooks/useInvite'
|
|
3
3
|
import { UploaderErrorType } from '@contember/react-uploader'
|
|
4
4
|
import { ChangeMyPasswordFormErrorCode, CreateApiKeyFormErrorCode } from '@contember/interface'
|
|
5
|
-
import { InviteFormErrorCode, LoginFormErrorCode, OtpPrepareFormErrorCode, OtpConfirmFormErrorCode, PasswordResetFormErrorCode, PasswordResetRequestFormErrorCode, UpdateProjectMemberFormErrorCode } from '@contember/react-identity'
|
|
5
|
+
import { InviteFormErrorCode, LoginFormErrorCode, OtpPrepareFormErrorCode, OtpConfirmFormErrorCode, PasswordResetFormErrorCode, PasswordResetRequestFormErrorCode, UpdateProjectMemberFormErrorCode, PasswordlessSignInInitFormErrorCode, PasswordlessSignInFormErrorCode } from '@contember/react-identity'
|
|
6
|
+
import { ActivatePasswordlessOtpErrorCode } from '@contember/graphql-client-tenant'
|
|
6
7
|
|
|
7
8
|
export const dict = {
|
|
8
9
|
deleteEntityDialog: {
|
|
@@ -194,7 +195,7 @@ export const dict = {
|
|
|
194
195
|
login: {
|
|
195
196
|
email: 'Email',
|
|
196
197
|
password: 'Password',
|
|
197
|
-
otpToken: 'OTP token',
|
|
198
|
+
otpToken: '2FA OTP token',
|
|
198
199
|
forgotPassword: 'Forgot password?',
|
|
199
200
|
login: 'Login',
|
|
200
201
|
errorMessages: {
|
|
@@ -275,13 +276,14 @@ export const dict = {
|
|
|
275
276
|
'TOKEN_EXPIRED': 'Token expired',
|
|
276
277
|
'TOKEN_NOT_FOUND': 'Token not found',
|
|
277
278
|
'TOKEN_USED': 'Token already used',
|
|
279
|
+
'TOKEN_INVALID': 'Invalid token',
|
|
278
280
|
} satisfies Record<PasswordResetFormErrorCode, string>,
|
|
279
281
|
title: 'Reset password',
|
|
280
282
|
description: 'Enter new password below',
|
|
281
283
|
success: 'Password has been reset',
|
|
282
284
|
},
|
|
283
285
|
passwordResetRequest: {
|
|
284
|
-
email: '
|
|
286
|
+
email: 'E-mail',
|
|
285
287
|
submit: 'Request reset code',
|
|
286
288
|
errorMessages: {
|
|
287
289
|
'FIELD_REQUIRED': 'This field is required',
|
|
@@ -295,6 +297,50 @@ export const dict = {
|
|
|
295
297
|
checkMail: 'Please check your mailbox for instructions on how to reset your password.',
|
|
296
298
|
entryCode: 'Or enter the reset code directly.',
|
|
297
299
|
},
|
|
300
|
+
passwordlessSignInInit: {
|
|
301
|
+
email: 'E-mail',
|
|
302
|
+
submit: 'Send magic link',
|
|
303
|
+
errorMessages: {
|
|
304
|
+
'FIELD_REQUIRED': 'This field is required',
|
|
305
|
+
'INVALID_VALUE': 'Invalid value',
|
|
306
|
+
'UNKNOWN_ERROR': 'Something went wrong. Please try again later',
|
|
307
|
+
'PERSON_NOT_FOUND': 'Unknown email',
|
|
308
|
+
'PASSWORDLESS_DISABLED': 'Passwordless sign-in is not available',
|
|
309
|
+
} satisfies Record<PasswordlessSignInInitFormErrorCode, string>,
|
|
310
|
+
title: 'Sign in',
|
|
311
|
+
description: 'Enter your email below to sign in to your account',
|
|
312
|
+
success: 'Magic link has been sent',
|
|
313
|
+
checkMail: 'Please check your mailbox for instructions on how to sign in.',
|
|
314
|
+
entryCode: 'Or enter the reset code directly.',
|
|
315
|
+
},
|
|
316
|
+
passwordlessSignIn: {
|
|
317
|
+
token: 'Verification code',
|
|
318
|
+
otpToken: '2FA OTP token',
|
|
319
|
+
submit: 'Sign in',
|
|
320
|
+
errorMessages: {
|
|
321
|
+
'FIELD_REQUIRED': 'This field is required',
|
|
322
|
+
'INVALID_VALUE': 'Invalid value',
|
|
323
|
+
'UNKNOWN_ERROR': 'Something went wrong. Please try again later',
|
|
324
|
+
'INVALID_OTP_TOKEN': 'Invalid OTP token',
|
|
325
|
+
'OTP_REQUIRED': undefined,
|
|
326
|
+
'PERSON_DISABLED': 'Person disabled',
|
|
327
|
+
'TOKEN_EXPIRED': 'Token expired',
|
|
328
|
+
'TOKEN_NOT_FOUND': 'Token not found',
|
|
329
|
+
'TOKEN_USED': 'Token already used',
|
|
330
|
+
'TOKEN_INVALID': 'Invalid token',
|
|
331
|
+
} satisfies Record<PasswordlessSignInFormErrorCode, string | undefined>,
|
|
332
|
+
title: 'Sign in',
|
|
333
|
+
},
|
|
334
|
+
otpActivation: {
|
|
335
|
+
errorMessages: {
|
|
336
|
+
'TOKEN_INVALID': 'This token is not valid. Please try again.',
|
|
337
|
+
'TOKEN_USED': 'Token already used',
|
|
338
|
+
'TOKEN_NOT_FOUND': 'Token not found',
|
|
339
|
+
'TOKEN_EXPIRED': 'Token expired',
|
|
340
|
+
'UNKNOWN_ERROR': 'Something went wrong. Please try again later',
|
|
341
|
+
} satisfies Record<ActivatePasswordlessOtpErrorCode | 'UNKNOWN_ERROR', string>,
|
|
342
|
+
},
|
|
343
|
+
|
|
298
344
|
updateProjectMember: {
|
|
299
345
|
updateSuccess: 'Roles updated',
|
|
300
346
|
roles: 'Roles',
|
|
@@ -39,7 +39,7 @@ export const DimensionsSwitcher = Component(({ options, dimension, children, slu
|
|
|
39
39
|
<DataViewLoaderState loaded>
|
|
40
40
|
|
|
41
41
|
<Popover>
|
|
42
|
-
<PopoverTrigger>
|
|
42
|
+
<PopoverTrigger asChild>
|
|
43
43
|
<Button variant={'outline'} size="sm">
|
|
44
44
|
<DimensionSwitcherCurrentValues dimension={dimension} slugField={slugField}>
|
|
45
45
|
{children}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { dataAttribute } from '@contember/utilities'
|
|
2
|
-
import { memo, ReactElement, ReactNode, TextareaHTMLAttributes } from 'react'
|
|
2
|
+
import { ComponentType, memo, ReactElement, ReactNode, TextareaHTMLAttributes } from 'react'
|
|
3
3
|
|
|
4
4
|
export interface HTMLTextAreaDivTargetProps extends TextareaHTMLAttributes<HTMLDivElement> { }
|
|
5
5
|
|
|
6
6
|
export interface EditorCanvasProps<P extends HTMLTextAreaDivTargetProps> {
|
|
7
|
-
underlyingComponent:
|
|
7
|
+
underlyingComponent: ComponentType<P>
|
|
8
8
|
componentProps: P
|
|
9
9
|
focusRing?: boolean
|
|
10
10
|
children?: ReactNode
|
package/resources/templates/template-workspace/admin/lib/tenant/forms/memberships-control.tsx
CHANGED
|
@@ -83,7 +83,7 @@ export const MembershipsControl = ({ setMemberships, memberships, roles }: Membe
|
|
|
83
83
|
})}
|
|
84
84
|
<div>
|
|
85
85
|
{remainingRoles.length ? <DropdownMenu>
|
|
86
|
-
<DropdownMenuTrigger>
|
|
86
|
+
<DropdownMenuTrigger asChild>
|
|
87
87
|
<Button variant="outline"><PlusIcon className="w-3 h-3" /></Button>
|
|
88
88
|
</DropdownMenuTrigger>
|
|
89
89
|
<DropdownMenuContent>
|
|
@@ -7,6 +7,7 @@ import { dict } from '../../dict'
|
|
|
7
7
|
|
|
8
8
|
export const PasswordResetFormFields = ({ hasToken }: { hasToken?: boolean }) => {
|
|
9
9
|
const form = usePasswordResetForm()
|
|
10
|
+
const fieldErrors = form.errors.map(it => it.field)
|
|
10
11
|
return (
|
|
11
12
|
<div className="relative flex flex-col gap-2">
|
|
12
13
|
{form.state === 'success' || form.state === 'submitting' ? <Loader position="absolute" /> : null}
|
|
@@ -15,7 +16,7 @@ export const PasswordResetFormFields = ({ hasToken }: { hasToken?: boolean }) =>
|
|
|
15
16
|
form={form} messages={dict.tenant.passwordReset.errorMessages}
|
|
16
17
|
/>
|
|
17
18
|
|
|
18
|
-
{hasToken
|
|
19
|
+
{(!hasToken || fieldErrors.includes('token')) && (
|
|
19
20
|
<TenantFormField
|
|
20
21
|
form={form} messages={dict.tenant.passwordReset.errorMessages} field="token"
|
|
21
22
|
type="text" required autoComplete="off"
|
package/resources/templates/template-workspace/admin/lib/tenant/forms/passwordless-signin-init.tsx
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { usePasswordlessSignInInitForm } from '@contember/react-identity'
|
|
2
|
+
import { Button } from '../../ui/button'
|
|
3
|
+
import { Loader } from '../../ui/loader'
|
|
4
|
+
import { TenantFormError, TenantFormField } from './common'
|
|
5
|
+
import { dict } from '../../dict'
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
export const PasswordlessSignInInitFormFields = () => {
|
|
9
|
+
const form = usePasswordlessSignInInitForm()
|
|
10
|
+
return (
|
|
11
|
+
<div className="relative flex flex-col gap-2">
|
|
12
|
+
{form.state === 'success' || form.state === 'submitting' ? <Loader position="absolute" /> : null}
|
|
13
|
+
|
|
14
|
+
<TenantFormError
|
|
15
|
+
form={form} messages={dict.tenant.passwordlessSignInInit.errorMessages}
|
|
16
|
+
/>
|
|
17
|
+
|
|
18
|
+
<TenantFormField
|
|
19
|
+
form={form} messages={dict.tenant.passwordlessSignInInit.errorMessages} field="email"
|
|
20
|
+
type="email" required autoFocus autoComplete="email"
|
|
21
|
+
>
|
|
22
|
+
{dict.tenant.passwordlessSignInInit.email}
|
|
23
|
+
</TenantFormField>
|
|
24
|
+
|
|
25
|
+
<Button type="submit" className="w-full" disabled={form.state === 'submitting'}>
|
|
26
|
+
{dict.tenant.passwordlessSignInInit.submit}
|
|
27
|
+
</Button>
|
|
28
|
+
</div>
|
|
29
|
+
)
|
|
30
|
+
}
|
|
31
|
+
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { usePasswordlessSignInForm } from '@contember/react-identity'
|
|
2
|
+
import { Button } from '../../ui/button'
|
|
3
|
+
import { Loader } from '../../ui/loader'
|
|
4
|
+
import { TenantFormError, TenantFormField } from './common'
|
|
5
|
+
import { dict } from '../../dict'
|
|
6
|
+
import { useEffect, useRef, useState } from 'react'
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
export const PasswordlessSignInFormFields = ({ type, email }: { type: 'token' | 'otp'; email?: string }) => {
|
|
10
|
+
const form = usePasswordlessSignInForm()
|
|
11
|
+
const fieldErrors = form.errors.map(it => it.field)
|
|
12
|
+
const buttonRef = useRef<HTMLButtonElement | null>(null)
|
|
13
|
+
const [initialTokenValue] = useState(form.values.token)
|
|
14
|
+
const hasToken = type === 'token' && initialTokenValue
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
if (hasToken) {
|
|
17
|
+
buttonRef.current?.click()
|
|
18
|
+
}
|
|
19
|
+
}, [hasToken])
|
|
20
|
+
const setValues = form.setValues
|
|
21
|
+
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
if (type === 'otp') {
|
|
24
|
+
setValues(it => ({ ...it, token: it.token.toUpperCase() }))
|
|
25
|
+
}
|
|
26
|
+
}, [setValues, type, form.values.token])
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<div className="relative flex flex-col gap-2">
|
|
30
|
+
{form.state === 'success' || form.state === 'submitting' ? <Loader position="absolute" /> : null}
|
|
31
|
+
|
|
32
|
+
<TenantFormError
|
|
33
|
+
form={form} messages={dict.tenant.passwordlessSignIn.errorMessages}
|
|
34
|
+
/>
|
|
35
|
+
|
|
36
|
+
{(!hasToken || fieldErrors.includes('token')) && <TenantFormField
|
|
37
|
+
form={form} messages={dict.tenant.passwordlessSignIn.errorMessages} field="token"
|
|
38
|
+
type="text" required autoComplete="off" autoFocus
|
|
39
|
+
className={type === 'otp' ? 'text-2xl font-bold font-mono' : ''}
|
|
40
|
+
>
|
|
41
|
+
{dict.tenant.passwordlessSignIn.token}
|
|
42
|
+
</TenantFormField>}
|
|
43
|
+
|
|
44
|
+
{(form.state === 'otp-required' || fieldErrors.includes('otpToken')) && (
|
|
45
|
+
<TenantFormField
|
|
46
|
+
form={form} messages={dict.tenant.passwordlessSignIn.errorMessages} field="otpToken" autoComplete="one-time-code"
|
|
47
|
+
type="text" required autoFocus maxLength={6}
|
|
48
|
+
>
|
|
49
|
+
{dict.tenant.passwordlessSignIn.otpToken}
|
|
50
|
+
</TenantFormField>
|
|
51
|
+
)}
|
|
52
|
+
|
|
53
|
+
<Button type="submit" className="w-full" disabled={form.state === 'submitting'} ref={buttonRef}>
|
|
54
|
+
{dict.tenant.passwordlessSignIn.submit}
|
|
55
|
+
</Button>
|
|
56
|
+
</div>
|
|
57
|
+
)
|
|
58
|
+
}
|
|
59
|
+
|
|
@@ -35,7 +35,7 @@ export const uiconfig = <T extends ConfigSchema | undefined>(config: Config<T, C
|
|
|
35
35
|
export type NoInfer<T> = T & { [K in keyof T]: T[K] }
|
|
36
36
|
|
|
37
37
|
export const uic = <El extends React.ElementType, Variants extends ConfigSchema | undefined = undefined>(Component: El, config: Config<Variants, NoInfer<El>>) => {
|
|
38
|
-
const cls = cva<any>(config?.baseClass, {
|
|
38
|
+
const cls = cva<any>(config?.baseClass as any, {
|
|
39
39
|
variants: config?.variants,
|
|
40
40
|
defaultVariants: config?.defaultVariants,
|
|
41
41
|
compoundVariants: config?.compoundVariants,
|
|
@@ -60,7 +60,7 @@ export const uic = <El extends React.ElementType, Variants extends ConfigSchema
|
|
|
60
60
|
}
|
|
61
61
|
let children = childrenBase
|
|
62
62
|
if (config?.wrapInner) {
|
|
63
|
-
children = React.createElement(config.wrapInner, props, children)
|
|
63
|
+
children = React.createElement(config.wrapInner, props as any, children)
|
|
64
64
|
}
|
|
65
65
|
if (config?.beforeChildren || config?.afterChildren) {
|
|
66
66
|
children = <>
|
|
@@ -71,7 +71,7 @@ export const uic = <El extends React.ElementType, Variants extends ConfigSchema
|
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
const innerEl = <Comp ref={ref} className={twMerge(clsx(cls(props), classNameProp))} {...(config.defaultProps ?? {})} {...rest}>{children}</Comp>
|
|
74
|
-
return config?.wrapOuter ? React.createElement(config.wrapOuter, props, innerEl) : innerEl
|
|
74
|
+
return config?.wrapOuter ? React.createElement(config.wrapOuter, props as any, innerEl) : innerEl
|
|
75
75
|
})
|
|
76
76
|
component.displayName = config?.displayName
|
|
77
77
|
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { PackageDownloader } from './PackageDownloader'
|
|
1
|
+
import { join } from 'node:path'
|
|
3
2
|
import { FileSystem } from './FileSystem'
|
|
4
3
|
import jsyaml from 'js-yaml'
|
|
5
4
|
|
|
@@ -12,7 +11,6 @@ export class TemplateInstaller {
|
|
|
12
11
|
|
|
13
12
|
constructor(
|
|
14
13
|
private readonly resourceDir: string,
|
|
15
|
-
private readonly packageDownloader: PackageDownloader,
|
|
16
14
|
private readonly fs: FileSystem,
|
|
17
15
|
) {
|
|
18
16
|
}
|
|
@@ -27,12 +25,7 @@ export class TemplateInstaller {
|
|
|
27
25
|
if (this.localTemplates[template]) {
|
|
28
26
|
template = this.localTemplates[template]
|
|
29
27
|
}
|
|
30
|
-
|
|
31
|
-
template = await this.packageDownloader.downloadPackage(template)
|
|
32
|
-
removeTemplate = async () => {
|
|
33
|
-
await this.fs.unlink(template)
|
|
34
|
-
}
|
|
35
|
-
}
|
|
28
|
+
|
|
36
29
|
const templateConfigFile = join(template, 'contember.template.yaml')
|
|
37
30
|
if (!(await this.fs.pathExists(templateConfigFile))) {
|
|
38
31
|
throw `${template} is not a Contember template`
|
package/src/run.ts
CHANGED
|
@@ -3,14 +3,12 @@ import { Application, CommandManager } from '@contember/cli-common'
|
|
|
3
3
|
import { WorkspaceCreateCommand } from './commands'
|
|
4
4
|
import { TemplateInstaller } from './lib/TemplateInstaller'
|
|
5
5
|
import { resourcesDir } from './paths'
|
|
6
|
-
import { PackageDownloader } from './lib/PackageDownloader'
|
|
7
6
|
import { FileSystem } from './lib/FileSystem'
|
|
8
7
|
|
|
9
8
|
(async () => {
|
|
10
9
|
const commandManager = new CommandManager({
|
|
11
10
|
['workspace']: () => new WorkspaceCreateCommand(new TemplateInstaller(
|
|
12
11
|
resourcesDir,
|
|
13
|
-
new PackageDownloader(new FileSystem()),
|
|
14
12
|
new FileSystem(),
|
|
15
13
|
)),
|
|
16
14
|
})
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const npa = require("npm-package-arg");
|
|
4
|
-
const getRegistryInfo = require("registry-info");
|
|
5
|
-
const getPackageJson = require("get-package-json-from-registry");
|
|
6
|
-
const node_path = require("node:path");
|
|
7
|
-
const downloadTarball = require("download-tarball");
|
|
8
|
-
var __defProp = Object.defineProperty;
|
|
9
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
10
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, key + "", value);
|
|
11
|
-
class PackageDownloader {
|
|
12
|
-
constructor(fs) {
|
|
13
|
-
this.fs = fs;
|
|
14
|
-
__publicField(this, "downloadPackage", async (pkgName) => {
|
|
15
|
-
const { scope } = npa(pkgName);
|
|
16
|
-
const { authorization } = getRegistryInfo(scope);
|
|
17
|
-
const headers = authorization ? { authorization } : {};
|
|
18
|
-
const pkg = await getPackageJson(pkgName);
|
|
19
|
-
const {
|
|
20
|
-
dist: { tarball }
|
|
21
|
-
} = pkg;
|
|
22
|
-
const tmpDir = await this.fs.createTempDir();
|
|
23
|
-
await downloadTarball({ url: tarball, gotOpts: { headers }, dir: tmpDir });
|
|
24
|
-
const dirContent = await this.fs.readDir(tmpDir);
|
|
25
|
-
if (dirContent.length !== 1 || dirContent[0] !== "package") {
|
|
26
|
-
throw "Invalid NPM package";
|
|
27
|
-
}
|
|
28
|
-
return node_path.join(tmpDir, "package");
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
exports.PackageDownloader = PackageDownloader;
|
|
33
|
-
//# sourceMappingURL=PackageDownloader.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PackageDownloader.cjs","sources":["../../../../../packages/create/src/lib/PackageDownloader.ts"],"sourcesContent":["import npa from 'npm-package-arg'\nimport getRegistryInfo from 'registry-info'\nimport getPackageJson from 'get-package-json-from-registry'\nimport { join } from 'node:path'\nimport downloadTarball from 'download-tarball'\nimport { FileSystem } from './FileSystem'\n\nexport class PackageDownloader {\n\n\tconstructor(\n\t\tprivate readonly fs: FileSystem,\n\t) {\n\t}\n\n\tdownloadPackage = async (pkgName: string): Promise<string> => {\n\t\tconst { scope } = npa(pkgName)\n\t\tconst { authorization } = getRegistryInfo(scope)\n\t\tconst headers = authorization ? { authorization } : {}\n\n\t\tconst pkg = await getPackageJson(pkgName)\n\t\tconst {\n\t\t\tdist: { tarball },\n\t\t} = pkg\n\n\t\tconst tmpDir = await this.fs.createTempDir()\n\t\tawait downloadTarball({ url: tarball, gotOpts: { headers }, dir: tmpDir })\n\t\tconst dirContent = await this.fs.readDir(tmpDir)\n\t\tif (dirContent.length !== 1 || dirContent[0] !== 'package') {\n\t\t\tthrow 'Invalid NPM package'\n\t\t}\n\t\treturn join(tmpDir, 'package')\n\t}\n}\n"],"names":["join"],"mappings":";;;;;;;;;;AAOO,MAAM,kBAAkB;AAAA,EAE9B,YACkB,IAChB;AADgB,SAAA,KAAA;AAIlB,kBAAA,MAAA,mBAAkB,OAAO,YAAqC;AAC7D,YAAM,EAAE,MAAA,IAAU,IAAI,OAAO;AAC7B,YAAM,EAAE,cAAA,IAAkB,gBAAgB,KAAK;AAC/C,YAAM,UAAU,gBAAgB,EAAE,cAAA,IAAkB,CAAA;AAE9C,YAAA,MAAM,MAAM,eAAe,OAAO;AAClC,YAAA;AAAA,QACL,MAAM,EAAE,QAAQ;AAAA,MACb,IAAA;AAEJ,YAAM,SAAS,MAAM,KAAK,GAAG,cAAc;AACrC,YAAA,gBAAgB,EAAE,KAAK,SAAS,SAAS,EAAE,WAAW,KAAK,OAAA,CAAQ;AACzE,YAAM,aAAa,MAAM,KAAK,GAAG,QAAQ,MAAM;AAC/C,UAAI,WAAW,WAAW,KAAK,WAAW,CAAC,MAAM,WAAW;AACrD,cAAA;AAAA,MACP;AACO,aAAAA,UAAA,KAAK,QAAQ,SAAS;AAAA,IAAA,CAC9B;AAAA,EAnBA;AAoBD;;"}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import npa from "npm-package-arg";
|
|
2
|
-
import getRegistryInfo from "registry-info";
|
|
3
|
-
import getPackageJson from "get-package-json-from-registry";
|
|
4
|
-
import { join } from "node:path";
|
|
5
|
-
import downloadTarball from "download-tarball";
|
|
6
|
-
var __defProp = Object.defineProperty;
|
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, key + "", value);
|
|
9
|
-
class PackageDownloader {
|
|
10
|
-
constructor(fs) {
|
|
11
|
-
this.fs = fs;
|
|
12
|
-
__publicField(this, "downloadPackage", async (pkgName) => {
|
|
13
|
-
const { scope } = npa(pkgName);
|
|
14
|
-
const { authorization } = getRegistryInfo(scope);
|
|
15
|
-
const headers = authorization ? { authorization } : {};
|
|
16
|
-
const pkg = await getPackageJson(pkgName);
|
|
17
|
-
const {
|
|
18
|
-
dist: { tarball }
|
|
19
|
-
} = pkg;
|
|
20
|
-
const tmpDir = await this.fs.createTempDir();
|
|
21
|
-
await downloadTarball({ url: tarball, gotOpts: { headers }, dir: tmpDir });
|
|
22
|
-
const dirContent = await this.fs.readDir(tmpDir);
|
|
23
|
-
if (dirContent.length !== 1 || dirContent[0] !== "package") {
|
|
24
|
-
throw "Invalid NPM package";
|
|
25
|
-
}
|
|
26
|
-
return join(tmpDir, "package");
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
export {
|
|
31
|
-
PackageDownloader
|
|
32
|
-
};
|
|
33
|
-
//# sourceMappingURL=PackageDownloader.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PackageDownloader.js","sources":["../../../../../packages/create/src/lib/PackageDownloader.ts"],"sourcesContent":["import npa from 'npm-package-arg'\nimport getRegistryInfo from 'registry-info'\nimport getPackageJson from 'get-package-json-from-registry'\nimport { join } from 'node:path'\nimport downloadTarball from 'download-tarball'\nimport { FileSystem } from './FileSystem'\n\nexport class PackageDownloader {\n\n\tconstructor(\n\t\tprivate readonly fs: FileSystem,\n\t) {\n\t}\n\n\tdownloadPackage = async (pkgName: string): Promise<string> => {\n\t\tconst { scope } = npa(pkgName)\n\t\tconst { authorization } = getRegistryInfo(scope)\n\t\tconst headers = authorization ? { authorization } : {}\n\n\t\tconst pkg = await getPackageJson(pkgName)\n\t\tconst {\n\t\t\tdist: { tarball },\n\t\t} = pkg\n\n\t\tconst tmpDir = await this.fs.createTempDir()\n\t\tawait downloadTarball({ url: tarball, gotOpts: { headers }, dir: tmpDir })\n\t\tconst dirContent = await this.fs.readDir(tmpDir)\n\t\tif (dirContent.length !== 1 || dirContent[0] !== 'package') {\n\t\t\tthrow 'Invalid NPM package'\n\t\t}\n\t\treturn join(tmpDir, 'package')\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;AAOO,MAAM,kBAAkB;AAAA,EAE9B,YACkB,IAChB;AADgB,SAAA,KAAA;AAIlB,kBAAA,MAAA,mBAAkB,OAAO,YAAqC;AAC7D,YAAM,EAAE,MAAA,IAAU,IAAI,OAAO;AAC7B,YAAM,EAAE,cAAA,IAAkB,gBAAgB,KAAK;AAC/C,YAAM,UAAU,gBAAgB,EAAE,cAAA,IAAkB,CAAA;AAE9C,YAAA,MAAM,MAAM,eAAe,OAAO;AAClC,YAAA;AAAA,QACL,MAAM,EAAE,QAAQ;AAAA,MACb,IAAA;AAEJ,YAAM,SAAS,MAAM,KAAK,GAAG,cAAc;AACrC,YAAA,gBAAgB,EAAE,KAAK,SAAS,SAAS,EAAE,WAAW,KAAK,OAAA,CAAQ;AACzE,YAAM,aAAa,MAAM,KAAK,GAAG,QAAQ,MAAM;AAC/C,UAAI,WAAW,WAAW,KAAK,WAAW,CAAC,MAAM,WAAW;AACrD,cAAA;AAAA,MACP;AACO,aAAA,KAAK,QAAQ,SAAS;AAAA,IAAA,CAC9B;AAAA,EAnBA;AAoBD;"}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const npa = require("npm-package-arg");
|
|
4
|
-
const getRegistryInfo = require("registry-info");
|
|
5
|
-
const getPackageJson = require("get-package-json-from-registry");
|
|
6
|
-
const node_path = require("node:path");
|
|
7
|
-
const downloadTarball = require("download-tarball");
|
|
8
|
-
var __defProp = Object.defineProperty;
|
|
9
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
10
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, key + "", value);
|
|
11
|
-
class PackageDownloader {
|
|
12
|
-
constructor(fs) {
|
|
13
|
-
this.fs = fs;
|
|
14
|
-
__publicField(this, "downloadPackage", async (pkgName) => {
|
|
15
|
-
const { scope } = npa(pkgName);
|
|
16
|
-
const { authorization } = getRegistryInfo(scope);
|
|
17
|
-
const headers = authorization ? { authorization } : {};
|
|
18
|
-
const pkg = await getPackageJson(pkgName);
|
|
19
|
-
const {
|
|
20
|
-
dist: { tarball }
|
|
21
|
-
} = pkg;
|
|
22
|
-
const tmpDir = await this.fs.createTempDir();
|
|
23
|
-
await downloadTarball({ url: tarball, gotOpts: { headers }, dir: tmpDir });
|
|
24
|
-
const dirContent = await this.fs.readDir(tmpDir);
|
|
25
|
-
if (dirContent.length !== 1 || dirContent[0] !== "package") {
|
|
26
|
-
throw "Invalid NPM package";
|
|
27
|
-
}
|
|
28
|
-
return node_path.join(tmpDir, "package");
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
exports.PackageDownloader = PackageDownloader;
|
|
33
|
-
//# sourceMappingURL=PackageDownloader.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PackageDownloader.cjs","sources":["../../../../../packages/create/src/lib/PackageDownloader.ts"],"sourcesContent":["import npa from 'npm-package-arg'\nimport getRegistryInfo from 'registry-info'\nimport getPackageJson from 'get-package-json-from-registry'\nimport { join } from 'node:path'\nimport downloadTarball from 'download-tarball'\nimport { FileSystem } from './FileSystem'\n\nexport class PackageDownloader {\n\n\tconstructor(\n\t\tprivate readonly fs: FileSystem,\n\t) {\n\t}\n\n\tdownloadPackage = async (pkgName: string): Promise<string> => {\n\t\tconst { scope } = npa(pkgName)\n\t\tconst { authorization } = getRegistryInfo(scope)\n\t\tconst headers = authorization ? { authorization } : {}\n\n\t\tconst pkg = await getPackageJson(pkgName)\n\t\tconst {\n\t\t\tdist: { tarball },\n\t\t} = pkg\n\n\t\tconst tmpDir = await this.fs.createTempDir()\n\t\tawait downloadTarball({ url: tarball, gotOpts: { headers }, dir: tmpDir })\n\t\tconst dirContent = await this.fs.readDir(tmpDir)\n\t\tif (dirContent.length !== 1 || dirContent[0] !== 'package') {\n\t\t\tthrow 'Invalid NPM package'\n\t\t}\n\t\treturn join(tmpDir, 'package')\n\t}\n}\n"],"names":["join"],"mappings":";;;;;;;;;;AAOO,MAAM,kBAAkB;AAAA,EAE9B,YACkB,IAChB;AADgB,SAAA,KAAA;AAIlB,kBAAA,MAAA,mBAAkB,OAAO,YAAqC;AAC7D,YAAM,EAAE,MAAA,IAAU,IAAI,OAAO;AAC7B,YAAM,EAAE,cAAA,IAAkB,gBAAgB,KAAK;AAC/C,YAAM,UAAU,gBAAgB,EAAE,cAAA,IAAkB,CAAA;AAE9C,YAAA,MAAM,MAAM,eAAe,OAAO;AAClC,YAAA;AAAA,QACL,MAAM,EAAE,QAAQ;AAAA,MACb,IAAA;AAEJ,YAAM,SAAS,MAAM,KAAK,GAAG,cAAc;AACrC,YAAA,gBAAgB,EAAE,KAAK,SAAS,SAAS,EAAE,WAAW,KAAK,OAAA,CAAQ;AACzE,YAAM,aAAa,MAAM,KAAK,GAAG,QAAQ,MAAM;AAC/C,UAAI,WAAW,WAAW,KAAK,WAAW,CAAC,MAAM,WAAW;AACrD,cAAA;AAAA,MACP;AACO,aAAAA,UAAA,KAAK,QAAQ,SAAS;AAAA,IAAA,CAC9B;AAAA,EAnBA;AAoBD;;"}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import npa from "npm-package-arg";
|
|
2
|
-
import getRegistryInfo from "registry-info";
|
|
3
|
-
import getPackageJson from "get-package-json-from-registry";
|
|
4
|
-
import { join } from "node:path";
|
|
5
|
-
import downloadTarball from "download-tarball";
|
|
6
|
-
var __defProp = Object.defineProperty;
|
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, key + "", value);
|
|
9
|
-
class PackageDownloader {
|
|
10
|
-
constructor(fs) {
|
|
11
|
-
this.fs = fs;
|
|
12
|
-
__publicField(this, "downloadPackage", async (pkgName) => {
|
|
13
|
-
const { scope } = npa(pkgName);
|
|
14
|
-
const { authorization } = getRegistryInfo(scope);
|
|
15
|
-
const headers = authorization ? { authorization } : {};
|
|
16
|
-
const pkg = await getPackageJson(pkgName);
|
|
17
|
-
const {
|
|
18
|
-
dist: { tarball }
|
|
19
|
-
} = pkg;
|
|
20
|
-
const tmpDir = await this.fs.createTempDir();
|
|
21
|
-
await downloadTarball({ url: tarball, gotOpts: { headers }, dir: tmpDir });
|
|
22
|
-
const dirContent = await this.fs.readDir(tmpDir);
|
|
23
|
-
if (dirContent.length !== 1 || dirContent[0] !== "package") {
|
|
24
|
-
throw "Invalid NPM package";
|
|
25
|
-
}
|
|
26
|
-
return join(tmpDir, "package");
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
export {
|
|
31
|
-
PackageDownloader
|
|
32
|
-
};
|
|
33
|
-
//# sourceMappingURL=PackageDownloader.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PackageDownloader.js","sources":["../../../../../packages/create/src/lib/PackageDownloader.ts"],"sourcesContent":["import npa from 'npm-package-arg'\nimport getRegistryInfo from 'registry-info'\nimport getPackageJson from 'get-package-json-from-registry'\nimport { join } from 'node:path'\nimport downloadTarball from 'download-tarball'\nimport { FileSystem } from './FileSystem'\n\nexport class PackageDownloader {\n\n\tconstructor(\n\t\tprivate readonly fs: FileSystem,\n\t) {\n\t}\n\n\tdownloadPackage = async (pkgName: string): Promise<string> => {\n\t\tconst { scope } = npa(pkgName)\n\t\tconst { authorization } = getRegistryInfo(scope)\n\t\tconst headers = authorization ? { authorization } : {}\n\n\t\tconst pkg = await getPackageJson(pkgName)\n\t\tconst {\n\t\t\tdist: { tarball },\n\t\t} = pkg\n\n\t\tconst tmpDir = await this.fs.createTempDir()\n\t\tawait downloadTarball({ url: tarball, gotOpts: { headers }, dir: tmpDir })\n\t\tconst dirContent = await this.fs.readDir(tmpDir)\n\t\tif (dirContent.length !== 1 || dirContent[0] !== 'package') {\n\t\t\tthrow 'Invalid NPM package'\n\t\t}\n\t\treturn join(tmpDir, 'package')\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;AAOO,MAAM,kBAAkB;AAAA,EAE9B,YACkB,IAChB;AADgB,SAAA,KAAA;AAIlB,kBAAA,MAAA,mBAAkB,OAAO,YAAqC;AAC7D,YAAM,EAAE,MAAA,IAAU,IAAI,OAAO;AAC7B,YAAM,EAAE,cAAA,IAAkB,gBAAgB,KAAK;AAC/C,YAAM,UAAU,gBAAgB,EAAE,cAAA,IAAkB,CAAA;AAE9C,YAAA,MAAM,MAAM,eAAe,OAAO;AAClC,YAAA;AAAA,QACL,MAAM,EAAE,QAAQ;AAAA,MACb,IAAA;AAEJ,YAAM,SAAS,MAAM,KAAK,GAAG,cAAc;AACrC,YAAA,gBAAgB,EAAE,KAAK,SAAS,SAAS,EAAE,WAAW,KAAK,OAAA,CAAQ;AACzE,YAAM,aAAa,MAAM,KAAK,GAAG,QAAQ,MAAM;AAC/C,UAAI,WAAW,WAAW,KAAK,WAAW,CAAC,MAAM,WAAW;AACrD,cAAA;AAAA,MACP;AACO,aAAA,KAAK,QAAQ,SAAS;AAAA,IAAA,CAC9B;AAAA,EAnBA;AAoBD;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PackageDownloader.d.ts","sourceRoot":"","sources":["../../../src/lib/PackageDownloader.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAEzC,qBAAa,iBAAiB;IAG5B,OAAO,CAAC,QAAQ,CAAC,EAAE;gBAAF,EAAE,EAAE,UAAU;IAIhC,eAAe,YAAmB,MAAM,KAAG,OAAO,CAAC,MAAM,CAAC,CAiBzD;CACD"}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import npa from 'npm-package-arg'
|
|
2
|
-
import getRegistryInfo from 'registry-info'
|
|
3
|
-
import getPackageJson from 'get-package-json-from-registry'
|
|
4
|
-
import { join } from 'node:path'
|
|
5
|
-
import downloadTarball from 'download-tarball'
|
|
6
|
-
import { FileSystem } from './FileSystem'
|
|
7
|
-
|
|
8
|
-
export class PackageDownloader {
|
|
9
|
-
|
|
10
|
-
constructor(
|
|
11
|
-
private readonly fs: FileSystem,
|
|
12
|
-
) {
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
downloadPackage = async (pkgName: string): Promise<string> => {
|
|
16
|
-
const { scope } = npa(pkgName)
|
|
17
|
-
const { authorization } = getRegistryInfo(scope)
|
|
18
|
-
const headers = authorization ? { authorization } : {}
|
|
19
|
-
|
|
20
|
-
const pkg = await getPackageJson(pkgName)
|
|
21
|
-
const {
|
|
22
|
-
dist: { tarball },
|
|
23
|
-
} = pkg
|
|
24
|
-
|
|
25
|
-
const tmpDir = await this.fs.createTempDir()
|
|
26
|
-
await downloadTarball({ url: tarball, gotOpts: { headers }, dir: tmpDir })
|
|
27
|
-
const dirContent = await this.fs.readDir(tmpDir)
|
|
28
|
-
if (dirContent.length !== 1 || dirContent[0] !== 'package') {
|
|
29
|
-
throw 'Invalid NPM package'
|
|
30
|
-
}
|
|
31
|
-
return join(tmpDir, 'package')
|
|
32
|
-
}
|
|
33
|
-
}
|