@uniformdev/cli 18.17.1-alpha.13 → 18.19.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/dist/{chunk-NNLVNLDW.mjs → chunk-6QA6UNAY.mjs} +24 -2
- package/dist/index.js +354 -324
- package/dist/index.mjs +331 -323
- package/dist/sync/index.js +24 -2
- package/dist/sync/index.mjs +1 -1
- package/package.json +7 -7
package/dist/index.mjs
CHANGED
|
@@ -22,7 +22,7 @@ import {
|
|
|
22
22
|
withFormatOptions,
|
|
23
23
|
withProjectOptions,
|
|
24
24
|
writeUniformPackage
|
|
25
|
-
} from "./chunk-
|
|
25
|
+
} from "./chunk-6QA6UNAY.mjs";
|
|
26
26
|
|
|
27
27
|
// src/index.ts
|
|
28
28
|
import yargs17 from "yargs";
|
|
@@ -549,6 +549,10 @@ var CompositionListModule = {
|
|
|
549
549
|
default: false,
|
|
550
550
|
describe: "Resolve pattern references in the composition"
|
|
551
551
|
},
|
|
552
|
+
resolveOverrides: {
|
|
553
|
+
type: "boolean",
|
|
554
|
+
default: false
|
|
555
|
+
},
|
|
552
556
|
componentIDs: {
|
|
553
557
|
type: "boolean",
|
|
554
558
|
default: false,
|
|
@@ -570,6 +574,7 @@ var CompositionListModule = {
|
|
|
570
574
|
project: projectId,
|
|
571
575
|
state,
|
|
572
576
|
resolvePatterns,
|
|
577
|
+
resolveOverrides,
|
|
573
578
|
componentIDs
|
|
574
579
|
}) => {
|
|
575
580
|
const fetch3 = nodeFetchProxy(proxy);
|
|
@@ -579,7 +584,8 @@ var CompositionListModule = {
|
|
|
579
584
|
offset,
|
|
580
585
|
state: convertCompositionState(state),
|
|
581
586
|
skipPatternResolution: !resolvePatterns,
|
|
582
|
-
withComponentIDs: componentIDs
|
|
587
|
+
withComponentIDs: componentIDs,
|
|
588
|
+
skipParameterResolution: !resolveOverrides
|
|
583
589
|
});
|
|
584
590
|
emitWithFormat(res.compositions, format, filename);
|
|
585
591
|
}
|
|
@@ -611,6 +617,7 @@ function createComponentInstanceEngineDataSource({
|
|
|
611
617
|
state: stateId,
|
|
612
618
|
skipPatternResolution: true,
|
|
613
619
|
skipParameterResolution: true,
|
|
620
|
+
skipOverridesResolution: true,
|
|
614
621
|
withComponentIDs: true
|
|
615
622
|
})).compositions,
|
|
616
623
|
{ pageSize: 100 }
|
|
@@ -926,6 +933,7 @@ var DataTypeGetModule = {
|
|
|
926
933
|
builder: (yargs18) => withFormatOptions(
|
|
927
934
|
withApiOptions(
|
|
928
935
|
withProjectOptions(
|
|
936
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
929
937
|
yargs18.positional("id", { demandOption: true, describe: "Data type public ID to fetch" })
|
|
930
938
|
)
|
|
931
939
|
)
|
|
@@ -2743,104 +2751,189 @@ var ContextCommand = {
|
|
|
2743
2751
|
}
|
|
2744
2752
|
};
|
|
2745
2753
|
|
|
2746
|
-
// src/
|
|
2747
|
-
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
|
|
2755
|
-
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
}
|
|
2762
|
-
]);
|
|
2763
|
-
telemetry.send("team picked", { teamId: result.teamId });
|
|
2764
|
-
return result;
|
|
2765
|
-
}
|
|
2754
|
+
// src/spinner.ts
|
|
2755
|
+
var makeSpinner = () => {
|
|
2756
|
+
const spinners = [];
|
|
2757
|
+
const stopAllSpinners = () => spinners.forEach((spinner) => spinner.stop());
|
|
2758
|
+
const spin = async (text) => {
|
|
2759
|
+
const spinner = await Promise.resolve().then(() => __toESM(__require("ora"))).then((ora) => ora.default(text).start());
|
|
2760
|
+
spinners.push(spinner);
|
|
2761
|
+
const minWait = new Promise((resolve) => setTimeout(resolve, 500));
|
|
2762
|
+
return async () => {
|
|
2763
|
+
await minWait;
|
|
2764
|
+
spinner.stop();
|
|
2765
|
+
};
|
|
2766
|
+
};
|
|
2767
|
+
return { stopAllSpinners, spin };
|
|
2768
|
+
};
|
|
2766
2769
|
|
|
2767
|
-
// src/
|
|
2770
|
+
// src/telemetry/telemetry.ts
|
|
2768
2771
|
import crypto from "crypto";
|
|
2769
|
-
import
|
|
2770
|
-
import { copy } from "fs-jetpack";
|
|
2771
|
-
import * as git from "isomorphic-git";
|
|
2772
|
-
import * as http from "isomorphic-git/http/node";
|
|
2773
|
-
import os from "os";
|
|
2774
|
-
import path from "path";
|
|
2772
|
+
import { PostHog } from "posthog-node";
|
|
2775
2773
|
|
|
2776
|
-
//
|
|
2777
|
-
|
|
2778
|
-
|
|
2779
|
-
|
|
2780
|
-
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
|
|
2784
|
-
|
|
2785
|
-
|
|
2786
|
-
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
|
|
2774
|
+
// package.json
|
|
2775
|
+
var package_default = {
|
|
2776
|
+
name: "@uniformdev/cli",
|
|
2777
|
+
version: "18.19.0",
|
|
2778
|
+
description: "Uniform command line interface tool",
|
|
2779
|
+
license: "SEE LICENSE IN LICENSE.txt",
|
|
2780
|
+
main: "./cli.js",
|
|
2781
|
+
types: "./dist/index.d.ts",
|
|
2782
|
+
sideEffects: false,
|
|
2783
|
+
scripts: {
|
|
2784
|
+
uniform: "node ./cli.js",
|
|
2785
|
+
build: "tsup",
|
|
2786
|
+
dev: "tsup --watch",
|
|
2787
|
+
clean: "rimraf dist",
|
|
2788
|
+
test: "jest --maxWorkers=1 --passWithNoTests",
|
|
2789
|
+
lint: 'eslint "src/**/*.{js,ts,tsx}"',
|
|
2790
|
+
format: 'prettier --write "src/**/*.{js,ts,tsx}"'
|
|
2791
|
+
},
|
|
2792
|
+
dependencies: {
|
|
2793
|
+
"@uniformdev/canvas": "workspace:*",
|
|
2794
|
+
"@uniformdev/context": "workspace:*",
|
|
2795
|
+
"@uniformdev/project-map": "workspace:*",
|
|
2796
|
+
diff: "^5.0.0",
|
|
2797
|
+
dotenv: "^16.0.3",
|
|
2798
|
+
execa: "5.1.1",
|
|
2799
|
+
"fs-jetpack": "5.1.0",
|
|
2800
|
+
graphql: "16.6.0",
|
|
2801
|
+
"graphql-request": "5.1.0",
|
|
2802
|
+
"https-proxy-agent": "^5.0.1",
|
|
2803
|
+
inquirer: "8.2.5",
|
|
2804
|
+
"isomorphic-git": "1.21.0",
|
|
2805
|
+
"isomorphic-unfetch": "^3.1.0",
|
|
2806
|
+
"js-yaml": "^4.1.0",
|
|
2807
|
+
jsonwebtoken: "9.0.0",
|
|
2808
|
+
"lodash.isequalwith": "^4.4.0",
|
|
2809
|
+
open: "8.4.0",
|
|
2810
|
+
ora: "6.1.2",
|
|
2811
|
+
"posthog-node": "2.5.3",
|
|
2812
|
+
slugify: "1.6.5",
|
|
2813
|
+
yargs: "^17.6.2",
|
|
2814
|
+
zod: "3.20.6"
|
|
2815
|
+
},
|
|
2816
|
+
devDependencies: {
|
|
2817
|
+
"@types/diff": "5.0.2",
|
|
2818
|
+
"@types/inquirer": "9.0.3",
|
|
2819
|
+
"@types/js-yaml": "4.0.5",
|
|
2820
|
+
"@types/jsonwebtoken": "9.0.1",
|
|
2821
|
+
"@types/lodash.isequalwith": "4.4.7",
|
|
2822
|
+
"@types/node": "18.11.17",
|
|
2823
|
+
"@types/yargs": "17.0.22",
|
|
2824
|
+
"p-limit": "4.0.0"
|
|
2825
|
+
},
|
|
2826
|
+
bin: {
|
|
2827
|
+
uniform: "./cli.js"
|
|
2828
|
+
},
|
|
2829
|
+
files: [
|
|
2830
|
+
"/dist"
|
|
2831
|
+
],
|
|
2832
|
+
publishConfig: {
|
|
2833
|
+
access: "public"
|
|
2792
2834
|
}
|
|
2793
|
-
return result.stdout;
|
|
2794
2835
|
};
|
|
2795
2836
|
|
|
2796
|
-
// src/
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
|
|
2837
|
+
// src/telemetry/telemetry.ts
|
|
2838
|
+
var POSTHOG_WRITE_ONLY_KEY = "phc_c8YoKI9984KOHBfNrCRfIKvL56aYd5OpYxOdYexRzH7";
|
|
2839
|
+
var Telemetry = class {
|
|
2840
|
+
constructor(prefix, disable = false) {
|
|
2841
|
+
this.prefix = prefix;
|
|
2842
|
+
this.distinctId = crypto.randomBytes(20).toString("hex");
|
|
2843
|
+
if (!disable) {
|
|
2844
|
+
this.posthog = new PostHog(POSTHOG_WRITE_ONLY_KEY, {
|
|
2845
|
+
flushAt: 1,
|
|
2846
|
+
flushInterval: 1
|
|
2847
|
+
});
|
|
2848
|
+
this.send("started");
|
|
2849
|
+
}
|
|
2850
|
+
}
|
|
2851
|
+
login(sub, user) {
|
|
2852
|
+
if (!this.posthog) {
|
|
2853
|
+
return;
|
|
2854
|
+
}
|
|
2855
|
+
const alias = this.distinctId;
|
|
2856
|
+
this.distinctId = sub;
|
|
2857
|
+
this.posthog.alias({ distinctId: this.distinctId, alias });
|
|
2858
|
+
this.posthog.identify({
|
|
2859
|
+
distinctId: this.distinctId,
|
|
2860
|
+
properties: {
|
|
2861
|
+
email: user.email_address,
|
|
2862
|
+
sub,
|
|
2863
|
+
teamCount: user.teams.length
|
|
2864
|
+
}
|
|
2814
2865
|
});
|
|
2815
|
-
|
|
2816
|
-
throw new Error(`Failed to fetch starter code: ${err.message}`);
|
|
2866
|
+
this.send("logged in");
|
|
2817
2867
|
}
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2868
|
+
send(event, properties = {}) {
|
|
2869
|
+
var _a;
|
|
2870
|
+
(_a = this.posthog) == null ? void 0 : _a.capture({
|
|
2871
|
+
distinctId: this.distinctId,
|
|
2872
|
+
event: [this.prefix, event].join(" "),
|
|
2873
|
+
properties: {
|
|
2874
|
+
version: package_default.version,
|
|
2875
|
+
...properties
|
|
2876
|
+
}
|
|
2877
|
+
});
|
|
2821
2878
|
}
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2879
|
+
shutdown() {
|
|
2880
|
+
var _a;
|
|
2881
|
+
this.send("exited", { exitCode: process.exitCode });
|
|
2882
|
+
return (_a = this.posthog) == null ? void 0 : _a.shutdownAsync();
|
|
2826
2883
|
}
|
|
2827
|
-
|
|
2828
|
-
Your project now lives in ${targetDir} \u2728`);
|
|
2829
|
-
return {
|
|
2830
|
-
runNpmInstall: async () => {
|
|
2831
|
-
console.log(`
|
|
2832
|
-
Installing project dependencies...
|
|
2884
|
+
};
|
|
2833
2885
|
|
|
2834
|
-
|
|
2835
|
-
|
|
2886
|
+
// src/commands/new/commands/new.ts
|
|
2887
|
+
import inquirer4 from "inquirer";
|
|
2888
|
+
|
|
2889
|
+
// src/auth/getBearerToken.ts
|
|
2890
|
+
import inquirer from "inquirer";
|
|
2891
|
+
import jwt from "jsonwebtoken";
|
|
2892
|
+
import open from "open";
|
|
2893
|
+
|
|
2894
|
+
// src/url.ts
|
|
2895
|
+
var makeUrl = (baseUrl, path4) => [baseUrl.trim().replace(/\/+$/, ""), path4.trim().replace(/^\/+/, "")].join("/");
|
|
2896
|
+
|
|
2897
|
+
// src/auth/getBearerToken.ts
|
|
2898
|
+
async function getBearerToken(baseUrl) {
|
|
2899
|
+
const { canOpen } = await inquirer.prompt([
|
|
2900
|
+
{
|
|
2901
|
+
type: "confirm",
|
|
2902
|
+
name: "canOpen",
|
|
2903
|
+
message: "Can we open a browser window to get a Uniform auth token?"
|
|
2904
|
+
}
|
|
2905
|
+
]);
|
|
2906
|
+
if (canOpen) {
|
|
2907
|
+
open(makeUrl(baseUrl, "/cli-login"));
|
|
2908
|
+
}
|
|
2909
|
+
const tokenAnswer = await inquirer.prompt([
|
|
2910
|
+
{
|
|
2911
|
+
type: "password",
|
|
2912
|
+
name: "authToken",
|
|
2913
|
+
message: "Paste your Uniform auth token"
|
|
2836
2914
|
}
|
|
2915
|
+
]);
|
|
2916
|
+
const authToken = tokenAnswer.authToken.trim();
|
|
2917
|
+
if (!authToken) {
|
|
2918
|
+
throw new Error("No auth token provided.");
|
|
2919
|
+
}
|
|
2920
|
+
const decoded = jwt.decode(authToken, { complete: false });
|
|
2921
|
+
if (!decoded) {
|
|
2922
|
+
throw new Error("Could not parse the token pasted.");
|
|
2923
|
+
}
|
|
2924
|
+
if (typeof decoded.sub !== "string" || typeof decoded === "string") {
|
|
2925
|
+
throw new Error("Invalid token pasted.");
|
|
2926
|
+
}
|
|
2927
|
+
return {
|
|
2928
|
+
authToken,
|
|
2929
|
+
decoded: { ...decoded, sub: decoded.sub }
|
|
2837
2930
|
};
|
|
2838
2931
|
}
|
|
2839
2932
|
|
|
2840
|
-
// src/
|
|
2933
|
+
// src/client.ts
|
|
2841
2934
|
import { z } from "zod";
|
|
2842
2935
|
|
|
2843
|
-
// src/
|
|
2936
|
+
// src/auth/api-key.ts
|
|
2844
2937
|
var READ_PERMISSIONS = ["PROJECT", "UPM_PUB", "OPT_PUB", "OPT_READ", "UPM_READ"];
|
|
2845
2938
|
var WRITE_PERMISSIONS = [
|
|
2846
2939
|
"PROJECT",
|
|
@@ -2888,10 +2981,7 @@ var makeApiKey = (teamId, projectId, name, permissions) => ({
|
|
|
2888
2981
|
var makeReadApiKey = (teamId, projectId) => makeApiKey(teamId, projectId, "Created by Uniform New (read)", READ_PERMISSIONS);
|
|
2889
2982
|
var makeWriteApiKey = (teamId, projectId) => makeApiKey(teamId, projectId, "Created by Uniform New (write)", WRITE_PERMISSIONS);
|
|
2890
2983
|
|
|
2891
|
-
// src/
|
|
2892
|
-
var makeUrl = (baseUrl, path4) => [baseUrl.trim().replace(/\/+$/, ""), path4.trim().replace(/^\/+/, "")].join("/");
|
|
2893
|
-
|
|
2894
|
-
// src/commands/new/client.ts
|
|
2984
|
+
// src/client.ts
|
|
2895
2985
|
var createTeamOrProjectSchema = z.object({ id: z.string().min(1) });
|
|
2896
2986
|
var createApiKeySchema = z.object({ apiKey: z.string().min(1) });
|
|
2897
2987
|
var getLimitsSchema = z.object({
|
|
@@ -3034,124 +3124,80 @@ var createClient = (baseUrl, authToken) => {
|
|
|
3034
3124
|
};
|
|
3035
3125
|
};
|
|
3036
3126
|
|
|
3037
|
-
// src/
|
|
3038
|
-
import
|
|
3039
|
-
|
|
3040
|
-
|
|
3041
|
-
query GetUserInfo($subject: String!) {
|
|
3042
|
-
info: identities_by_pk(subject: $subject) {
|
|
3043
|
-
name
|
|
3044
|
-
email_address
|
|
3045
|
-
teams: organizations_identities {
|
|
3046
|
-
team: organization {
|
|
3047
|
-
name
|
|
3048
|
-
id
|
|
3049
|
-
sites {
|
|
3050
|
-
name
|
|
3051
|
-
id
|
|
3052
|
-
}
|
|
3053
|
-
}
|
|
3054
|
-
}
|
|
3055
|
-
}
|
|
3056
|
-
}
|
|
3057
|
-
`;
|
|
3058
|
-
var schema = z2.object({
|
|
3059
|
-
info: z2.object({
|
|
3060
|
-
name: z2.string().min(1),
|
|
3061
|
-
email_address: z2.string().min(1),
|
|
3062
|
-
teams: z2.array(
|
|
3063
|
-
z2.object({
|
|
3064
|
-
team: z2.object({
|
|
3065
|
-
name: z2.string().min(1),
|
|
3066
|
-
id: z2.string().min(1),
|
|
3067
|
-
sites: z2.array(
|
|
3068
|
-
z2.object({
|
|
3069
|
-
name: z2.string().min(1),
|
|
3070
|
-
id: z2.string().min(1)
|
|
3071
|
-
})
|
|
3072
|
-
)
|
|
3073
|
-
})
|
|
3074
|
-
})
|
|
3075
|
-
)
|
|
3076
|
-
})
|
|
3077
|
-
});
|
|
3078
|
-
var getUserInfo = async (baseUrl, authToken, subject) => {
|
|
3127
|
+
// src/npm.ts
|
|
3128
|
+
import execa from "execa";
|
|
3129
|
+
var runNpm = async (workDir, args, { inherit, env } = {}) => {
|
|
3130
|
+
let result;
|
|
3079
3131
|
try {
|
|
3080
|
-
|
|
3081
|
-
|
|
3082
|
-
|
|
3083
|
-
|
|
3084
|
-
|
|
3085
|
-
} else {
|
|
3086
|
-
throw new Error(`Invalid GraphQL response: ${parseResult.error.message}`);
|
|
3087
|
-
}
|
|
3132
|
+
result = await execa("npm", args, {
|
|
3133
|
+
cwd: workDir,
|
|
3134
|
+
env: env != null ? env : {},
|
|
3135
|
+
...inherit ? { stdout: "inherit", stderr: "inherit" } : {}
|
|
3136
|
+
});
|
|
3088
3137
|
} catch (err) {
|
|
3089
|
-
throw new Error(`Failed to
|
|
3090
|
-
|
|
3138
|
+
throw new Error(`Failed to execute npm ${args.join(" ")}
|
|
3139
|
+
${err.message}`);
|
|
3091
3140
|
}
|
|
3141
|
+
if (result.exitCode !== 0) {
|
|
3142
|
+
throw new Error(`Command npm ${args.join(" ")} exitted with code ${result == null ? void 0 : result.exitCode}}: ${result.stderr}`);
|
|
3143
|
+
}
|
|
3144
|
+
return result.stdout;
|
|
3092
3145
|
};
|
|
3093
3146
|
|
|
3094
|
-
// src/
|
|
3095
|
-
|
|
3096
|
-
|
|
3097
|
-
|
|
3147
|
+
// src/projects/cloneStarter.ts
|
|
3148
|
+
import crypto2 from "crypto";
|
|
3149
|
+
import fs from "fs";
|
|
3150
|
+
import { copy } from "fs-jetpack";
|
|
3151
|
+
import * as git from "isomorphic-git";
|
|
3152
|
+
import * as http from "isomorphic-git/http/node";
|
|
3153
|
+
import os from "os";
|
|
3154
|
+
import path from "path";
|
|
3155
|
+
async function cloneStarter({
|
|
3098
3156
|
spin,
|
|
3099
|
-
|
|
3157
|
+
githubPath,
|
|
3158
|
+
targetDir,
|
|
3159
|
+
dotEnvFile
|
|
3100
3160
|
}) {
|
|
3101
|
-
const
|
|
3102
|
-
const
|
|
3103
|
-
|
|
3104
|
-
|
|
3105
|
-
await
|
|
3106
|
-
|
|
3161
|
+
const done = await spin("Fetching starter code...");
|
|
3162
|
+
const cloneDir = path.join(os.tmpdir(), `uniform-new-${crypto2.randomBytes(20).toString("hex")}`);
|
|
3163
|
+
const [user, repo, ...pathSegments] = githubPath.split("/");
|
|
3164
|
+
try {
|
|
3165
|
+
await git.clone({
|
|
3166
|
+
fs,
|
|
3167
|
+
http,
|
|
3168
|
+
url: `https://github.com/${user}/${repo}`,
|
|
3169
|
+
dir: cloneDir,
|
|
3170
|
+
singleBranch: true,
|
|
3171
|
+
depth: 1
|
|
3172
|
+
});
|
|
3173
|
+
} catch (err) {
|
|
3174
|
+
throw new Error(`Failed to fetch starter code: ${err.message}`);
|
|
3107
3175
|
}
|
|
3108
3176
|
await done();
|
|
3109
|
-
|
|
3110
|
-
|
|
3111
|
-
}
|
|
3112
|
-
|
|
3113
|
-
// src/commands/new/actions/getBearerToken.ts
|
|
3114
|
-
import inquirer2 from "inquirer";
|
|
3115
|
-
import jwt from "jsonwebtoken";
|
|
3116
|
-
import open from "open";
|
|
3117
|
-
async function getBearerToken(baseUrl) {
|
|
3118
|
-
const { canOpen } = await inquirer2.prompt([
|
|
3119
|
-
{
|
|
3120
|
-
type: "confirm",
|
|
3121
|
-
name: "canOpen",
|
|
3122
|
-
message: "Can we open a browser window to get a Uniform auth token?"
|
|
3123
|
-
}
|
|
3124
|
-
]);
|
|
3125
|
-
if (canOpen) {
|
|
3126
|
-
open(makeUrl(baseUrl, "/cli-login"));
|
|
3127
|
-
}
|
|
3128
|
-
const tokenAnswer = await inquirer2.prompt([
|
|
3129
|
-
{
|
|
3130
|
-
type: "password",
|
|
3131
|
-
name: "authToken",
|
|
3132
|
-
message: "Paste your Uniform auth token"
|
|
3133
|
-
}
|
|
3134
|
-
]);
|
|
3135
|
-
const authToken = tokenAnswer.authToken.trim();
|
|
3136
|
-
if (!authToken) {
|
|
3137
|
-
throw new Error("No auth token provided.");
|
|
3138
|
-
}
|
|
3139
|
-
const decoded = jwt.decode(authToken, { complete: false });
|
|
3140
|
-
if (!decoded) {
|
|
3141
|
-
throw new Error("Could not parse the token pasted.");
|
|
3177
|
+
if (fs.existsSync(targetDir) && fs.readdirSync(targetDir).length > 0) {
|
|
3178
|
+
throw new Error(`"${targetDir}" is not empty`);
|
|
3142
3179
|
}
|
|
3143
|
-
|
|
3144
|
-
|
|
3180
|
+
const starterDir = path.join(cloneDir, ...pathSegments);
|
|
3181
|
+
copy(starterDir, targetDir, { overwrite: true });
|
|
3182
|
+
if (dotEnvFile) {
|
|
3183
|
+
fs.writeFileSync(path.resolve(targetDir, ".env"), dotEnvFile, "utf-8");
|
|
3145
3184
|
}
|
|
3185
|
+
console.log(`
|
|
3186
|
+
Your project now lives in ${targetDir} \u2728`);
|
|
3146
3187
|
return {
|
|
3147
|
-
|
|
3148
|
-
|
|
3188
|
+
runNpmInstall: async () => {
|
|
3189
|
+
console.log(`
|
|
3190
|
+
Installing project dependencies...
|
|
3191
|
+
|
|
3192
|
+
`);
|
|
3193
|
+
await runNpm(targetDir, ["i"], { inherit: true });
|
|
3194
|
+
}
|
|
3149
3195
|
};
|
|
3150
3196
|
}
|
|
3151
3197
|
|
|
3152
|
-
// src/
|
|
3198
|
+
// src/projects/getOrCreateProject.ts
|
|
3153
3199
|
import fs2, { existsSync, mkdirSync } from "fs";
|
|
3154
|
-
import
|
|
3200
|
+
import inquirer2 from "inquirer";
|
|
3155
3201
|
import path2 from "path";
|
|
3156
3202
|
import slugify from "slugify";
|
|
3157
3203
|
var newProjectId = "$new";
|
|
@@ -3209,7 +3255,7 @@ async function getNewProjectName({
|
|
|
3209
3255
|
}) {
|
|
3210
3256
|
let projectName = explicitName;
|
|
3211
3257
|
if (!projectName) {
|
|
3212
|
-
const answer = await
|
|
3258
|
+
const answer = await inquirer2.prompt([
|
|
3213
3259
|
{
|
|
3214
3260
|
type: "input",
|
|
3215
3261
|
name: "name",
|
|
@@ -3253,7 +3299,7 @@ async function chooseExistingProject({
|
|
|
3253
3299
|
value: t.id
|
|
3254
3300
|
}));
|
|
3255
3301
|
const choices = createNew ? [{ name: "Create new project...", value: newProjectId }].concat(projects) : projects;
|
|
3256
|
-
const result = await
|
|
3302
|
+
const result = await inquirer2.prompt([
|
|
3257
3303
|
{
|
|
3258
3304
|
type: "list",
|
|
3259
3305
|
name: "projectId",
|
|
@@ -3287,6 +3333,100 @@ function validateProjectName(projectName, checkTargetDir, explicitTargetDir) {
|
|
|
3287
3333
|
}
|
|
3288
3334
|
}
|
|
3289
3335
|
|
|
3336
|
+
// src/teams/chooseTeam.ts
|
|
3337
|
+
import inquirer3 from "inquirer";
|
|
3338
|
+
async function chooseTeam(user, prompt, telemetry) {
|
|
3339
|
+
const result = await inquirer3.prompt([
|
|
3340
|
+
{
|
|
3341
|
+
type: "list",
|
|
3342
|
+
name: "teamId",
|
|
3343
|
+
message: prompt,
|
|
3344
|
+
choices: user.teams.map((team) => ({
|
|
3345
|
+
name: team.team.name,
|
|
3346
|
+
value: team.team.id
|
|
3347
|
+
}))
|
|
3348
|
+
}
|
|
3349
|
+
]);
|
|
3350
|
+
telemetry.send("team picked", { teamId: result.teamId });
|
|
3351
|
+
return result;
|
|
3352
|
+
}
|
|
3353
|
+
|
|
3354
|
+
// src/auth/user-info.ts
|
|
3355
|
+
import { gql, request } from "graphql-request";
|
|
3356
|
+
import { z as z2 } from "zod";
|
|
3357
|
+
var query = gql`
|
|
3358
|
+
query GetUserInfo($subject: String!) {
|
|
3359
|
+
info: identities_by_pk(subject: $subject) {
|
|
3360
|
+
name
|
|
3361
|
+
email_address
|
|
3362
|
+
teams: organizations_identities {
|
|
3363
|
+
team: organization {
|
|
3364
|
+
name
|
|
3365
|
+
id
|
|
3366
|
+
sites {
|
|
3367
|
+
name
|
|
3368
|
+
id
|
|
3369
|
+
}
|
|
3370
|
+
}
|
|
3371
|
+
}
|
|
3372
|
+
}
|
|
3373
|
+
}
|
|
3374
|
+
`;
|
|
3375
|
+
var schema = z2.object({
|
|
3376
|
+
info: z2.object({
|
|
3377
|
+
name: z2.string().min(1),
|
|
3378
|
+
email_address: z2.string().min(1),
|
|
3379
|
+
teams: z2.array(
|
|
3380
|
+
z2.object({
|
|
3381
|
+
team: z2.object({
|
|
3382
|
+
name: z2.string().min(1),
|
|
3383
|
+
id: z2.string().min(1),
|
|
3384
|
+
sites: z2.array(
|
|
3385
|
+
z2.object({
|
|
3386
|
+
name: z2.string().min(1),
|
|
3387
|
+
id: z2.string().min(1)
|
|
3388
|
+
})
|
|
3389
|
+
)
|
|
3390
|
+
})
|
|
3391
|
+
})
|
|
3392
|
+
)
|
|
3393
|
+
})
|
|
3394
|
+
});
|
|
3395
|
+
var getUserInfo = async (baseUrl, authToken, subject) => {
|
|
3396
|
+
try {
|
|
3397
|
+
const endpoint = makeUrl(baseUrl, "/v1/graphql");
|
|
3398
|
+
const res = await request(endpoint, query, { subject }, { Authorization: `Bearer ${authToken}` });
|
|
3399
|
+
const parseResult = schema.safeParse(res);
|
|
3400
|
+
if (parseResult.success) {
|
|
3401
|
+
return parseResult.data.info;
|
|
3402
|
+
} else {
|
|
3403
|
+
throw new Error(`Invalid GraphQL response: ${parseResult.error.message}`);
|
|
3404
|
+
}
|
|
3405
|
+
} catch (err) {
|
|
3406
|
+
throw new Error(`Failed to fetch user account:
|
|
3407
|
+
${err.message}`);
|
|
3408
|
+
}
|
|
3409
|
+
};
|
|
3410
|
+
|
|
3411
|
+
// src/teams/fetchUserAndEnsureTeamExists.ts
|
|
3412
|
+
async function fetchUserAndEnsureFirstTeamExists({
|
|
3413
|
+
baseUrl,
|
|
3414
|
+
auth: { authToken, decoded },
|
|
3415
|
+
spin,
|
|
3416
|
+
telemetry
|
|
3417
|
+
}) {
|
|
3418
|
+
const uniformClient = createClient(baseUrl, authToken);
|
|
3419
|
+
const done = await spin("Fetching user information...");
|
|
3420
|
+
let user = await getUserInfo(baseUrl, authToken, decoded.sub);
|
|
3421
|
+
if (user.teams.length < 1) {
|
|
3422
|
+
await uniformClient.createTeam(`${user.name}'s team`);
|
|
3423
|
+
user = await getUserInfo(baseUrl, authToken, decoded.sub);
|
|
3424
|
+
}
|
|
3425
|
+
await done();
|
|
3426
|
+
telemetry.login(decoded.sub, user);
|
|
3427
|
+
return user;
|
|
3428
|
+
}
|
|
3429
|
+
|
|
3290
3430
|
// src/commands/new/commands/new.ts
|
|
3291
3431
|
async function newHandler({
|
|
3292
3432
|
spin,
|
|
@@ -3518,138 +3658,6 @@ function validateIntegrationName(integrationName, explicitOutputPath) {
|
|
|
3518
3658
|
return { targetDir, typeSlug };
|
|
3519
3659
|
}
|
|
3520
3660
|
|
|
3521
|
-
// src/commands/new/spinner.ts
|
|
3522
|
-
var makeSpinner = () => {
|
|
3523
|
-
const spinners = [];
|
|
3524
|
-
const stopAllSpinners = () => spinners.forEach((spinner) => spinner.stop());
|
|
3525
|
-
const spin = async (text) => {
|
|
3526
|
-
const spinner = await Promise.resolve().then(() => __toESM(__require("ora"))).then((ora) => ora.default(text).start());
|
|
3527
|
-
spinners.push(spinner);
|
|
3528
|
-
const minWait = new Promise((resolve) => setTimeout(resolve, 500));
|
|
3529
|
-
return async () => {
|
|
3530
|
-
await minWait;
|
|
3531
|
-
spinner.stop();
|
|
3532
|
-
};
|
|
3533
|
-
};
|
|
3534
|
-
return { stopAllSpinners, spin };
|
|
3535
|
-
};
|
|
3536
|
-
|
|
3537
|
-
// src/commands/new/telemetry.ts
|
|
3538
|
-
import crypto2 from "crypto";
|
|
3539
|
-
import { PostHog } from "posthog-node";
|
|
3540
|
-
|
|
3541
|
-
// package.json
|
|
3542
|
-
var package_default = {
|
|
3543
|
-
name: "@uniformdev/cli",
|
|
3544
|
-
version: "18.17.0",
|
|
3545
|
-
description: "Uniform command line interface tool",
|
|
3546
|
-
license: "SEE LICENSE IN LICENSE.txt",
|
|
3547
|
-
main: "./cli.js",
|
|
3548
|
-
types: "./dist/index.d.ts",
|
|
3549
|
-
sideEffects: false,
|
|
3550
|
-
scripts: {
|
|
3551
|
-
uniform: "node ./cli.js",
|
|
3552
|
-
build: "tsup",
|
|
3553
|
-
dev: "tsup --watch",
|
|
3554
|
-
clean: "rimraf dist",
|
|
3555
|
-
test: "jest --maxWorkers=1 --passWithNoTests",
|
|
3556
|
-
lint: 'eslint "src/**/*.{js,ts,tsx}"',
|
|
3557
|
-
format: 'prettier --write "src/**/*.{js,ts,tsx}"'
|
|
3558
|
-
},
|
|
3559
|
-
dependencies: {
|
|
3560
|
-
"@uniformdev/canvas": "workspace:*",
|
|
3561
|
-
"@uniformdev/context": "workspace:*",
|
|
3562
|
-
"@uniformdev/project-map": "workspace:*",
|
|
3563
|
-
execa: "5.1.1",
|
|
3564
|
-
"fs-jetpack": "5.1.0",
|
|
3565
|
-
graphql: "16.6.0",
|
|
3566
|
-
"graphql-request": "5.1.0",
|
|
3567
|
-
inquirer: "8.2.5",
|
|
3568
|
-
"isomorphic-git": "1.21.0",
|
|
3569
|
-
jsonwebtoken: "9.0.0",
|
|
3570
|
-
open: "8.4.0",
|
|
3571
|
-
ora: "6.1.2",
|
|
3572
|
-
"posthog-node": "2.2.3",
|
|
3573
|
-
slugify: "1.6.5",
|
|
3574
|
-
diff: "^5.0.0",
|
|
3575
|
-
dotenv: "^16.0.3",
|
|
3576
|
-
"https-proxy-agent": "^5.0.1",
|
|
3577
|
-
"isomorphic-unfetch": "^3.1.0",
|
|
3578
|
-
"js-yaml": "^4.1.0",
|
|
3579
|
-
"lodash.isequalwith": "^4.4.0",
|
|
3580
|
-
yargs: "^17.6.2",
|
|
3581
|
-
zod: "3.20.2"
|
|
3582
|
-
},
|
|
3583
|
-
devDependencies: {
|
|
3584
|
-
"@types/inquirer": "9.0.3",
|
|
3585
|
-
"@types/jsonwebtoken": "9.0.1",
|
|
3586
|
-
"@types/node": "18.11.17",
|
|
3587
|
-
"@types/diff": "5.0.2",
|
|
3588
|
-
"@types/js-yaml": "4.0.5",
|
|
3589
|
-
"@types/lodash.isequalwith": "4.4.7",
|
|
3590
|
-
"@types/yargs": "17.0.22",
|
|
3591
|
-
"p-limit": "4.0.0"
|
|
3592
|
-
},
|
|
3593
|
-
bin: {
|
|
3594
|
-
uniform: "./cli.js"
|
|
3595
|
-
},
|
|
3596
|
-
files: [
|
|
3597
|
-
"/dist"
|
|
3598
|
-
],
|
|
3599
|
-
publishConfig: {
|
|
3600
|
-
access: "public"
|
|
3601
|
-
}
|
|
3602
|
-
};
|
|
3603
|
-
|
|
3604
|
-
// src/commands/new/telemetry.ts
|
|
3605
|
-
var POSTHOG_WRITE_ONLY_KEY = "phc_c8YoKI9984KOHBfNrCRfIKvL56aYd5OpYxOdYexRzH7";
|
|
3606
|
-
var Telemetry = class {
|
|
3607
|
-
constructor(prefix, disable = false) {
|
|
3608
|
-
this.prefix = prefix;
|
|
3609
|
-
this.distinctId = crypto2.randomBytes(20).toString("hex");
|
|
3610
|
-
if (!disable) {
|
|
3611
|
-
this.posthog = new PostHog(POSTHOG_WRITE_ONLY_KEY, {
|
|
3612
|
-
flushAt: 1,
|
|
3613
|
-
flushInterval: 1
|
|
3614
|
-
});
|
|
3615
|
-
this.send("started");
|
|
3616
|
-
}
|
|
3617
|
-
}
|
|
3618
|
-
login(sub, user) {
|
|
3619
|
-
if (!this.posthog) {
|
|
3620
|
-
return;
|
|
3621
|
-
}
|
|
3622
|
-
const alias = this.distinctId;
|
|
3623
|
-
this.distinctId = sub;
|
|
3624
|
-
this.posthog.alias({ distinctId: this.distinctId, alias });
|
|
3625
|
-
this.posthog.identify({
|
|
3626
|
-
distinctId: this.distinctId,
|
|
3627
|
-
properties: {
|
|
3628
|
-
email: user.email_address,
|
|
3629
|
-
sub,
|
|
3630
|
-
teamCount: user.teams.length
|
|
3631
|
-
}
|
|
3632
|
-
});
|
|
3633
|
-
this.send("logged in");
|
|
3634
|
-
}
|
|
3635
|
-
send(event, properties = {}) {
|
|
3636
|
-
var _a;
|
|
3637
|
-
(_a = this.posthog) == null ? void 0 : _a.capture({
|
|
3638
|
-
distinctId: this.distinctId,
|
|
3639
|
-
event: [this.prefix, event].join(" "),
|
|
3640
|
-
properties: {
|
|
3641
|
-
version: package_default.version,
|
|
3642
|
-
...properties
|
|
3643
|
-
}
|
|
3644
|
-
});
|
|
3645
|
-
}
|
|
3646
|
-
shutdown() {
|
|
3647
|
-
var _a;
|
|
3648
|
-
this.send("exited", { exitCode: process.exitCode });
|
|
3649
|
-
return (_a = this.posthog) == null ? void 0 : _a.shutdownAsync();
|
|
3650
|
-
}
|
|
3651
|
-
};
|
|
3652
|
-
|
|
3653
3661
|
// src/commands/new/index.ts
|
|
3654
3662
|
var stableApiHost = "https://uniform.app";
|
|
3655
3663
|
var apiHostDefault = process.env.UNIFORM_CLI_BASE_URL || stableApiHost;
|