Skip to content

Commit

Permalink
undo convert changes
Browse files Browse the repository at this point in the history
  • Loading branch information
rnegron committed Dec 3, 2024
1 parent 549acae commit 6612ca0
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions packages/cli/src/utils/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ const prettifyJSON = (origString) => JSON.stringify(origString, null, 2);
const renderTemplate = async (
templateFile,
templateContext,
prettify = true,
prettify = true
) => {
const templateBuf = await readFile(templateFile);
const template = templateBuf.toString();
let content = _.template(template, { interpolate: /<%=([\s\S]+?)%>/g })(
templateContext,
templateContext
);

if (prettify) {
Expand Down Expand Up @@ -99,7 +99,7 @@ const getAuthFieldKeys = (appDefinition) => {

const renderPackageJson = async (appInfo, appDefinition) => {
const name = _.kebabCase(
appInfo.title || _.get(appInfo, ['general', 'title']),
appInfo.title || _.get(appInfo, ['general', 'title'])
);

// Not using escapeSpecialChars because we don't want to escape single quotes (not
Expand Down Expand Up @@ -180,7 +180,7 @@ const renderSource = (definition, functions = {}) => {
funcName = `${funcNameBase}${funcNum}`;
}
functions[funcName] = `const ${funcName} = async (${args.join(
', ',
', '
)}) => {\n${source}\n};`;

this.parent.update(makePlaceholder(funcName));
Expand All @@ -195,7 +195,7 @@ const renderDefinitionSlice = (definitionSlice, filename) => {
renderSource(exportBlock, functionBlock);

exportBlock = `module.exports = ${replacePlaceholders(
JSON.stringify(exportBlock),
JSON.stringify(exportBlock)
)};\n`;

functionBlock = Object.values(functionBlock).join('\n\n');
Expand All @@ -206,9 +206,8 @@ const renderDefinitionSlice = (definitionSlice, filename) => {
} catch (err) {
console.warn(
`Warning: Your code has syntax error in ${chalk.underline.bold(
filename,
)}. ` +
`It will be left as is and won't be prettified.\n\n${err.message}`,
filename
)}. ` + `It will be left as is and won't be prettified.\n\n${err.message}`
);
return uglyCode;
}
Expand Down Expand Up @@ -239,7 +238,7 @@ const renderIndex = async (appDefinition) => {
// replace version and platformVersion with dynamic reference
exportBlock.version = makePlaceholder("require('./package.json').version");
exportBlock.platformVersion = makePlaceholder(
"require('zapier-platform-core').version",
"require('zapier-platform-core').version"
);

if (appDefinition.authentication) {
Expand Down Expand Up @@ -270,7 +269,7 @@ const renderIndex = async (appDefinition) => {
exportBlock[stepType][makePlaceholder(`[${importName}.key]`)] =
makePlaceholder(importName);
});
},
}
);

if (!_.isEmpty(appDefinition.hydrators)) {
Expand All @@ -283,20 +282,20 @@ const renderIndex = async (appDefinition) => {
if (appDefinition.legacy && appDefinition.legacy.scriptingSource) {
importBlock.push("\nconst fs = require('fs');");
importBlock.push(
"const scriptingSource = fs.readFileSync('./scripting.js', { encoding: 'utf8' });",
"const scriptingSource = fs.readFileSync('./scripting.js', { encoding: 'utf8' });"
);
exportBlock.legacy.scriptingSource = makePlaceholder('scriptingSource');
}

exportBlock = `module.exports = ${replacePlaceholders(
JSON.stringify(exportBlock),
JSON.stringify(exportBlock)
)};`;

importBlock = importBlock.join('\n');
functionBlock = Object.values(functionBlock).join('\n\n');

return prettifyJs(
importBlock + '\n\n' + functionBlock + '\n\n' + exportBlock,
importBlock + '\n\n' + functionBlock + '\n\n' + exportBlock
);
};

Expand Down Expand Up @@ -340,7 +339,7 @@ const writeScripting = async (appDefinition, newAppDir) => {
await createFile(
appDefinition.legacy.scriptingSource,
'scripting.js',
newAppDir,
newAppDir
);
};

Expand Down Expand Up @@ -386,7 +385,7 @@ const convertApp = async (appInfo, appDefinition, newAppDir) => {
_.each(appDefinition[stepType], (definition, key) => {
promises.push(
writeStep(stepType, definition, key, newAppDir),
writeStepTest(stepType, definition, key, newAppDir),
writeStepTest(stepType, definition, key, newAppDir)
);
});
});
Expand All @@ -406,7 +405,7 @@ const convertApp = async (appInfo, appDefinition, newAppDir) => {
writeIndex(appDefinition, newAppDir),
writeEnvironment(appDefinition, newAppDir),
writeGitIgnore(newAppDir),
writeZapierAppRc(appInfo, appDefinition, newAppDir),
writeZapierAppRc(appInfo, appDefinition, newAppDir)
);

return Promise.all(promises);
Expand Down

0 comments on commit 6612ca0

Please sign in to comment.