Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update for better use as module (#66)
* fix name * add version * update build system - export to `hacks.<hack_name>` instead of stripping exports with plugin - split build script into: - `build`: accepts filenames and outputs built hacks - `cli`: builds hacks from repo source - `index`: exports the build function - add optional command line args to build script * update dependencies for testing * update lockfile * update version to account for new export behaviour all minor, except corrupt which is major due to a complication in how hackOptions is being used (pretty sure that one's broken atm anyway) * run build
- Loading branch information
Showing
85 changed files
with
2,923 additions
and
2,248 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 |
---|---|---|
@@ -1,5 +1,10 @@ | ||
{ | ||
"presets": [ | ||
"env" | ||
] | ||
} | ||
"@babel/env" | ||
], | ||
"env": { | ||
"test": { | ||
"plugins": ["@babel/plugin-transform-runtime"] | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,57 +1,37 @@ | ||
import { readdirSync } from "fs"; | ||
import { | ||
basename | ||
} from "path"; | ||
|
||
import rollup from "rollup"; | ||
import clear from "rollup-plugin-clear"; | ||
import eslint from "rollup-plugin-eslint"; | ||
import nodeResolve from "rollup-plugin-node-resolve"; | ||
import commonjs from "rollup-plugin-commonjs"; | ||
|
||
import headerComment from "./HeaderCommentPlugin"; | ||
import topLevelOptions from "./TopLevelOptionsPlugin"; | ||
import readme from "./ReadmePlugin"; | ||
import stripExportsPlugin from "./StripExportsPlugin"; | ||
|
||
const inputDir = "./src/"; | ||
const outputDir = "./dist/"; | ||
|
||
function build(src) { | ||
export async function buildOne(src = '', plugins = []) { | ||
const inputOptions = { | ||
input: `${inputDir}${src}`, | ||
input: src, | ||
external: [ | ||
'bitsy' | ||
], | ||
plugins: [ | ||
clear({ | ||
targets: [outputDir] | ||
}), | ||
nodeResolve(), | ||
commonjs(), | ||
stripExportsPlugin(), | ||
readme.plugin(), | ||
headerComment(), | ||
topLevelOptions(), | ||
eslint({}) | ||
] | ||
commonjs() | ||
].concat(plugins) | ||
}; | ||
|
||
const outputOptions = { | ||
file: `${outputDir}${src.replace(/\s/g, '-')}`, | ||
format: "iife", | ||
globals: { | ||
bitsy: 'window' | ||
} | ||
}, | ||
name: `hacks.${basename(src, '.js').replace(/\s/g,'_')}`, | ||
}; | ||
|
||
return rollup.rollup(inputOptions) | ||
.then(bundle => { | ||
return bundle.write(outputOptions); | ||
}); | ||
const bundle = await rollup.rollup(inputOptions) | ||
const output = await bundle.generate(outputOptions); | ||
return output.code; | ||
} | ||
|
||
Promise.all( | ||
readdirSync(inputDir) | ||
.filter(file => file.match(/^.*?(?<!\.test)\.js$/)) | ||
.map(build) | ||
).then(() => { | ||
readme.parse(); | ||
readme.write(); | ||
}); | ||
export async function build(hacks = [], plugins) { | ||
const output = await Promise.all(hacks.map(hack => buildOne(hack, plugins))); | ||
return 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import fs from 'fs'; | ||
import { | ||
basename | ||
} from "path"; | ||
import eslint from "rollup-plugin-eslint"; | ||
|
||
import headerComment from "./HeaderCommentPlugin"; | ||
import topLevelOptions from "./TopLevelOptionsPlugin"; | ||
import readme from "./ReadmePlugin"; | ||
|
||
import build from './index'; | ||
|
||
const fsp = fs.promises; | ||
|
||
const inputDir = "./src/"; | ||
const outputDir = "./dist/"; | ||
|
||
async function buildHacks(hacks) { | ||
const outputFiles = hacks.map(name => `${outputDir}${basename(name).replace(/\s/g, '-')}`); | ||
|
||
// make dist | ||
!fs.existsSync(outputDir) && await fsp.mkdir(outputDir); | ||
|
||
// cleanup old dist | ||
await Promise.all(outputFiles.map(file => fs.existsSync(file) && fsp.unlink(file))); | ||
|
||
// build | ||
const output = await build(hacks, [ | ||
eslint({}), | ||
readme.plugin(), | ||
headerComment(), | ||
topLevelOptions() | ||
]); | ||
|
||
// write to dist | ||
await Promise.all(output.map((file, idx) => fsp.writeFile(outputFiles[idx], file))); | ||
|
||
readme.parse(); | ||
readme.write(); | ||
} | ||
|
||
async function getArgs() { | ||
// use command-line args if present | ||
if (process.argv.length > 2) { | ||
return process.argv.slice(2); | ||
} | ||
|
||
// use source files otherwise | ||
const srcFiles = await fsp.readdir(inputDir); | ||
return srcFiles | ||
.filter(file => file.match(/^.*?(?<!\.test)\.js$/)) | ||
.map(file => `${inputDir}${file}`); | ||
} | ||
|
||
getArgs() | ||
.then(buildHacks) | ||
.then(() => console.log('👍')) | ||
.catch(err => console.error('👎\n', err)); |
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
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
Oops, something went wrong.