MCPcopy Create free account
hub / github.com/BYVoid/OpenCC / createLocalInstalledShape

Function createLocalInstalledShape

node/test.js:15–37  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

13const cases = parseJSON(fs.readFileSync('test/testcases/testcases.json', 'utf-8')).cases || [];
14
15function createLocalInstalledShape() {
16 const rootDir = path.resolve(__dirname, '..');
17 const jiebaPackageDir = path.join(rootDir, 'plugins', 'jieba', 'node');
18 const libName = os.platform() === 'win32' ? 'opencc-jieba.dll'
19 : os.platform() === 'darwin' ? 'libopencc-jieba.dylib'
20 : 'libopencc-jieba.so';
21 const requiredFiles = [
22 path.join(jiebaPackageDir, 'index.js'),
23 path.join(jiebaPackageDir, 'data', 's2twp_jieba.json'),
24 path.join(jiebaPackageDir, 'data', 'tw2sp_jieba.json'),
25 path.join(jiebaPackageDir, 'data', 'jieba_dict', 'jieba_merged.ocd2'),
26 path.join(jiebaPackageDir, 'prebuilds', `${os.platform()}-${os.arch()}`, libName),
27 ];
28 if (!requiredFiles.every((file) => fs.existsSync(file))) {
29 return null;
30 }
31 const root = fs.mkdtempSync(path.join(os.tmpdir(), 'opencc-node-jieba-'));
32 const nodeModulesDir = path.join(root, 'node_modules');
33 fs.mkdirSync(nodeModulesDir, { recursive: true });
34 fs.symlinkSync(rootDir, path.join(nodeModulesDir, 'opencc'), 'dir');
35 fs.symlinkSync(jiebaPackageDir, path.join(nodeModulesDir, 'opencc-jieba'), 'dir');
36 return root;
37}
38
39const testSync = function (tc, cfg, expected) {
40 const opencc = new OpenCC(cfg + '.json');

Callers 1

test.jsFile · 0.85

Calls 1

joinMethod · 0.45

Tested by

no test coverage detected