Merge branch 'master' of github.com:datopian/portal.js into feature/i18n-next10

This commit is contained in:
steveoni 2020-12-03 12:43:22 +01:00
commit 65f4200bd5
22 changed files with 16619 additions and 55 deletions

View File

@ -2,16 +2,16 @@ name: Cypress Integration Tests
on: [push]
jobs:
cypress-run:
runs-on: ubuntu-latest
runs-on: ubuntu-16.04
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Cypress run
uses: cypress-io/github-action@v1
uses: cypress-io/github-action@v2
with:
working-directory: packages/portal
browser: chrome
build: yarn run build
start: yarn start
wait-on: 'http://localhost:3000'
wait-on: "http://localhost:3000"

View File

@ -3,5 +3,8 @@
"private": true,
"devDependencies": {
"lerna": "^3.22.1"
}
},
"workspaces":[
"packages/**"
]
}

1
packages/create-portal-app/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
node_modules

View File

@ -0,0 +1,7 @@
{
"trailingComma": "es5",
"tabWidth": 2,
"semi": false,
"singleQuote": true,
"printWidth": 79
}

View File

@ -0,0 +1,36 @@
# Create Portal App
<br/>
<img src="resources/create-portal-app.gif">
<br/>
<br/>
This is a friendly way to start using `portal.js`. Using this CLI helps you to set up fast and easly one portal.js with the default template.
The CLI automatically create the project folder, install main dependencies, generate a new git repository and change package name.
<br/>
## Requirements
- Yarn (> 1.22.10) or Npm (> 6.14.5)
- Git
<br/>
## How to use
To create a new portal.js application you can send the project name as first argument.
```
create-portal-app my-app
```
<br/>
## Options
`create-portal-app` comes with options:
- **--use-npm** - This option allows to use npm instead yarn as default package manager

View File

@ -0,0 +1,23 @@
const path = require('path')
const fs = require('fs')
const spawn = require('cross-spawn')
function parserPath(projectPath) {
return [process.cwd(), projectPath].join(path.sep)
}
function copy(root, destination) {
const destinationPath = parserPath(destination)
return spawn.sync('cp', ['-r', root, destinationPath])
}
function isPathInUse(projectPath) {
const fullPath = parserPath(projectPath)
const isPathExists = fs.existsSync(fullPath)
if (isPathExists) {
return fs.readdirSync(fullPath).length
}
return isPathExists
}
module.exports = { parserPath, copy, isPathInUse }

View File

@ -0,0 +1,52 @@
const spawn = require('cross-spawn')
const path = require('path')
const execSync = require('child_process').execSync
const semver = require('semver')
/**
*
* @param {String} projectName Project name to be created
* @param {Boolean} isYarn Check if will be installed under yarn or NPM
*/
function install(projectName, isYarn) {
return new Promise((resolve, reject) => {
const appPath = [process.cwd(), projectName].join(path.sep)
//change the directory to the app directory
process.chdir(appPath)
const command = isYarn ? 'yarn' : 'npm'
const args = isYarn ? [''] : ['install']
const exec = spawn(command, args, {
stdio: 'pipe',
env: { ...process.env, ADBLOCK: '1', DISABLE_OPENCOLLECTIVE: '1' },
})
exec.on('close', (code) => {
if (code !== 0) {
reject({ command: `${command} ${args[0]}` })
return
}
resolve()
})
})
}
/**
* Method to initialize git repo on the new project
*/
async function initGit() {
spawn(`git`, [`init`, `-q`])
}
/**
* Check the version for npm and Yarn
* @param {String} pname
* @returns Boolean
*/
function checkPackageVersion(pname) {
let userVersion = execSync(`${pname} --version`).toString()
let expectedVersion = pname === 'yarn' ? '1.22.10' : '6.14.5'
return !semver.lt(userVersion, expectedVersion)
}
module.exports = { install, initGit, checkPackageVersion }

View File

@ -0,0 +1,18 @@
const fs = require('fs')
const { parserPath } = require('./copy')
function _replacePackage(projectName) {
const appPath = parserPath(projectName)
const packagePath = `${appPath}/package.json`
const data = JSON.parse(fs.readFileSync(packagePath, 'utf8'))
data.name = projectName
delete data.homepage
fs.writeFileSync(packagePath, JSON.stringify(data, null, 2))
}
function replaceContent(projectName) {
_replacePackage(projectName)
}
module.exports = replaceContent

View File

@ -0,0 +1,163 @@
#!/usr/bin/env node
const Listr = require('listr')
const { program } = require('commander')
const chalk = require('chalk')
const prompts = require('prompts')
const path = require('path')
const figlet = require('figlet')
const package = require('./package.json')
const { copy, isPathInUse } = require('./helpers/copy')
const { install, initGit, checkPackageVersion } = require('./helpers/install')
const replace = require('./helpers/replace')
// Output path to create new portal app
let projectPath = ''
// Commander parameters to specify CLI behavior
program
.name(package.name)
.version(package.version)
.arguments('[dir]')
.usage(`${chalk.yellow('[dir]')}`)
.description({
dir: 'Directory to be used on install Portal.js',
})
.action((name) => (projectPath = name))
.option('--use-npm', 'Install dependencies using npm instead yarn')
.parse(process.argv)
/**
* Method to ask a custon name if was not passed as parameter
* returns the value passed from terminal input
*/
async function promptPath() {
return prompts({
type: 'text',
name: 'path',
message: 'Choose a name to your project',
initial: '',
validate: (name) => {
projectPath = name
if (isPathInUse(projectPath)) {
return `${chalk.yellow(
'Path ' +
chalk.redBright(projectPath) +
' is already in use and is not empty.'
)}`
}
return true
},
})
}
/**
* Main method to start CLI and validate inputs
*/
async function run() {
if(checkPackageVersion(program.useNpm? 'npm' : 'yarn')) {
console.log()
console.log(`${chalk.yellowBright('Your package manager version is outdated, please update before continue.')}`)
console.log()
return
}
if (typeof projectPath === 'string') {
projectPath = projectPath.trim()
}
if (!projectPath) {
const response = await promptPath()
if (typeof response.path === 'string') {
projectPath = response.path.trim()
}
}
if (!projectPath) {
//TODO separate log methods
console.log()
console.log('Please choose a name to your project:')
console.log()
console.log('Example:')
console.log(
`${chalk.cyan(program.name())} ${chalk.yellow('ny-portal-app')}`
)
console.log()
process.exit(1)
}
const root = path.join(__dirname + '/../portal')
if (isPathInUse(projectPath)) {
console.log()
console.log(
`${chalk.yellow(
'Path ' +
chalk.redBright(projectPath) +
' is already in use and is not empty.'
)}`
)
console.log()
process.exit(1)
}
// print a fancy Portal.js in the terminal
console.log(
chalk.yellow(figlet.textSync('Portal.Js', { horizontalLayout: 'full' }))
)
console.log()
console.log(`Creating new portal.js app in ${chalk.cyan(projectPath)}`)
console.log()
//Tasks workflow
const tasks = new Listr([
{
title: 'Fetching Content',
task: () => copy(root, projectPath),
},
{
title: 'Updating Content',
task: () => replace(projectPath),
},
{
title: 'Installing Dependencies',
task: () => install(projectPath, program.useNpm),
},
{
title: 'Git Init',
task: () => initGit(projectPath),
},
])
tasks.run().then(() => {
console.log()
console.log(`${chalk.greenBright('Instalation Completed Successfully')}`)
console.log()
console.log(
`Run ${chalk.cyan('cd ' + projectPath)} and ${chalk.green(program.useNpm ? 'npm run dev' : 'yarn dev')}`
)
console.log()
console.log('Enjoy =)')
})
}
//Main CLI execution workflow
run().catch((error) => {
console.log(error.name)
if (error.install) {
console.log()
console.log(
`${chalk.redBright('Error on Create App :')}${chalk.yellow(
error.message.toString()
)}`
)
} else {
console.log(`${chalk.red('Unexpected Error. Please report it as a bug')}`)
console.log(error)
}
console.log()
process.exit(1)
})

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,27 @@
{
"name": "create-portal-app",
"version": "1.0.0",
"description": "Create Portal App CLI",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"chalk": "^4.1.0",
"commander": "^6.2.0",
"cpy": "^8.1.1",
"cross-spawn": "^7.0.3",
"figlet": "^1.5.0",
"listr": "^0.14.3",
"ora": "^5.1.0",
"prompts": "^2.4.0"
},
"files": [
"bin"
],
"bin": {
"create-portal-app": "index.js"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

View File

@ -0,0 +1,14 @@
{
"name": "Datahub",
"version": "1.0.0",
"description": "Create Portal App CLI",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"chalk": "^4.1.0"
}
}

2
packages/portal/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
node_modules/
.next/

View File

@ -1,7 +1,9 @@
<h1 style="text-align: center;">
PORTAL.js
The javascript framework for<br/>
data portals
<h1 align="center">
🌀 Portal.JS<br/>
The javascript framework for<br/>
data portals
</h1>
🌀 `Portal` is a framework for rapidly building rich data portal frontends using a modern frontend approach (javascript, React, SSR).

View File

@ -11,12 +11,12 @@ describe('Test Home Page', () => {
cy.get('form').contains('Search');
});
it('submits the search form', () => {
cy.get('form').find('[type="text"]').type('my-dataset');
cy.get('form').submit();
cy.url().should('include', '/search?q=my-dataset&sort=');
cy.get('.text-3xl').and('contain.text', 'results found');
});
// it('submits the search form', () => {
// cy.get('form').find('[type="text"]').type('gdp');
// cy.get('form').submit();
// cy.url().should('include', '/search?q=gdp&sort=');
// cy.get('.text-3xl').and('contain.text', '1 results found');
// });
it('shows the recent datasets', () => {
cy.contains('Recent Datasets');

View File

@ -8,11 +8,14 @@ describe('Test Search Page', () => {
cy.contains('Search');
});
it('should return a search result', () => {
cy.get('form').find('[type="text"]').type('world population');
cy.get('form').submit();
cy.url().should('include', 'search?q=world%20population&sort=');
cy.get('.text-3xl').should('have.text', '1 results found');
cy.get('.text-xl > .text-primary').should('have.text', 'World Population');
});
// it('should return a search result', () => {
// cy.get('form').find('[type="text"]').type('gdp');
// cy.get('form').submit();
// cy.url().should('include', 'search?q=gdp&sort=');
// cy.get('.text-3xl').should('have.text', '1 results found');
// cy.get('.text-xl > .text-primary').should(
// 'have.text',
// 'Country, Regional and World GDP (Gross Domestic Product)'
// );
// });
});

View File

@ -38,14 +38,10 @@ export const GET_RESOURCES_QUERY = gql`
name
resources {
name
id
title
description
format
size
created
last_modified
url
}
}
}

View File

@ -3509,7 +3509,7 @@ byte-size@^5.0.1:
resolved "https://registry.yarnpkg.com/byte-size/-/byte-size-5.0.1.tgz#4b651039a5ecd96767e71a3d7ed380e48bed4191"
integrity sha512-/XuKeqWocKsYa/cBY1YbSJSWWqTi4cFgr9S6OyM7PBaPbr9zvNGwWP33vt0uqGhwDdN+y3yhbXVILEUpnwEWGw==
bytes@3.1.0, bytes@^3.0.0, bytes@^3.1.0:
bytes@^3.0.0, bytes@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/bytes/-/bytes-3.1.0.tgz#f6cf7933a360e0588fa9fde85651cdc7f805d1f6"
integrity sha512-zauLjrfCG+xvoyaqLoV8bLVXXNGC4JqlxFCutSDWA6fJrTo2ZuvLYTqZ7aHBLZSMOopbzwv8f+wZcVzfVTI2Dg==
@ -3782,21 +3782,6 @@ chokidar@^3.3.0:
optionalDependencies:
fsevents "~2.1.2"
chokidar@^3.4.1:
version "3.4.2"
resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-3.4.2.tgz#38dc8e658dec3809741eb3ef7bb0a47fe424232d"
integrity sha512-IZHaDeBeI+sZJRX7lGcXsdzgvZqKv6sECqsbErJA4mHWfpRrD8B97kSFN4cQz6nGBGiuFia1MKR4d6c1o8Cv7A==
dependencies:
anymatch "~3.1.1"
braces "~3.0.2"
glob-parent "~5.1.0"
is-binary-path "~2.1.0"
is-glob "~4.0.1"
normalize-path "~3.0.0"
readdirp "~3.4.0"
optionalDependencies:
fsevents "~2.1.2"
chownr@^1.1.1, chownr@^1.1.2:
version "1.1.4"
resolved "https://registry.yarnpkg.com/chownr/-/chownr-1.1.4.tgz#6fc9d7b42d32a583596337666e7d08084da2cc6b"
@ -4632,6 +4617,13 @@ debug@^2.2.0, debug@^2.3.3, debug@^2.6.9:
dependencies:
ms "2.0.0"
debug@^2.2.0, debug@^2.3.3, debug@^2.6.9:
version "2.6.9"
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f"
integrity sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==
dependencies:
ms "2.0.0"
debug@^3.1.0:
version "3.2.6"
resolved "https://registry.yarnpkg.com/debug/-/debug-3.2.6.tgz#e83d17de16d8a7efb7717edbe5fb10135eee629b"
@ -5066,15 +5058,6 @@ end-of-stream@^1.0.0, end-of-stream@^1.1.0, end-of-stream@^1.4.1:
dependencies:
once "^1.4.0"
enhanced-resolve@^4.3.0:
version "4.3.0"
resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-4.3.0.tgz#3b806f3bfafc1ec7de69551ef93cca46c1704126"
integrity sha512-3e87LvavsdxyoCfGusJnrZ5G8SLPOFeHSNpZI/ATL9a5leXo2k0w6MKnbqhdBad9qTobSfB20Ld7UmgoNbAZkQ==
dependencies:
graceful-fs "^4.1.2"
memory-fs "^0.5.0"
tapable "^1.0.0"
enquirer@^2.3.5:
version "2.3.5"
resolved "https://registry.yarnpkg.com/enquirer/-/enquirer-2.3.5.tgz#3ab2b838df0a9d8ab9e7dff235b0e8712ef92381"
@ -11104,11 +11087,6 @@ setimmediate@^1.0.4:
resolved "https://registry.yarnpkg.com/setimmediate/-/setimmediate-1.0.5.tgz#290cbb232e306942d7d7ea9b83732ab7856f8285"
integrity sha1-KQy7Iy4waULX1+qbg3Mqt4VvgoU=
setprototypeof@1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/setprototypeof/-/setprototypeof-1.1.1.tgz#7e95acb24aa92f5885e0abef5ba131330d4ae683"
integrity sha512-JvdAWfbXeIGaZ9cILp38HntZSFSo3mWg6xGcJJsd+d4aRMOqauag1C63dJfDw7OaMYwEbHMOxEZ1lqVRYP2OAw==
setprototypeof@1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/setprototypeof/-/setprototypeof-1.2.0.tgz#66c9a24a73f9fc28cbe66b09fed3d33dcaf1b424"

14268
yarn.lock Normal file

File diff suppressed because it is too large Load Diff