Skip to content

Commit

Permalink
implement typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
8633brown committed May 27, 2021
1 parent 17a5dce commit a79e649
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 130 deletions.
55 changes: 0 additions & 55 deletions index.js

This file was deleted.

26 changes: 26 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require('./license')

module.exports = {
signature: "abcjs-basic v" + require('./version'),
renderAbc: require('./src/api/abc_tunebook_svg'),
TimingCallbacks: require('./src/api/abc_timing_callbacks'),
setGlyph: require('./src/write/abc_glyphs').setSymbol,
synth: {
CreateSynth: require('./src/synth/create-synth'),
instrumentIndexToName: require('./src/synth/instrument-index-to-name'),
pitchToNoteName: require('./src/synth/pitch-to-note-name'),
SynthController: require('./src/synth/synth-controller'),
SynthSequence: require('./src/synth/synth-sequence'),
CreateSynthControl: require('./src/synth/create-synth-control'),
registerAudioContext: require('./src/synth/register-audio-context'),
activeAudioContext: require('./src/synth/active-audio-context'),
supportsAudio: require('./src/synth/supports-audio'),
playEvent: require('./src/synth/play-event'),
getMidiFile: require('./src/synth/get-midi-file'),
sequence: require('./src/synth/abc_midi_sequencer'),
},
Editor: require('./src/edit/abc_editor'),
EditArea: require('./src/edit/abc_editarea'),
...require('./src/api/abc_animation'),
...require('./src/api/abc_tunebook'),
};
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
"chai": "4.3.4",
"core-js": "3.9.0",
"mocha": "8.3.2",
"ts-loader": "^9.2.2",
"typescript": "^4.3.2",
"vuepress": "2.0.0-beta.8",
"vuex": "4.0.0",
"webpack": "5.33.2",
Expand Down
11 changes: 11 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"outDir": "./dist/",
"noImplicitAny": true,
"module": "commonjs",
"target": "es5",
"jsx": "react",
"allowJs": false,
"moduleResolution": "node",
}
}
157 changes: 82 additions & 75 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,86 +1,93 @@
const pkg = require("./package.json");
const TerserPlugin = require('terser-webpack-plugin');
const WebpackBundleAnalyzer = require("webpack-bundle-analyzer")
.BundleAnalyzerPlugin;
.BundleAnalyzerPlugin;

module.exports = (env = {} , argv) => {
const defaults = (argv, type) => {
const config = {
target: ['web', 'es5'],
output: {
library: {
amd: 'abcjs',
root: 'ABCJS',
commonjs: 'abcjs'
},
libraryTarget: 'umd',
globalObject: 'this',
filename: argv.mode === 'development' ? `abcjs-${type}.js` : `abcjs-${type}-min.js`,
},
devtool: argv.mode === 'development' ? 'source-map' : false,
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
options: {
cacheDirectory: (argv.mode === 'development'),
presets: [
[
'@babel/preset-env',
{
debug: false,
corejs: '3.9',
useBuiltIns: 'usage',
targets: 'defaults, ie >= 9, safari >= 5.1'
}
]
]
}
}
}
],
},
mode: 'production',
optimization:{
minimizer: [
new TerserPlugin({
extractComments: {
filename: '[file].LICENSE',
condition: /^\*\**!/i,
banner: makeBanner(type)
},
}),
],
}
}
const defaults = (argv, type) => {
const config = {
target: ['web', 'es5'],
output: {
library: {
amd: 'abcjs',
root: 'ABCJS',
commonjs: 'abcjs'
},
libraryTarget: 'umd',
globalObject: 'this',
filename: argv.mode === 'development' ? `abcjs-${type}.js` : `abcjs-${type}-min.js`,
},
devtool: argv.mode === 'development' ? 'source-map' : false,
module: {
rules: [
{
test: /\.ts$/,
exclude: /node_modules/,
use: [
{
loader: "babel-loader",
options: {
sourceType: 'unambiguous',
cacheDirectory: (argv.mode === 'development'),
presets: [
[
'@babel/preset-env',
{
debug: false,
corejs: '3.9',
useBuiltIns: 'usage',
targets: 'defaults, ie >= 9, safari >= 5.1'
}
]
]
}
},
'ts-loader',
]
}
],
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
},
mode: 'production',
optimization:{
minimizer: [
new TerserPlugin({
extractComments: {
filename: '[file].LICENSE',
condition: /^\*\**!/i,
banner: makeBanner(type)
},
}),
],
}
}

if (env.analyze) {
config.plugins = [
new WebpackBundleAnalyzer({
analyzerMode: "static"
})
]
}
return config
}
if (env.analyze) {
config.plugins = [
new WebpackBundleAnalyzer({
analyzerMode: "static"
})
]
}
return config
}

return [
{
name: 'basic',
entry: `./index.js`,
...defaults(argv, 'basic')
}, {
name: 'plugin',
entry: `./plugin.js`,
...defaults(argv, 'plugin')
}
]
return [
{
name: 'basic',
entry: `./index.ts`,
...defaults(argv, 'basic')
}, {
name: 'plugin',
entry: `./plugin.js`,
...defaults(argv, 'plugin')
}
]
};

function makeBanner(type) {
let banner = `abcjs_${type} v${pkg.version} Copyright © 2009-2021 Paul Rosen and Gregory Dyke (https://abcjs.net) */\n`
return banner + `/*! For license information please see abcjs_${type}.LICENSE`;
let banner = `abcjs_${type} v${pkg.version} Copyright © 2009-2021 Paul Rosen and Gregory Dyke (https://abcjs.net) */\n`
return banner + `/*! For license information please see abcjs_${type}.LICENSE`;
}

0 comments on commit a79e649

Please sign in to comment.