Repository: nowa-webpack/nowa Branch: master Commit: 8da38f00b925 Files: 12 Total size: 11.7 KB Directory structure: gitextract_qmgksik3/ ├── .editorconfig ├── .gitignore ├── LICENSE ├── README.md ├── bin/ │ ├── nowa │ └── nowa.cmd ├── index.js ├── package.json ├── src/ │ ├── check.js │ ├── index.js │ └── update-notifier.js └── uninstall.js ================================================ FILE CONTENTS ================================================ ================================================ FILE: .editorconfig ================================================ root = true [*] indent_style = space indent_size = 2 charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.md] trim_trailing_whitespace = false ================================================ FILE: .gitignore ================================================ node_modules ~* *~ .DS_Store ================================================ FILE: LICENSE ================================================ The MIT License (MIT) Copyright (c) 2016 nowa Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: README.md ================================================ # nowa [![NPM version](https://img.shields.io/npm/v/nowa.svg?style=flat)](https://npmjs.org/package/nowa) nowa webpack solution ---- ## Feature - Generate a [webpack](https://github.com/webpack/webpack) based boilerplate. - Run a local server for web developer, support proxy and HMR. - Easy to use and customize third-party UI components. - Support customized webpack.config.js. - Support `buildvars` to automatically output bundles with different varible combinations. Checkout [https://nowa-webpack.github.io/](https://nowa-webpack.github.io/) for more information. ## Install - Install nowa ```bash $ npm i nowa -g ``` - Install all frequently-used nowa plugins ([build](https://github.com/nowa-webpack/nowa-build), [init](https://github.com/nowa-webpack/nowa-init), [lib](https://github.com/nowa-webpack/nowa-lib), [server](https://github.com/nowa-webpack/nowa-server)) ```bash $ nowa install ``` > You can install any plugin by `nowa install `. > Find more plugins, visit [here](https://www.npmjs.com/search?q=nowa-). ## Usage - Generate a boilerplate. ```bash $ mkdir test && cd test $ nowa init uxcore ``` - Start a local dev server. ```bash $ nowa server ``` - Build project. ```bash $ nowa build ``` - Build libraries. ```bash $ nowa lib ``` ================================================ FILE: bin/nowa ================================================ #!/usr/bin/env node module.exports = require('../'); ================================================ FILE: bin/nowa.cmd ================================================ @IF EXIST "%~dp0\node.exe" ( "%~dp0\node.exe" "%~dp0\..\nowa\bin\nowa" %* ) ELSE ( @SETLOCAL @SET PATHEXT=%PATHEXT:;.JS;=;% node "%~dp0\..\nowa\bin\nowa" %* ) ================================================ FILE: index.js ================================================ #!/usr/bin/env node module.exports = require('./src'); ================================================ FILE: package.json ================================================ { "name": "nowa", "version": "1.2.2", "description": "nowa webpack solution", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "preuninstall": "node ./uninstall.js" }, "repository": { "type": "git", "url": "https://github.com/nowa-webpack/nowa.git" }, "keywords": [ "nowa", "webpack", "server", "builder" ], "author": "gbk ", "license": "MIT", "bugs": { "url": "https://github.com/nowa-webpack/nowa/issues" }, "homepage": "https://github.com/nowa-webpack/nowa#readme", "dependencies": { "chalk": "~1.1.3", "commander": "~2.9.0", "nowa-install": "^1.0.0", "nowa-plugin": "^1.0.0", "package-json": "~2.3.2", "resolve": "~1.1.7", "semver": "~5.1.0" }, "bin": { "nowa": "./bin/nowa" }, "engines": { "node": ">=4.0.0", "npm": "^3.0.0" } } ================================================ FILE: src/check.js ================================================ /* * @Author: gbk * @Date: 2016-06-25 17:44:38 * @Last Modified by: gbk * @Last Modified time: 2016-06-25 22:26:03 */ 'use strict'; var os = require('os'); var fs = require('fs'); var path = require('path'); var packageJson = require('package-json'); var configRoot = path.join(os.homedir(), '.nowa'); var versionsPath = path.join(configRoot, 'latest-versions.json'); // tasks definiation var majorVersion = process.argv[2].split('.')[0]; var tasks = process.argv.slice(3).map(function(command) { return packageJson(command, majorVersion); }); tasks.push(packageJson('nowa', 'latest')) tasks.push(new Promise(function(resolve) { fs.mkdir(configRoot, resolve); })); // run tasks new Promise(function(resolve, reject) { fs.readFile(versionsPath, 'utf-8', function(err, data) { if (data) { data = JSON.parse(data); // check interval by 1 day if (Date.now() - data.update > 3600000 * 24) { resolve(Promise.all(tasks)); } else { reject(); } } else { resolve(Promise.all(tasks)); } }); }).then(function(pkgs) { // write to versions store var versions = {}; pkgs.forEach(function(pkg) { versions[pkg.name] = pkg.version; }); fs.writeFile(versionsPath, JSON.stringify({ versions: versions, update: Date.now() })); }); ================================================ FILE: src/index.js ================================================ /* * @Author: gbk * @Date: 2016-04-11 16:43:10 * @Last Modified by: gbk * @Last Modified time: 2017-03-23 21:33:26 */ 'use strict'; var fs = require('fs'); var path = require('path'); var resolve = require('resolve'); var program = require('commander'); var chalk = require('chalk'); var semver = require('semver'); var updateNotifier = require('./update-notifier'); var pkg = require('../package.json'); var argvs = process.argv; var command = argvs[2]; // check nodejs version if (!semver.satisfies(process.version, pkg.engines.node)) { console.log(chalk.red.bold('Require nodejs version ' + pkg.engines.node + ', current ' + process.version)); console.log('Download the latest nodejs here ' + chalk.green('https://nodejs.org/en/download/')); process.exit(); } // program definiation program .version(pkg.version) .usage(' [options]'); // dirs to find plugins var moduleDirs = [ path.join(__dirname, '..', 'node_modules'), path.join(__dirname, '..', '..') ]; program._moduleDirs = moduleDirs; // locate the plugin var pluginPath = findPluginPath(command); if (pluginPath) { // plugin found // check update of current command updateNotifier(pkg.version, 'nowa-' + command); // regist current plugin var pluginDef = require(pluginPath); var plugin = program.command(pluginDef.command || command); if (pluginDef.description) { plugin.description(pluginDef.description); } // set options if (pluginDef.options) { // default options in abc.json var defaultOpts = loadDefaultOpts(process.cwd(), 'abc.json'); var optNameReg = /\-\-(\w+)/; pluginDef.options.forEach(function(optArgs) { if (optArgs) { plugin.option.apply(plugin, optArgs); // replace default value with options in abc.json var matches = optNameReg.exec(optArgs[0]); if (matches && matches[1] in defaultOpts) { plugin[matches[1]] = defaultOpts[matches[1]] } } }); } // set action if (pluginDef.action) { plugin.action(function(cmd, opts) { if (cmd instanceof program.Command) { opts = cmd; cmd = ''; } opts = opts || {}; // run plugin action if (cmd) { pluginDef.action.call(this, cmd, opts); } else { pluginDef.action.call(this, opts); } }); } } else if (!command) { // plugin not found var plugins; var pluginPool = {}; moduleDirs.forEach(function(modulesDir, index) { // search plugins plugins = fs.readdirSync(modulesDir).filter(function(name) { // filter by name return /^nowa\-\w+$/.test(name); }); // regist all the plugins plugins.forEach(function(name) { // ensure local plugins not be overridden if (!pluginPool[name]) { pluginPool[name] = true; // regist a plugin for help var pluginPkg = require(path.join(modulesDir, name, 'package.json')); program .command(name.substring(5)) .description(pluginPkg.description + chalk.green(' (v' + pluginPkg.version + ')')); } }); }); // check update of all plugins updateNotifier.apply(null, [ pkg.version ].concat(plugins)); } // parse command line arguments program.parse(argvs); // output help if no argv specified if (!argvs.slice(2).length) { program.outputHelp(); } // locate the plugin by command function findPluginPath(command) { if (command && /^\w+$/.test(command)) { try { return resolve.sync('nowa-' + command, { paths: moduleDirs }); } catch (e) { console.log(''); console.log(' ' + chalk.green.bold(command) + ' command is not installed.'); console.log(' You can try to install it by ' + chalk.blue.bold('nowa install ' + command) + '.'); console.log(''); } } } // load default options function loadDefaultOpts(startDir, configFile) { try { return require(path.join(startDir, configFile)).options || {}; } catch (e) { var dir = path.dirname(startDir); if (dir === startDir) { return {}; } return loadDefaultOpts(dir, configFile); } } ================================================ FILE: src/update-notifier.js ================================================ /* * @Author: gbk * @Date: 2016-06-25 12:42:56 * @Last Modified by: gbk * @Last Modified time: 2017-06-21 20:53:33 */ 'use strict'; var os = require('os'); var fs = require('fs'); var path = require('path'); var spawn = require('child_process').spawn; var chalk = require('chalk'); var semver = require('semver'); module.exports = function() { // do not show update tip inside nowa-gui if (process.env.NOWA_GUI) { return; } // check for nowa-gui installation try { fs.statSync(path.join(os.homedir(), '.nowa-gui', 'user_config.json')) } catch (e) { console.log( chalk.yellow( '\n Nowa GUI for all platform is available now!' + '\n You can download it here:' + '\n https://nowa-webpack.github.io/') ); } // read latest versions var versionsFile = path.join(os.homedir(), '.nowa', 'latest-versions.json'); var store = {}; try { store = JSON.parse(fs.readFileSync(versionsFile, 'utf-8')); } catch(e) {} var versions = store.versions || {}; // compare versions and show tip var isTipShow = false; var argvs = Array.prototype.slice.call(arguments, 0); argvs.slice(1).concat([ 'nowa' ]).forEach(function(plugin) { try { var pkg = require(path.join(__dirname, '..', '..', plugin, 'package.json')); if (versions[plugin] && semver.lt(pkg.version, versions[plugin])) { if (plugin === 'nowa') { // do not show nowa update tip if any plugins need update if (!isTipShow) { console.log( chalk.yellow( '\n Update available: ' + plugin + '@' + versions[plugin] + ' (Current: ' + pkg.version + ')' + '\n Run `npm i nowa -g` to update.') ); } } else { console.log( chalk.yellow( '\n Update available: ' + plugin + '@' + versions[plugin] + ' (Current: ' + pkg.version + ')' + '\n Run `nowa install ' + plugin.substring(5) + '` to update.') ); } isTipShow = true; } } catch(e) { } }); // fetch latest versions spawn(process.execPath, [ path.join(__dirname, 'check') ].concat(argvs), { detached: true, stdio: 'ignore' }).unref(); }; ================================================ FILE: uninstall.js ================================================ /* * @Author: gbk * @Date: 2016-06-26 10:38:07 * @Last Modified by: gbk * @Last Modified time: 2017-03-20 10:51:44 */ 'use strict'; var os = require('os'); var path = require('path'); var exec = require('child_process').execSync; var configRoot = path.join(os.homedir(), '.nowa'); var rimrafPath = path.join(configRoot, 'install', '.bin', 'rimraf'); var installMods = path.join(configRoot, 'install', '*'); exec('node ' + rimrafPath + ' ../nowa-* ' + installMods);