@contentful/create-contentful-app 2.2.0 → 2.2.1

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/lib/index.js CHANGED
@@ -130,7 +130,7 @@ async function initProject(appName, options) {
130
130
  manager: packageManager,
131
131
  interactive: isInteractive,
132
132
  });
133
- await (0, template_1.cloneTemplateIn)(fullAppFolder, templateSource);
133
+ (0, template_1.cloneTemplateIn)(templateSource, fullAppFolder);
134
134
  if (!isInteractive && (0, utils_1.isContentfulTemplate)(templateSource) && normalizedOptions.function) {
135
135
  // If function flag is specified, but no function name is provided, we default to external-references
136
136
  // for legacy support
package/lib/template.js CHANGED
@@ -22,33 +22,108 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
25
  Object.defineProperty(exports, "__esModule", { value: true });
29
26
  exports.cloneTemplateIn = void 0;
30
27
  const path_1 = require("path");
31
28
  const fs_1 = require("fs");
32
- const tiged_1 = __importDefault(require("tiged"));
29
+ const os_1 = require("os");
33
30
  const rimraf = __importStar(require("rimraf"));
31
+ const child_process_1 = require("child_process");
34
32
  const logger_1 = require("./logger");
35
33
  const utils_1 = require("./utils");
36
- async function clone(source, destination) {
37
- const d = (0, tiged_1.default)(source, { mode: 'tar', disableCache: true });
34
+ function clone(source, destination) {
38
35
  try {
39
- await d.clone(destination);
36
+ if ((0, fs_1.existsSync)(destination)) {
37
+ try {
38
+ const files = (0, child_process_1.execSync)(`ls -la "${destination}"`, { encoding: 'utf8' });
39
+ if (files.split('\n').length > 3) {
40
+ throw new Error('Destination directory is not empty.');
41
+ }
42
+ }
43
+ catch {
44
+ // Ignore
45
+ }
46
+ }
47
+ if (isContentfulTemplate(source)) {
48
+ cloneContentfulTemplate(source, destination);
49
+ }
50
+ else {
51
+ // Try to handle external repositories
52
+ (0, child_process_1.execSync)(`git clone --depth 1 "${source}" "${destination}"`, { stdio: 'ignore' });
53
+ try {
54
+ (0, child_process_1.execSync)(`rm -rf "${destination}/.git"`);
55
+ }
56
+ catch {
57
+ // Ignore
58
+ }
59
+ }
40
60
  }
41
61
  catch (e) {
42
- if (e.code === 'DEST_NOT_EMPTY') {
43
- // In this case, we know that tiged will suggest users
44
- // provide a 'force' flag - this is a flag for tiged though
45
- // and not CCA. So we swallow the details of this error
46
- // to avoid confusing people.
47
- throw new Error('Destination directory is not empty.');
62
+ if (e.message?.includes('Destination directory is not empty')) {
63
+ throw e;
48
64
  }
49
- throw e;
65
+ if (e.message?.includes('not found') || e.message?.includes('does not exist')) {
66
+ throw new Error(`Repository not found: ${source}`);
67
+ }
68
+ throw new Error(`Failed to clone repository: ${e.message}`);
50
69
  }
51
70
  }
71
+ function cloneContentfulTemplate(source, destination) {
72
+ const templatePath = source.replace('contentful/apps/', '');
73
+ const tempDir = (0, path_1.resolve)((0, os_1.tmpdir)(), `contentful-clone-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`);
74
+ try {
75
+ (0, child_process_1.execSync)(`git clone --depth 1 https://github.com/contentful/apps.git "${tempDir}"`, {
76
+ stdio: 'ignore',
77
+ });
78
+ try {
79
+ (0, child_process_1.execSync)(`mkdir -p "${destination}"`);
80
+ }
81
+ catch {
82
+ // Windows fallback
83
+ try {
84
+ (0, child_process_1.execSync)(`mkdir "${destination}"`);
85
+ }
86
+ catch {
87
+ // Ignore
88
+ }
89
+ }
90
+ const sourcePath = (0, path_1.resolve)(tempDir, templatePath);
91
+ try {
92
+ (0, child_process_1.execSync)(`cp -r "${sourcePath}"/* "${destination}"/`);
93
+ }
94
+ catch {
95
+ (0, child_process_1.execSync)(`xcopy "${sourcePath}\\*" "${destination}\\" /E /I /Y`);
96
+ }
97
+ try {
98
+ (0, child_process_1.execSync)(`rm -rf "${tempDir}"`);
99
+ }
100
+ catch {
101
+ try {
102
+ (0, child_process_1.execSync)(`rmdir /S /Q "${tempDir}"`);
103
+ }
104
+ catch {
105
+ // Ignore
106
+ }
107
+ }
108
+ }
109
+ catch (error) {
110
+ try {
111
+ (0, child_process_1.execSync)(`rm -rf "${tempDir}"`);
112
+ }
113
+ catch {
114
+ try {
115
+ (0, child_process_1.execSync)(`rmdir /S /Q "${tempDir}"`);
116
+ }
117
+ catch {
118
+ // Ignore
119
+ }
120
+ }
121
+ throw error;
122
+ }
123
+ }
124
+ function isContentfulTemplate(source) {
125
+ return source.startsWith('contentful/apps/');
126
+ }
52
127
  function validate(destination) {
53
128
  const packageJSONLocation = `${destination}/package.json`;
54
129
  if (!(0, fs_1.existsSync)(packageJSONLocation)) {
@@ -66,8 +141,8 @@ function cleanUp(destination) {
66
141
  (0, utils_1.rmIfExists)((0, path_1.resolve)(destination, 'package-lock.json'));
67
142
  (0, utils_1.rmIfExists)((0, path_1.resolve)(destination, 'yarn.lock'));
68
143
  }
69
- async function cloneTemplateIn(destination, source) {
70
- await clone(source, destination);
144
+ function cloneTemplateIn(source, destination) {
145
+ clone(source, destination);
71
146
  try {
72
147
  validate(destination);
73
148
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentful/create-contentful-app",
3
- "version": "2.2.0",
3
+ "version": "2.2.1",
4
4
  "description": "A template for building Contentful Apps",
5
5
  "keywords": [
6
6
  "contentful",
@@ -44,7 +44,6 @@
44
44
  "merge-options": "^3.0.4",
45
45
  "node-fetch": "2.6.7",
46
46
  "rimraf": "5.0.8",
47
- "tiged": "^2.12.7",
48
47
  "tildify": "2.0.0",
49
48
  "validate-npm-package-name": "6.0.2"
50
49
  },
@@ -74,11 +73,11 @@
74
73
  "@types/validate-npm-package-name": "4.0.2",
75
74
  "chai": "^4.3.7",
76
75
  "chai-as-promised": "^7.1.1",
77
- "contentful-management": "11.54.4",
76
+ "contentful-management": "11.57.2",
78
77
  "mocha": "^11.2.2",
79
78
  "sinon": "^21.0.0",
80
79
  "sinon-chai": "^3.7.0",
81
80
  "ts-node": "^10.9.2"
82
81
  },
83
- "gitHead": "4c69fe11610e734125777512ec1322e26f4e5456"
82
+ "gitHead": "e0b130de301a54c18aea2237067095078c0a229f"
84
83
  }