-
Notifications
You must be signed in to change notification settings - Fork 26
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
8 changed files
with
117 additions
and
7 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,69 @@ | ||
// markers for dependencies usage | ||
const fs = require('fs'); | ||
const { promisify } = require('util'); | ||
const path = require('path'); | ||
|
||
const encoding = 'utf8'; | ||
|
||
const iconMarkerPath = path.join( | ||
require('os').tmpdir(), | ||
'./antd-v4-icon.marker.txt', | ||
); | ||
|
||
const compatibleMarkerPath = path.join( | ||
require('os').tmpdir(), | ||
'./antd4-v4-compatible.marker.txt', | ||
); | ||
|
||
const dependencyMarkerPathMap = { | ||
'@ant-design/icons': iconMarkerPath, | ||
'@ant-design/compatible': compatibleMarkerPath, | ||
}; | ||
|
||
const fsOpenAsync = promisify(fs.open); | ||
const fsUnlinkAsync = promisify(fs.unlink); | ||
const fsAppendFileAsync = promisify(fs.appendFile); | ||
const fsReadFileAsync = promisify(fs.readFile); | ||
|
||
async function start() { | ||
return await Promise.all( | ||
Object.values(dependencyMarkerPathMap).map(markPath => | ||
fsOpenAsync(markPath, 'w'), | ||
), | ||
); | ||
} | ||
|
||
async function markDependency(dependency) { | ||
const markerPath = dependencyMarkerPathMap[dependency]; | ||
if (markerPath) { | ||
// add times count | ||
await fsAppendFileAsync(markerPath, '1', encoding); | ||
} | ||
} | ||
|
||
async function output() { | ||
const dependencies = Object.keys(dependencyMarkerPathMap); | ||
const jobs = dependencies.map(async dependencyName => { | ||
const markerPath = dependencyMarkerPathMap[dependencyName]; | ||
const content = await fsReadFileAsync(markerPath, encoding); | ||
const times = content.length; | ||
await fsUnlinkAsync(markerPath); | ||
return times; | ||
}); | ||
const result = await Promise.all(jobs); | ||
return dependencies.reduce((prev, dependencyName, index) => { | ||
const times = result[index]; | ||
if (times) { | ||
// eslint-disable-next-line no-param-reassign | ||
prev[dependencyName] = times; | ||
} | ||
|
||
return prev; | ||
}, {}); | ||
} | ||
|
||
module.exports = { | ||
start, | ||
markDependency, | ||
output, | ||
}; |
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
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