Skip to content

Commit

Permalink
Fixed the next issue
Browse files Browse the repository at this point in the history
  • Loading branch information
eladgel committed Nov 7, 2018
1 parent ac5472e commit 58f8e2b
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion scripts/generateBundledResourcesHash.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ function addJsBundleAndMetaToManifest() {
console.log(finalHash);

var savedResourcesManifestPath = assetsDir + "/" + CODE_PUSH_HASH_FILE_NAME;

if (!fs.existsSync(assetsDir)) {
mkDirByPathSync(assetsDir)
}

fs.writeFileSync(savedResourcesManifestPath, finalHash);

// "CodePushHash.json" file name breaks flow type checking.
Expand All @@ -92,6 +97,31 @@ function addJsBundleAndMetaToManifest() {
});
}

function mkDirByPathSync(targetDir, {isRelativeToScript = false} = {}) {
const sep = path.sep;
const initDir = path.isAbsolute(targetDir) ? sep : '';
const baseDir = isRelativeToScript ? __dirname : '.';

targetDir.split(sep).reduce((parentDir, childDir) => {
const curDir = path.resolve(baseDir, parentDir, childDir);
try {
console.log(`Directory ${curDir} creating!`);
if (!fs.existsSync(curDir)) {
fs.mkdirSync(curDir);
}
console.log(`Directory ${curDir} created!`);
} catch (err) {
if (err.code !== 'EEXIST') {
throw err;
}

console.log(`Directory ${curDir} already exists!`);
}

return curDir;
}, initDir);
}

function addFileToManifest(folder, assetFile, manifest, done) {
var fullFilePath = path.join(folder, assetFile);
if (!fileExists(fullFilePath)) {
Expand Down Expand Up @@ -122,4 +152,4 @@ function fileExists(file) {

if (tempFileLocalPath) {
fs.unlinkSync(tempFileLocalPath);
}
}

0 comments on commit 58f8e2b

Please sign in to comment.