chore(start): automate start package generate

This commit is contained in:
Pooya Parsa 2017-07-13 14:40:12 +04:30
parent 0fece913e5
commit eb595d1952
5 changed files with 127 additions and 37 deletions

View File

@ -5,7 +5,7 @@ const rollupAlias = require('rollup-plugin-alias')
const rollupCommonJS = require('rollup-plugin-commonjs') const rollupCommonJS = require('rollup-plugin-commonjs')
const rollupReplace = require('rollup-plugin-replace') const rollupReplace = require('rollup-plugin-replace')
const rollupNodeResolve = require('rollup-plugin-node-resolve') const rollupNodeResolve = require('rollup-plugin-node-resolve')
const packageJson = require('./package.json') const packageJson = require('../package.json')
const dependencies = Object.keys(packageJson.dependencies) const dependencies = Object.keys(packageJson.dependencies)
const version = packageJson.version || process.env.VERSION const version = packageJson.version || process.env.VERSION
@ -22,7 +22,7 @@ const banner =
// ----------------------------- // -----------------------------
// Aliases // Aliases
// ----------------------------- // -----------------------------
const rootDir = resolve(__dirname) const rootDir = resolve(__dirname, '..')
const libDir = resolve(rootDir, 'lib') const libDir = resolve(rootDir, 'lib')
const distDir = resolve(rootDir, 'dist') const distDir = resolve(rootDir, 'dist')
@ -31,7 +31,7 @@ const aliases = {
builder: resolve(libDir, 'builder/index.js'), builder: resolve(libDir, 'builder/index.js'),
common: resolve(libDir, 'common/index.js'), common: resolve(libDir, 'common/index.js'),
utils: resolve(libDir, 'common/utils.js'), utils: resolve(libDir, 'common/utils.js'),
app: resolve(libDir, 'app'), app: resolve(libDir, 'app')
} }
// ----------------------------- // -----------------------------
@ -45,10 +45,6 @@ const builds = {
core: { core: {
entry: resolve(libDir, 'core/index.js'), entry: resolve(libDir, 'core/index.js'),
dest: resolve(distDir, 'core.js') dest: resolve(distDir, 'core.js')
},
builder: {
entry: resolve(libDir, 'builder/index.js'),
dest: resolve(distDir, 'builder.js')
} }
} }
@ -83,9 +79,9 @@ function genConfig (opts) {
presets: [ presets: [
'babel-preset-es2015-rollup' 'babel-preset-es2015-rollup'
], ],
"env": { 'env': {
"test": { 'test': {
"plugins": [ "istanbul" ] 'plugins': [ 'istanbul' ]
} }
} }
}, opts.babel)), }, opts.babel)),

92
build/start.js Executable file
View File

@ -0,0 +1,92 @@
#!/usr/bin/env node
const { readFileSync, readJSONSync, writeFileSync, copySync, removeSync } = require('fs-extra')
const { resolve, relative } = require('path')
// Dirs
const rootDir = resolve(__dirname, '..')
const startDir = resolve(rootDir, 'start')
// Read main package.json
const packageJSON = readJSONSync(resolve(rootDir, 'package.json'))
// Required and Excluded packages for start
let requires = [
'source-map-support'
]
const excludes = [
'path',
'fs'
].concat(Object.keys(packageJSON.devDependencies))
// Parse dist/core.js for all external dependencies
const requireRegex = /require\('([-\w]+)'\)/g
const rawCore = readFileSync(resolve(rootDir, 'dist/core.js'))
let match = requireRegex.exec(rawCore)
while (match) {
requires.push(match[1])
match = requireRegex.exec(rawCore)
}
// Apply Excludes
requires = requires.filter(r => excludes.indexOf(r) === -1)
// Resolve version constrains
let dependencies = {}
requires.forEach(r => {
if (!packageJSON.dependencies[r]) {
console.warn('cannot resolve dependency version for ' + r)
return
}
dependencies[r] = packageJSON.dependencies[r]
})
// Drop fields
let drops = ['devDependencies', 'scripts', 'nyc', 'types']
drops.forEach(k => {
delete packageJSON[k]
})
// Update dependencies
packageJSON.dependencies = dependencies
// Update package meta
packageJSON.name = 'nuxt-start'
packageJSON.description = 'runtime-only build for nuxt'
// Update package.json
writeFileSync(resolve(startDir, 'package.json'), JSON.stringify(packageJSON, null, 2))
// Copy required files
const excludeFiles = [
'README.md',
'.gitignore'
]
packageJSON.files.forEach(file => {
if (excludeFiles.indexOf(file) !== -1) {
return
}
let src = resolve(rootDir, file)
let dst = resolve(startDir, file)
// console.log(relative(rootDir, src), '~>', relative(rootDir, dst))
removeSync(dst)
copySync(src, dst)
})
// Remove extras
const extraFiles = [
'bin/nuxt-build',
'bin/nuxt-generate',
'bin/nuxt-dev',
'dist/nuxt.js',
'dist/nuxt.js.map'
]
extraFiles.forEach(file => {
removeSync(resolve(startDir, file))
})
// Patch index.js
const startIndexjs = resolve(startDir, 'index.js')
writeFileSync(startIndexjs, String(readFileSync(startIndexjs)).replace('./dist/nuxt', './dist/core'))
console.log('generated ' + packageJSON.name + '@' + packageJSON.version)

View File

@ -52,13 +52,14 @@
"test": "npm run lint && cross-env NODE_ENV=test npm run build:nuxt && nyc ava --verbose --serial test/ -- && nyc report --reporter=html", "test": "npm run lint && cross-env NODE_ENV=test npm run build:nuxt && nyc ava --verbose --serial test/ -- && nyc report --reporter=html",
"coverage": "nyc report --reporter=text-lcov > coverage.lcov && codecov", "coverage": "nyc report --reporter=text-lcov > coverage.lcov && codecov",
"lint": "eslint --ext .js,.vue bin lib pages test/*.js --ignore-pattern app", "lint": "eslint --ext .js,.vue bin lib pages test/*.js --ignore-pattern app",
"build": "rimraf dist/ && npm run build:nuxt && npm run build:core && npm run build:builder", "build": "rimraf dist/ && npm run build:nuxt && npm run build:core",
"build:nuxt": "rollup -c rollup.config.js --environment TARGET:nuxt", "build:nuxt": "rollup -c build/rollup.config.js --environment TARGET:nuxt",
"build:core": "rollup -c rollup.config.js --environment TARGET:core", "build:core": "rollup -c build/rollup.config.js --environment TARGET:core",
"build:builder": "rollup -c rollup.config.js --environment TARGET:builder",
"watch": "npm run build:nuxt -- -w", "watch": "npm run build:nuxt -- -w",
"make-start": "./build/start.js",
"precommit": "npm run lint", "precommit": "npm run lint",
"prepublish": "npm run build", "prepublish": "npm run build && npm run make-start",
"postpublish": "cd start && npm publish",
"postinstall": "opencollective postinstall" "postinstall": "opencollective postinstall"
}, },
"engines": { "engines": {

6
start/.gitignore vendored
View File

@ -1,3 +1,3 @@
bin *
dist !README.md
lib !package.json

View File

@ -1,7 +1,7 @@
{ {
"name": "nuxt-start", "name": "nuxt-start",
"version": "0.0.0", "version": "1.0.0-alpha.4",
"description": "A minimalistic framework for server-rendered Vue.js applications (inspired by Next.js)", "description": "runtime-only build for nuxt",
"contributors": [ "contributors": [
{ {
"name": "Sebastien Chopin (@Atinux)" "name": "Sebastien Chopin (@Atinux)"
@ -23,6 +23,7 @@
"bin", "bin",
"dist", "dist",
"lib", "lib",
"index.d.ts",
"index.js" "index.js"
], ],
"keywords": [ "keywords": [
@ -37,35 +38,35 @@
"vue isomorphic", "vue isomorphic",
"vue versatile" "vue versatile"
], ],
"homepage": "https://github.com/nuxt/nuxt.js/start#readme", "homepage": "https://github.com/nuxt/nuxt.js#readme",
"bin": { "bin": {
"nuxt": "./bin/nuxt" "nuxt": "./bin/nuxt"
}, },
"scripts": {
"build": "rm -rf bin/* dist/* lib/* && cd .. && npm run build && cp -r bin dist lib start",
"prepublish": "npm run build"
},
"engines": { "engines": {
"node": ">=4.3.0 <5.0.0 || >=5.10", "node": ">=4.3.0 <5.0.0 || >=5.10",
"npm": ">=3.0.0" "npm": ">=3.0.0"
}, },
"dependencies": { "dependencies": {
"ansi-html": "^0.0.7", "source-map-support": "^0.4.15",
"chalk": "^1.1.3", "lodash": "^4.17.4",
"compression": "^1.6.2", "hash-sum": "^1.0.2",
"connect": "^3.6.2", "tappable": "^1.0.1",
"debug": "^2.6.8", "debug": "^2.6.8",
"chalk": "^2.0.1",
"ansi-html": "^0.0.7",
"serialize-javascript": "^1.3.0",
"etag": "^1.8.0", "etag": "^1.8.0",
"fresh": "^0.5.0", "fresh": "^0.5.0",
"fs-extra": "^3.0.1",
"hash-sum": "^1.0.2",
"lodash": "^4.17.4",
"minimist": "^1.2.0",
"pify": "^3.0.0", "pify": "^3.0.0",
"serialize-javascript": "^1.3.0",
"serve-static": "^1.12.3", "serve-static": "^1.12.3",
"source-map-support": "^0.4.15", "compression": "^1.7.0",
"tappable": "^1.0.1", "fs-extra": "^3.0.1",
"vue-server-renderer": "~2.3.4" "vue-server-renderer": "~2.4.1",
"connect": "^3.6.2"
},
"collective": {
"type": "opencollective",
"url": "https://opencollective.com/nuxtjs",
"logo": "https://opencollective.com/nuxtjs/logo.txt?reverse=true&variant=variant2"
} }
} }