@uniformdev/cli 18.17.1-alpha.13 → 18.18.1-alpha.12
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/index.js +322 -322
- package/dist/index.mjs +322 -322
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -4717,104 +4717,189 @@ var ContextCommand = {
|
|
|
4717
4717
|
}
|
|
4718
4718
|
};
|
|
4719
4719
|
|
|
4720
|
-
// src/
|
|
4721
|
-
var
|
|
4722
|
-
|
|
4723
|
-
|
|
4724
|
-
|
|
4725
|
-
|
|
4726
|
-
|
|
4727
|
-
|
|
4728
|
-
|
|
4729
|
-
|
|
4730
|
-
|
|
4731
|
-
|
|
4732
|
-
|
|
4733
|
-
|
|
4734
|
-
|
|
4735
|
-
}
|
|
4736
|
-
]);
|
|
4737
|
-
telemetry.send("team picked", { teamId: result.teamId });
|
|
4738
|
-
return result;
|
|
4739
|
-
}
|
|
4720
|
+
// src/spinner.ts
|
|
4721
|
+
var makeSpinner = () => {
|
|
4722
|
+
const spinners = [];
|
|
4723
|
+
const stopAllSpinners = () => spinners.forEach((spinner) => spinner.stop());
|
|
4724
|
+
const spin = async (text) => {
|
|
4725
|
+
const spinner = await Promise.resolve().then(() => __toESM(require("ora"))).then((ora) => ora.default(text).start());
|
|
4726
|
+
spinners.push(spinner);
|
|
4727
|
+
const minWait = new Promise((resolve) => setTimeout(resolve, 500));
|
|
4728
|
+
return async () => {
|
|
4729
|
+
await minWait;
|
|
4730
|
+
spinner.stop();
|
|
4731
|
+
};
|
|
4732
|
+
};
|
|
4733
|
+
return { stopAllSpinners, spin };
|
|
4734
|
+
};
|
|
4740
4735
|
|
|
4741
|
-
// src/
|
|
4736
|
+
// src/telemetry/telemetry.ts
|
|
4742
4737
|
var import_crypto = __toESM(require("crypto"));
|
|
4743
|
-
var
|
|
4744
|
-
var import_fs_jetpack = require("fs-jetpack");
|
|
4745
|
-
var git = __toESM(require("isomorphic-git"));
|
|
4746
|
-
var http = __toESM(require("isomorphic-git/http/node"));
|
|
4747
|
-
var import_os = __toESM(require("os"));
|
|
4748
|
-
var import_path3 = __toESM(require("path"));
|
|
4738
|
+
var import_posthog_node = require("posthog-node");
|
|
4749
4739
|
|
|
4750
|
-
//
|
|
4751
|
-
var
|
|
4752
|
-
|
|
4753
|
-
|
|
4754
|
-
|
|
4755
|
-
|
|
4756
|
-
|
|
4757
|
-
|
|
4758
|
-
|
|
4759
|
-
|
|
4760
|
-
|
|
4761
|
-
|
|
4762
|
-
|
|
4763
|
-
|
|
4764
|
-
|
|
4765
|
-
|
|
4740
|
+
// package.json
|
|
4741
|
+
var package_default = {
|
|
4742
|
+
name: "@uniformdev/cli",
|
|
4743
|
+
version: "18.18.0",
|
|
4744
|
+
description: "Uniform command line interface tool",
|
|
4745
|
+
license: "SEE LICENSE IN LICENSE.txt",
|
|
4746
|
+
main: "./cli.js",
|
|
4747
|
+
types: "./dist/index.d.ts",
|
|
4748
|
+
sideEffects: false,
|
|
4749
|
+
scripts: {
|
|
4750
|
+
uniform: "node ./cli.js",
|
|
4751
|
+
build: "tsup",
|
|
4752
|
+
dev: "tsup --watch",
|
|
4753
|
+
clean: "rimraf dist",
|
|
4754
|
+
test: "jest --maxWorkers=1 --passWithNoTests",
|
|
4755
|
+
lint: 'eslint "src/**/*.{js,ts,tsx}"',
|
|
4756
|
+
format: 'prettier --write "src/**/*.{js,ts,tsx}"'
|
|
4757
|
+
},
|
|
4758
|
+
dependencies: {
|
|
4759
|
+
"@uniformdev/canvas": "workspace:*",
|
|
4760
|
+
"@uniformdev/context": "workspace:*",
|
|
4761
|
+
"@uniformdev/project-map": "workspace:*",
|
|
4762
|
+
execa: "5.1.1",
|
|
4763
|
+
"fs-jetpack": "5.1.0",
|
|
4764
|
+
graphql: "16.6.0",
|
|
4765
|
+
"graphql-request": "5.1.0",
|
|
4766
|
+
inquirer: "8.2.5",
|
|
4767
|
+
"isomorphic-git": "1.21.0",
|
|
4768
|
+
jsonwebtoken: "9.0.0",
|
|
4769
|
+
open: "8.4.0",
|
|
4770
|
+
ora: "6.1.2",
|
|
4771
|
+
"posthog-node": "2.2.3",
|
|
4772
|
+
slugify: "1.6.5",
|
|
4773
|
+
diff: "^5.0.0",
|
|
4774
|
+
dotenv: "^16.0.3",
|
|
4775
|
+
"https-proxy-agent": "^5.0.1",
|
|
4776
|
+
"isomorphic-unfetch": "^3.1.0",
|
|
4777
|
+
"js-yaml": "^4.1.0",
|
|
4778
|
+
"lodash.isequalwith": "^4.4.0",
|
|
4779
|
+
yargs: "^17.6.2",
|
|
4780
|
+
zod: "3.20.6"
|
|
4781
|
+
},
|
|
4782
|
+
devDependencies: {
|
|
4783
|
+
"@types/inquirer": "9.0.3",
|
|
4784
|
+
"@types/jsonwebtoken": "9.0.1",
|
|
4785
|
+
"@types/node": "18.11.17",
|
|
4786
|
+
"@types/diff": "5.0.2",
|
|
4787
|
+
"@types/js-yaml": "4.0.5",
|
|
4788
|
+
"@types/lodash.isequalwith": "4.4.7",
|
|
4789
|
+
"@types/yargs": "17.0.22",
|
|
4790
|
+
"p-limit": "4.0.0"
|
|
4791
|
+
},
|
|
4792
|
+
bin: {
|
|
4793
|
+
uniform: "./cli.js"
|
|
4794
|
+
},
|
|
4795
|
+
files: [
|
|
4796
|
+
"/dist"
|
|
4797
|
+
],
|
|
4798
|
+
publishConfig: {
|
|
4799
|
+
access: "public"
|
|
4766
4800
|
}
|
|
4767
|
-
return result.stdout;
|
|
4768
4801
|
};
|
|
4769
4802
|
|
|
4770
|
-
// src/
|
|
4771
|
-
|
|
4772
|
-
|
|
4773
|
-
|
|
4774
|
-
|
|
4775
|
-
|
|
4776
|
-
|
|
4777
|
-
|
|
4778
|
-
|
|
4779
|
-
|
|
4780
|
-
|
|
4781
|
-
|
|
4782
|
-
|
|
4783
|
-
|
|
4784
|
-
|
|
4785
|
-
|
|
4786
|
-
|
|
4787
|
-
|
|
4803
|
+
// src/telemetry/telemetry.ts
|
|
4804
|
+
var POSTHOG_WRITE_ONLY_KEY = "phc_c8YoKI9984KOHBfNrCRfIKvL56aYd5OpYxOdYexRzH7";
|
|
4805
|
+
var Telemetry = class {
|
|
4806
|
+
constructor(prefix, disable = false) {
|
|
4807
|
+
this.prefix = prefix;
|
|
4808
|
+
this.distinctId = import_crypto.default.randomBytes(20).toString("hex");
|
|
4809
|
+
if (!disable) {
|
|
4810
|
+
this.posthog = new import_posthog_node.PostHog(POSTHOG_WRITE_ONLY_KEY, {
|
|
4811
|
+
flushAt: 1,
|
|
4812
|
+
flushInterval: 1
|
|
4813
|
+
});
|
|
4814
|
+
this.send("started");
|
|
4815
|
+
}
|
|
4816
|
+
}
|
|
4817
|
+
login(sub, user) {
|
|
4818
|
+
if (!this.posthog) {
|
|
4819
|
+
return;
|
|
4820
|
+
}
|
|
4821
|
+
const alias = this.distinctId;
|
|
4822
|
+
this.distinctId = sub;
|
|
4823
|
+
this.posthog.alias({ distinctId: this.distinctId, alias });
|
|
4824
|
+
this.posthog.identify({
|
|
4825
|
+
distinctId: this.distinctId,
|
|
4826
|
+
properties: {
|
|
4827
|
+
email: user.email_address,
|
|
4828
|
+
sub,
|
|
4829
|
+
teamCount: user.teams.length
|
|
4830
|
+
}
|
|
4788
4831
|
});
|
|
4789
|
-
|
|
4790
|
-
throw new Error(`Failed to fetch starter code: ${err.message}`);
|
|
4832
|
+
this.send("logged in");
|
|
4791
4833
|
}
|
|
4792
|
-
|
|
4793
|
-
|
|
4794
|
-
|
|
4834
|
+
send(event, properties = {}) {
|
|
4835
|
+
var _a;
|
|
4836
|
+
(_a = this.posthog) == null ? void 0 : _a.capture({
|
|
4837
|
+
distinctId: this.distinctId,
|
|
4838
|
+
event: [this.prefix, event].join(" "),
|
|
4839
|
+
properties: {
|
|
4840
|
+
version: package_default.version,
|
|
4841
|
+
...properties
|
|
4842
|
+
}
|
|
4843
|
+
});
|
|
4795
4844
|
}
|
|
4796
|
-
|
|
4797
|
-
|
|
4798
|
-
|
|
4799
|
-
|
|
4845
|
+
shutdown() {
|
|
4846
|
+
var _a;
|
|
4847
|
+
this.send("exited", { exitCode: process.exitCode });
|
|
4848
|
+
return (_a = this.posthog) == null ? void 0 : _a.shutdownAsync();
|
|
4800
4849
|
}
|
|
4801
|
-
|
|
4802
|
-
Your project now lives in ${targetDir} \u2728`);
|
|
4803
|
-
return {
|
|
4804
|
-
runNpmInstall: async () => {
|
|
4805
|
-
console.log(`
|
|
4806
|
-
Installing project dependencies...
|
|
4850
|
+
};
|
|
4807
4851
|
|
|
4808
|
-
|
|
4809
|
-
|
|
4852
|
+
// src/commands/new/commands/new.ts
|
|
4853
|
+
var import_inquirer4 = __toESM(require("inquirer"));
|
|
4854
|
+
|
|
4855
|
+
// src/auth/getBearerToken.ts
|
|
4856
|
+
var import_inquirer = __toESM(require("inquirer"));
|
|
4857
|
+
var import_jsonwebtoken = __toESM(require("jsonwebtoken"));
|
|
4858
|
+
var import_open = __toESM(require("open"));
|
|
4859
|
+
|
|
4860
|
+
// src/url.ts
|
|
4861
|
+
var makeUrl = (baseUrl, path4) => [baseUrl.trim().replace(/\/+$/, ""), path4.trim().replace(/^\/+/, "")].join("/");
|
|
4862
|
+
|
|
4863
|
+
// src/auth/getBearerToken.ts
|
|
4864
|
+
async function getBearerToken(baseUrl) {
|
|
4865
|
+
const { canOpen } = await import_inquirer.default.prompt([
|
|
4866
|
+
{
|
|
4867
|
+
type: "confirm",
|
|
4868
|
+
name: "canOpen",
|
|
4869
|
+
message: "Can we open a browser window to get a Uniform auth token?"
|
|
4810
4870
|
}
|
|
4871
|
+
]);
|
|
4872
|
+
if (canOpen) {
|
|
4873
|
+
(0, import_open.default)(makeUrl(baseUrl, "/cli-login"));
|
|
4874
|
+
}
|
|
4875
|
+
const tokenAnswer = await import_inquirer.default.prompt([
|
|
4876
|
+
{
|
|
4877
|
+
type: "password",
|
|
4878
|
+
name: "authToken",
|
|
4879
|
+
message: "Paste your Uniform auth token"
|
|
4880
|
+
}
|
|
4881
|
+
]);
|
|
4882
|
+
const authToken = tokenAnswer.authToken.trim();
|
|
4883
|
+
if (!authToken) {
|
|
4884
|
+
throw new Error("No auth token provided.");
|
|
4885
|
+
}
|
|
4886
|
+
const decoded = import_jsonwebtoken.default.decode(authToken, { complete: false });
|
|
4887
|
+
if (!decoded) {
|
|
4888
|
+
throw new Error("Could not parse the token pasted.");
|
|
4889
|
+
}
|
|
4890
|
+
if (typeof decoded.sub !== "string" || typeof decoded === "string") {
|
|
4891
|
+
throw new Error("Invalid token pasted.");
|
|
4892
|
+
}
|
|
4893
|
+
return {
|
|
4894
|
+
authToken,
|
|
4895
|
+
decoded: { ...decoded, sub: decoded.sub }
|
|
4811
4896
|
};
|
|
4812
4897
|
}
|
|
4813
4898
|
|
|
4814
|
-
// src/
|
|
4899
|
+
// src/client.ts
|
|
4815
4900
|
var import_zod = require("zod");
|
|
4816
4901
|
|
|
4817
|
-
// src/
|
|
4902
|
+
// src/auth/api-key.ts
|
|
4818
4903
|
var READ_PERMISSIONS = ["PROJECT", "UPM_PUB", "OPT_PUB", "OPT_READ", "UPM_READ"];
|
|
4819
4904
|
var WRITE_PERMISSIONS = [
|
|
4820
4905
|
"PROJECT",
|
|
@@ -4862,10 +4947,7 @@ var makeApiKey = (teamId, projectId, name, permissions) => ({
|
|
|
4862
4947
|
var makeReadApiKey = (teamId, projectId) => makeApiKey(teamId, projectId, "Created by Uniform New (read)", READ_PERMISSIONS);
|
|
4863
4948
|
var makeWriteApiKey = (teamId, projectId) => makeApiKey(teamId, projectId, "Created by Uniform New (write)", WRITE_PERMISSIONS);
|
|
4864
4949
|
|
|
4865
|
-
// src/
|
|
4866
|
-
var makeUrl = (baseUrl, path4) => [baseUrl.trim().replace(/\/+$/, ""), path4.trim().replace(/^\/+/, "")].join("/");
|
|
4867
|
-
|
|
4868
|
-
// src/commands/new/client.ts
|
|
4950
|
+
// src/client.ts
|
|
4869
4951
|
var createTeamOrProjectSchema = import_zod.z.object({ id: import_zod.z.string().min(1) });
|
|
4870
4952
|
var createApiKeySchema = import_zod.z.object({ apiKey: import_zod.z.string().min(1) });
|
|
4871
4953
|
var getLimitsSchema = import_zod.z.object({
|
|
@@ -5008,124 +5090,80 @@ var createClient = (baseUrl, authToken) => {
|
|
|
5008
5090
|
};
|
|
5009
5091
|
};
|
|
5010
5092
|
|
|
5011
|
-
// src/
|
|
5012
|
-
var
|
|
5013
|
-
var
|
|
5014
|
-
|
|
5015
|
-
query GetUserInfo($subject: String!) {
|
|
5016
|
-
info: identities_by_pk(subject: $subject) {
|
|
5017
|
-
name
|
|
5018
|
-
email_address
|
|
5019
|
-
teams: organizations_identities {
|
|
5020
|
-
team: organization {
|
|
5021
|
-
name
|
|
5022
|
-
id
|
|
5023
|
-
sites {
|
|
5024
|
-
name
|
|
5025
|
-
id
|
|
5026
|
-
}
|
|
5027
|
-
}
|
|
5028
|
-
}
|
|
5029
|
-
}
|
|
5030
|
-
}
|
|
5031
|
-
`;
|
|
5032
|
-
var schema = import_zod2.z.object({
|
|
5033
|
-
info: import_zod2.z.object({
|
|
5034
|
-
name: import_zod2.z.string().min(1),
|
|
5035
|
-
email_address: import_zod2.z.string().min(1),
|
|
5036
|
-
teams: import_zod2.z.array(
|
|
5037
|
-
import_zod2.z.object({
|
|
5038
|
-
team: import_zod2.z.object({
|
|
5039
|
-
name: import_zod2.z.string().min(1),
|
|
5040
|
-
id: import_zod2.z.string().min(1),
|
|
5041
|
-
sites: import_zod2.z.array(
|
|
5042
|
-
import_zod2.z.object({
|
|
5043
|
-
name: import_zod2.z.string().min(1),
|
|
5044
|
-
id: import_zod2.z.string().min(1)
|
|
5045
|
-
})
|
|
5046
|
-
)
|
|
5047
|
-
})
|
|
5048
|
-
})
|
|
5049
|
-
)
|
|
5050
|
-
})
|
|
5051
|
-
});
|
|
5052
|
-
var getUserInfo = async (baseUrl, authToken, subject) => {
|
|
5093
|
+
// src/npm.ts
|
|
5094
|
+
var import_execa = __toESM(require("execa"));
|
|
5095
|
+
var runNpm = async (workDir, args, { inherit, env } = {}) => {
|
|
5096
|
+
let result;
|
|
5053
5097
|
try {
|
|
5054
|
-
|
|
5055
|
-
|
|
5056
|
-
|
|
5057
|
-
|
|
5058
|
-
|
|
5059
|
-
} else {
|
|
5060
|
-
throw new Error(`Invalid GraphQL response: ${parseResult.error.message}`);
|
|
5061
|
-
}
|
|
5098
|
+
result = await (0, import_execa.default)("npm", args, {
|
|
5099
|
+
cwd: workDir,
|
|
5100
|
+
env: env != null ? env : {},
|
|
5101
|
+
...inherit ? { stdout: "inherit", stderr: "inherit" } : {}
|
|
5102
|
+
});
|
|
5062
5103
|
} catch (err) {
|
|
5063
|
-
throw new Error(`Failed to
|
|
5064
|
-
|
|
5104
|
+
throw new Error(`Failed to execute npm ${args.join(" ")}
|
|
5105
|
+
${err.message}`);
|
|
5065
5106
|
}
|
|
5107
|
+
if (result.exitCode !== 0) {
|
|
5108
|
+
throw new Error(`Command npm ${args.join(" ")} exitted with code ${result == null ? void 0 : result.exitCode}}: ${result.stderr}`);
|
|
5109
|
+
}
|
|
5110
|
+
return result.stdout;
|
|
5066
5111
|
};
|
|
5067
5112
|
|
|
5068
|
-
// src/
|
|
5069
|
-
|
|
5070
|
-
|
|
5071
|
-
|
|
5113
|
+
// src/projects/cloneStarter.ts
|
|
5114
|
+
var import_crypto2 = __toESM(require("crypto"));
|
|
5115
|
+
var import_fs6 = __toESM(require("fs"));
|
|
5116
|
+
var import_fs_jetpack = require("fs-jetpack");
|
|
5117
|
+
var git = __toESM(require("isomorphic-git"));
|
|
5118
|
+
var http = __toESM(require("isomorphic-git/http/node"));
|
|
5119
|
+
var import_os = __toESM(require("os"));
|
|
5120
|
+
var import_path3 = __toESM(require("path"));
|
|
5121
|
+
async function cloneStarter({
|
|
5072
5122
|
spin,
|
|
5073
|
-
|
|
5123
|
+
githubPath,
|
|
5124
|
+
targetDir,
|
|
5125
|
+
dotEnvFile
|
|
5074
5126
|
}) {
|
|
5075
|
-
const
|
|
5076
|
-
const
|
|
5077
|
-
|
|
5078
|
-
|
|
5079
|
-
await
|
|
5080
|
-
|
|
5081
|
-
|
|
5082
|
-
|
|
5083
|
-
|
|
5084
|
-
|
|
5085
|
-
|
|
5086
|
-
|
|
5087
|
-
|
|
5088
|
-
|
|
5089
|
-
var import_jsonwebtoken = __toESM(require("jsonwebtoken"));
|
|
5090
|
-
var import_open = __toESM(require("open"));
|
|
5091
|
-
async function getBearerToken(baseUrl) {
|
|
5092
|
-
const { canOpen } = await import_inquirer2.default.prompt([
|
|
5093
|
-
{
|
|
5094
|
-
type: "confirm",
|
|
5095
|
-
name: "canOpen",
|
|
5096
|
-
message: "Can we open a browser window to get a Uniform auth token?"
|
|
5097
|
-
}
|
|
5098
|
-
]);
|
|
5099
|
-
if (canOpen) {
|
|
5100
|
-
(0, import_open.default)(makeUrl(baseUrl, "/cli-login"));
|
|
5101
|
-
}
|
|
5102
|
-
const tokenAnswer = await import_inquirer2.default.prompt([
|
|
5103
|
-
{
|
|
5104
|
-
type: "password",
|
|
5105
|
-
name: "authToken",
|
|
5106
|
-
message: "Paste your Uniform auth token"
|
|
5107
|
-
}
|
|
5108
|
-
]);
|
|
5109
|
-
const authToken = tokenAnswer.authToken.trim();
|
|
5110
|
-
if (!authToken) {
|
|
5111
|
-
throw new Error("No auth token provided.");
|
|
5127
|
+
const done = await spin("Fetching starter code...");
|
|
5128
|
+
const cloneDir = import_path3.default.join(import_os.default.tmpdir(), `uniform-new-${import_crypto2.default.randomBytes(20).toString("hex")}`);
|
|
5129
|
+
const [user, repo, ...pathSegments] = githubPath.split("/");
|
|
5130
|
+
try {
|
|
5131
|
+
await git.clone({
|
|
5132
|
+
fs: import_fs6.default,
|
|
5133
|
+
http,
|
|
5134
|
+
url: `https://github.com/${user}/${repo}`,
|
|
5135
|
+
dir: cloneDir,
|
|
5136
|
+
singleBranch: true,
|
|
5137
|
+
depth: 1
|
|
5138
|
+
});
|
|
5139
|
+
} catch (err) {
|
|
5140
|
+
throw new Error(`Failed to fetch starter code: ${err.message}`);
|
|
5112
5141
|
}
|
|
5113
|
-
|
|
5114
|
-
if (
|
|
5115
|
-
throw new Error("
|
|
5142
|
+
await done();
|
|
5143
|
+
if (import_fs6.default.existsSync(targetDir) && import_fs6.default.readdirSync(targetDir).length > 0) {
|
|
5144
|
+
throw new Error(`"${targetDir}" is not empty`);
|
|
5116
5145
|
}
|
|
5117
|
-
|
|
5118
|
-
|
|
5146
|
+
const starterDir = import_path3.default.join(cloneDir, ...pathSegments);
|
|
5147
|
+
(0, import_fs_jetpack.copy)(starterDir, targetDir, { overwrite: true });
|
|
5148
|
+
if (dotEnvFile) {
|
|
5149
|
+
import_fs6.default.writeFileSync(import_path3.default.resolve(targetDir, ".env"), dotEnvFile, "utf-8");
|
|
5119
5150
|
}
|
|
5151
|
+
console.log(`
|
|
5152
|
+
Your project now lives in ${targetDir} \u2728`);
|
|
5120
5153
|
return {
|
|
5121
|
-
|
|
5122
|
-
|
|
5154
|
+
runNpmInstall: async () => {
|
|
5155
|
+
console.log(`
|
|
5156
|
+
Installing project dependencies...
|
|
5157
|
+
|
|
5158
|
+
`);
|
|
5159
|
+
await runNpm(targetDir, ["i"], { inherit: true });
|
|
5160
|
+
}
|
|
5123
5161
|
};
|
|
5124
5162
|
}
|
|
5125
5163
|
|
|
5126
|
-
// src/
|
|
5164
|
+
// src/projects/getOrCreateProject.ts
|
|
5127
5165
|
var import_fs7 = __toESM(require("fs"));
|
|
5128
|
-
var
|
|
5166
|
+
var import_inquirer2 = __toESM(require("inquirer"));
|
|
5129
5167
|
var import_path4 = __toESM(require("path"));
|
|
5130
5168
|
var import_slugify = __toESM(require("slugify"));
|
|
5131
5169
|
var newProjectId = "$new";
|
|
@@ -5183,7 +5221,7 @@ async function getNewProjectName({
|
|
|
5183
5221
|
}) {
|
|
5184
5222
|
let projectName = explicitName;
|
|
5185
5223
|
if (!projectName) {
|
|
5186
|
-
const answer = await
|
|
5224
|
+
const answer = await import_inquirer2.default.prompt([
|
|
5187
5225
|
{
|
|
5188
5226
|
type: "input",
|
|
5189
5227
|
name: "name",
|
|
@@ -5227,7 +5265,7 @@ async function chooseExistingProject({
|
|
|
5227
5265
|
value: t.id
|
|
5228
5266
|
}));
|
|
5229
5267
|
const choices = createNew ? [{ name: "Create new project...", value: newProjectId }].concat(projects) : projects;
|
|
5230
|
-
const result = await
|
|
5268
|
+
const result = await import_inquirer2.default.prompt([
|
|
5231
5269
|
{
|
|
5232
5270
|
type: "list",
|
|
5233
5271
|
name: "projectId",
|
|
@@ -5261,6 +5299,100 @@ function validateProjectName(projectName, checkTargetDir, explicitTargetDir) {
|
|
|
5261
5299
|
}
|
|
5262
5300
|
}
|
|
5263
5301
|
|
|
5302
|
+
// src/teams/chooseTeam.ts
|
|
5303
|
+
var import_inquirer3 = __toESM(require("inquirer"));
|
|
5304
|
+
async function chooseTeam(user, prompt, telemetry) {
|
|
5305
|
+
const result = await import_inquirer3.default.prompt([
|
|
5306
|
+
{
|
|
5307
|
+
type: "list",
|
|
5308
|
+
name: "teamId",
|
|
5309
|
+
message: prompt,
|
|
5310
|
+
choices: user.teams.map((team) => ({
|
|
5311
|
+
name: team.team.name,
|
|
5312
|
+
value: team.team.id
|
|
5313
|
+
}))
|
|
5314
|
+
}
|
|
5315
|
+
]);
|
|
5316
|
+
telemetry.send("team picked", { teamId: result.teamId });
|
|
5317
|
+
return result;
|
|
5318
|
+
}
|
|
5319
|
+
|
|
5320
|
+
// src/auth/user-info.ts
|
|
5321
|
+
var import_graphql_request = require("graphql-request");
|
|
5322
|
+
var import_zod2 = require("zod");
|
|
5323
|
+
var query = import_graphql_request.gql`
|
|
5324
|
+
query GetUserInfo($subject: String!) {
|
|
5325
|
+
info: identities_by_pk(subject: $subject) {
|
|
5326
|
+
name
|
|
5327
|
+
email_address
|
|
5328
|
+
teams: organizations_identities {
|
|
5329
|
+
team: organization {
|
|
5330
|
+
name
|
|
5331
|
+
id
|
|
5332
|
+
sites {
|
|
5333
|
+
name
|
|
5334
|
+
id
|
|
5335
|
+
}
|
|
5336
|
+
}
|
|
5337
|
+
}
|
|
5338
|
+
}
|
|
5339
|
+
}
|
|
5340
|
+
`;
|
|
5341
|
+
var schema = import_zod2.z.object({
|
|
5342
|
+
info: import_zod2.z.object({
|
|
5343
|
+
name: import_zod2.z.string().min(1),
|
|
5344
|
+
email_address: import_zod2.z.string().min(1),
|
|
5345
|
+
teams: import_zod2.z.array(
|
|
5346
|
+
import_zod2.z.object({
|
|
5347
|
+
team: import_zod2.z.object({
|
|
5348
|
+
name: import_zod2.z.string().min(1),
|
|
5349
|
+
id: import_zod2.z.string().min(1),
|
|
5350
|
+
sites: import_zod2.z.array(
|
|
5351
|
+
import_zod2.z.object({
|
|
5352
|
+
name: import_zod2.z.string().min(1),
|
|
5353
|
+
id: import_zod2.z.string().min(1)
|
|
5354
|
+
})
|
|
5355
|
+
)
|
|
5356
|
+
})
|
|
5357
|
+
})
|
|
5358
|
+
)
|
|
5359
|
+
})
|
|
5360
|
+
});
|
|
5361
|
+
var getUserInfo = async (baseUrl, authToken, subject) => {
|
|
5362
|
+
try {
|
|
5363
|
+
const endpoint = makeUrl(baseUrl, "/v1/graphql");
|
|
5364
|
+
const res = await (0, import_graphql_request.request)(endpoint, query, { subject }, { Authorization: `Bearer ${authToken}` });
|
|
5365
|
+
const parseResult = schema.safeParse(res);
|
|
5366
|
+
if (parseResult.success) {
|
|
5367
|
+
return parseResult.data.info;
|
|
5368
|
+
} else {
|
|
5369
|
+
throw new Error(`Invalid GraphQL response: ${parseResult.error.message}`);
|
|
5370
|
+
}
|
|
5371
|
+
} catch (err) {
|
|
5372
|
+
throw new Error(`Failed to fetch user account:
|
|
5373
|
+
${err.message}`);
|
|
5374
|
+
}
|
|
5375
|
+
};
|
|
5376
|
+
|
|
5377
|
+
// src/teams/fetchUserAndEnsureTeamExists.ts
|
|
5378
|
+
async function fetchUserAndEnsureFirstTeamExists({
|
|
5379
|
+
baseUrl,
|
|
5380
|
+
auth: { authToken, decoded },
|
|
5381
|
+
spin,
|
|
5382
|
+
telemetry
|
|
5383
|
+
}) {
|
|
5384
|
+
const uniformClient = createClient(baseUrl, authToken);
|
|
5385
|
+
const done = await spin("Fetching user information...");
|
|
5386
|
+
let user = await getUserInfo(baseUrl, authToken, decoded.sub);
|
|
5387
|
+
if (user.teams.length < 1) {
|
|
5388
|
+
await uniformClient.createTeam(`${user.name}'s team`);
|
|
5389
|
+
user = await getUserInfo(baseUrl, authToken, decoded.sub);
|
|
5390
|
+
}
|
|
5391
|
+
await done();
|
|
5392
|
+
telemetry.login(decoded.sub, user);
|
|
5393
|
+
return user;
|
|
5394
|
+
}
|
|
5395
|
+
|
|
5264
5396
|
// src/commands/new/commands/new.ts
|
|
5265
5397
|
async function newHandler({
|
|
5266
5398
|
spin,
|
|
@@ -5492,138 +5624,6 @@ function validateIntegrationName(integrationName, explicitOutputPath) {
|
|
|
5492
5624
|
return { targetDir, typeSlug };
|
|
5493
5625
|
}
|
|
5494
5626
|
|
|
5495
|
-
// src/commands/new/spinner.ts
|
|
5496
|
-
var makeSpinner = () => {
|
|
5497
|
-
const spinners = [];
|
|
5498
|
-
const stopAllSpinners = () => spinners.forEach((spinner) => spinner.stop());
|
|
5499
|
-
const spin = async (text) => {
|
|
5500
|
-
const spinner = await Promise.resolve().then(() => __toESM(require("ora"))).then((ora) => ora.default(text).start());
|
|
5501
|
-
spinners.push(spinner);
|
|
5502
|
-
const minWait = new Promise((resolve) => setTimeout(resolve, 500));
|
|
5503
|
-
return async () => {
|
|
5504
|
-
await minWait;
|
|
5505
|
-
spinner.stop();
|
|
5506
|
-
};
|
|
5507
|
-
};
|
|
5508
|
-
return { stopAllSpinners, spin };
|
|
5509
|
-
};
|
|
5510
|
-
|
|
5511
|
-
// src/commands/new/telemetry.ts
|
|
5512
|
-
var import_crypto2 = __toESM(require("crypto"));
|
|
5513
|
-
var import_posthog_node = require("posthog-node");
|
|
5514
|
-
|
|
5515
|
-
// package.json
|
|
5516
|
-
var package_default = {
|
|
5517
|
-
name: "@uniformdev/cli",
|
|
5518
|
-
version: "18.17.0",
|
|
5519
|
-
description: "Uniform command line interface tool",
|
|
5520
|
-
license: "SEE LICENSE IN LICENSE.txt",
|
|
5521
|
-
main: "./cli.js",
|
|
5522
|
-
types: "./dist/index.d.ts",
|
|
5523
|
-
sideEffects: false,
|
|
5524
|
-
scripts: {
|
|
5525
|
-
uniform: "node ./cli.js",
|
|
5526
|
-
build: "tsup",
|
|
5527
|
-
dev: "tsup --watch",
|
|
5528
|
-
clean: "rimraf dist",
|
|
5529
|
-
test: "jest --maxWorkers=1 --passWithNoTests",
|
|
5530
|
-
lint: 'eslint "src/**/*.{js,ts,tsx}"',
|
|
5531
|
-
format: 'prettier --write "src/**/*.{js,ts,tsx}"'
|
|
5532
|
-
},
|
|
5533
|
-
dependencies: {
|
|
5534
|
-
"@uniformdev/canvas": "workspace:*",
|
|
5535
|
-
"@uniformdev/context": "workspace:*",
|
|
5536
|
-
"@uniformdev/project-map": "workspace:*",
|
|
5537
|
-
execa: "5.1.1",
|
|
5538
|
-
"fs-jetpack": "5.1.0",
|
|
5539
|
-
graphql: "16.6.0",
|
|
5540
|
-
"graphql-request": "5.1.0",
|
|
5541
|
-
inquirer: "8.2.5",
|
|
5542
|
-
"isomorphic-git": "1.21.0",
|
|
5543
|
-
jsonwebtoken: "9.0.0",
|
|
5544
|
-
open: "8.4.0",
|
|
5545
|
-
ora: "6.1.2",
|
|
5546
|
-
"posthog-node": "2.2.3",
|
|
5547
|
-
slugify: "1.6.5",
|
|
5548
|
-
diff: "^5.0.0",
|
|
5549
|
-
dotenv: "^16.0.3",
|
|
5550
|
-
"https-proxy-agent": "^5.0.1",
|
|
5551
|
-
"isomorphic-unfetch": "^3.1.0",
|
|
5552
|
-
"js-yaml": "^4.1.0",
|
|
5553
|
-
"lodash.isequalwith": "^4.4.0",
|
|
5554
|
-
yargs: "^17.6.2",
|
|
5555
|
-
zod: "3.20.2"
|
|
5556
|
-
},
|
|
5557
|
-
devDependencies: {
|
|
5558
|
-
"@types/inquirer": "9.0.3",
|
|
5559
|
-
"@types/jsonwebtoken": "9.0.1",
|
|
5560
|
-
"@types/node": "18.11.17",
|
|
5561
|
-
"@types/diff": "5.0.2",
|
|
5562
|
-
"@types/js-yaml": "4.0.5",
|
|
5563
|
-
"@types/lodash.isequalwith": "4.4.7",
|
|
5564
|
-
"@types/yargs": "17.0.22",
|
|
5565
|
-
"p-limit": "4.0.0"
|
|
5566
|
-
},
|
|
5567
|
-
bin: {
|
|
5568
|
-
uniform: "./cli.js"
|
|
5569
|
-
},
|
|
5570
|
-
files: [
|
|
5571
|
-
"/dist"
|
|
5572
|
-
],
|
|
5573
|
-
publishConfig: {
|
|
5574
|
-
access: "public"
|
|
5575
|
-
}
|
|
5576
|
-
};
|
|
5577
|
-
|
|
5578
|
-
// src/commands/new/telemetry.ts
|
|
5579
|
-
var POSTHOG_WRITE_ONLY_KEY = "phc_c8YoKI9984KOHBfNrCRfIKvL56aYd5OpYxOdYexRzH7";
|
|
5580
|
-
var Telemetry = class {
|
|
5581
|
-
constructor(prefix, disable = false) {
|
|
5582
|
-
this.prefix = prefix;
|
|
5583
|
-
this.distinctId = import_crypto2.default.randomBytes(20).toString("hex");
|
|
5584
|
-
if (!disable) {
|
|
5585
|
-
this.posthog = new import_posthog_node.PostHog(POSTHOG_WRITE_ONLY_KEY, {
|
|
5586
|
-
flushAt: 1,
|
|
5587
|
-
flushInterval: 1
|
|
5588
|
-
});
|
|
5589
|
-
this.send("started");
|
|
5590
|
-
}
|
|
5591
|
-
}
|
|
5592
|
-
login(sub, user) {
|
|
5593
|
-
if (!this.posthog) {
|
|
5594
|
-
return;
|
|
5595
|
-
}
|
|
5596
|
-
const alias = this.distinctId;
|
|
5597
|
-
this.distinctId = sub;
|
|
5598
|
-
this.posthog.alias({ distinctId: this.distinctId, alias });
|
|
5599
|
-
this.posthog.identify({
|
|
5600
|
-
distinctId: this.distinctId,
|
|
5601
|
-
properties: {
|
|
5602
|
-
email: user.email_address,
|
|
5603
|
-
sub,
|
|
5604
|
-
teamCount: user.teams.length
|
|
5605
|
-
}
|
|
5606
|
-
});
|
|
5607
|
-
this.send("logged in");
|
|
5608
|
-
}
|
|
5609
|
-
send(event, properties = {}) {
|
|
5610
|
-
var _a;
|
|
5611
|
-
(_a = this.posthog) == null ? void 0 : _a.capture({
|
|
5612
|
-
distinctId: this.distinctId,
|
|
5613
|
-
event: [this.prefix, event].join(" "),
|
|
5614
|
-
properties: {
|
|
5615
|
-
version: package_default.version,
|
|
5616
|
-
...properties
|
|
5617
|
-
}
|
|
5618
|
-
});
|
|
5619
|
-
}
|
|
5620
|
-
shutdown() {
|
|
5621
|
-
var _a;
|
|
5622
|
-
this.send("exited", { exitCode: process.exitCode });
|
|
5623
|
-
return (_a = this.posthog) == null ? void 0 : _a.shutdownAsync();
|
|
5624
|
-
}
|
|
5625
|
-
};
|
|
5626
|
-
|
|
5627
5627
|
// src/commands/new/index.ts
|
|
5628
5628
|
var stableApiHost = "https://uniform.app";
|
|
5629
5629
|
var apiHostDefault = process.env.UNIFORM_CLI_BASE_URL || stableApiHost;
|