async function create(ctx) { const { name } = await ctx.inquirer.prompt([{ type: 'input', name: 'name', message: 'Please input a package name', validate: name => !!name, }]); const conf = await getSolutionConf(ctx); const root = resolve(ctx.cwd, conf.root); const fullPath = resolve(root, name); if (existsSync(fullPath)) { return ctx.console.error('Already exist:', name); } await ctx.utils.mkdirp(fullPath); await ctx.utils.exec('dn init', { cwd: fullPath }); }
export default function resolve(from, to) { return path.resolve(from, to); }
async function getAllPackages(ctx) { const { packages = [] } = await getSolutionConf(ctx); if (ctx.__packages) return ctx.__packages; ctx.__packages = await Promise.all(packages.map(async ({ path, deps }) => { const root = await getPackageRoot(ctx, path); const packageFile = resolve(root, './package.json'); const package = require(packageFile); const name = package.name; const value = root; return { root, path, deps, name, value, package, packageFile }; })); return ctx.__packages; }
describe('copy', () => { it('test', () => { copySource.call(acyort) assert(existsSync(resolve(__dirname, '../fixtures/temp/favicon.ico')) === true) removeSync(resolve(__dirname, '../fixtures/temp')) config.templatePath = 'no exist' copySource.call(acyort) assert(existsSync(resolve(__dirname, '../fixtures/temp/favicon.ico')) === false) config.templatePath = undefined copySource.call(acyort) assert(existsSync(resolve(__dirname, '../fixtures/temp/favicon.ico')) === false) }) })
app.get('/favicon:ext', (req, res)=> { res.sendFile(resolve(__dirname, `../assets/favicon${req.params.ext}`)) })
const createLibPaths = () => { const [utilFormat, utilDir] = process.platform === 'win32' ? ['.cmd', 'node_modules\\.bin\\'] : ['', 'node_modules/.bin/'] LIB_PATHS = _.reduce( fs .readdirSync(resolve('node_modules/.bin')) .filter(file => !file.match(/.*\.cmd$/)), (bin, name) => (bin[name] = `${utilDir}${name}${utilFormat}`) && bin, {} ) }
const getWebRouterEntryFile = (entry: string, router: string) => { const entryFile = path.resolve(this.vueTemplateFloder, this.entryFileName) const routerFile = path.resolve(this.vueTemplateFloder, this.routerFileName) fse.outputFileSync(entryFile, getEntryFileContent(entry, routerFile)) fse.outputFileSync(routerFile, getRouterFileContent(router)) return { index: entryFile, } }
const getNormalEntryFile = (entries: string[], base: string, isweb: boolean): any => { let result = {} entries.forEach(entry => { const extname = path.extname(entry) const basename = entry.replace(`${base}${this.isWin ? '\\' : '/'}`, '').replace(extname, '') const templatePathForWeb = path.resolve(this.vueTemplateFloder, basename + '.web.js') const templatePathForNative = path.resolve(this.vueTemplateFloder, basename + '.js') if (isweb) { fse.outputFileSync(templatePathForWeb, getWebEntryFileContent(templatePathForWeb, entry, base)) result[basename] = templatePathForWeb } else { fse.outputFileSync(templatePathForNative, getWeexEntryFileContent(templatePathForNative, entry)) result[basename] = templatePathForNative } }) return result }
describe('config api', () => { const c = { a: 0, b: '1', base: resolve(__dirname, './fixtures'), } const cf = new Config(c) it('api test', () => { assert(cf.get('a') === 0) assert(cf.get('b') === '1') assert(cf.get().a === 0) cf.set('a', 1) cf.set('c', false) assert(cf.get('a') === 1) assert(cf.get('c') === false) }) })
gulp.task('clean-build', function() { return require('rimraf').sync(resolve(__dirname, 'build')); });
const getEntryFileContent = (source, routerpath) => { const hasPluginInstalled = fse.existsSync(path.resolve(this.pluginFileName)) let dependence = `import Vue from 'vue'\n` dependence += `import weex from 'weex-vue-render'\n` let relativePluginPath = path.resolve(this.pluginConfigFileName) let entryContents = fse.readFileSync(source).toString() let contents = '' entryContents = dependence + entryContents entryContents = entryContents.replace(/\/\* weex initialized/, match => `weex.init(Vue)\n${match}`) if (this.isWin) { relativePluginPath = relativePluginPath.replace(/\\/g, '\\\\') } if (hasPluginInstalled) { contents += `\n// If detact plugins/plugin.js is exist, import and the plugin.js\n` contents += `import plugins from '${relativePluginPath}';\n` contents += `plugins.forEach(function (plugin) {\n\tweex.install(plugin)\n});\n\n` entryContents = entryContents.replace(/\.\/router/, routerpath) entryContents = entryContents.replace(/weex\.init/, match => `${contents}${match}`) } return entryContents }
const router = app => { const routesPath = resolve(__dirname, '../routes') const instance = new Route(app, routesPath) instance.init() }