Skip to content

Commit

Permalink
chore: update to es module (electron#1869)
Browse files Browse the repository at this point in the history
* update to es module

* fix script

* fix wizard
  • Loading branch information
Toinane authored Aug 25, 2021
1 parent 94f09f7 commit db9a401
Show file tree
Hide file tree
Showing 31 changed files with 8,938 additions and 592 deletions.
10 changes: 9 additions & 1 deletion categories.js
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
module.exports = require('./meta/categories.json')
import fs from 'fs'
import path from 'path'
import { _dirname } from './lib/dirname.js'

const categories = JSON.parse(
fs.readFileSync(path.join(_dirname(import.meta), './meta/categories.json'))
)

export default categories
2 changes: 1 addition & 1 deletion lib/app-categories.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = [
export default [
'Books',
'Business',
'Catalogs',
Expand Down
6 changes: 3 additions & 3 deletions lib/apps-with-github-repos.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const apps = require('./raw-app-list')()
const parseGitUrl = require('github-url-to-object')
import apps from './raw-app-list.js'
import parseGitUrl from 'github-url-to-object'

module.exports = apps.filter((app) => {
export default apps.filter((app) => {
// inherit repository from website if possible
if (!app.repository && parseGitUrl(app.website)) app.repository = app.website
if (!app.repository) return false
Expand Down
19 changes: 10 additions & 9 deletions lib/broken-links.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
const fetch = require('node-fetch')
const fsPromises = require('fs').promises
const isUrl = require('is-url')
const path = require('path')
const readdirp = require('readdirp')
const yaml = require('yaml')
import fetch from 'node-fetch'
import fs from 'fs'
import isUrl from 'is-url'
import path from 'path'
import readdirp from 'readdirp'
import yaml from 'yaml'
import { _dirname } from './dirname.js'

const topDir = path.dirname(__dirname)
const topDir = path.dirname(_dirname(import.meta))

// walk an object subtree looking for URL strings
const getObjectUrls = (root) => {
Expand Down Expand Up @@ -36,7 +37,7 @@ const scrape = (url) =>
// report broken links to console.log().
// return a Promise that resolves as an array of broken links: [ { url, err }, ... ]
const processYmlEntry = (entry) =>
fsPromises
fs
.readFile(entry.fullPath, { encoding: 'utf8' })
.then((file) => {
try {
Expand Down Expand Up @@ -90,4 +91,4 @@ const findBrokenLinks = (start = 0, end = Infinity) =>
})
.then((arr) => arr.filter((inner) => !!inner.result.length))

module.exports = findBrokenLinks
export default findBrokenLinks
24 changes: 12 additions & 12 deletions lib/colors.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
'use strict'

const fs = require('fs')
const colorConvert = require('color-convert')
const getImageColors = require('get-image-colors')
const mime = require('mime-types')
const path = require('path')
const pickAGoodColor = require('pick-a-good-color')
const revHash = require('rev-hash')
const stringify = require('json-stable-stringify')
import fs from 'fs'
import colorConvert from 'color-convert'
import getImageColors from 'get-image-colors'
import mime from 'mime-types'
import path from 'path'
import pickAGoodColor from 'pick-a-good-color'
import revHash from 'rev-hash'
import stringify from 'json-stable-stringify'

/**
* Generates good colors for an image.
Expand Down Expand Up @@ -69,10 +69,10 @@ async function getColors(slugsAndIconPaths, oldColors, root) {
* @param colorsFile: the file that keeps the list of complimentary colors
* @param root: repo toplevel directory so that saved iconPaths are relative to it
*/
const rebuildColorFile = (slugsAndIconPaths, colorsFile, root) => {
const rebuildColorFile = async (slugsAndIconPaths, colorsFile, root) => {
let oldColors
try {
oldColors = require(colorsFile)
oldColors = await import(colorsFile)
} catch (e) {
oldColors = {}
}
Expand All @@ -86,5 +86,5 @@ const rebuildColorFile = (slugsAndIconPaths, colorsFile, root) => {
})
}

module.exports = rebuildColorFile
module.exports.getColors = getColors
export default rebuildColorFile
export { getColors }
6 changes: 6 additions & 0 deletions lib/dirname.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { fileURLToPath } from 'url'
import { dirname } from 'path'

export const _dirname = (importMeta) => dirname(_filename(importMeta))
export const _filename = (importMeta) =>
importMeta.url ? fileURLToPath(importMeta.url) : ''
6 changes: 3 additions & 3 deletions lib/github.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
if (!process.env.GH_TOKEN) {
require('dotenv-safe').config()
await import('dotenv-safe/config.js')
}

const { Octokit } = require('@octokit/rest')
import { Octokit } from '@octokit/rest'
const github = new Octokit({
auth: process.env.GH_TOKEN,
})

module.exports = github
export default github
2 changes: 1 addition & 1 deletion lib/grandfathered-descriptions.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Apps in this list were submitted before tests were added
// to enforce the submission guidelines for descriptions
module.exports = [
export default [
'1clipboard',
'5eclient',
'aalarm',
Expand Down
2 changes: 1 addition & 1 deletion lib/grandfathered-links.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Apps in this list were submitted before tests were added
// to enforce the submission guidelines for links
module.exports = [
export default [
'1clipboard',
'autobeat-player',
'backlog',
Expand Down
2 changes: 1 addition & 1 deletion lib/grandfathered-small-icons.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Apps in this list were submitted before we bumped the minimum
// icon dimension from 128 to 256.

module.exports = [
export default [
'airtame',
'aiting',
'ansel',
Expand Down
19 changes: 10 additions & 9 deletions lib/old-electron-apps.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
const fetch = require('node-fetch')
const fsPromises = require('fs').promises
const isUrl = require('is-url')
const path = require('path')
const readdirp = require('readdirp')
const yaml = require('yaml')
import fetch from 'node-fetch'
import fs from 'fs'
import isUrl from 'is-url'
import path from 'path'
import readdirp from 'readdirp'
import yaml from 'yaml'
import { _dirname } from './dirname.js'

const topDir = path.dirname(__dirname)
const topDir = path.dirname(_dirname(import.meta))

// walk an object subtree looking for URL strings
const getObjectUrls = (root) => {
Expand Down Expand Up @@ -52,7 +53,7 @@ const scrape = (url) => {
// report broken links to console.log().
// return a Promise that resolves as an array of broken links: [ { url, err }, ... ]
const processYmlEntry = (entry) =>
fsPromises
fs
.readFile(entry.fullPath, { encoding: 'utf8' })
.then((file) => {
try {
Expand Down Expand Up @@ -96,4 +97,4 @@ const findOldElectronApps = (start = 0, end = Infinity) =>
return result
})

module.exports = findOldElectronApps
export default findOldElectronApps
58 changes: 31 additions & 27 deletions lib/raw-app-list.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,34 @@
const fs = require('fs')
const path = require('path')
const yaml = require('js-yaml')
import fs from 'fs'
import yaml from 'js-yaml'
import path from 'path'
import { _dirname } from './dirname.js'

module.exports = function getSlugs() {
return fs
.readdirSync(path.join(__dirname, '../apps'))
.filter((filename) => {
return fs
.statSync(path.join(__dirname, `../apps/${filename}`))
.isDirectory()
})
.sort()
.reduce((slugs, slug) => {
const yamlFile = path.join(__dirname, `../apps/${slug}/${slug}.yml`)
const meta = yaml.load(fs.readFileSync(yamlFile))
export default fs
.readdirSync(path.join(_dirname(import.meta), '../apps'))
.filter((filename) => {
return fs
.statSync(path.join(_dirname(import.meta), `../apps/${filename}`))
.isDirectory()
})
.sort()
.reduce((slugs, slug) => {
const yamlFile = path.join(
_dirname(import.meta),
`../apps/${slug}/${slug}.yml`
)
const meta = yaml.load(fs.readFileSync(yamlFile))

if (meta.disabled) {
return slugs
} else {
const app = {
slug: slug,
iconPath: path.join(__dirname, `../apps/${slug}/${slug}-icon.png`),
...meta
}
return [...slugs, app]
if (meta.disabled) {
return slugs
} else {
const app = {
slug: slug,
iconPath: path.join(
_dirname(import.meta),
`../apps/${slug}/${slug}-icon.png`
),
...meta,
}

}, [])
}
return [...slugs, app]
}
}, [])
Loading

0 comments on commit db9a401

Please sign in to comment.