init (graduate from prototype)

This commit is contained in:
Evan You
2018-09-19 11:35:38 -04:00
commit 3401f6b460
63 changed files with 8372 additions and 0 deletions

75
scripts/bootstrap.js vendored Normal file
View File

@@ -0,0 +1,75 @@
// create package.json, README, etc. for packages that don't have them yet
const args = require('minimist')(process.argv.slice(2))
const fs = require('fs')
const path = require('path')
const baseVersion = require('../lerna.json').version
const packagesDir = path.resolve(__dirname, '../packages')
const files = fs.readdirSync(packagesDir)
files.forEach(shortName => {
if (!fs.statSync(path.join(packagesDir, shortName)).isDirectory()) {
return
}
const name = shortName === `vue` ? shortName : `@vue/${shortName}`
const pkgPath = path.join(packagesDir, shortName, `package.json`)
if (args.force || !fs.existsSync(pkgPath)) {
const json = {
name,
version: baseVersion,
description: name,
main: 'index.js',
module: `dist/${shortName}.esm.js`,
typings: 'dist/index.d.ts',
repository: {
type: 'git',
url: 'git+https://github.com/vuejs/vue.git'
},
keywords: ['vue'],
author: 'Evan You',
license: 'MIT',
bugs: {
url: 'https://github.com/vuejs/vue/issues'
},
homepage: `https://github.com/vuejs/vue/tree/dev/packages/${shortName}#readme`
}
fs.writeFileSync(pkgPath, JSON.stringify(json, null, 2))
}
const readmePath = path.join(packagesDir, shortName, `README.md`)
if (args.force || !fs.existsSync(readmePath)) {
fs.writeFileSync(readmePath, `# ${name}`)
}
const npmIgnorePath = path.join(packagesDir, shortName, `.npmignore`)
if (args.force || !fs.existsSync(npmIgnorePath)) {
fs.writeFileSync(npmIgnorePath, `__tests__/\n__mocks__/\ndist/packages`)
}
const srcDir = path.join(packagesDir, shortName, `src`)
const indexPath = path.join(packagesDir, shortName, `src/index.ts`)
if (args.force || !fs.existsSync(indexPath)) {
if (!fs.existsSync(srcDir)) {
fs.mkdirSync(srcDir)
}
fs.writeFileSync(indexPath, ``)
}
const nodeIndexPath = path.join(packagesDir, shortName, 'index.js')
if (args.force || !fs.existsSync(nodeIndexPath)) {
fs.writeFileSync(
nodeIndexPath,
`
'use strict'
if (process.env.NODE_ENV === 'production') {
module.exports = require('./dist/${shortName}.cjs.prod.js')
} else {
module.exports = require('./dist/${shortName}.cjs.js')
}
`.trim() + '\n'
)
}
})

70
scripts/build.js Normal file
View File

@@ -0,0 +1,70 @@
const fs = require('fs-extra')
const path = require('path')
const zlib = require('zlib')
const chalk = require('chalk')
const execa = require('execa')
const dts = require('dts-bundle')
const { targets, fuzzyMatchTarget } = require('./utils')
const target = process.argv[2]
;(async () => {
if (!target) {
await buildAll(targets)
checkAllSizes(targets)
} else {
await buildAll(fuzzyMatchTarget(target))
checkAllSizes(fuzzyMatchTarget(target))
}
})()
async function buildAll (targets) {
for (const target of targets) {
await build(target)
}
}
async function build (target) {
const pkgDir = path.resolve(`packages/${target}`)
await fs.remove(`${pkgDir}/dist`)
await execa('rollup', [
'-c',
'--environment',
`NODE_ENV:production,TARGET:${target}`
], { stdio: 'inherit' })
const dtsOptions = {
name: target === 'vue' ? target : `@vue/${target}`,
main: `${pkgDir}/dist/packages/${target}/src/index.d.ts`,
out: `${pkgDir}/dist/index.d.ts`
}
dts.bundle(dtsOptions)
console.log()
console.log(chalk.blue(chalk.bold(`generated typings at ${dtsOptions.out}`)))
await fs.remove(`${pkgDir}/dist/packages`)
}
function checkAllSizes (targets) {
console.log()
for (const target of targets) {
checkSize(target)
}
console.log()
}
function checkSize (target) {
const pkgDir = path.resolve(`packages/${target}`)
const esmProdBuild = `${pkgDir}/dist/${target}.esm-browser.prod.js`
if (fs.existsSync(esmProdBuild)) {
const file = fs.readFileSync(esmProdBuild)
const minSize = (file.length / 1024).toFixed(2) + 'kb'
const gzipped = zlib.gzipSync(file)
const gzipSize = (gzipped.length / 1024).toFixed(2) + 'kb'
console.log(`${
chalk.gray(chalk.bold(target))
} min:${minSize} / gzip:${gzipSize}`)
}
}

25
scripts/dev.js Normal file
View File

@@ -0,0 +1,25 @@
// Run Rollup in watch mode for a single package for development.
// Only the ES modules format will be generated, as it is expected to be tested
// in a modern browser using <script type="module">.
// Defaults to watch the `vue` meta package.
// To specific the package to watch, simply pass its name. e.g.
// ```
// yarn dev observer
// ```
const execa = require('execa')
const { targets, fuzzyMatchTarget } = require('./utils')
const target = fuzzyMatchTarget(process.argv[2] || 'runtime-dom')
execa(
'rollup',
[
'-wc',
'--environment',
`TARGET:${target},FORMATS:umd`
],
{
stdio: 'inherit'
}
)

19
scripts/utils.js Normal file
View File

@@ -0,0 +1,19 @@
const fs = require('fs')
const targets = exports.targets = fs.readdirSync('packages').filter(f => {
return fs.statSync(`packages/${f}`).isDirectory()
})
exports.fuzzyMatchTarget = partialTarget => {
const matched = []
for (const target of targets) {
if (target.match(partialTarget)) {
matched.push(target)
}
}
if (matched.length) {
return matched
} else {
throw new Error(`Target ${partialTarget} not found!`)
}
}

32
scripts/verifyCommit.js Normal file
View File

@@ -0,0 +1,32 @@
// Invoked on the commit-msg git hook by yorkie.
const chalk = require('chalk')
const msgPath = process.env.GIT_PARAMS
const msg = require('fs')
.readFileSync(msgPath, 'utf-8')
.trim()
const commitRE = /^(revert: )?(feat|fix|docs|style|refactor|perf|test|workflow|ci|chore|types)(\(.+\))?: .{1,50}/
if (!commitRE.test(msg)) {
console.log()
console.error(
` ${chalk.bgRed.white(' ERROR ')} ${chalk.red(
`invalid commit message format.`
)}\n\n` +
chalk.red(
` Proper commit message format is required for automated changelog generation. Examples:\n\n`
) +
` ${chalk.green(`feat(compiler): add 'comments' option`)}\n` +
` ${chalk.green(
`fix(v-model): handle events on blur (close #28)`
)}\n\n` +
chalk.red(` See .github/COMMIT_CONVENTION.md for more details.\n`) +
chalk.red(
` You can also use ${chalk.cyan(
`npm run commit`
)} to interactively generate a commit message.\n`
)
)
process.exit(1)
}