|
|
@ -30,6 +30,7 @@ import { |
|
|
removeCommentsFromCss, |
|
|
removeCommentsFromCss, |
|
|
removeCommentsFromJs, |
|
|
removeCommentsFromJs, |
|
|
replaceNames, |
|
|
replaceNames, |
|
|
|
|
|
syncFilesWithCloud, |
|
|
uploadFile, |
|
|
uploadFile, |
|
|
verifyVersion, |
|
|
verifyVersion, |
|
|
zipProject |
|
|
zipProject |
|
|
@ -38,7 +39,6 @@ import PluginError from 'plugin-error'; |
|
|
import {Server} from "socket.io"; |
|
|
import {Server} from "socket.io"; |
|
|
import {createServer} from 'http'; |
|
|
import {createServer} from 'http'; |
|
|
import {authtoken, connect} from "ngrok"; |
|
|
import {authtoken, connect} from "ngrok"; |
|
|
import {exec} from "child_process"; |
|
|
|
|
|
import bodyParser from "body-parser"; |
|
|
import bodyParser from "body-parser"; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
@ -260,6 +260,13 @@ app.get('/publish', async (req, res) => { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
await syncFilesWithCloud(path.join(projectPath, 'block.json'), bs); |
|
|
|
|
|
} catch (err) { |
|
|
|
|
|
res.json({success: false, message: err}); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
res.json({success: true}); |
|
|
res.json({success: true}); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
@ -284,31 +291,19 @@ app.get('/data', async (req, res) => { |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
app.post('/sync', async (req, res) => { |
|
|
app.post('/sync', async (req, res) => { |
|
|
const blockJson = await readJSONFile(path.join(projectPath, `block.json`)); |
|
|
|
|
|
const blockName = blockJson.name.startsWith('@') ? blockJson.name : `@${blockJson.name}`; |
|
|
|
|
|
|
|
|
|
|
|
if (req.body['ignore']) { |
|
|
if (req.body['ignore']) { |
|
|
ignoreVersionSync = true; |
|
|
ignoreVersionSync = true; |
|
|
res.json({status: 200, message: 'Version upgrade is ignored.'}); |
|
|
res.json({status: 200, message: 'Version upgrade is ignored.'}); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
bs.pause(); |
|
|
try { |
|
|
|
|
|
await syncFilesWithCloud(path.join(projectPath, `block.json`), bs, true); |
|
|
// Looks like it takes time to pause the browser-sync server, so delay(setTimeout) is necessary.
|
|
|
} catch (err) { |
|
|
setTimeout(() => { |
|
|
res.status(500).json({status: 500, message: err}); |
|
|
exec(`node ./node_modules/@axe-web/create-block/create-block.js sync --source ${blockName}`, (err, stdout, stderr) => { |
|
|
|
|
|
if (err || stderr) { |
|
|
|
|
|
console.error('Error:', err || stderr); |
|
|
|
|
|
res.status(500).json({status: 500, message: err || stderr}); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
console.log(stdout); |
|
|
|
|
|
|
|
|
|
|
|
bs.resume(); |
|
|
|
|
|
res.json({status: 200, message: 'Successfully synced!'}); |
|
|
res.json({status: 200, message: 'Successfully synced!'}); |
|
|
}); |
|
|
|
|
|
}) |
|
|
|
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
// Errors handler
|
|
|
// Errors handler
|
|
|
|