Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat: update typedoc and improvemnts to docs cmd #727

Merged
merged 4 commits into from
Jan 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ updateNotifier({
}).notify()

const cli = require('yargs')
const { config } = require('./src/config/user')
const { userConfig } = require('./src/config/user')
cli
.scriptName('aegir')
.env('AEGIR')
Expand All @@ -28,7 +28,7 @@ cli
.example('npm test -- -- --browsers Firefox', 'If `npm test` translates to `aegir test -t browser` and you want to forward options you need to use `-- --` instead.')
.epilog('Use `$0 <command> --help` to learn more about each command.')
.middleware((yargs) => {
yargs.config = config()
yargs.config = userConfig
})
.commandDir('cmds')
.help()
Expand All @@ -37,19 +37,19 @@ cli
.option('debug', {
desc: 'Show debug output.',
type: 'boolean',
default: false,
alias: 'd'
alias: 'd',
default: userConfig.debug
})
// TODO remove after webpack 5 upgrade
.options('node', {
type: 'boolean',
describe: 'Flag to control if bundler should inject node globals or built-ins.',
default: false
default: userConfig.node
})
.options('ts', {
type: 'boolean',
describe: 'Enable support for Typescript',
default: false
default: userConfig.ts // needs to be changed to another name to not conflict with the ts cmd options
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed now?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes this enables support for TS repos, actual TS code not like ours which are JS with JSDocs types

})
.group(['help', 'version', 'debug', 'node', 'ts'], 'Global Options:')
.demandCommand(1, 'You need at least one command.')
Expand Down
8 changes: 4 additions & 4 deletions cmds/build.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict'

const { userConfig } = require('../src/config/user')
/**
* @typedef {import("yargs").Argv} Argv
* @typedef {import("yargs").Arguments} Arguments
Expand All @@ -21,18 +21,18 @@ module.exports = {
bundle: {
type: 'boolean',
describe: 'Build the JS standalone bundle.',
default: true
default: userConfig.build.bundle
},
bundlesize: {
alias: 'b',
type: 'boolean',
describe: 'Analyse bundle size. Default threshold is 100kB, you can override that in `.aegir.js` with the property `bundlesize.maxSize`.',
default: false
default: userConfig.build.bundlesize
},
types: {
type: 'boolean',
describe: 'Build the Typescripts type declarations.',
default: true
default: userConfig.build.types
}
})
},
Expand Down
8 changes: 7 additions & 1 deletion cmds/docs.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use strict'
const { userConfig } = require('../src/config/user')

const EPILOG = `
Typescript config file is required to generated docs. Try \`aegir ts --preset config > tsconfig.json\`
Expand All @@ -18,7 +19,12 @@ module.exports = {
alias: 'p',
type: 'boolean',
describe: 'Publish to GitHub Pages',
default: false
default: userConfig.docs.publish
},
entryPoint: {
type: 'string',
describe: 'Specifies the entry points to be documented by TypeDoc. TypeDoc will examine the exports of these files and create documentation according to the exports. Either files or directories may be specified. If a directory is specified, all source files within the directory will be included as an entry point.',
default: userConfig.docs.entryPoint
}
}
)
Expand Down
16 changes: 13 additions & 3 deletions cmds/lint.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
'use strict'

const { userConfig } = require('../src/config/user')
module.exports = {
command: 'lint',
desc: 'Lint all project files',
builder: {
fix: {
alias: 'f',
type: 'boolean',
describe: 'Automatically fix errors if possible',
default: false
describe: 'Automatically fix errors if possible.',
default: userConfig.lint.fix
},
files: {
type: 'array',
describe: 'Files to lint.',
default: userConfig.lint.files
},
silent: {
type: 'boolean',
describe: 'Disable eslint output.',
default: userConfig.lint.silent
}
},
handler (argv) {
Expand Down
3 changes: 1 addition & 2 deletions cmds/ts.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const EPILOG = `
Presets:
\`check\` Runs the type checker with your local config (without writing any files). .
\`types\` Emits type declarations to \`dist\` folder.
\`docs\` Generates documentation based on type declarations to the \`docs\` folder.
\`config\` Prints base config to stdout.

Note:
Expand All @@ -22,7 +21,7 @@ module.exports = {
.options({
preset: {
type: 'string',
choices: ['config', 'check', 'types', 'docs'],
choices: ['config', 'check', 'types'],
describe: 'Preset to run',
alias: 'p'
},
Expand Down
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"@types/dirty-chai": "^2.0.2",
"@types/mocha": "^8.2.0",
"@types/node": "^14.14.22",
"aegir-typedoc-theme": "^0.1.0",
"@types/sinon": "^9.0.10",
"babel-loader": "^8.2.2",
"buffer": "^6.0.3",
"bytes": "^3.1.0",
Expand All @@ -85,14 +85,12 @@
"conventional-changelog": "^3.1.24",
"conventional-github-releaser": "^3.1.5",
"cors": "^2.8.5",
"cosmiconfig": "^7.0.0",
"dirty-chai": "^2.0.1",
"electron-mocha": "^10.0.0",
"eslint": "^7.18.0",
"eslint-config-ipfs": "^1.0.0",
"execa": "^5.0.0",
"extract-zip": "^2.0.1",
"findup-sync": "^4.0.0",
"fs-extra": "^9.1.0",
"gh-pages": "^3.1.0",
"git-authors-cli": "^1.0.33",
Expand All @@ -110,6 +108,7 @@
"karma-mocha-webworker": "^1.3.0",
"karma-sourcemap-loader": "~0.3.8",
"karma-webpack": "4.0.2",
"lilconfig": "^2.0.2",
"listr": "~0.14.2",
"merge-options": "^3.0.4",
"mocha": "^8.2.1",
Expand All @@ -127,7 +126,7 @@
"strip-bom": "^4.0.0",
"strip-json-comments": "^3.1.1",
"terser-webpack-plugin": "^3.0.5",
"typedoc": "^0.20.16",
"typedoc": "^0.20.17",
"typescript": "4.1.x",
"update-notifier": "^5.0.0",
"webpack": "^4.43.0",
Expand All @@ -138,12 +137,14 @@
"yargs-parser": "^20.2.3"
},
"devDependencies": {
"@types/bytes": "^3.1.0",
"@types/fs-extra": "^9.0.6",
"@types/listr": "^0.14.2",
"@types/polka": "^0.5.2",
"@types/semver": "^7.3.4",
"@types/yargs": "^15.0.12",
"electron": "^11.2.0",
"iso-url": "^1.0.0",
"mock-require": "^3.0.2",
"sinon": "^9.2.3"
},
"engines": {
Expand Down
17 changes: 10 additions & 7 deletions src/build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@
'use strict'

const path = require('path')
const fs = require('fs')
const { readJsonSync } = require('fs-extra')
const bytes = require('bytes')
const execa = require('execa')
const { premove: del } = require('premove')
const { fromAegir, gzipSize, pkg, hasTsconfig } = require('./../utils')
const userConfig = require('../config/user')
const tsCmd = require('../ts')
const { userConfig } = require('../config/user')

const config = userConfig()

/**
* Build command
*
* @param {any} argv
*/
module.exports = async (argv) => {
const input = argv._.slice(1)
const forwardOptions = argv['--'] ? argv['--'] : []
Expand Down Expand Up @@ -44,9 +47,9 @@ module.exports = async (argv) => {
})

if (argv.bundlesize) {
const stats = JSON.parse(fs.readFileSync(path.join(process.cwd(), 'dist/stats.json')))
const stats = readJsonSync(path.join(process.cwd(), 'dist/stats.json'))
const gzip = await gzipSize(path.join(stats.outputPath, stats.assets[0].name))
const maxsize = bytes(config.bundlesize.maxSize)
const maxsize = bytes(/** @type {string} */(userConfig.bundlesize.maxSize))
const diff = gzip - maxsize

console.log('Use http://webpack.github.io/analyse/ to load "./dist/stats.json".')
Expand All @@ -61,6 +64,6 @@ module.exports = async (argv) => {
}

if (argv.types && hasTsconfig) {
await tsCmd({ preset: 'types' })
await tsCmd({ ...argv, preset: 'types' })
}
}
2 changes: 1 addition & 1 deletion src/config/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const webpack = require('webpack')
const path = require('path')
const webpackConfig = require('./webpack.config')
const { fromRoot, hasFile } = require('../utils')
const userConfig = require('./user')()
const { userConfig } = require('./user')
const isTSEnable = process.env.AEGIR_TS === 'true'
const isWebworker = process.env.AEGIR_RUNNER === 'webworker'

Expand Down
98 changes: 63 additions & 35 deletions src/config/user.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable no-console */
'use strict'

const { cosmiconfigSync } = require('cosmiconfig')
const { lilconfigSync } = require('lilconfig')
const merge = require('merge-options')
const utils = require('../utils')

Expand Down Expand Up @@ -28,53 +29,80 @@ function normalizeHooks (hooks = {}) {
return merge(result, hooks)
}

function userConfig () {
const userConfig = utils.getUserConfig()
const config = (searchFrom) => {
let userConfig
try {
const configExplorer = lilconfigSync('aegir', {

const user = merge(
searchPlaces: [
'package.json',
'.aegir.js'
]
})
const lilconfig = configExplorer.search(searchFrom)
if (lilconfig) {
userConfig = lilconfig.config
} else {
userConfig = {}
}
} catch (err) {
console.error(err)
throw new Error('Error finding your config file.')
}
const conf = merge(
{
// global options
debug: false,
node: false,
ts: false,
// old options
webpack: {},
karma: {},
hooks: {},
entry: utils.fromRoot('src', 'index.js'),
bundlesize: {
path: './dist/index.min.js',
maxSize: '100kB'
},
// build cmd options
build: {
bundle: true,
bundlesize: false,
types: true
},
// linter cmd options
lint: {
silent: false,
fix: false,
files: [
'*.{js,ts}',
'bin/**',
'config/**/*.{js,ts}',
'test/**/*.{js,ts}',
'src/**/*.{js,ts}',
'tasks/**/*.{js,ts}',
'benchmarks/**/*.{js,ts}',
'utils/**/*.{js,ts}',
'!**/node_modules/**',
'!**/*.d.ts'
]
},
// docs cmd options
docs: {
publish: false,
entryPoint: 'src/index.js'
}
},
userConfig
)

user.hooks = normalizeHooks(user.hooks)

return user
}

const config = () => {
let cosmiconfig
try {
const configExplorer = cosmiconfigSync('aegir', {
searchPlaces: ['package.json', '.aegir.js']
})
const { config } = configExplorer.search()
cosmiconfig = config || {}
} catch (err) {
cosmiconfig = {}
}
const conf = merge({
webpack: {},
karma: {},
hooks: {},
entry: utils.fromRoot('src', 'index.js'),
bundlesize: {
path: './dist/index.min.js',
maxSize: '100kB'
userConfig,
{
hooks: normalizeHooks(userConfig.hooks)
}
},
cosmiconfig)
)

return conf
}

module.exports = userConfig
userConfig.config = config
module.exports = {
userConfig: config(),
config
}
2 changes: 1 addition & 1 deletion src/config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const merge = require('webpack-merge')
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer')
const TerserPlugin = require('terser-webpack-plugin')
const { fromRoot, pkg, paths, getLibraryName } = require('../utils')
const userConfig = require('./user')()
const { userConfig } = require('./user')
const isProduction = process.env.NODE_ENV === 'production'
const isTSEnable = process.env.AEGIR_TS === 'true'

Expand Down
Loading