Skip to content

Commit

Permalink
Migrate project to TypeScript
Browse files Browse the repository at this point in the history
  • Loading branch information
Amir Naderi authored and VahidNaderi committed Oct 2, 2023
1 parent 69d8685 commit 0d4c673
Show file tree
Hide file tree
Showing 34 changed files with 5,865 additions and 759 deletions.
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
node_modules
releases
# Project exclude paths
/dist/
/node_modules/
/releases/
*.crx
*.pem
1 change: 0 additions & 1 deletion _config.yml

This file was deleted.

62 changes: 44 additions & 18 deletions deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,59 @@ const fs = require('fs-extra');
const zipper = require("zip-local");
const jsonfile = require('jsonfile');
const path = require('path');
const { execSync } = require('child_process');

var buildLocation = path.join(__dirname, "releases");
let appFolder = path.join(__dirname, "src");
let manifestFilePath = path.join(appFolder, "manifest.json");
let releaseLocation = path.join(__dirname, "releases");
let distFolder = path.join(__dirname, "dist");
let publicFolder = path.join(__dirname, "public");
let manifestFilePath = path.join(publicFolder, "manifest.json");

fs.exists(buildLocation).then(res => {
if (!res) {
fs.mkdir(buildLocation);
}
preparePackage();
});
function buildPackage() {
return execSync("npm run build");
}

function getNewVersion(oldVersion) {
let splitedVer = oldVersion.split('.');
var ver = parseInt(splitedVer[2]);
ver++;
return `${splitedVer[0]}.${splitedVer[1]}.${ver}`;
}

function preparePackage() {
// read manifest file
var manifest = jsonfile.readFileSync(manifestFilePath);
function getNewVersion() {
let splitedVer = manifest.version.split('.');
var ver = parseInt(splitedVer[2]);
ver++;
return `${splitedVer[0]}.${splitedVer[1]}.${ver}`;
}
var version = getNewVersion();
var version = getNewVersion(manifest.version);
// replace version
manifest.version = version;
// save manifest file
jsonfile.writeFileSync(manifestFilePath, manifest);

// create zip
zipper.sync.zip(appFolder).compress().save(path.join(buildLocation, "googlerankchecker.zip"));
}
zipper.sync.zip(distFolder).compress().save(path.join(releaseLocation, "googlerankchecker.zip"));
}

async function buildAndPrepare() {
// Check if releaseLocation exists, create it if not
const res = await fs.exists(releaseLocation);
if (!res) {
await fs.mkdir(releaseLocation);
}
// Try to build the package, catch any errors
let isBuildSuccessful = false;
try {
buildPackage();
isBuildSuccessful = true;
} catch (error) {
console.log(error.message);
console.log("Use 'npm run build' to see the exact error.");
}
// If the build was successful, prepare the package
if (isBuildSuccessful) {
preparePackage();
}
}

// Invoke the buildAndPrepare
(async () => {
await buildAndPrepare();
})();
Loading

0 comments on commit 0d4c673

Please sign in to comment.