Skip to content

Commit

Permalink
feat: publish shell and adapter, fix dependency resolution (#221)
Browse files Browse the repository at this point in the history
* feat: publish shell and adapter to npm, use app-level dep resolution

* chore: remove console.log

* fix: don't install shell dependencies in cache directory

* chore: force shell overwrite in example

* chore: update example yarn.lock

* fix: link node_modules from copied shell directory
  • Loading branch information
amcgee authored Jan 3, 2020
1 parent 3c07a48 commit dd1c51a
Show file tree
Hide file tree
Showing 25 changed files with 17,475 additions and 11,329 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
22 changes: 15 additions & 7 deletions shell/adapter/package.json → adapter/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
{
"name": "@dhis2/app-adapter",
"version": "1.0.0",
"private": true,
"version": "3.0.2",
"repository": {
"type": "git",
"url": "https://github.com/amcgee/dhis2-app-platform",
"directory": "adapter"
},
"author": "Austin McGee <[email protected]>",
"license": "BSD-3-Clause",
"publishConfig": {
"access": "public"
},
"main": "build/cjs/lib.js",
"module": "build/es/lib.js",
"files": [
Expand All @@ -11,9 +20,11 @@
"@dhis2/ui-widgets": "^2.0.4",
"moment": "^2.24.0"
},
"devDependencies": {},
"devDependencies": {
"@dhis2/cli-app-scripts": "3.0.0"
},
"scripts": {
"build": "../../cli/bin/d2-app-scripts build"
"build": "d2-app-scripts build"
},
"peerDependencies": {
"@dhis2/app-runtime": "^2.0.4",
Expand All @@ -25,8 +36,5 @@
"react": "^16.8.6",
"react-dom": "^16.8.6",
"styled-jsx": "^3.2.1"
},
"installConfig": {
"pnp": true
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion cli/config/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const visualize = require('rollup-plugin-visualizer')

const { reporter, chalk } = require('@dhis2/cli-helpers-engine')

const standardLibs = require('./standard-libs.json')
const standardLibs = require('@dhis2/app-shell/package.json').dependencies

// Exclude local app-shell dependencies
Object.entries(standardLibs).forEach(([dep, version]) => {
Expand Down
11 changes: 0 additions & 11 deletions cli/config/standard-libs.json

This file was deleted.

34 changes: 8 additions & 26 deletions cli/package.json
Original file line number Diff line number Diff line change
@@ -1,35 +1,34 @@
{
"name": "@dhis2/cli-app-scripts",
"version": "3.0.2",
"main": "src/index.js",
"repository": "https://github.com/amcgee/dhis2-app-platform",
"repository": {
"type": "git",
"url": "https://github.com/amcgee/dhis2-app-platform",
"directory": "cli"
},
"author": "Austin McGee <[email protected]>",
"license": "BSD-3-Clause",
"publishConfig": {
"access": "public"
},
"main": "src/index.js",
"files": [
"assets",
"bin",
"config",
"src"
],
"//": "****** Includes standard libraries from app-shell, so that tests work ******",
"dependencies": {
"@babel/core": "^7.6.2",
"@babel/plugin-proposal-class-properties": "^7.4.4",
"@babel/plugin-proposal-object-rest-spread": "^7.4.4",
"@babel/preset-env": "^7.6.2",
"@babel/preset-react": "^7.0.0",
"@babel/preset-typescript": "^7.6.0",
"@dhis2/app-runtime": "^2.0.4",
"@dhis2/app-shell": "3.0.2",
"@dhis2/cli-helpers-engine": "^1.5.0",
"@dhis2/d2-i18n": "^1.0.5",
"@dhis2/ui-core": "^4.1.1",
"archiver": "^3.1.1",
"babel-jest": "^24.9.0",
"chokidar": "^3.3.0",
"classnames": "^2.2.6",
"detect-port": "^1.3.0",
"dotenv": "^8.1.0",
"dotenv-expand": "^5.1.0",
Expand All @@ -40,35 +39,18 @@
"i18next-scanner": "^2.10.3",
"jest-cli": "^24.9.0",
"lodash": "^4.17.11",
"moment": "^2.24.0",
"parse-author": "^2.0.0",
"parse-gitignore": "^1.0.1",
"prop-types": "^15.7.2",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"rollup": "^1.21.4",
"rollup-plugin-babel": "^4.3.2",
"rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-json": "^4.0.0",
"rollup-plugin-node-resolve": "^5.0.1",
"rollup-plugin-postcss": "^2.0.3",
"rollup-plugin-replace": "^2.2.0",
"rollup-plugin-visualizer": "^3.2.2",
"styled-jsx": "^3.2.2"
"rollup-plugin-visualizer": "^3.2.2"
},
"bin": {
"d2-app-scripts": "./bin/d2-app-scripts"
},
"scripts": {
"assets:prep": "rimraf assets && mkdirp assets",
"assets:copy": "copyfiles ../shell/* \"../shell/**/*\" assets/shell --all --exclude \"../shell/**/node_modules/**\" --exclude \"../shell/**/.pnp/**\" --exclude \"../shell/**/.pnp.js\"",
"assets:clean": "cd assets/shell && rimraf node_modules .pnp.js .pnp adapter/node_modules adapter/.pnp.js adapter/.pnp",
"build": "yarn assets:prep && yarn assets:copy",
"prepublishOnly": "yarn build"
},
"devDependencies": {
"copyfiles": "^2.1.1",
"mkdirp": "^0.5.1",
"rimraf": "^3.0.0"
}
}
12 changes: 6 additions & 6 deletions cli/src/lib/paths.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
const path = require('path')
const { reporter } = require('@dhis2/cli-helpers-engine')

const shellSource = path.dirname(
require.resolve('@dhis2/app-shell/package.json')
)
const shellAppDirname = 'src/D2App'

module.exports = (cwd = process.cwd()) => {
Expand All @@ -17,12 +20,9 @@ module.exports = (cwd = process.cwd()) => {
),
jestConfigDefaults: path.join(__dirname, '../../config/jest.config.js'),

shellSource: path.join(__dirname, '../../assets/shell'),
shellSourceEntrypoint: path.join(
__dirname,
'../../assets/shell/src/App.js'
),
shellSourcePublic: path.join(__dirname, '../../assets/shell/public'),
shellSource,
shellSourceEntrypoint: path.join(shellSource, 'src/App.js'),
shellSourcePublic: path.join(shellSource, 'public'),

base,
package: path.join(base, './package.json'),
Expand Down
77 changes: 40 additions & 37 deletions cli/src/lib/shell/bootstrap.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
const fs = require('fs-extra')
const path = require('path')
const { reporter, chalk, exec } = require('@dhis2/cli-helpers-engine')
const { reporter, chalk } = require('@dhis2/cli-helpers-engine')

const scriptsVersion = require(path.join(__dirname, '../../../package.json'))
.version
const currentShellVersion = require('@dhis2/app-shell/package.json').version

const getShellVersion = metaFile => {
if (fs.existsSync(metaFile)) {
const getShellVersion = shellDir => {
const shellPkg = path.join(shellDir, 'package.json')
if (fs.existsSync(shellPkg)) {
try {
const meta = require(metaFile)
return meta.version
const pkg = require(shellPkg)
return pkg.version
} catch (e) {
reporter.debug('Failed to load meta file', e)
reporter.debug('Failed to load shell package.json file', e)
// ignore
}
}
Expand All @@ -20,31 +20,34 @@ const getShellVersion = metaFile => {

const bootstrapShell = async (paths, { shell, force = false } = {}) => {
const source = shell ? path.resolve(shell) : paths.shellSource,
dest = paths.shell,
metaFile = path.join(paths.d2, 'meta.json')
dest = paths.shell

if (fs.pathExistsSync(dest)) {
const versionMismatch = getShellVersion(metaFile) !== scriptsVersion
if (versionMismatch) {
reporter.print(
chalk.dim(
chalk.yellow(
'Local shell version does not match scripts version'
if (!shell) {
const versionMismatch =
getShellVersion(dest) !== currentShellVersion
if (versionMismatch) {
reporter.print(
chalk.dim(
chalk.yellow(
'Local shell version does not match scripts version'
)
)
)
)
}
}

if (!shell && !force && !versionMismatch) {
reporter.print(
chalk.dim(
`A local appShell exists, skipping bootstrap. ${chalk.bold(
'Use --force to update.'
)}`
if (!force && !versionMismatch) {
reporter.print(
chalk.dim(
`A local appShell exists, skipping bootstrap. ${chalk.bold(
'Use --force to update.'
)}`
)
)
)
return dest
return dest
}
}

reporter.print(chalk.dim('Removing existing directory...'))
await fs.remove(dest)
}
Expand All @@ -62,17 +65,17 @@ const bootstrapShell = async (paths, { shell, force = false } = {}) => {
src.indexOf(paths.shellAppDirname) === -1,
})

await fs.writeJSONSync(metaFile, {
version: scriptsVersion,
})

reporter.print(chalk.dim('Installing dependencies...'))

await exec({
cmd: 'yarn',
args: ['install', '--frozen-lockfile', '--prefer-offline'],
cwd: dest,
})
const srcNodeModules = path.join(source, 'node_modules')
const destNodeModules = path.join(dest, 'node_modules')
if (fs.exists(srcNodeModules)) {
reporter.debug(
`Linking ${path.relative(
paths.base,
destNodeModules
)} to ${path.relative(paths.base, srcNodeModules)}...`
)
await fs.ensureSymlink(srcNodeModules, destNodeModules)
}
}

module.exports = bootstrapShell
9 changes: 7 additions & 2 deletions examples/simple-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@
"author": "Austin McGee <[email protected]>",
"license": "BSD-3-Clause",
"private": true,
"dependencies": {},
"devDependencies": {},
"devDependencies": {
"@dhis2/cli-app-scripts": "file:../../cli"
},
"scripts": {
"start": "../../cli/bin/d2-app-scripts start",
"build": "../../cli/bin/d2-app-scripts build",
"test": "../../cli/bin/d2-app-scripts test"
},
"resolutions": {
"@dhis2/app-shell": "file:../../shell",
"@dhis2/app-adapter": "file:../../adapter"
},
"peerDependencies": {
"@dhis2/app-runtime": "*",
"@dhis2/d2-i18n": "*",
Expand Down
Loading

0 comments on commit dd1c51a

Please sign in to comment.