This repository has been archived by the owner on Jan 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 471
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
165 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
'use strict' | ||
|
||
const fs = require('hexo-fs'); | ||
|
||
module.exports = function buildGenerator(sourcePath, distPath) { | ||
return { | ||
path: distPath, | ||
data: () => fs.createReadStream(sourcePath), | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
'use strict' | ||
|
||
const path = require('path'); | ||
const url = require('url'); | ||
const buildGenerator = require('./buildGenerator'); | ||
|
||
module.exports = function buildGeneratorsFromManifest(manifest, dirname, distPath) { | ||
const files = Object.keys(manifest).map(key => path.resolve(dirname, manifest[key])); | ||
return files.map((file) => { | ||
return buildGenerator(file, url.resolve(distPath, path.basename(file))) | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
'use strict' | ||
|
||
const fs = require('hexo-fs'); | ||
const crypto = require('crypto'); | ||
|
||
module.exports = function getFileMD5(filePath) { | ||
const rs = fs.readFileSync(filePath), | ||
hash = crypto.createHash('md5'); | ||
return (hash.update(rs).digest('hex')); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'use strict' | ||
|
||
const path = require('path'); | ||
|
||
module.exports = function getNodeModulePath(packageName) { | ||
return path.dirname(require.resolve(packageName + '/package.json')); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
'use strict' | ||
|
||
const fs = require('hexo-fs'); | ||
const path = require('path'); | ||
|
||
module.exports = function listFiles(dir) { | ||
const lsDir = fs.readdirSync(dir); | ||
const files = []; | ||
for (const filename of lsDir) { | ||
const pathname = path.join(dir, filename); | ||
if (fs.statSync(pathname).isDirectory()) { | ||
files.push(...listFiles(pathname)); | ||
} | ||
else files.push(pathname); | ||
} | ||
return files; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const path = require('path'); | ||
'use strict' | ||
|
||
const url = require('url'); | ||
const fs = require('fs'); | ||
const buildGenerator = require('./buildGenerator'); | ||
const listFiles = require('./listFiles'); | ||
|
||
module.exports = function loadModelFrom(modelPath, modelrootUrl) { | ||
const packageFile = path.resolve(modelPath, 'package.json'); | ||
const packageInfo = fs.existsSync(packageFile) && require(packageFile); | ||
const assetsDir = path.resolve(modelPath, './assets/'); | ||
const modelFiles = listFiles(assetsDir); | ||
const modelGenerators = modelFiles.map(file => { | ||
return buildGenerator(file, url.resolve(modelrootUrl, path.relative(assetsDir, file))) | ||
}); | ||
// find the model.json from model files | ||
const modelJsonUrl = modelGenerators.reduce((p, generator) => { | ||
if (!p && generator.path.endsWith('.model.json')) { | ||
return generator.path; | ||
} else { | ||
return p; | ||
} | ||
}, undefined); | ||
return { | ||
generators: modelGenerators, | ||
jsonUrl: modelJsonUrl, | ||
packageInfo | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters