mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-28 22:32:42 +00:00
chore(start): automate start package generate
This commit is contained in:
parent
0fece913e5
commit
eb595d1952
@ -5,7 +5,7 @@ const rollupAlias = require('rollup-plugin-alias')
|
||||
const rollupCommonJS = require('rollup-plugin-commonjs')
|
||||
const rollupReplace = require('rollup-plugin-replace')
|
||||
const rollupNodeResolve = require('rollup-plugin-node-resolve')
|
||||
const packageJson = require('./package.json')
|
||||
const packageJson = require('../package.json')
|
||||
|
||||
const dependencies = Object.keys(packageJson.dependencies)
|
||||
const version = packageJson.version || process.env.VERSION
|
||||
@ -22,7 +22,7 @@ const banner =
|
||||
// -----------------------------
|
||||
// Aliases
|
||||
// -----------------------------
|
||||
const rootDir = resolve(__dirname)
|
||||
const rootDir = resolve(__dirname, '..')
|
||||
const libDir = resolve(rootDir, 'lib')
|
||||
const distDir = resolve(rootDir, 'dist')
|
||||
|
||||
@ -31,7 +31,7 @@ const aliases = {
|
||||
builder: resolve(libDir, 'builder/index.js'),
|
||||
common: resolve(libDir, 'common/index.js'),
|
||||
utils: resolve(libDir, 'common/utils.js'),
|
||||
app: resolve(libDir, 'app'),
|
||||
app: resolve(libDir, 'app')
|
||||
}
|
||||
|
||||
// -----------------------------
|
||||
@ -45,10 +45,6 @@ const builds = {
|
||||
core: {
|
||||
entry: resolve(libDir, 'core/index.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: [
|
||||
'babel-preset-es2015-rollup'
|
||||
],
|
||||
"env": {
|
||||
"test": {
|
||||
"plugins": [ "istanbul" ]
|
||||
'env': {
|
||||
'test': {
|
||||
'plugins': [ 'istanbul' ]
|
||||
}
|
||||
}
|
||||
}, opts.babel)),
|
92
build/start.js
Executable file
92
build/start.js
Executable 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)
|
11
package.json
11
package.json
@ -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",
|
||||
"coverage": "nyc report --reporter=text-lcov > coverage.lcov && codecov",
|
||||
"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:nuxt": "rollup -c rollup.config.js --environment TARGET:nuxt",
|
||||
"build:core": "rollup -c rollup.config.js --environment TARGET:core",
|
||||
"build:builder": "rollup -c rollup.config.js --environment TARGET:builder",
|
||||
"build": "rimraf dist/ && npm run build:nuxt && npm run build:core",
|
||||
"build:nuxt": "rollup -c build/rollup.config.js --environment TARGET:nuxt",
|
||||
"build:core": "rollup -c build/rollup.config.js --environment TARGET:core",
|
||||
"watch": "npm run build:nuxt -- -w",
|
||||
"make-start": "./build/start.js",
|
||||
"precommit": "npm run lint",
|
||||
"prepublish": "npm run build",
|
||||
"prepublish": "npm run build && npm run make-start",
|
||||
"postpublish": "cd start && npm publish",
|
||||
"postinstall": "opencollective postinstall"
|
||||
},
|
||||
"engines": {
|
||||
|
6
start/.gitignore
vendored
6
start/.gitignore
vendored
@ -1,3 +1,3 @@
|
||||
bin
|
||||
dist
|
||||
lib
|
||||
*
|
||||
!README.md
|
||||
!package.json
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "nuxt-start",
|
||||
"version": "0.0.0",
|
||||
"description": "A minimalistic framework for server-rendered Vue.js applications (inspired by Next.js)",
|
||||
"version": "1.0.0-alpha.4",
|
||||
"description": "runtime-only build for nuxt",
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Sebastien Chopin (@Atinux)"
|
||||
@ -23,6 +23,7 @@
|
||||
"bin",
|
||||
"dist",
|
||||
"lib",
|
||||
"index.d.ts",
|
||||
"index.js"
|
||||
],
|
||||
"keywords": [
|
||||
@ -37,35 +38,35 @@
|
||||
"vue isomorphic",
|
||||
"vue versatile"
|
||||
],
|
||||
"homepage": "https://github.com/nuxt/nuxt.js/start#readme",
|
||||
"homepage": "https://github.com/nuxt/nuxt.js#readme",
|
||||
"bin": {
|
||||
"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": {
|
||||
"node": ">=4.3.0 <5.0.0 || >=5.10",
|
||||
"npm": ">=3.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"ansi-html": "^0.0.7",
|
||||
"chalk": "^1.1.3",
|
||||
"compression": "^1.6.2",
|
||||
"connect": "^3.6.2",
|
||||
"source-map-support": "^0.4.15",
|
||||
"lodash": "^4.17.4",
|
||||
"hash-sum": "^1.0.2",
|
||||
"tappable": "^1.0.1",
|
||||
"debug": "^2.6.8",
|
||||
"chalk": "^2.0.1",
|
||||
"ansi-html": "^0.0.7",
|
||||
"serialize-javascript": "^1.3.0",
|
||||
"etag": "^1.8.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",
|
||||
"serialize-javascript": "^1.3.0",
|
||||
"serve-static": "^1.12.3",
|
||||
"source-map-support": "^0.4.15",
|
||||
"tappable": "^1.0.1",
|
||||
"vue-server-renderer": "~2.3.4"
|
||||
"compression": "^1.7.0",
|
||||
"fs-extra": "^3.0.1",
|
||||
"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"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user