dev #9
+29
@@ -13,6 +13,7 @@ import fs from "fs/promises";
|
|||||||
import {constants} from "fs";
|
import {constants} from "fs";
|
||||||
import fetch from "node-fetch";
|
import fetch from "node-fetch";
|
||||||
import mime from "mime-types";
|
import mime from "mime-types";
|
||||||
|
import {exec} from "child_process";
|
||||||
|
|
||||||
const __filename = fileURLToPath(import.meta.url);
|
const __filename = fileURLToPath(import.meta.url);
|
||||||
const __dirname = path.dirname(__filename);
|
const __dirname = path.dirname(__filename);
|
||||||
@@ -302,3 +303,31 @@ export async function verifyVersion(projectPath, blocksRegistry) {
|
|||||||
const block = await getBlockFromCloud('@' + blockJson.name, blocksRegistry);
|
const block = await getBlockFromCloud('@' + blockJson.name, blocksRegistry);
|
||||||
return block.version === blockJson.version;
|
return block.version === blockJson.version;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function syncFilesWithCloud(jsonBlockPath, bs, sourceFiles = false) {
|
||||||
|
const blockJson = await readJSONFile(jsonBlockPath);
|
||||||
|
const blockName = blockJson.name.startsWith('@') ? blockJson.name : `@${blockJson.name}`;
|
||||||
|
|
||||||
|
bs.pause();
|
||||||
|
|
||||||
|
// Looks like it takes time to pause the browser-sync server, so delay(setTimeout) is necessary.
|
||||||
|
await new Promise((resolve) => setTimeout(() => resolve(), 1000));
|
||||||
|
|
||||||
|
await new Promise((resolve) => {
|
||||||
|
const args = sourceFiles ? '--source' : '';
|
||||||
|
const createBlockModulePath = `./node_modules/@axe-web/create-block`;
|
||||||
|
|
||||||
|
exec(`node ${createBlockModulePath}/create-block.js sync ${args} ${blockName}`, (err, stdout, stderr) => {
|
||||||
|
if (err || stderr) {
|
||||||
|
const message = err || stderr;
|
||||||
|
console.error('Error:', message);
|
||||||
|
throw new Error(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(stdout);
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
bs.resume();
|
||||||
|
}
|
||||||
|
|||||||
+3
-3
@@ -7,9 +7,9 @@
|
|||||||
"url": "https://axe-web.com/"
|
"url": "https://axe-web.com/"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"info": "BLOCK_NAME=timeline-scroll MODULE_PATH= node debug.js",
|
"info": "BLOCK_NAME=swiper-test MODULE_PATH= node debug.js",
|
||||||
"dev": "BLOCK_NAME=timeline-scroll MODULE_PATH= node server.js",
|
"dev": "BLOCK_NAME=swiper-test MODULE_PATH= node server.js",
|
||||||
"build-platform": "BLOCK_NAME=timeline-scroll MODULE_PATH= node ./build.js",
|
"build-platform": "BLOCK_NAME=swiper-test MODULE_PATH= node ./build.js",
|
||||||
"dev-dev-tool": "rollup --config rollup.config.js --watch",
|
"dev-dev-tool": "rollup --config rollup.config.js --watch",
|
||||||
"build-dev-tool": "rollup --config rollup.config.js"
|
"build-dev-tool": "rollup --config rollup.config.js"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -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);
|
||||||
|
} catch (err) {
|
||||||
|
res.status(500).json({status: 500, message: err});
|
||||||
|
}
|
||||||
|
|
||||||
// Looks like it takes time to pause the browser-sync server, so delay(setTimeout) is necessary.
|
res.json({status: 200, message: 'Successfully synced!'});
|
||||||
setTimeout(() => {
|
|
||||||
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!'});
|
|
||||||
});
|
|
||||||
})
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Errors handler
|
// Errors handler
|
||||||
|
|||||||
Reference in New Issue
Block a user