@slicemachine/init 1.1.9-alpha.3 → 1.1.10-alpha.2

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/build/index.js CHANGED
@@ -23,6 +23,16 @@ const tmp = require('tmp');
23
23
  const AdmZip = require('adm-zip');
24
24
  const fsExtra = require('fs-extra');
25
25
  const fs = require('fs');
26
+ const cookie = require('@slicemachine/core/build/utils/cookie');
27
+ const Libraries = require('@slicemachine/core/build/libraries');
28
+ const models = require('@slicemachine/core/build/models');
29
+ const mime = require('mime');
30
+ const snakeCase = require('lodash.snakecase');
31
+ const FormData = require('form-data');
32
+ const uniqid = require('uniqid');
33
+ const customtypes = require('@prismicio/types-internal/lib/customtypes');
34
+ const Either$1 = require('fp-ts/lib/Either');
35
+ const t = require('io-ts');
26
36
 
27
37
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
28
38
 
@@ -55,12 +65,19 @@ const hapi__namespace = /*#__PURE__*/_interopNamespace(hapi);
55
65
  const open__default = /*#__PURE__*/_interopDefaultLegacy(open);
56
66
  const NodeUtils__namespace = /*#__PURE__*/_interopNamespace(NodeUtils);
57
67
  const inquirer__namespace = /*#__PURE__*/_interopNamespace(inquirer);
68
+ const inquirer__default = /*#__PURE__*/_interopDefaultLegacy(inquirer);
58
69
  const Separator__default = /*#__PURE__*/_interopDefaultLegacy(Separator);
59
70
  const axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
60
71
  const tmp__default = /*#__PURE__*/_interopDefaultLegacy(tmp);
61
72
  const AdmZip__default = /*#__PURE__*/_interopDefaultLegacy(AdmZip);
62
73
  const fsExtra__default = /*#__PURE__*/_interopDefaultLegacy(fsExtra);
63
74
  const fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
75
+ const Libraries__namespace = /*#__PURE__*/_interopNamespace(Libraries);
76
+ const mime__default = /*#__PURE__*/_interopDefaultLegacy(mime);
77
+ const snakeCase__default = /*#__PURE__*/_interopDefaultLegacy(snakeCase);
78
+ const FormData__default = /*#__PURE__*/_interopDefaultLegacy(FormData);
79
+ const uniqid__default = /*#__PURE__*/_interopDefaultLegacy(uniqid);
80
+ const t__namespace = /*#__PURE__*/_interopNamespace(t);
64
81
 
65
82
  var __accessCheck = (obj, member, msg) => {
66
83
  if (!member.has(obj))
@@ -403,16 +420,25 @@ function depsForFramework(framework) {
403
420
  return "";
404
421
  }
405
422
  }
406
- async function installRequiredDependencies(cwd, framework) {
407
- const yarnLock = NodeUtils__namespace.Files.exists(NodeUtils__namespace.YarnLockPath(cwd));
408
- const installDevDependencyCommand = yarnLock ? "yarn add -D" : "npm install --save-dev";
409
- const installDependencyCommand = yarnLock ? "yarn add" : "npm install --save";
410
- const spinner = spinner$1("Downloading Slice Machine");
411
- spinner.start();
423
+ async function addAndInstallDeps(framework, useYarn = false) {
424
+ const installDevDependencyCommand = useYarn ? "yarn add -D" : "npm install --save-dev";
425
+ const installDependencyCommand = useYarn ? "yarn add" : "npm install --save";
412
426
  const { stderr } = await execCommand(`${installDevDependencyCommand} ${SM_PACKAGE_NAME}`);
413
427
  const deps = depsForFramework(framework);
414
428
  if (deps)
415
429
  await execCommand(`${installDependencyCommand} ${deps}`);
430
+ return stderr;
431
+ }
432
+ async function installDeps(useYarn = false) {
433
+ const installCommand = useYarn ? "yarn" : "npm install";
434
+ const { stderr } = await execCommand(installCommand);
435
+ return stderr;
436
+ }
437
+ async function installRequiredDependencies(cwd, framework, skipDependencies) {
438
+ const yarnLock = NodeUtils__namespace.Files.exists(NodeUtils__namespace.YarnLockPath(cwd));
439
+ const spinner = spinner$1("Installing Slice Machine");
440
+ spinner.start();
441
+ const stderr = await (skipDependencies ? installDeps(yarnLock) : addAndInstallDeps(framework, yarnLock));
416
442
  const pathToPkg = path__default["default"].join(NodeUtils__namespace.PackagePaths(cwd).value(), SM_PACKAGE_NAME);
417
443
  const isPackageInstalled = NodeUtils__namespace.Files.exists(pathToPkg);
418
444
  if (isPackageInstalled || !stderr.length) {
@@ -672,17 +698,19 @@ async function loginOrBypass(base) {
672
698
 
673
699
  const defaultSliceMachineVersion = "0.0.41";
674
700
  async function configureProject(cwd, base, repositoryDomainName, framework, sliceLibPath = [], tracking = true) {
675
- const spinner = spinner$1(`Configuring your ${framework.value} & Prismic project...`);
701
+ const frameworkName = NodeUtils__namespace.Framework.fancyName(framework.value);
702
+ const spinner = spinner$1(`Configuring your ${frameworkName} and Prismic project...`);
676
703
  spinner.start();
677
704
  try {
678
705
  const manifest = NodeUtils__namespace.retrieveManifest(cwd);
679
706
  const packageJson = NodeUtils__namespace.retrieveJsonPackage(cwd);
680
707
  const sliceMachineVersionInstalled = getTheSliceMachineVersionInstalled(packageJson);
681
708
  const manifestAlreadyExistWithContent = manifest.exists && manifest.content;
709
+ const libs = manifest.content && manifest.content.libraries && manifest.content.libraries.length > 0 ? manifest.content.libraries : ["@/slices"];
682
710
  const manifestUpdated = {
683
711
  ...manifestAlreadyExistWithContent ? manifest.content : { _latest: sliceMachineVersionInstalled },
684
712
  apiEndpoint: Prismic__namespace.Endpoints.buildRepositoryEndpoint(base, repositoryDomainName),
685
- libraries: ["@/slices", ...sliceLibPath],
713
+ libraries: [...libs, ...sliceLibPath],
686
714
  ...framework.manuallyAdded ? { framework: framework.value } : {},
687
715
  ...!tracking ? { tracking } : {}
688
716
  };
@@ -691,7 +719,7 @@ async function configureProject(cwd, base, repositoryDomainName, framework, slic
691
719
  else
692
720
  NodeUtils__namespace.patchManifest(cwd, manifestUpdated);
693
721
  const pathToSlicesFolder = NodeUtils__namespace.CustomPaths(cwd).library("slices").value();
694
- if (!NodeUtils__namespace.Files.exists(pathToSlicesFolder)) {
722
+ if (!NodeUtils__namespace.Files.exists(pathToSlicesFolder) && libs.includes("@/slices")) {
695
723
  NodeUtils__namespace.Files.mkdir(pathToSlicesFolder, { recursive: true });
696
724
  }
697
725
  NodeUtils__namespace.addJsonPackageSmScript(cwd);
@@ -729,7 +757,8 @@ const extractVersionNumberFromSemver = (semver) => {
729
757
  function displayFinalMessage(cwd) {
730
758
  const yarnLock = NodeUtils__namespace.Files.exists(NodeUtils__namespace.YarnLockPath(cwd));
731
759
  const command = `${yarnLock ? "yarn" : "npm"} run ${core.CONSTS.SCRIPT_NAME}`;
732
- console.log(`${white("\u25A0")} Run ${purple(command)} to now launch Slice Machine`);
760
+ console.log();
761
+ console.log(`${white("\u25A0")} Run ${purple(command)} to start Slice Machine`);
733
762
  }
734
763
 
735
764
  const Dependencies = {
@@ -837,6 +866,364 @@ async function installLib(cwd, libGithubPath, branch = "HEAD") {
837
866
  }
838
867
  }
839
868
 
869
+ function handleErrors(prefix, err) {
870
+ if (axios__default["default"].isAxiosError(err) && err.response) {
871
+ writeError$1(`${prefix} | [${err.response.status}]: ${err.response.statusText}`);
872
+ } else if (err instanceof Error) {
873
+ writeError$1(`${prefix} ${err.message}`);
874
+ } else {
875
+ writeError$1(`${prefix} ${String(err)}`);
876
+ }
877
+ }
878
+ async function getRemoteSliceIds(customTypeApiEndpoint, repository, authorization) {
879
+ const addr = `${stripLastSlash(customTypeApiEndpoint)}/slices`;
880
+ return axios__default["default"].get(addr, {
881
+ headers: {
882
+ Authorization: `Bearer ${authorization}`,
883
+ repository
884
+ }
885
+ }).then((res) => {
886
+ return Array.isArray(res.data) ? res.data.map((model) => model.id) : [];
887
+ });
888
+ }
889
+ async function sendModelToPrismic(repository, authorization, customTypesApiEndpoint, remoteSliceIds, model) {
890
+ const data = models.Slices.fromSM(model);
891
+ const updateOrInsertUrl = `${customTypesApiEndpoint}slices/${remoteSliceIds.includes(model.id) ? "update" : "insert"}`;
892
+ return axios__default["default"].post(updateOrInsertUrl, data, {
893
+ headers: {
894
+ Authorization: `Bearer ${authorization}`,
895
+ repository
896
+ }
897
+ }).then(() => {
898
+ return;
899
+ }).catch((err) => {
900
+ handleErrors(`sending slice ${model.id}, please try again. If the problem persists, contact us.`, err);
901
+ throw err;
902
+ });
903
+ }
904
+ async function sendManyModelsToPrismic(repository, authorization, customTypesApiEndpoint, remoteSliceIds, models) {
905
+ return Promise.all(models.map((model) => sendModelToPrismic(repository, authorization, customTypesApiEndpoint, remoteSliceIds, model))).then(() => {
906
+ return;
907
+ }).catch(() => {
908
+ process.exit(1);
909
+ });
910
+ }
911
+ function stripLastSlash(str) {
912
+ return str.replace(/\/*$/g, "");
913
+ }
914
+ function getRemoteCustomTypeIds(customTypeApiEndpoint, repository, authorization) {
915
+ const addr = `${stripLastSlash(customTypeApiEndpoint)}/customtypes`;
916
+ return axios__default["default"].get(addr, {
917
+ headers: {
918
+ Authorization: `Bearer ${authorization}`,
919
+ repository
920
+ }
921
+ }).then((res) => {
922
+ return Array.isArray(res.data) ? res.data.map((ct) => ct.id) : [];
923
+ });
924
+ }
925
+ async function sendCustomTypeToPrismic(repository, authorization, customTypeApiEndpoint, remoteCustomTypeIds, customType) {
926
+ const shouldUpdate = remoteCustomTypeIds.includes(customType.id);
927
+ const addr = `${stripLastSlash(customTypeApiEndpoint)}/customtypes/${shouldUpdate ? "update" : "insert"}`;
928
+ return axios__default["default"].post(addr, customType, {
929
+ headers: {
930
+ repository,
931
+ Authorization: `Bearer ${authorization}`
932
+ }
933
+ }).then(() => {
934
+ return;
935
+ }).catch((err) => {
936
+ handleErrors(`sending custom type ${customType.id}, please try again. If the problem persists, contact us.`, err);
937
+ throw err;
938
+ });
939
+ }
940
+ async function sendManyCustomTypesToPrismic(repository, authorization, customTypeApiEndpoint, remoteCustomTypeIds, customTypes) {
941
+ return Promise.all(customTypes.map((customType) => sendCustomTypeToPrismic(repository, authorization, customTypeApiEndpoint, remoteCustomTypeIds, customType))).then(() => {
942
+ return;
943
+ }).catch(() => {
944
+ process.exit(1);
945
+ });
946
+ }
947
+
948
+ const ProductionApisEndpoints = {
949
+ Models: "https://customtypes.prismic.io/",
950
+ AclProvider: "https://0yyeb2g040.execute-api.us-east-1.amazonaws.com/prod/"
951
+ };
952
+ const StageApisEndpoints = {
953
+ Models: "https://customtypes.wroom.io/",
954
+ AclProvider: "https://2iamcvnxf4.execute-api.us-east-1.amazonaws.com/stage/"
955
+ };
956
+ const getEndpointsFromBase = (base) => {
957
+ const url = new URL(base);
958
+ if (url.hostname === "wroom.io")
959
+ return StageApisEndpoints;
960
+ return ProductionApisEndpoints;
961
+ };
962
+
963
+ async function promptToPushSlices() {
964
+ return inquirer__default["default"].prompt([
965
+ {
966
+ type: "confirm",
967
+ name: "pushSlices",
968
+ default: false,
969
+ message: "Your repository already contains Slices. Do you want to continue pushing your local Slices?"
970
+ }
971
+ ]).then((res) => res.pushSlices);
972
+ }
973
+ async function promptToPushCustomTypes() {
974
+ return inquirer__default["default"].prompt([
975
+ {
976
+ type: "confirm",
977
+ name: "pushCustomTypes",
978
+ default: false,
979
+ message: "Your repository already contains Custom Types. Do you want to continue pushing your local Slices?"
980
+ }
981
+ ]).then((res) => res.pushCustomTypes);
982
+ }
983
+
984
+ async function createAcl(address, repository, authorization) {
985
+ return axios__default["default"].get(address + "create", {
986
+ headers: {
987
+ repository,
988
+ Authorization: `Bearer ${authorization}`,
989
+ "User-Agent": "slice-machine"
990
+ }
991
+ }).then((res) => res.data);
992
+ }
993
+ async function createFormForS3(key, filename, filePath, acl) {
994
+ const form = new FormData__default["default"]();
995
+ Object.entries(acl.values.fields).forEach(([k, value]) => {
996
+ form.append(k, value);
997
+ });
998
+ form.append("key", key);
999
+ const contentType = mime__default["default"].getType(filePath);
1000
+ contentType && form.append("Content-Type", contentType);
1001
+ return fs__default["default"].promises.readFile(filePath).then((file) => {
1002
+ form.append("file", file, { filename });
1003
+ return form;
1004
+ }).catch(() => {
1005
+ writeError$1(`Error reading preview image: ${filename}`);
1006
+ return null;
1007
+ });
1008
+ }
1009
+ function createS3Key(repository, sliceName, variationId, filename) {
1010
+ return `${repository}/shared-slices/${snakeCase__default["default"](sliceName)}/${snakeCase__default["default"](variationId)}-${uniqid__default["default"]()}/${filename}`;
1011
+ }
1012
+ async function sendVariationPreviewToS3(acl, repository, sliceName, variationId, filePath) {
1013
+ const filename = path__default["default"].basename(filePath);
1014
+ const key = createS3Key(repository, sliceName, variationId, filename);
1015
+ const form = await createFormForS3(key, filename, filePath, acl);
1016
+ if (form === null)
1017
+ return null;
1018
+ if (form.hasKnownLength() === false) {
1019
+ writeError$1(`[slice/push] An error occurred while uploading preview image ${filePath} as length in unknown`);
1020
+ }
1021
+ const errorMessage = `[slice/push] An error occurred while uploading preview images for ${sliceName}-${variationId} - please contact support`;
1022
+ return axios__default["default"].post(acl.values.url, form, {
1023
+ headers: {
1024
+ ...form.getHeaders(),
1025
+ "Content-Length": String(form.getLengthSync())
1026
+ }
1027
+ }).then((res) => {
1028
+ if (res.status !== 204) {
1029
+ writeError$1(errorMessage);
1030
+ writeError$1(`${res.status}: ${res.statusText}`);
1031
+ return null;
1032
+ } else {
1033
+ return `${acl.imgixEndpoint}/${key}`;
1034
+ }
1035
+ }).catch((err) => {
1036
+ writeError$1(errorMessage);
1037
+ if (axios__default["default"].isAxiosError(err) && err.response) {
1038
+ writeError$1(`${err.response.status}: ${err.response.statusText}`);
1039
+ } else if (err instanceof Error) {
1040
+ writeError$1(err.message);
1041
+ } else {
1042
+ writeError$1(String(err));
1043
+ }
1044
+ return null;
1045
+ });
1046
+ }
1047
+ async function maybeAddImageUrlToVariation(acl, repository, modelId, pathToScreenShot, variation) {
1048
+ const imageUrl = await sendVariationPreviewToS3(acl, repository, modelId, variation.id, pathToScreenShot);
1049
+ if (!imageUrl)
1050
+ return variation;
1051
+ return {
1052
+ ...variation,
1053
+ imageUrl
1054
+ };
1055
+ }
1056
+ async function addImageUrlsToVariations(acl, repository, modelId, screenshotPaths, variations) {
1057
+ return Promise.all(variations.map(async (variation) => {
1058
+ const screenshot = screenshotPaths[variation.id];
1059
+ if (!screenshot || !screenshot.path)
1060
+ return variation;
1061
+ return maybeAddImageUrlToVariation(acl, repository, modelId, screenshot.path, variation);
1062
+ }));
1063
+ }
1064
+ async function maybeUpdateModelVariationsWithImageUrl(acl, repository, component) {
1065
+ const { screenshotPaths, model } = component;
1066
+ const variations = await addImageUrlsToVariations(acl, repository, model.id, screenshotPaths, model.variations);
1067
+ return {
1068
+ ...model,
1069
+ variations
1070
+ };
1071
+ }
1072
+ async function addImageUrlsToModelVariations(acl, repository, components) {
1073
+ return Promise.all(components.map(async (component) => maybeUpdateModelVariationsWithImageUrl(acl, repository, component)));
1074
+ }
1075
+
1076
+ async function sendSlicesFromStarter(base, repository, authorization, libraryPaths, cwd) {
1077
+ const endpoints = getEndpointsFromBase(base);
1078
+ const libraries = Libraries__namespace.libraries(cwd, libraryPaths);
1079
+ if (libraries.length === 0)
1080
+ return Promise.resolve(false);
1081
+ const remoteSlices = await getRemoteSliceIds(endpoints.Models, repository, authorization);
1082
+ if (remoteSlices.length) {
1083
+ const pushAnyway = await promptToPushSlices();
1084
+ if (pushAnyway === false)
1085
+ return Promise.resolve(true);
1086
+ }
1087
+ const spinner = spinner$1("Pushing existing Slice models to your repository");
1088
+ spinner.start();
1089
+ const acl = await createAcl(endpoints.AclProvider, repository, authorization);
1090
+ const components = libraries.reduce((acc, lib) => {
1091
+ return [...acc, ...lib.components];
1092
+ }, []);
1093
+ const models = await addImageUrlsToModelVariations(acl, repository, components);
1094
+ await sendManyModelsToPrismic(repository, authorization, endpoints.Models, remoteSlices, models);
1095
+ spinner.succeed();
1096
+ return Promise.resolve(true);
1097
+ }
1098
+
1099
+ function readCustomTypes(cwd) {
1100
+ const customTypePaths = NodeUtils.CustomTypesPaths(cwd);
1101
+ const dir = customTypePaths.value();
1102
+ if (NodeUtils.Files.isDirectory(dir) === false)
1103
+ return [];
1104
+ const fileNames = NodeUtils.Files.readDirectory(dir);
1105
+ const files = fileNames.reduce((acc, fileName) => {
1106
+ const filePath = customTypePaths.customType(fileName).model();
1107
+ const json = NodeUtils.Files.safeReadJson(filePath);
1108
+ if (!json)
1109
+ return acc;
1110
+ const file = customtypes.CustomType.decode(json);
1111
+ if (file instanceof Error) {
1112
+ writeError$1(`reading ${filePath}: ${file.message}`);
1113
+ return acc;
1114
+ }
1115
+ if (Either$1.isLeft(file)) {
1116
+ writeError$1(`validating ${filePath}: ${JSON.stringify(file.left)}`);
1117
+ return acc;
1118
+ }
1119
+ return [...acc, file.right];
1120
+ }, []);
1121
+ return files;
1122
+ }
1123
+ async function sendCustomTypesFromStarter(repository, authorization, base, cwd) {
1124
+ const customTypeApiEndpoint = getEndpointsFromBase(base).Models;
1125
+ const customTypes = readCustomTypes(cwd);
1126
+ if (customTypes.length === 0)
1127
+ return Promise.resolve(false);
1128
+ const remoteCustomTypeIds = await getRemoteCustomTypeIds(customTypeApiEndpoint, repository, authorization);
1129
+ if (remoteCustomTypeIds.length) {
1130
+ const shouldPush = await promptToPushCustomTypes();
1131
+ if (shouldPush === false)
1132
+ return Promise.resolve(false);
1133
+ }
1134
+ const spinner = spinner$1("Pushing existing custom types to your repository");
1135
+ spinner.start();
1136
+ await sendManyCustomTypesToPrismic(repository, authorization, customTypeApiEndpoint, remoteCustomTypeIds, customTypes);
1137
+ spinner.succeed();
1138
+ return Promise.resolve(true);
1139
+ }
1140
+
1141
+ const SignatureFileReader = t__namespace.type({
1142
+ signature: t__namespace.string
1143
+ });
1144
+ async function readSignatureFile(cwd) {
1145
+ const pathToFile = path__default["default"].join(cwd, "documents", "index.json");
1146
+ return fs__default["default"].promises.readFile(pathToFile, "utf-8").then((res) => {
1147
+ const data = JSON.parse(res);
1148
+ return Either.getOrElseW(() => {
1149
+ throw new Error("Unable to read document signature file");
1150
+ })(SignatureFileReader.decode(data));
1151
+ });
1152
+ }
1153
+ async function lsdir(dir) {
1154
+ return fs__default["default"].promises.readdir(dir).then((dirs) => {
1155
+ return dirs.filter((name) => fs__default["default"].statSync(path__default["default"].join(dir, name)).isDirectory()).map((subdirectory) => path__default["default"].join(dir, subdirectory));
1156
+ });
1157
+ }
1158
+ async function lsfiles(dir) {
1159
+ return fs__default["default"].promises.readdir(dir).then((dirs) => {
1160
+ return dirs.filter((name) => fs__default["default"].statSync(path__default["default"].join(dir, name)).isFile()).map((file) => path__default["default"].join(dir, file));
1161
+ });
1162
+ }
1163
+ async function readDocuments(cwd) {
1164
+ const documentDir = path__default["default"].join(cwd, "documents");
1165
+ const dirs = await lsdir(documentDir);
1166
+ const files = (await Promise.all(dirs.map((dir) => lsfiles(dir)))).flat();
1167
+ const documentObj = files.reduce((acc, file) => {
1168
+ const fileContent = fs__default["default"].readFileSync(file, "utf-8");
1169
+ const filename = path__default["default"].parse(file).name;
1170
+ acc[filename] = JSON.parse(fileContent);
1171
+ return acc;
1172
+ }, {});
1173
+ return JSON.stringify(documentObj);
1174
+ }
1175
+ const sendDocumentsFromStarter = async (repository, cookies, base, cwd) => {
1176
+ const pathToDocuments = path__default["default"].join(cwd, "documents");
1177
+ const pathToSignatureFile = path__default["default"].join(pathToDocuments, "index.json");
1178
+ if (!fs__default["default"].existsSync(pathToSignatureFile)) {
1179
+ return Promise.resolve(false);
1180
+ }
1181
+ const signatureObj = await readSignatureFile(cwd);
1182
+ const documentsStr = await readDocuments(cwd);
1183
+ const payload = {
1184
+ signature: signatureObj.signature,
1185
+ documents: documentsStr
1186
+ };
1187
+ const prismicUrl = new URL(base);
1188
+ prismicUrl.hostname = `${repository}.${prismicUrl.hostname}`;
1189
+ prismicUrl.pathname = "starter/documents";
1190
+ const endpointURL = prismicUrl.toString();
1191
+ const spinner = spinner$1("Pushing existing documents to your repository");
1192
+ spinner.start();
1193
+ return axios__default["default"].post(endpointURL, payload, {
1194
+ headers: {
1195
+ "User-Agent": "prismic-cli/0",
1196
+ Cookie: cookies
1197
+ }
1198
+ }).then(() => {
1199
+ spinner.succeed();
1200
+ fs__default["default"].rmSync(pathToDocuments, { recursive: true, force: true });
1201
+ return true;
1202
+ }).catch((e) => {
1203
+ var _a;
1204
+ spinner.fail();
1205
+ if (((_a = e.response) == null ? void 0 : _a.data) === "Repository should not contain documents") {
1206
+ writeError$1("The selected repository is not empty, documents cannot be uploaded. Please choose an empty repository or delete the documents contained in your repository.");
1207
+ } else {
1208
+ handleErrors("sending documents, please try again. If the problem persists, contact us.", e);
1209
+ }
1210
+ process.exit(1);
1211
+ });
1212
+ };
1213
+
1214
+ async function sendStarterData(repository, base, cookies, cwd) {
1215
+ const smJson = NodeUtils.retrieveManifest(cwd);
1216
+ const hasDocuments = NodeUtils.Files.exists(path__default["default"].join(cwd, "documents"));
1217
+ if (smJson.exists === false || hasDocuments === false)
1218
+ return Promise.resolve(false);
1219
+ const authTokenFromCookie = cookie.parsePrismicAuthToken(cookies);
1220
+ if (smJson.content && smJson.content.libraries) {
1221
+ await sendSlicesFromStarter(base, repository, authTokenFromCookie, smJson.content.libraries, cwd);
1222
+ }
1223
+ await sendCustomTypesFromStarter(repository, authTokenFromCookie, base, cwd);
1224
+ return sendDocumentsFromStarter(repository, cookies, base, cwd);
1225
+ }
1226
+
840
1227
  async function init() {
841
1228
  const cwd = findArgument(process.argv, "cwd") || process.cwd();
842
1229
  const base = findArgument(process.argv, "base") || core.CONSTS.DEFAULT_BASE;
@@ -859,9 +1246,10 @@ async function init() {
859
1246
  const frameworkResult = await detectFramework(cwd);
860
1247
  const repositoryDomainName = await chooseOrCreateARepository(cwd, frameworkResult.value, config.cookies, config.base, maybeRepositorySubdomain);
861
1248
  Tracker.get().setRepository(repositoryDomainName);
862
- await installRequiredDependencies(cwd, frameworkResult.value);
863
1249
  const sliceLibPath = lib ? await installLib(cwd, lib, branch) : void 0;
1250
+ const wasStarter = await sendStarterData(repositoryDomainName, config.base, config.cookies, cwd);
864
1251
  await configureProject(cwd, base, repositoryDomainName, frameworkResult, sliceLibPath, isTrackingAvailable);
1252
+ await installRequiredDependencies(cwd, frameworkResult.value, wasStarter);
865
1253
  displayFinalMessage(cwd);
866
1254
  }
867
1255
  init().then(() => {