Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Chore: fill test entry with template
- Loading branch information
1 parent
b986009
commit 9177859
Showing
4 changed files
with
84 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#!./node_modules/.bin/babel-node | ||
import os from 'os'; | ||
import path from 'path'; | ||
import { fill } from 'myrmidon'; | ||
import { rollup } from 'rollup'; | ||
import commonjs from '@rollup/plugin-commonjs'; | ||
import resolve from '@rollup/plugin-node-resolve'; | ||
import json from '@rollup/plugin-json'; | ||
import multi from '@rollup/plugin-multi-entry'; | ||
import babel from '@rollup/plugin-babel'; | ||
import fs from 'fs-extra'; | ||
import uuid from 'uuid'; | ||
|
||
const isMain = !module.parent; | ||
|
||
async function replaceWithTemplate(templatePath, context, destPath) { | ||
const content = await fs.readFile(templatePath); | ||
const filled = fill(content.toString(), context); | ||
const backupPath = path.resolve(os.tmpdir(), uuid.v4()); | ||
|
||
await fs.move(destPath, backupPath); | ||
await fs.writeFile(destPath, filled); | ||
|
||
return backupPath; | ||
} | ||
|
||
async function run() { | ||
try { | ||
const backup = await replaceWithTemplate(path.resolve('tests/entry.static.js'), { entry: '../tmp/package/lib' }, path.resolve('tests/entry.js')); | ||
|
||
try { | ||
const bundle = await rollup({ | ||
input : 'tests/**/*test.js', | ||
plugins : [ | ||
babel({ exclude: 'node_modules/**' }), | ||
resolve({ preferBuiltins: true }), | ||
commonjs({ | ||
include : [ /node_modules/ ], | ||
sourceMap : false | ||
}), | ||
json({ | ||
include : 'node_modules/**', | ||
compact : true | ||
}), | ||
multi() | ||
] | ||
}); | ||
|
||
console.log(bundle.watchFiles); | ||
await bundle.write({ | ||
file : 'tmp/tests.js', | ||
format : 'cjs' | ||
}); | ||
} catch (error) { | ||
console.error('ROLLUP ERROR'); | ||
throw error; | ||
} finally { | ||
await fs.move(backup, path.resolve('tests/entry.js'), { overwrite: true }); | ||
} | ||
console.log('Done'); | ||
process.exit(0); | ||
} catch (error) { | ||
console.error(error); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
|
||
if (isMain) run(process.argv.slice(2)); |
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 |
---|---|---|
@@ -1,7 +1,12 @@ | ||
import path from 'path'; | ||
|
||
const isBuild = process.env.BUILD && [ '1', 'true' ].includes(process.env.BUILD); | ||
const entry = process.env.ENTRY && path.resolve(process.env.ENTRY); | ||
const entry = process.env.ENTRY && path.resolve(process.env.ENTRY) | ||
|| isBuild && path.resolve(__dirname, '../lib') | ||
|| path.resolve(__dirname, '../src'); | ||
|
||
module.exports = entry && require(entry) || isBuild && require('../lib') || require('../src'); | ||
module.exports = require(entry); | ||
|
||
module.exports._load = function (relPath) { | ||
return require(path.join(entry, relPath)); | ||
}; |
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 @@ | ||
import path from 'path'; | ||
|
||
export default require('{entry}'); | ||
|
||
export function _load(relPath) { | ||
return require(path.join('{entry}', relPath)); | ||
} |