Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
silent
} = detectEnv();
// build script
const script = buildCommand({
platform,
msvs_version,
debug,
runtime,
electronVersion: dependentElectronVersion
});
console.log(script);
// print build info
signale.info("Package Version =", packageVersion);
signale.info("Platform =", platform);
signale.info("Dependent Electron Version =", dependentElectronVersion);
signale.info("Build Runtime =", runtime, "\n");
// create two stream and start
signale.pending("Build C++ addon for Agora Electron SDK...\n");
const errLogWriteStream = fs.createWriteStream("error-log.txt", {
flags: "a"
});
const buildStream = shell.exec(
script,
{
silent: silent
},
(code, stdout, stderr) => {
if (code !== 0) {
rimraf(removeDir, err => {
if (err) {
signale.fatal(err);
process.exit(1);
}
// print download info
signale.info('Package Version =', packageVersion);
signale.info('Platform =', platform);
signale.info('Dependent Electron Version =', dependentElectronVersion);
signale.info('Download Url =', downloadUrl, '\n');
// start
signale.pending('Downloading prebuilt C++ addon for Agora Electron SDK...\n');
download(downloadUrl, outputDir, {
strip: 1,
extract: true
}).then(() => {
signale.success('Success', 'Download finished');
}).catch(err => {
signale.fatal('Failed', err);
});
});
};
getLogger() {
let logger = new Signale({ interactive: false });
logger.config({
displayTimestamp: true
});
if (process.env.DEBUG) {
let consoleLog = console.log;
// consoleLog = function() {};
logger = {
success: consoleLog,
await: consoleLog,
watch: consoleLog,
fatal: consoleLog,
info: consoleLog,
time: consoleLog,
timeEnd: consoleLog
}
const prettierConfig = getPrettierConfig();
list.forEach(filePath => {
if (existsSync(filePath)) {
const ext = extname(filePath).replace(/^\./, '');
const text = readFileSync(filePath, 'utf8');
const formatText = format(text, {
parser: PRETTIER_PARSER[ext],
...prettierConfig,
});
writeFileSync(filePath, formatText, 'utf8');
}
});
signale.success(`${chalk.cyan('prettier')} success!`);
}
// eslint
if (preCommitConfig.eslint) {
const eslintConfig = getEsLintConfig();
const eslintBin = require.resolve('eslint/bin/eslint');
const args = [eslintBin, '-c', eslintConfig, ...list, '--fix'];
try {
await runCmd('node', args);
} catch (code) {
process.exit(code);
}
signale.success(`${chalk.cyan('eslint')} success!`);
}
msvs_version,
debug,
runtime,
electronVersion: dependentElectronVersion
});
console.log(script);
// print build info
signale.info("Package Version =", packageVersion);
signale.info("Platform =", platform);
signale.info("Dependent Electron Version =", dependentElectronVersion);
signale.info("Build Runtime =", runtime, "\n");
// create two stream and start
signale.pending("Build C++ addon for Agora Electron SDK...\n");
const errLogWriteStream = fs.createWriteStream("error-log.txt", {
flags: "a"
});
const buildStream = shell.exec(
script,
{
silent: silent
},
(code, stdout, stderr) => {
if (code !== 0) {
// failed
errLogWriteStream.write(stderr, "utf8");
signale.fatal(
"Failed to build, check complete error log in",
shell.pwd() + "/error-log.txt\n"
);
async function shutdown() {
logger.pending("Shutting down...");
// attempts to cleanup docker containers
await execa.sync(
'docker kill $(docker ps -q --filter "label=wflow") || true',
{ shell: true }
);
// removes all data from workspaces
rimraf.sync(`${tempDirectory}/wflow`);
logger.success("Thanks for using Workflow!");
process.exit();
}
rimraf(removeDir, err => {
if (err) {
signale.fatal(err);
process.exit(1);
}
// print download info
signale.info('Package Version =', packageVersion);
signale.info('Platform =', platform);
signale.info('Dependent Electron Version =', dependentElectronVersion);
signale.info('Download Url =', downloadUrl, '\n');
// start
signale.pending('Downloading prebuilt C++ addon for Agora Electron SDK...\n');
download(downloadUrl, outputDir, {
strip: 1,
extract: true
}).then(() => {
signale.success('Success', 'Download finished');
}).catch(err => {
signale.fatal('Failed', err);
});
});
};
return () => {
// Allow only building for specific browser targets.
// Useful in local dev for faster builds.
if (process.env.TARGETS && !process.env.TARGETS.includes(browser)) {
return
}
signale.await(`Building the ${title} ${env} bundle`)
copyExtensionAssets(buildDir)
const zipDest = path.resolve(process.cwd(), `${BUILDS_DIR}/bundles/${BROWSER_BUNDLE_ZIPS[browser]}`)
if (zipDest) {
shelljs.mkdir('-p', `./${BUILDS_DIR}/bundles`)
shelljs.exec(`cd ${buildDir} && zip -q -r ${zipDest} *`)
}
signale.success(`Done building the ${title} ${env} bundle`)
}
}
through.obj((file, env, cb) => {
try {
file.contents = Buffer.from(
transform({
file,
type,
}),
);
// .jsx -> .js
file.path = file.path.replace(extname(file.path), '.js');
cb(null, file);
} catch (e) {
signale.error(`Compiled faild: ${file.path}`);
cb(null);
}
}),
),
await mkdir(`${basePath}/data`, { recursive: true });
} catch (e) {
// logger.info(`${basePath}/data already existed. But that's ok`);
}
try {
await mkdir(workPath, { recursive: true });
} catch (e) {
// logger.info(`workPath already existed. But that's ok`);
}
try {
await mkdir(codePath, { recursive: true });
await mkdir(logPath, { recursive: true });
} catch (e) {
logger.error(e);
}
return {
workPath,
codePath,
logPath
};
}