-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
deps: use new cds build API @sap/cds-dk >= 7.5.0 (#508)
- Loading branch information
1 parent
820f971
commit ef22ebe
Showing
3 changed files
with
42 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,48 @@ | ||
const cds = require('@sap/cds') | ||
const { fs, path } = cds.utils | ||
|
||
if (!cds.env.fiori.lean_draft) { | ||
throw new Error('"@cap-js/postgres" only works if cds.fiori.lean_draft is enabled. Please adapt your configuration.') | ||
} | ||
|
||
// requires @sap/cds-dk version >= 7.3.2 | ||
cds.build?.register?.('postgres', { | ||
impl: '@cap-js/postgres/lib/build.js', | ||
taskDefaults: { src: cds.env.folders.db } | ||
// requires @sap/cds-dk version >= 7.5.0 | ||
cds.build?.register?.('postgres', class PostgresBuildPlugin extends cds.build.Plugin { | ||
|
||
static taskDefaults = { src: cds.env.folders.db } | ||
|
||
static hasTask() { return cds.requires.db?.kind === 'postgres' } | ||
|
||
init() { | ||
// different from the default build output structure | ||
this.task.dest = path.join(cds.root, cds.env.build.target !== '.' ? cds.env.build.target : 'gen', 'pg') | ||
} | ||
|
||
async build() { | ||
const model = await this.model() | ||
if (!model) return | ||
|
||
const promises = [] | ||
if (fs.existsSync(path.join(this.task.src, 'package.json'))) { | ||
promises.push(this.copy(path.join(this.task.src, 'package.json')).to('package.json')) | ||
} else { | ||
promises.push( | ||
this.write({ | ||
dependencies: { '@sap/cds': '^7', '@cap-js/postgres': '^1' }, | ||
scripts: { start: 'cds-deploy' }, | ||
}).to('package.json'), | ||
) | ||
} | ||
promises.push(this.write(cds.compile.to.json(model)).to(path.join('db', 'csn.json'))) | ||
|
||
let data | ||
if (fs.existsSync(path.join(this.task.src, 'data'))) { | ||
data = 'data' | ||
} else if (fs.existsSync(path.join(this.task.src, 'csv'))) { | ||
data = 'csv' | ||
} | ||
if (data) { | ||
promises.push(this.copy(data).to(path.join('db', 'data'))) | ||
} | ||
return Promise.all(promises) | ||
} | ||
}) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters