Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@dcloudio/uni-cli-shared

Package Overview
Dependencies
Maintainers
3
Versions
1736
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dcloudio/uni-cli-shared - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

120

lib/pages.js
const path = require('path')
const {
getJson,
parseJson
getJson,
parseJson
} = require('./json')
function getPagesJson() {
return processPagesJson(getJson('pages.json'))
function getPagesJson () {
return processPagesJson(getJson('pages.json'))
}
function parsePagesJson(content) {
return processPagesJson(parseJson(content))
function parsePagesJson (content) {
return processPagesJson(parseJson(content))
}
function filterPages(pages = []) {
for (let i = pages.length - 1; i >= 0; i--) {
const page = pages[i]
if (!isValidPage(page.path)) {
pages.splice(i, 1)
}
}
function filterPages (pages = []) {
for (let i = pages.length - 1; i >= 0; i--) {
const page = pages[i]
if (!isValidPage(page.path)) {
pages.splice(i, 1)
}
}
}
function processPagesJson(pagesJson) {
// pages
filterPages(pagesJson.pages)
// subPackages
if (Array.isArray(pagesJson.subPackages) && pagesJson.subPackages.length) {
pagesJson.subPackages.forEach(subPackage => {
filterPages(subPackage.pages)
})
}
function processPagesJson (pagesJson) {
// pages
filterPages(pagesJson.pages)
// subPackages
if (Array.isArray(pagesJson.subPackages) && pagesJson.subPackages.length) {
pagesJson.subPackages.forEach(subPackage => {
filterPages(subPackage.pages)
})
}
return pagesJson
return pagesJson
}
function isValidPage(pagePath) {
if (pagePath.indexOf('platforms') === 0) { // 平台相关
return pagePath.indexOf('platforms/' + process.env.UNI_PLATFORM) === 0
}
return true
function isValidPage (pagePath) {
if (pagePath.indexOf('platforms') === 0) { // 平台相关
return pagePath.indexOf('platforms/' + process.env.UNI_PLATFORM) === 0
}
return true
}
function getMainJsPath(page) {
return path.resolve(process.env.UNI_INPUT_DIR, 'main.js?' + JSON.stringify({
page
}))
function getMainJsPath (page) {
return path.resolve(process.env.UNI_INPUT_DIR, 'main.js?' + JSON.stringify({
page
}))
}
function parsePages(pagesJson, pageCallback, subPageCallback) {
if (!pagesJson) {
pagesJson = getPagesJson()
}
function parsePages (pagesJson, pageCallback, subPageCallback) {
if (!pagesJson) {
pagesJson = getPagesJson()
}
process.UNI_ENTRY = {
'common/main': path.resolve(process.env.UNI_INPUT_DIR, 'main.js')
}
process.UNI_SUB_PACKAGES_ROOT = {}
process.UNI_ENTRY = {
'common/main': path.resolve(process.env.UNI_INPUT_DIR, 'main.js')
}
process.UNI_SUB_PACKAGES_ROOT = {}
// pages
pagesJson.pages.forEach(page => {
process.UNI_ENTRY[page.path] = getMainJsPath(page.path)
pageCallback && pageCallback(page)
})
// subPackages
if (Array.isArray(pagesJson.subPackages) && pagesJson.subPackages.length) {
pagesJson.subPackages.forEach(({
root,
pages
}) => pages.forEach(page => {
const pagePath = path.join(root, page.path)
process.UNI_ENTRY[pagePath] = getMainJsPath(pagePath)
process.UNI_SUB_PACKAGES_ROOT[pagePath] = root
subPageCallback && subPageCallback(root, page)
}))
}
// pages
pagesJson.pages.forEach(page => {
process.UNI_ENTRY[page.path] = getMainJsPath(page.path)
pageCallback && pageCallback(page)
})
// subPackages
if (Array.isArray(pagesJson.subPackages) && pagesJson.subPackages.length) {
pagesJson.subPackages.forEach(({
root,
pages
}) => pages.forEach(page => {
const pagePath = path.join(root, page.path)
process.UNI_ENTRY[pagePath] = getMainJsPath(pagePath)
process.UNI_SUB_PACKAGES_ROOT[pagePath] = root
subPageCallback && subPageCallback(root, page)
}))
}
}
module.exports = {
parsePages,
getPagesJson,
parsePagesJson
parsePages,
getPagesJson,
parsePagesJson
}

@@ -6,9 +6,9 @@ const path = require('path')

const PLATFORMS = [
'h5',
'app-plus',
'mp-weixin',
'mp-baidu',
'mp-alipay',
'mp-toutiao',
'quickapp'
'h5',
'app-plus',
'mp-weixin',
'mp-baidu',
'mp-alipay',
'mp-toutiao',
'quickapp'
]

@@ -20,41 +20,40 @@

function removeExt(str, ext) {
if (ext) {
const reg = new RegExp(ext.replace(/\./, '\\.') + '$')
return str.replace(reg, '')
}
return str.replace(/\.\w+$/g, '')
function removeExt (str, ext) {
if (ext) {
const reg = new RegExp(ext.replace(/\./, '\\.') + '$')
return str.replace(reg, '')
}
return str.replace(/\.\w+$/g, '')
}
function hashify(filepath) {
const filename = removeExt(path.basename(filepath))
const relativePath = removeExt(path.relative(process.env.UNI_INPUT_DIR, filepath))
return hash(relativePath)
function hashify (filepath) {
const relativePath = removeExt(path.relative(process.env.UNI_INPUT_DIR, filepath))
return hash(relativePath)
}
function md5(str) {
const hash = crypto.createHash('md5')
hash.update(str)
return hash.digest('hex')
function md5 (str) {
const hash = crypto.createHash('md5')
hash.update(str)
return hash.digest('hex')
}
module.exports = {
md5,
hasOwn(obj, key) {
return hasOwnProperty.call(obj, key)
},
parseStyle(style = {}) {
Object.keys(style).forEach(name => {
if (PLATFORMS.includes(name)) {
if (name === process.env.UNI_PLATFORM) {
Object.assign(style, style[name] || {})
}
delete style[name]
}
})
return style
},
hashify,
removeExt,
normalizePath
md5,
hasOwn (obj, key) {
return hasOwnProperty.call(obj, key)
},
parseStyle (style = {}) {
Object.keys(style).forEach(name => {
if (PLATFORMS.includes(name)) {
if (name === process.env.UNI_PLATFORM) {
Object.assign(style, style[name] || {})
}
delete style[name]
}
})
return style
},
hashify,
removeExt,
normalizePath
}
{
"name": "@dcloudio/uni-cli-shared",
"version": "0.0.1",
"version": "0.0.2",
"description": "uni-cli-shared",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc