Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@contentful/create-contentful-app

Package Overview
Dependencies
Maintainers
164
Versions
610
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@contentful/create-contentful-app - npm Package Compare versions

Comparing version 1.8.1 to 1.8.2

66

lib/includeAppAction.js

@@ -20,33 +20,35 @@ "use strict";

const constants_1 = require("./constants");
function cloneAppAction(templateIsTypescript, destination) {
const actionPath = (0, path_1.resolve)(templateIsTypescript
? 'src/app-actions/typescript/index.ts'
: 'src/app-actions/javascript/index.js');
const manifestPath = (0, path_1.resolve)(templateIsTypescript
? `src/app-actions/typescript/${constants_1.CONTENTFUL_APP_MANIFEST}`
: `src/app-actions/javascript/${constants_1.CONTENTFUL_APP_MANIFEST}`);
// write the action
const appAction = (0, fs_1.readFileSync)(actionPath, { encoding: 'utf-8' }).toString();
const appActionDirectoryPath = `${destination}/actions`;
(0, fs_1.mkdirSync)(appActionDirectoryPath);
(0, fs_1.writeFileSync)(`${appActionDirectoryPath}/example${templateIsTypescript ? '.ts' : '.js'}`, appAction);
// write the manifest
const manifest = JSON.parse((0, fs_1.readFileSync)(manifestPath, { encoding: 'utf-8' }));
(0, fs_1.writeFileSync)(`${destination}/${constants_1.CONTENTFUL_APP_MANIFEST}`, JSON.stringify(manifest));
// write the build file if necessary
if (!templateIsTypescript) {
const buildFilePath = 'src/app-actions/javascript/build-actions.js';
const buildFile = (0, fs_1.readFileSync)(buildFilePath, { encoding: 'utf-8' }).toString();
(0, fs_1.writeFileSync)(`${destination}/build-actions.js`, buildFile);
}
// modify package.json build commands
const packageJsonLocation = `${destination}/package.json`;
const packageJsonExists = (0, fs_1.existsSync)(packageJsonLocation);
if (!packageJsonExists) {
console.error('Failed to add app action build commands.');
return;
}
const packageJson = JSON.parse((0, fs_1.readFileSync)(packageJsonLocation, { encoding: 'utf-8' }));
const updatedPackageJson = Object.assign(Object.assign({}, packageJson), { scripts: Object.assign(Object.assign({}, packageJson.scripts), { 'build-actions': `${templateIsTypescript ? 'tsc actions/*.ts --outDir build/actions' : 'node build-actions.js'}`, build: `${packageJson.scripts.build} && npm run build-actions` }) });
(0, fs_1.writeFileSync)(packageJsonLocation, JSON.stringify(updatedPackageJson, null, ' '));
const degit_1 = __importDefault(require("degit"));
const logger_1 = require("./logger");
function cloneAppAction(destination, templateIsTypescript) {
return __awaiter(this, void 0, void 0, function* () {
try {
console.log((0, logger_1.highlight)('---- Cloning hosted app action.'));
// Clone the app actions template to the created directory under the folder 'actions'
const templateSource = (0, path_1.join)('contentful/apps/examples/hosted-app-action-templates', templateIsTypescript ? 'typescript' : 'javascript');
const appActionDirectoryPath = (0, path_1.resolve)(`${destination}/actions`);
const d = yield (0, degit_1.default)(templateSource, { mode: 'tar', cache: false });
yield d.clone(appActionDirectoryPath);
// move the manifest from the actions folder to the root folder
(0, fs_1.renameSync)(`${appActionDirectoryPath}/${constants_1.CONTENTFUL_APP_MANIFEST}`, `${destination}/${constants_1.CONTENTFUL_APP_MANIFEST}`);
// move the build file from the actions folder to the root folder, if necessary
if (!templateIsTypescript) {
(0, fs_1.renameSync)(`${appActionDirectoryPath}/build-actions.js`, `${destination}/build-actions.js`);
}
// modify package.json build commands
const packageJsonLocation = (0, path_1.resolve)(`${destination}/package.json`);
const packageJsonExists = (0, fs_1.existsSync)(packageJsonLocation);
if (!packageJsonExists) {
console.error('Failed to add app action build commands.');
return;
}
const packageJson = JSON.parse((0, fs_1.readFileSync)(packageJsonLocation, { encoding: 'utf-8' }));
const updatedPackageJson = Object.assign(Object.assign({}, packageJson), { scripts: Object.assign(Object.assign({}, packageJson.scripts), { 'build-actions': `${templateIsTypescript ? 'tsc actions/*.ts --outDir build/actions' : 'node build-actions.js'}`, build: `${packageJson.scripts.build} && npm run build-actions` }) });
(0, fs_1.writeFileSync)(packageJsonLocation, JSON.stringify(updatedPackageJson, null, ' '));
}
catch (e) {
console.log(e);
process.exit(1);
}
});
}

@@ -66,5 +68,5 @@ exports.cloneAppAction = cloneAppAction;

const templateIsTypescript = templateSource.includes('typescript');
cloneAppAction(templateIsTypescript, fullAppFolder);
cloneAppAction(fullAppFolder, templateIsTypescript);
}
});
exports.promptIncludeActionInTemplate = promptIncludeActionInTemplate;

@@ -110,8 +110,4 @@ #!/usr/bin/env node

yield (0, template_1.cloneTemplateIn)(fullAppFolder, templateSource);
// // Ask to include a hosted app action if the user has selected a template
// if (isInteractive && isContentfulTemplate(templateSource)) {
// await promptIncludeActionInTemplate({ fullAppFolder, templateSource });
// }
if (!isInteractive && (0, utils_1.isContentfulTemplate)(templateSource) && normalizedOptions.action) {
(0, includeAppAction_1.cloneAppAction)(!!normalizedOptions.typescript, fullAppFolder);
(0, includeAppAction_1.cloneAppAction)(fullAppFolder, !!normalizedOptions.typescript);
}

@@ -161,3 +157,3 @@ updatePackageName(fullAppFolder);

].join('\n'))
// .option('-a, --action', 'include a hosted app action in your app')
.option('-a, --action', 'include a hosted app action in the ts or js template')
.action(initProject);

@@ -164,0 +160,0 @@ yield commander_1.program.parseAsync();

@@ -49,3 +49,3 @@ "use strict";

catch (e) {
throw new Error(`Invalid template: invalid "${packageJSONLocation}".`);
throw new Error(`Invalid template: invalid ${packageJSONLocation}.`);
}

@@ -52,0 +52,0 @@ }

{
"name": "@contentful/create-contentful-app",
"version": "1.8.1",
"version": "1.8.2",
"description": "A template for building Contentful Apps",

@@ -72,3 +72,3 @@ "keywords": [

},
"gitHead": "73ac7a7815a48c595df7f92457e6a7dd5c5e9a49"
"gitHead": "f79e7a9fbde908b671d26e783ffeafd3d96a81e9"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc