@upstart.gg/sdk 0.0.104 → 0.0.105
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/shared/ajv.js +1 -1
- package/dist/shared/attributes.js +1 -1
- package/dist/shared/bricks/manifests/accordion.manifest.js +1 -1
- package/dist/shared/bricks/manifests/all-manifests.js +1 -1
- package/dist/shared/bricks/manifests/button.manifest.js +1 -1
- package/dist/shared/bricks/manifests/card.manifest.js +1 -1
- package/dist/shared/bricks/manifests/carousel.manifest.js +1 -1
- package/dist/shared/bricks/manifests/container.manifest.js +1 -1
- package/dist/shared/bricks/manifests/divider.manifest.js +1 -1
- package/dist/shared/bricks/manifests/footer.manifest.js +1 -1
- package/dist/shared/bricks/manifests/form.manifest.js +1 -1
- package/dist/shared/bricks/manifests/hero.manifest.js +1 -1
- package/dist/shared/bricks/manifests/icon.manifest.js +1 -1
- package/dist/shared/bricks/manifests/image.manifest.js +1 -1
- package/dist/shared/bricks/manifests/images-gallery.manifest.js +1 -1
- package/dist/shared/bricks/manifests/map.manifest.js +1 -1
- package/dist/shared/bricks/manifests/navbar.manifest.js +1 -1
- package/dist/shared/bricks/manifests/sidebar.manifest.js +1 -1
- package/dist/shared/bricks/manifests/social-links.manifest.js +1 -1
- package/dist/shared/bricks/manifests/testimonials.manifest.js +1 -1
- package/dist/shared/bricks/manifests/text.manifest.js +1 -1
- package/dist/shared/bricks/manifests/timeline.manifest.js +1 -1
- package/dist/shared/bricks/manifests/video.manifest.js +1 -1
- package/dist/shared/bricks.js +1 -1
- package/dist/shared/chunk-245ZLDVB.js +3 -0
- package/dist/shared/{chunk-QALNFBY7.js → chunk-2D6ZEIDX.js} +1 -1
- package/dist/shared/{chunk-CW5FWW5W.js → chunk-4BLCQRF5.js} +1 -1
- package/dist/shared/{chunk-TEPFFY32.js → chunk-5MGYT6FI.js} +1 -1
- package/dist/shared/{chunk-HQQYIKTE.js → chunk-CS5N4UQU.js} +1 -1
- package/dist/shared/{chunk-5IEGQ7YT.js → chunk-FRWB3BF3.js} +1 -1
- package/dist/shared/{chunk-I5S2MPPR.js → chunk-HYXCHFS5.js} +1 -1
- package/dist/shared/{chunk-TCZBR3ZU.js → chunk-IKSRCRZZ.js} +1 -1
- package/dist/shared/{chunk-LJQXN32B.js → chunk-ISF6EBPX.js} +1 -1
- package/dist/shared/{chunk-UK6H3FDX.js → chunk-JDBVMPSI.js} +1 -1
- package/dist/shared/{chunk-UISES3HA.js → chunk-M3Z3XDUC.js} +1 -1
- package/dist/shared/{chunk-22KRCQK5.js → chunk-MWP5IU33.js} +1 -1
- package/dist/shared/{chunk-7L3UOEMR.js → chunk-NCSLTHKN.js} +1 -1
- package/dist/shared/{chunk-O22VV7YR.js → chunk-OWON727Q.js} +1 -1
- package/dist/shared/{chunk-CEXHD4BO.js → chunk-P5RC56CL.js} +2 -2
- package/dist/shared/{chunk-ZFTWLZ3G.js → chunk-QI3BZDXL.js} +1 -1
- package/dist/shared/{chunk-F6MLW6DO.js → chunk-RDSK2G6V.js} +1 -1
- package/dist/shared/{chunk-I43NIQ2K.js → chunk-RXRPFXDF.js} +1 -1
- package/dist/shared/{chunk-POYVTV5F.js → chunk-VFGMOA4M.js} +1 -1
- package/dist/shared/{chunk-VDHLON5R.js → chunk-VPD626ML.js} +1 -1
- package/dist/shared/{chunk-WCNVFVDK.js → chunk-VROOAFFW.js} +1 -1
- package/dist/shared/{chunk-E2EBTWJI.js → chunk-WB4PGCZQ.js} +1 -1
- package/dist/shared/chunk-X2RJL33B.js +3 -0
- package/dist/shared/{chunk-OQIFFJ7I.js → chunk-X4ZBUWUL.js} +1 -1
- package/dist/shared/datasources/external/rss/fetcher.d.ts +1 -1
- package/dist/shared/datasources/external/rss/fetcher.d.ts.map +1 -1
- package/dist/shared/page.js +1 -1
- package/dist/shared/site.js +1 -1
- package/package.json +5 -9
- package/dist/shared/chunk-GPKRRX3D.js +0 -3
- package/dist/shared/chunk-JFDOR3UH.js +0 -3
- package/src/node/cli/api.ts +0 -101
- package/src/node/cli/commands/cmd-build.ts +0 -64
- package/src/node/cli/commands/login/cmd-login.ts +0 -111
- package/src/node/cli/commands/logout/cmd-logout.ts +0 -11
- package/src/node/cli/commands/publish/cmd-publish.ts +0 -135
- package/src/node/cli/commands/publish/parse-gitignore.ts +0 -278
- package/src/node/cli/commands/publish/uploader.ts +0 -333
- package/src/node/cli/constants.ts +0 -14
- package/src/node/cli/is-logged-in.ts +0 -28
- package/src/node/cli/program.ts +0 -77
- package/src/node/cli/store.ts +0 -64
- package/src/node/cli/tests/api.test.ts +0 -161
- package/src/node/cli/types.ts +0 -34
- package/src/node/cli/utils.ts +0 -20
- package/src/node/shared/config.ts +0 -69
- package/src/node/shared/logger.ts +0 -44
- package/src/shared/ajv.ts +0 -103
- package/src/shared/analytics/init.ts +0 -14
- package/src/shared/analytics/track.ts +0 -21
- package/src/shared/analytics/types.ts +0 -13
- package/src/shared/attributes.ts +0 -211
- package/src/shared/brick-manifest.ts +0 -110
- package/src/shared/bricks/manifests/accordion.manifest.ts +0 -179
- package/src/shared/bricks/manifests/all-manifests.ts +0 -92
- package/src/shared/bricks/manifests/button.manifest.ts +0 -145
- package/src/shared/bricks/manifests/card.manifest.ts +0 -269
- package/src/shared/bricks/manifests/carousel.manifest.ts +0 -106
- package/src/shared/bricks/manifests/container.manifest.ts +0 -357
- package/src/shared/bricks/manifests/divider.manifest.ts +0 -121
- package/src/shared/bricks/manifests/footer.manifest.ts +0 -487
- package/src/shared/bricks/manifests/form.manifest.ts +0 -112
- package/src/shared/bricks/manifests/hero.manifest.ts +0 -132
- package/src/shared/bricks/manifests/icon.manifest.ts +0 -130
- package/src/shared/bricks/manifests/image.manifest.ts +0 -203
- package/src/shared/bricks/manifests/images-gallery.manifest.ts +0 -227
- package/src/shared/bricks/manifests/map.manifest.ts +0 -75
- package/src/shared/bricks/manifests/navbar.manifest.ts +0 -344
- package/src/shared/bricks/manifests/sidebar.manifest.ts +0 -90
- package/src/shared/bricks/manifests/social-links.manifest.ts +0 -370
- package/src/shared/bricks/manifests/testimonials.manifest.ts +0 -397
- package/src/shared/bricks/manifests/tests/header.manifest.test.ts +0 -10
- package/src/shared/bricks/manifests/text.manifest.ts +0 -164
- package/src/shared/bricks/manifests/timeline.manifest.ts +0 -456
- package/src/shared/bricks/manifests/video.manifest.ts +0 -59
- package/src/shared/bricks/props/_style-presets.ts +0 -352
- package/src/shared/bricks/props/align.ts +0 -59
- package/src/shared/bricks/props/background.ts +0 -118
- package/src/shared/bricks/props/boolean.ts +0 -11
- package/src/shared/bricks/props/border.ts +0 -84
- package/src/shared/bricks/props/color.ts +0 -24
- package/src/shared/bricks/props/common.ts +0 -37
- package/src/shared/bricks/props/container.ts +0 -356
- package/src/shared/bricks/props/css-length.ts +0 -25
- package/src/shared/bricks/props/datasource.ts +0 -60
- package/src/shared/bricks/props/date.ts +0 -24
- package/src/shared/bricks/props/effects.ts +0 -123
- package/src/shared/bricks/props/enum.ts +0 -42
- package/src/shared/bricks/props/file.ts +0 -12
- package/src/shared/bricks/props/geolocation.ts +0 -30
- package/src/shared/bricks/props/helpers.ts +0 -101
- package/src/shared/bricks/props/image.ts +0 -90
- package/src/shared/bricks/props/number.ts +0 -16
- package/src/shared/bricks/props/padding.ts +0 -21
- package/src/shared/bricks/props/position.ts +0 -27
- package/src/shared/bricks/props/preset.ts +0 -136
- package/src/shared/bricks/props/string.ts +0 -56
- package/src/shared/bricks/props/tests/align.test.ts +0 -37
- package/src/shared/bricks/props/tests/background.test.ts +0 -102
- package/src/shared/bricks/props/tests/border.test.ts +0 -38
- package/src/shared/bricks/props/tests/effects.test.ts +0 -37
- package/src/shared/bricks/props/tests/helpers.test.ts +0 -133
- package/src/shared/bricks/props/tests/image.test.ts +0 -71
- package/src/shared/bricks/props/tests/padding.ts +0 -12
- package/src/shared/bricks/props/tests/string.test.ts +0 -79
- package/src/shared/bricks/props/text.ts +0 -66
- package/src/shared/bricks/props/types.ts +0 -57
- package/src/shared/bricks.ts +0 -232
- package/src/shared/context.ts +0 -39
- package/src/shared/datarecords/external/airtable/handler.ts +0 -21
- package/src/shared/datarecords/external/airtable/options.ts +0 -22
- package/src/shared/datarecords/external/generic-webhook/handler.ts +0 -10
- package/src/shared/datarecords/external/generic-webhook/options.ts +0 -13
- package/src/shared/datarecords/external/google/oauth/config.ts +0 -30
- package/src/shared/datarecords/external/google/sheets/handler.ts +0 -26
- package/src/shared/datarecords/external/google/sheets/options.ts +0 -9
- package/src/shared/datarecords/types.ts +0 -120
- package/src/shared/datarecords.ts +0 -5
- package/src/shared/datasources/README.md +0 -3
- package/src/shared/datasources/external/facebook/posts/fetcher.ts +0 -52
- package/src/shared/datasources/external/facebook/posts/sample.ts +0 -35
- package/src/shared/datasources/external/facebook/posts/schema.ts +0 -33
- package/src/shared/datasources/external/facebook/posts/tests/fetcher.test.ts +0 -73
- package/src/shared/datasources/external/http-json/fetcher.ts +0 -28
- package/src/shared/datasources/external/http-json/options.ts +0 -12
- package/src/shared/datasources/external/http-json/schema.ts +0 -6
- package/src/shared/datasources/external/http-json/tests/fetcher.test.ts +0 -70
- package/src/shared/datasources/external/instagram/feed/fetcher.ts +0 -33
- package/src/shared/datasources/external/instagram/feed/sample.ts +0 -22
- package/src/shared/datasources/external/instagram/feed/schema.ts +0 -23
- package/src/shared/datasources/external/instagram/feed/tests/fetcher.test.ts +0 -64
- package/src/shared/datasources/external/mastodon/account/fetcher.ts +0 -24
- package/src/shared/datasources/external/mastodon/account/sample.ts +0 -33
- package/src/shared/datasources/external/mastodon/account/schema.ts +0 -45
- package/src/shared/datasources/external/mastodon/account/tests/fetcher.test.ts +0 -47
- package/src/shared/datasources/external/mastodon/options.ts +0 -11
- package/src/shared/datasources/external/mastodon/status/fetcher.ts +0 -35
- package/src/shared/datasources/external/mastodon/status/sample.array.ts +0 -59
- package/src/shared/datasources/external/mastodon/status/sample.single.ts +0 -55
- package/src/shared/datasources/external/mastodon/status/schema.ts +0 -130
- package/src/shared/datasources/external/mastodon/status/tests/fetcher.test.ts +0 -74
- package/src/shared/datasources/external/meta/oauth/config.ts +0 -16
- package/src/shared/datasources/external/meta/options.ts +0 -11
- package/src/shared/datasources/external/rss/fetcher.ts +0 -29
- package/src/shared/datasources/external/rss/options.ts +0 -11
- package/src/shared/datasources/external/rss/sample.ts +0 -22
- package/src/shared/datasources/external/rss/schema.ts +0 -42
- package/src/shared/datasources/external/threads/media/fetcher.ts +0 -53
- package/src/shared/datasources/external/threads/media/sample.ts +0 -44
- package/src/shared/datasources/external/threads/media/schema.ts +0 -37
- package/src/shared/datasources/external/tiktok/oauth/config.ts +0 -17
- package/src/shared/datasources/external/tiktok/video/fetcher.ts +0 -39
- package/src/shared/datasources/external/tiktok/video/options.ts +0 -12
- package/src/shared/datasources/external/tiktok/video/sample.ts +0 -26
- package/src/shared/datasources/external/tiktok/video/schema.ts +0 -27
- package/src/shared/datasources/external/youtube/list/fetcher.ts +0 -37
- package/src/shared/datasources/external/youtube/list/options.ts +0 -15
- package/src/shared/datasources/external/youtube/list/sample.ts +0 -33
- package/src/shared/datasources/external/youtube/list/schema.ts +0 -38
- package/src/shared/datasources/external/youtube/oauth/config.ts +0 -15
- package/src/shared/datasources/fetcher.ts +0 -17
- package/src/shared/datasources/internal/blog/schema.ts +0 -69
- package/src/shared/datasources/internal/changelog/schema.ts +0 -48
- package/src/shared/datasources/internal/contact-info/schema.ts +0 -20
- package/src/shared/datasources/internal/cv/schema.ts +0 -217
- package/src/shared/datasources/internal/faq/schema.ts +0 -27
- package/src/shared/datasources/internal/job-board/schema.ts +0 -228
- package/src/shared/datasources/internal/links/schema.ts +0 -15
- package/src/shared/datasources/internal/recipes/schema.ts +0 -42
- package/src/shared/datasources/internal/restaurant/schema.ts +0 -225
- package/src/shared/datasources/provider-options.ts +0 -7
- package/src/shared/datasources/samples.ts +0 -26
- package/src/shared/datasources/schemas.ts +0 -45
- package/src/shared/datasources/types.ts +0 -276
- package/src/shared/datasources/utils.ts +0 -16
- package/src/shared/datasources.ts +0 -42
- package/src/shared/env.ts +0 -23
- package/src/shared/errors.ts +0 -1
- package/src/shared/images.ts +0 -44
- package/src/shared/index.ts +0 -3
- package/src/shared/layout-constants.ts +0 -25
- package/src/shared/manifest.ts +0 -50
- package/src/shared/oauth.ts +0 -16
- package/src/shared/page.ts +0 -61
- package/src/shared/prompt.ts +0 -9
- package/src/shared/responsive.ts +0 -5
- package/src/shared/site.ts +0 -97
- package/src/shared/sitemap.ts +0 -66
- package/src/shared/social-icons.ts +0 -307
- package/src/shared/tests/attributes.test.ts +0 -37
- package/src/shared/theme.ts +0 -245
- package/src/shared/themes/README.md +0 -34
- package/src/shared/themes/color-system.ts +0 -127
- package/src/shared/utils/canvas-data-uri.ts +0 -2
- package/src/shared/utils/invariant.ts +0 -25
- package/src/shared/utils/json-date.ts +0 -8
- package/src/shared/utils/merge.ts +0 -12
- package/src/shared/utils/object-hash.ts +0 -7
- package/src/shared/utils/schema.ts +0 -35
- package/src/shared/utils/try-catch.ts +0 -12
- package/src/shared/utils/typed-ref.ts +0 -41
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import chalk from "chalk";
|
|
2
|
-
import { confirm } from "@inquirer/prompts";
|
|
3
|
-
import open from "open";
|
|
4
|
-
import { CLI_LOGIN_CLIENT_ID, OAUTH_ENDPOINT_DEVICE_CODE, OAUTH_ENDPOINT_TOKEN } from "../../constants";
|
|
5
|
-
import { post } from "../../api";
|
|
6
|
-
import type { Logger } from "~/node/shared/logger";
|
|
7
|
-
import type { CommandArgOpts, CommonOptions } from "../../types";
|
|
8
|
-
import { accessStore } from "../../store";
|
|
9
|
-
|
|
10
|
-
export async function pollForLogin(deviceCode: string, logger: Logger) {
|
|
11
|
-
while (true) {
|
|
12
|
-
const body = new URLSearchParams({
|
|
13
|
-
grant_type: "device_code",
|
|
14
|
-
device_code: deviceCode,
|
|
15
|
-
client_id: CLI_LOGIN_CLIENT_ID,
|
|
16
|
-
});
|
|
17
|
-
const tokenResponse = await post<DeviceCodeTokenSuccessResponse, DeviceCodeTokenErrorResponse>(
|
|
18
|
-
OAUTH_ENDPOINT_TOKEN,
|
|
19
|
-
body,
|
|
20
|
-
);
|
|
21
|
-
const { data, isSuccess } = tokenResponse;
|
|
22
|
-
|
|
23
|
-
if (isSuccess) {
|
|
24
|
-
return data;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
if (data.error === "authorization_pending") {
|
|
28
|
-
await new Promise((resolve) => setTimeout(resolve, 5000));
|
|
29
|
-
} else {
|
|
30
|
-
// other error handling
|
|
31
|
-
logger.error(`Error while polling for login: ${data.error_description ?? data.error}`);
|
|
32
|
-
return false;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export async function login({ options, logger }: CommandArgOpts<CommonOptions>) {
|
|
38
|
-
logger.info(`Logging in to Enpage...\n`);
|
|
39
|
-
|
|
40
|
-
const { isError, data } = await post<DeviceCodeResponse>(OAUTH_ENDPOINT_DEVICE_CODE, {
|
|
41
|
-
client_id: CLI_LOGIN_CLIENT_ID,
|
|
42
|
-
scope: "profile,templates:publish",
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
if (isError) {
|
|
46
|
-
logger.error("Failed to get device code. Please try again.");
|
|
47
|
-
logger.error(`Error: ${data.error_description ?? data.error}`);
|
|
48
|
-
process.exit(1);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const { verification_uri, device_code } = data;
|
|
52
|
-
|
|
53
|
-
const confirmed = await confirm({
|
|
54
|
-
message: `Would you like to open the login page in your browser?`,
|
|
55
|
-
default: true,
|
|
56
|
-
}).catch((e) => {
|
|
57
|
-
process.exit(0);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
if (confirmed) {
|
|
61
|
-
open(verification_uri);
|
|
62
|
-
} else {
|
|
63
|
-
logger.info(`\nPlease visit the following URL to login:\n ${verification_uri}\n`);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
logger.info(chalk.gray("\nWaiting for login...\n"));
|
|
67
|
-
|
|
68
|
-
const loginData = await pollForLogin(device_code, logger);
|
|
69
|
-
|
|
70
|
-
if (!loginData) {
|
|
71
|
-
logger.error("Login failed. Please try again.");
|
|
72
|
-
process.exit(1);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// Store the access token info
|
|
76
|
-
accessStore.set({
|
|
77
|
-
...loginData,
|
|
78
|
-
...(loginData.expires_in ? { expires_at: Date.now() + loginData.expires_in * 1000 } : {}),
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
logger.info("Login successful!\n");
|
|
82
|
-
process.exitCode = 0;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
type DeviceCodeResponse = {
|
|
86
|
-
success: true;
|
|
87
|
-
device_code: string;
|
|
88
|
-
user_code: string;
|
|
89
|
-
verification_uri: string;
|
|
90
|
-
verification_uri_complete?: string; // Optional as per RFC 8628
|
|
91
|
-
expires_in: number;
|
|
92
|
-
interval?: number; // Optional as per RFC 8628
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
// Union type for the response
|
|
96
|
-
|
|
97
|
-
type DeviceCodeTokenSuccessResponse = {
|
|
98
|
-
success: true;
|
|
99
|
-
access_token: string;
|
|
100
|
-
token_type: string;
|
|
101
|
-
expires_in?: number;
|
|
102
|
-
refresh_token?: string;
|
|
103
|
-
scope?: string;
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
// Error response type for token request
|
|
107
|
-
type DeviceCodeTokenErrorResponse = {
|
|
108
|
-
error: "authorization_pending" | "slow_down" | "access_denied" | "expired_token" | string;
|
|
109
|
-
error_description?: string;
|
|
110
|
-
error_uri?: string;
|
|
111
|
-
};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { CommandArgOpts, CommonOptions } from "../../types";
|
|
2
|
-
import { accessStore } from "../../store";
|
|
3
|
-
|
|
4
|
-
export async function logout({ options, logger }: CommandArgOpts<CommonOptions>) {
|
|
5
|
-
logger.info(`Logging out fom Enpage...`);
|
|
6
|
-
|
|
7
|
-
accessStore.clear();
|
|
8
|
-
|
|
9
|
-
logger.info("Done.\n");
|
|
10
|
-
process.exit(0);
|
|
11
|
-
}
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
import { resolve } from "node:path";
|
|
2
|
-
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
3
|
-
import chalk from "chalk";
|
|
4
|
-
import type { CommandArgOpts } from "../../types";
|
|
5
|
-
import { formatAPIError, getPackageManager } from "../../utils";
|
|
6
|
-
import { getTokenOrThrow } from "../../store";
|
|
7
|
-
import { uploadTemplate } from "./uploader";
|
|
8
|
-
import path from "node:path";
|
|
9
|
-
import { post } from "../../api";
|
|
10
|
-
import { API_ENDPOINT_REGISTER_TEMPLATE } from "../../constants";
|
|
11
|
-
import { loadConfigFromJsFile, validateTemplateConfig } from "~/node/shared/config";
|
|
12
|
-
import { isLoggedIn } from "../../is-logged-in";
|
|
13
|
-
|
|
14
|
-
export async function publish({ options, args, logger }: CommandArgOpts) {
|
|
15
|
-
// check if user is logged in
|
|
16
|
-
if (!(await isLoggedIn(true))) {
|
|
17
|
-
const pkgCmd = getPackageManager();
|
|
18
|
-
logger.error(
|
|
19
|
-
` ${chalk.redBright("Error")}: User token not found. Please run ${chalk.cyan(`${pkgCmd} run enpage:login`)} to authenticate or set the ${chalk.cyan("ENPAGE_API_TOKEN")} environment variable.\n`,
|
|
20
|
-
);
|
|
21
|
-
process.exit(1);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const templateDir = args.length
|
|
25
|
-
? path.isAbsolute(args[0])
|
|
26
|
-
? args[0]
|
|
27
|
-
: resolve(process.cwd(), args[0])
|
|
28
|
-
: process.cwd();
|
|
29
|
-
|
|
30
|
-
if (!existsSync(templateDir)) {
|
|
31
|
-
logger.error(` Template directory not found: ${templateDir}. Aborting.\n`);
|
|
32
|
-
process.exit(1);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const distDir =
|
|
36
|
-
args.length > 1
|
|
37
|
-
? path.isAbsolute(args[1])
|
|
38
|
-
? args[1]
|
|
39
|
-
: resolve(process.cwd(), args[1])
|
|
40
|
-
: resolve(templateDir, "dist");
|
|
41
|
-
|
|
42
|
-
if (!existsSync(distDir)) {
|
|
43
|
-
logger.error(
|
|
44
|
-
` Dist directory not found: ${distDir}.\n Please run 'build' before publishing. Aborting.\n`,
|
|
45
|
-
);
|
|
46
|
-
process.exit(1);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// check if enpage.config.js and package.json exist in the current directory
|
|
50
|
-
// if not, exit with an error
|
|
51
|
-
if (!existsSync(resolve(templateDir, "enpage.config.js"))) {
|
|
52
|
-
logger.error(
|
|
53
|
-
` ${chalk.redBright("Error")}: file enpage.config.js not found in ${templateDir}. Aborting.\n`,
|
|
54
|
-
);
|
|
55
|
-
process.exit(1);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// load manifest from both enpage.config.js and package.json
|
|
59
|
-
// manifest.json is used to store the template ID for future updates
|
|
60
|
-
const config = await loadConfigFromJsFile(resolve(templateDir, "enpage.config.js"), logger);
|
|
61
|
-
|
|
62
|
-
validateTemplateConfig(config, logger);
|
|
63
|
-
|
|
64
|
-
const token = getTokenOrThrow();
|
|
65
|
-
const pkgLocation = getPackageLocation(templateDir);
|
|
66
|
-
|
|
67
|
-
if (!pkgLocation) {
|
|
68
|
-
logger.error(` ${chalk.redBright("Error")}: package.json file not found in ${templateDir}. Aborting.\n`);
|
|
69
|
-
process.exit(1);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// load package.json to get the template ID (if it exists)
|
|
73
|
-
const pkg = await getPackageJsonContents(pkgLocation);
|
|
74
|
-
|
|
75
|
-
if (!pkg) {
|
|
76
|
-
logger.error(
|
|
77
|
-
` ${chalk.redBright("Error")}: cannot read/parse package.json file in ${templateDir}. Aborting.\n`,
|
|
78
|
-
);
|
|
79
|
-
process.exit(1);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if (!pkg.enpage?.id) {
|
|
83
|
-
// call API to create a new template
|
|
84
|
-
const { data, isError, status } = await post<{ success: true; template: { id: string } }>(
|
|
85
|
-
API_ENDPOINT_REGISTER_TEMPLATE,
|
|
86
|
-
{}, // todo: fill with template data
|
|
87
|
-
);
|
|
88
|
-
if (isError) {
|
|
89
|
-
logger.error(` ${chalk.redBright("Error")}: Cannot register template: ${formatAPIError(data)}\n`);
|
|
90
|
-
process.exit(1);
|
|
91
|
-
}
|
|
92
|
-
pkg.enpage ??= {};
|
|
93
|
-
pkg.enpage.id = data.template.id;
|
|
94
|
-
|
|
95
|
-
// save the template ID to package.json
|
|
96
|
-
try {
|
|
97
|
-
if (!options.dryRun) writeFileSync(pkgLocation, JSON.stringify(pkg, null, 2));
|
|
98
|
-
} catch (e) {
|
|
99
|
-
logger.error(
|
|
100
|
-
` ${chalk.redBright("Error")}: Cannot update template id in package.json file located in ${templateDir}. Aborting.\n`,
|
|
101
|
-
);
|
|
102
|
-
process.exit(1);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
const templateId = pkg.enpage.id;
|
|
107
|
-
|
|
108
|
-
// submit template to Enpage
|
|
109
|
-
logger.info(`Submitting template to Enpage...\n`);
|
|
110
|
-
|
|
111
|
-
const uploadResults = await uploadTemplate(templateId, templateDir, token, options.dryRun);
|
|
112
|
-
|
|
113
|
-
if (!uploadResults.success) {
|
|
114
|
-
logger.error("\nUpload failed. See details above.\n");
|
|
115
|
-
process.exit(1);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
logger.success(`Template ${templateId} published.\n`);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
function getPackageLocation(templateDir: string) {
|
|
122
|
-
return existsSync(resolve(templateDir, "package.json"))
|
|
123
|
-
? resolve(templateDir, "package.json")
|
|
124
|
-
: existsSync(resolve(templateDir, "template-package.json"))
|
|
125
|
-
? resolve(templateDir, "template-package.json")
|
|
126
|
-
: false;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
function getPackageJsonContents(pkgJsonPath: string) {
|
|
130
|
-
try {
|
|
131
|
-
return JSON.parse(readFileSync(pkgJsonPath, "utf-8"));
|
|
132
|
-
} catch (e) {
|
|
133
|
-
return null;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
@@ -1,278 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* parse-gitignore <https://github.com/jonschlinkert/parse-gitignore>
|
|
3
|
-
* Copyright (c) 2015-present, Jon Schlinkert.
|
|
4
|
-
* Released under the MIT License.
|
|
5
|
-
*
|
|
6
|
-
* Converted to typescript by Matthias E. <matthias@upstart.gg>
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import * as fs from "node:fs";
|
|
10
|
-
|
|
11
|
-
// eslint-disable-next-line no-control-regex
|
|
12
|
-
const INVALID_PATH_CHARS_REGEX = /[<>"|?*\n\r\t\f\x00-\x1F]/;
|
|
13
|
-
const GLOBSTAR_REGEX = /(?:^|\/)[*]{2}($|\/)/;
|
|
14
|
-
const MAX_PATH_LENGTH = 260 - 12;
|
|
15
|
-
|
|
16
|
-
interface ParseOptions {
|
|
17
|
-
path?: string;
|
|
18
|
-
dedupe?: boolean;
|
|
19
|
-
unique?: boolean;
|
|
20
|
-
ignore?: string[];
|
|
21
|
-
unignore?: string[];
|
|
22
|
-
format?: boolean;
|
|
23
|
-
formatSection?: (section: Section) => string;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
interface Section {
|
|
27
|
-
name: string;
|
|
28
|
-
comment?: string;
|
|
29
|
-
patterns: string[];
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
interface ParsedGitignore {
|
|
33
|
-
sections: Section[];
|
|
34
|
-
patterns: string[];
|
|
35
|
-
path?: string;
|
|
36
|
-
input: Buffer;
|
|
37
|
-
format: (opts?: ParseOptions) => string;
|
|
38
|
-
dedupe: (opts?: ParseOptions) => ParsedGitignore;
|
|
39
|
-
globs: (opts?: ParseOptions) => GlobResult[];
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
interface GlobResult {
|
|
43
|
-
type: "ignore" | "unignore";
|
|
44
|
-
path: string | null;
|
|
45
|
-
patterns: string[];
|
|
46
|
-
index: number;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const isObject = (v: unknown): v is Record<string, unknown> =>
|
|
50
|
-
v !== null && typeof v === "object" && !Array.isArray(v);
|
|
51
|
-
|
|
52
|
-
const isValidPath = (input: unknown): input is string =>
|
|
53
|
-
typeof input === "string" && input.length <= MAX_PATH_LENGTH && !INVALID_PATH_CHARS_REGEX.test(input);
|
|
54
|
-
|
|
55
|
-
const split = (str: string): string[] => str.split(/\r\n?|\n/);
|
|
56
|
-
const isComment = (str: string): boolean => str.startsWith("#");
|
|
57
|
-
const isParsed = (input: unknown): input is ParsedGitignore =>
|
|
58
|
-
isObject(input) && Array.isArray(input.patterns) && Array.isArray(input.sections);
|
|
59
|
-
|
|
60
|
-
const patterns = (input: string): string[] =>
|
|
61
|
-
split(input)
|
|
62
|
-
.map((l) => l.trim())
|
|
63
|
-
.filter((line) => line !== "" && !isComment(line));
|
|
64
|
-
|
|
65
|
-
const parse = (input: string | ParsedGitignore, options: ParseOptions = {}): ParsedGitignore => {
|
|
66
|
-
let filepath = options.path;
|
|
67
|
-
|
|
68
|
-
if (isParsed(input)) return input;
|
|
69
|
-
if (isValidPath(input) && fs.existsSync(input)) {
|
|
70
|
-
filepath = input;
|
|
71
|
-
input = fs.readFileSync(input, "utf8");
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const lines = split(input);
|
|
75
|
-
const names = new Map<string, Section>();
|
|
76
|
-
|
|
77
|
-
let parsed: ParsedGitignore = { sections: [], patterns: [] } as unknown as ParsedGitignore;
|
|
78
|
-
let section: Section = { name: "default", patterns: [] };
|
|
79
|
-
let prev: Section | null = null;
|
|
80
|
-
|
|
81
|
-
for (const line of lines) {
|
|
82
|
-
const value = line.trim();
|
|
83
|
-
|
|
84
|
-
if (value.startsWith("#")) {
|
|
85
|
-
const [, name] = /^#+\s*(.*)\s*$/.exec(value) || [];
|
|
86
|
-
|
|
87
|
-
if (prev) {
|
|
88
|
-
names.delete(prev.name);
|
|
89
|
-
prev.comment = prev.comment ? `${prev.comment}\n${value}` : value;
|
|
90
|
-
prev.name = name ? `${prev.name.trim()}\n${name.trim()}` : prev.name.trim();
|
|
91
|
-
names.set(prev.name.toLowerCase().trim(), prev);
|
|
92
|
-
continue;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
section = { name: name?.trim() || "", comment: value, patterns: [] };
|
|
96
|
-
names.set(section.name.toLowerCase(), section);
|
|
97
|
-
parsed.sections.push(section);
|
|
98
|
-
prev = section;
|
|
99
|
-
continue;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
if (value !== "") {
|
|
103
|
-
section.patterns.push(value);
|
|
104
|
-
parsed.patterns.push(value);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
prev = null;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
if (options.dedupe === true || options.unique === true) {
|
|
111
|
-
parsed = dedupe(parsed, { ...options, format: false });
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
parsed.path = filepath;
|
|
115
|
-
parsed.input = Buffer.from(input);
|
|
116
|
-
parsed.format = (opts?: ParseOptions) => format(parsed, { ...options, ...opts });
|
|
117
|
-
parsed.dedupe = (opts?: ParseOptions) => dedupe(parsed, { ...options, ...opts });
|
|
118
|
-
parsed.globs = (opts?: ParseOptions) => globs(parsed, { path: filepath, ...options, ...opts });
|
|
119
|
-
return parsed;
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
const parseFile = (filepath: string, options?: ParseOptions): ParsedGitignore =>
|
|
123
|
-
parse(fs.readFileSync(filepath, "utf8"), options);
|
|
124
|
-
|
|
125
|
-
const dedupe = (input: string | ParsedGitignore, options: ParseOptions): ParsedGitignore => {
|
|
126
|
-
const parsed = parse(input, { ...options, dedupe: false });
|
|
127
|
-
|
|
128
|
-
const names = new Map<string, Section>();
|
|
129
|
-
const res: ParsedGitignore = { sections: [], patterns: [] } as unknown as ParsedGitignore;
|
|
130
|
-
let current: Section;
|
|
131
|
-
|
|
132
|
-
// first, combine duplicate sections
|
|
133
|
-
for (const section of parsed.sections) {
|
|
134
|
-
const { name = "", comment, patterns } = section;
|
|
135
|
-
const key = name.trim().toLowerCase();
|
|
136
|
-
|
|
137
|
-
for (const pattern of patterns) {
|
|
138
|
-
if (!res.patterns.includes(pattern)) {
|
|
139
|
-
res.patterns.push(pattern);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
if (name && names.has(key)) {
|
|
144
|
-
current = names.get(key)!;
|
|
145
|
-
current.patterns = [...current.patterns, ...patterns];
|
|
146
|
-
} else {
|
|
147
|
-
current = { name, comment, patterns };
|
|
148
|
-
res.sections.push(current);
|
|
149
|
-
names.set(key, current);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// next, de-dupe patterns in each section
|
|
154
|
-
for (const section of res.sections) {
|
|
155
|
-
section.patterns = [...new Set(section.patterns)];
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
return res;
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
const glob = (pattern: string): string => {
|
|
162
|
-
// Return if a glob pattern has already been specified for sub-directories
|
|
163
|
-
if (GLOBSTAR_REGEX.test(pattern)) {
|
|
164
|
-
return pattern;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
// If there is a separator at the beginning or middle (or both) of the pattern,
|
|
168
|
-
// then the pattern is relative to the directory level of the particular .gitignore
|
|
169
|
-
// file itself. Otherwise the pattern may also match at any level below the
|
|
170
|
-
// .gitignore level. relative paths only
|
|
171
|
-
let relative = false;
|
|
172
|
-
if (pattern.startsWith("/")) {
|
|
173
|
-
pattern = pattern.slice(1);
|
|
174
|
-
relative = true;
|
|
175
|
-
} else if (pattern.slice(1, pattern.length - 1).includes("/")) {
|
|
176
|
-
relative = true;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
// If there is a separator at the end of the pattern then the pattern will only match directories.
|
|
180
|
-
pattern += pattern.endsWith("/") ? "**/" : "/**";
|
|
181
|
-
|
|
182
|
-
// If not relative, the pattern can match any files and directories.
|
|
183
|
-
return relative ? pattern : `**/${pattern}`;
|
|
184
|
-
};
|
|
185
|
-
|
|
186
|
-
const globs = (input: string | ParsedGitignore, options: ParseOptions = {}): GlobResult[] => {
|
|
187
|
-
const parsed = parse(input, options);
|
|
188
|
-
const result: GlobResult[] = [];
|
|
189
|
-
let index = 0;
|
|
190
|
-
|
|
191
|
-
const globPatterns = parsed.patterns
|
|
192
|
-
.concat(options.ignore || [])
|
|
193
|
-
.concat((options.unignore || []).map((p) => (!p.startsWith("!") ? `!${p}` : p)));
|
|
194
|
-
|
|
195
|
-
const push = (prefix: string, pattern: string) => {
|
|
196
|
-
const prev = result[result.length - 1];
|
|
197
|
-
const type = prefix ? "unignore" : "ignore";
|
|
198
|
-
|
|
199
|
-
if (prev && prev.type === type) {
|
|
200
|
-
if (!prev.patterns.includes(pattern)) {
|
|
201
|
-
prev.patterns.push(pattern);
|
|
202
|
-
}
|
|
203
|
-
} else {
|
|
204
|
-
result.push({ type, path: options.path || null, patterns: [pattern], index });
|
|
205
|
-
index++;
|
|
206
|
-
}
|
|
207
|
-
};
|
|
208
|
-
|
|
209
|
-
for (let pattern of globPatterns) {
|
|
210
|
-
let prefix = "";
|
|
211
|
-
|
|
212
|
-
// An optional prefix "!" which negates the pattern; any matching file excluded by
|
|
213
|
-
// a previous pattern will become included again
|
|
214
|
-
if (pattern.startsWith("!")) {
|
|
215
|
-
pattern = pattern.slice(1);
|
|
216
|
-
prefix = "!";
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
// add the raw pattern to the results
|
|
220
|
-
push(prefix, pattern.startsWith("/") ? pattern.slice(1) : pattern);
|
|
221
|
-
|
|
222
|
-
// add the glob pattern to the results
|
|
223
|
-
push(prefix, glob(pattern));
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
return result;
|
|
227
|
-
};
|
|
228
|
-
|
|
229
|
-
/**
|
|
230
|
-
* Formats a .gitignore section
|
|
231
|
-
*/
|
|
232
|
-
const formatSection = (section: Section = { name: "", patterns: [] }): string => {
|
|
233
|
-
const output = [section.comment || ""];
|
|
234
|
-
|
|
235
|
-
if (section.patterns?.length) {
|
|
236
|
-
output.push(section.patterns.join("\n"));
|
|
237
|
-
output.push("");
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
return output.join("\n");
|
|
241
|
-
};
|
|
242
|
-
|
|
243
|
-
/**
|
|
244
|
-
* Format a .gitignore file from the given input or object from `.parse()`.
|
|
245
|
-
* @param {String | ParsedGitignore} input File path or contents.
|
|
246
|
-
* @param {ParseOptions} options
|
|
247
|
-
* @return {String} Returns formatted string.
|
|
248
|
-
* @api public
|
|
249
|
-
*/
|
|
250
|
-
const format = (input: string | ParsedGitignore, options: ParseOptions = {}): string => {
|
|
251
|
-
const parsed = parse(input, options);
|
|
252
|
-
|
|
253
|
-
const fn = options.formatSection || formatSection;
|
|
254
|
-
const sections = parsed.sections || parsed;
|
|
255
|
-
const output: string[] = [];
|
|
256
|
-
|
|
257
|
-
for (const section of ([] as Section[]).concat(sections)) {
|
|
258
|
-
output.push(fn(section));
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
return output.join("\n");
|
|
262
|
-
};
|
|
263
|
-
|
|
264
|
-
export {
|
|
265
|
-
parse,
|
|
266
|
-
parseFile,
|
|
267
|
-
dedupe,
|
|
268
|
-
format,
|
|
269
|
-
globs,
|
|
270
|
-
formatSection,
|
|
271
|
-
patterns,
|
|
272
|
-
type ParseOptions,
|
|
273
|
-
type Section,
|
|
274
|
-
type ParsedGitignore,
|
|
275
|
-
type GlobResult,
|
|
276
|
-
};
|
|
277
|
-
|
|
278
|
-
export default parse;
|